mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 17:16:06 +00:00
[clang][NFC] Refactor SourceLocExpr::IdentKind
This patch converts `SourceLocExpr::IdentKind` into a scoped enum at namespace scope, making it eligible to be forward-declared. This is needed by `preferred_type` annotations on bit-fields.
This commit is contained in:
parent
83888a5404
commit
99e7e7a597
@ -4735,6 +4735,16 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
enum class SourceLocIdentKind {
|
||||
Function,
|
||||
FuncSig,
|
||||
File,
|
||||
FileName,
|
||||
Line,
|
||||
Column,
|
||||
SourceLocStruct
|
||||
};
|
||||
|
||||
/// Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(),
|
||||
/// __builtin_FUNCTION(), __builtin_FUNCSIG(), __builtin_FILE(),
|
||||
/// __builtin_FILE_NAME() or __builtin_source_location().
|
||||
@ -4743,19 +4753,9 @@ class SourceLocExpr final : public Expr {
|
||||
DeclContext *ParentContext;
|
||||
|
||||
public:
|
||||
enum IdentKind {
|
||||
Function,
|
||||
FuncSig,
|
||||
File,
|
||||
FileName,
|
||||
Line,
|
||||
Column,
|
||||
SourceLocStruct
|
||||
};
|
||||
|
||||
SourceLocExpr(const ASTContext &Ctx, IdentKind Type, QualType ResultTy,
|
||||
SourceLocation BLoc, SourceLocation RParenLoc,
|
||||
DeclContext *Context);
|
||||
SourceLocExpr(const ASTContext &Ctx, SourceLocIdentKind Type,
|
||||
QualType ResultTy, SourceLocation BLoc,
|
||||
SourceLocation RParenLoc, DeclContext *Context);
|
||||
|
||||
/// Build an empty call expression.
|
||||
explicit SourceLocExpr(EmptyShell Empty) : Expr(SourceLocExprClass, Empty) {}
|
||||
@ -4768,20 +4768,20 @@ public:
|
||||
/// Return a string representing the name of the specific builtin function.
|
||||
StringRef getBuiltinStr() const;
|
||||
|
||||
IdentKind getIdentKind() const {
|
||||
return static_cast<IdentKind>(SourceLocExprBits.Kind);
|
||||
SourceLocIdentKind getIdentKind() const {
|
||||
return static_cast<SourceLocIdentKind>(SourceLocExprBits.Kind);
|
||||
}
|
||||
|
||||
bool isIntType() const {
|
||||
switch (getIdentKind()) {
|
||||
case File:
|
||||
case FileName:
|
||||
case Function:
|
||||
case FuncSig:
|
||||
case SourceLocStruct:
|
||||
case SourceLocIdentKind::File:
|
||||
case SourceLocIdentKind::FileName:
|
||||
case SourceLocIdentKind::Function:
|
||||
case SourceLocIdentKind::FuncSig:
|
||||
case SourceLocIdentKind::SourceLocStruct:
|
||||
return false;
|
||||
case Line:
|
||||
case Column:
|
||||
case SourceLocIdentKind::Line:
|
||||
case SourceLocIdentKind::Column:
|
||||
return true;
|
||||
}
|
||||
llvm_unreachable("unknown source location expression kind");
|
||||
|
@ -6086,14 +6086,13 @@ public:
|
||||
|
||||
// __builtin_LINE(), __builtin_FUNCTION(), __builtin_FUNCSIG(),
|
||||
// __builtin_FILE(), __builtin_COLUMN(), __builtin_source_location()
|
||||
ExprResult ActOnSourceLocExpr(SourceLocExpr::IdentKind Kind,
|
||||
ExprResult ActOnSourceLocExpr(SourceLocIdentKind Kind,
|
||||
SourceLocation BuiltinLoc,
|
||||
SourceLocation RPLoc);
|
||||
|
||||
// Build a potentially resolved SourceLocExpr.
|
||||
ExprResult BuildSourceLocExpr(SourceLocExpr::IdentKind Kind,
|
||||
QualType ResultTy, SourceLocation BuiltinLoc,
|
||||
SourceLocation RPLoc,
|
||||
ExprResult BuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy,
|
||||
SourceLocation BuiltinLoc, SourceLocation RPLoc,
|
||||
DeclContext *ParentContext);
|
||||
|
||||
// __null
|
||||
|
@ -2196,31 +2196,31 @@ bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx,
|
||||
return true;
|
||||
}
|
||||
|
||||
SourceLocExpr::SourceLocExpr(const ASTContext &Ctx, IdentKind Kind,
|
||||
SourceLocExpr::SourceLocExpr(const ASTContext &Ctx, SourceLocIdentKind Kind,
|
||||
QualType ResultTy, SourceLocation BLoc,
|
||||
SourceLocation RParenLoc,
|
||||
DeclContext *ParentContext)
|
||||
: Expr(SourceLocExprClass, ResultTy, VK_PRValue, OK_Ordinary),
|
||||
BuiltinLoc(BLoc), RParenLoc(RParenLoc), ParentContext(ParentContext) {
|
||||
SourceLocExprBits.Kind = Kind;
|
||||
SourceLocExprBits.Kind = llvm::to_underlying(Kind);
|
||||
setDependence(ExprDependence::None);
|
||||
}
|
||||
|
||||
StringRef SourceLocExpr::getBuiltinStr() const {
|
||||
switch (getIdentKind()) {
|
||||
case File:
|
||||
case SourceLocIdentKind::File:
|
||||
return "__builtin_FILE";
|
||||
case FileName:
|
||||
case SourceLocIdentKind::FileName:
|
||||
return "__builtin_FILE_NAME";
|
||||
case Function:
|
||||
case SourceLocIdentKind::Function:
|
||||
return "__builtin_FUNCTION";
|
||||
case FuncSig:
|
||||
case SourceLocIdentKind::FuncSig:
|
||||
return "__builtin_FUNCSIG";
|
||||
case Line:
|
||||
case SourceLocIdentKind::Line:
|
||||
return "__builtin_LINE";
|
||||
case Column:
|
||||
case SourceLocIdentKind::Column:
|
||||
return "__builtin_COLUMN";
|
||||
case SourceLocStruct:
|
||||
case SourceLocIdentKind::SourceLocStruct:
|
||||
return "__builtin_source_location";
|
||||
}
|
||||
llvm_unreachable("unexpected IdentKind!");
|
||||
@ -2255,7 +2255,7 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
|
||||
};
|
||||
|
||||
switch (getIdentKind()) {
|
||||
case SourceLocExpr::FileName: {
|
||||
case SourceLocIdentKind::FileName: {
|
||||
// __builtin_FILE_NAME() is a Clang-specific extension that expands to the
|
||||
// the last part of __builtin_FILE().
|
||||
SmallString<256> FileName;
|
||||
@ -2263,26 +2263,26 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
|
||||
FileName, PLoc, Ctx.getLangOpts(), Ctx.getTargetInfo());
|
||||
return MakeStringLiteral(FileName);
|
||||
}
|
||||
case SourceLocExpr::File: {
|
||||
case SourceLocIdentKind::File: {
|
||||
SmallString<256> Path(PLoc.getFilename());
|
||||
clang::Preprocessor::processPathForFileMacro(Path, Ctx.getLangOpts(),
|
||||
Ctx.getTargetInfo());
|
||||
return MakeStringLiteral(Path);
|
||||
}
|
||||
case SourceLocExpr::Function:
|
||||
case SourceLocExpr::FuncSig: {
|
||||
case SourceLocIdentKind::Function:
|
||||
case SourceLocIdentKind::FuncSig: {
|
||||
const auto *CurDecl = dyn_cast<Decl>(Context);
|
||||
const auto Kind = getIdentKind() == SourceLocExpr::Function
|
||||
const auto Kind = getIdentKind() == SourceLocIdentKind::Function
|
||||
? PredefinedExpr::Function
|
||||
: PredefinedExpr::FuncSig;
|
||||
return MakeStringLiteral(
|
||||
CurDecl ? PredefinedExpr::ComputeName(Kind, CurDecl) : std::string(""));
|
||||
}
|
||||
case SourceLocExpr::Line:
|
||||
case SourceLocIdentKind::Line:
|
||||
return APValue(Ctx.MakeIntValue(PLoc.getLine(), Ctx.UnsignedIntTy));
|
||||
case SourceLocExpr::Column:
|
||||
case SourceLocIdentKind::Column:
|
||||
return APValue(Ctx.MakeIntValue(PLoc.getColumn(), Ctx.UnsignedIntTy));
|
||||
case SourceLocExpr::SourceLocStruct: {
|
||||
case SourceLocIdentKind::SourceLocStruct: {
|
||||
// Fill in a std::source_location::__impl structure, by creating an
|
||||
// artificial file-scoped CompoundLiteralExpr, and returning a pointer to
|
||||
// that.
|
||||
|
@ -2820,22 +2820,22 @@ ExprResult Parser::ParseBuiltinPrimaryExpression() {
|
||||
SkipUntil(tok::r_paren, StopAtSemi);
|
||||
return ExprError();
|
||||
}
|
||||
SourceLocExpr::IdentKind Kind = [&] {
|
||||
SourceLocIdentKind Kind = [&] {
|
||||
switch (T) {
|
||||
case tok::kw___builtin_FILE:
|
||||
return SourceLocExpr::File;
|
||||
return SourceLocIdentKind::File;
|
||||
case tok::kw___builtin_FILE_NAME:
|
||||
return SourceLocExpr::FileName;
|
||||
return SourceLocIdentKind::FileName;
|
||||
case tok::kw___builtin_FUNCTION:
|
||||
return SourceLocExpr::Function;
|
||||
return SourceLocIdentKind::Function;
|
||||
case tok::kw___builtin_FUNCSIG:
|
||||
return SourceLocExpr::FuncSig;
|
||||
return SourceLocIdentKind::FuncSig;
|
||||
case tok::kw___builtin_LINE:
|
||||
return SourceLocExpr::Line;
|
||||
return SourceLocIdentKind::Line;
|
||||
case tok::kw___builtin_COLUMN:
|
||||
return SourceLocExpr::Column;
|
||||
return SourceLocIdentKind::Column;
|
||||
case tok::kw___builtin_source_location:
|
||||
return SourceLocExpr::SourceLocStruct;
|
||||
return SourceLocIdentKind::SourceLocStruct;
|
||||
default:
|
||||
llvm_unreachable("invalid keyword");
|
||||
}
|
||||
|
@ -17542,25 +17542,25 @@ static CXXRecordDecl *LookupStdSourceLocationImpl(Sema &S, SourceLocation Loc) {
|
||||
return ImplDecl;
|
||||
}
|
||||
|
||||
ExprResult Sema::ActOnSourceLocExpr(SourceLocExpr::IdentKind Kind,
|
||||
ExprResult Sema::ActOnSourceLocExpr(SourceLocIdentKind Kind,
|
||||
SourceLocation BuiltinLoc,
|
||||
SourceLocation RPLoc) {
|
||||
QualType ResultTy;
|
||||
switch (Kind) {
|
||||
case SourceLocExpr::File:
|
||||
case SourceLocExpr::FileName:
|
||||
case SourceLocExpr::Function:
|
||||
case SourceLocExpr::FuncSig: {
|
||||
case SourceLocIdentKind::File:
|
||||
case SourceLocIdentKind::FileName:
|
||||
case SourceLocIdentKind::Function:
|
||||
case SourceLocIdentKind::FuncSig: {
|
||||
QualType ArrTy = Context.getStringLiteralArrayType(Context.CharTy, 0);
|
||||
ResultTy =
|
||||
Context.getPointerType(ArrTy->getAsArrayTypeUnsafe()->getElementType());
|
||||
break;
|
||||
}
|
||||
case SourceLocExpr::Line:
|
||||
case SourceLocExpr::Column:
|
||||
case SourceLocIdentKind::Line:
|
||||
case SourceLocIdentKind::Column:
|
||||
ResultTy = Context.UnsignedIntTy;
|
||||
break;
|
||||
case SourceLocExpr::SourceLocStruct:
|
||||
case SourceLocIdentKind::SourceLocStruct:
|
||||
if (!StdSourceLocationImplDecl) {
|
||||
StdSourceLocationImplDecl =
|
||||
LookupStdSourceLocationImpl(*this, BuiltinLoc);
|
||||
@ -17575,8 +17575,7 @@ ExprResult Sema::ActOnSourceLocExpr(SourceLocExpr::IdentKind Kind,
|
||||
return BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc, CurContext);
|
||||
}
|
||||
|
||||
ExprResult Sema::BuildSourceLocExpr(SourceLocExpr::IdentKind Kind,
|
||||
QualType ResultTy,
|
||||
ExprResult Sema::BuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy,
|
||||
SourceLocation BuiltinLoc,
|
||||
SourceLocation RPLoc,
|
||||
DeclContext *ParentContext) {
|
||||
|
@ -3587,8 +3587,8 @@ public:
|
||||
///
|
||||
/// By default, performs semantic analysis to build the new expression.
|
||||
/// Subclasses may override this routine to provide different behavior.
|
||||
ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind,
|
||||
QualType ResultTy, SourceLocation BuiltinLoc,
|
||||
ExprResult RebuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy,
|
||||
SourceLocation BuiltinLoc,
|
||||
SourceLocation RPLoc,
|
||||
DeclContext *ParentContext) {
|
||||
return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
|
||||
@ -12115,7 +12115,7 @@ TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
|
||||
|
||||
template <typename Derived>
|
||||
ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
|
||||
bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function &&
|
||||
bool NeedRebuildFunc = E->getIdentKind() == SourceLocIdentKind::Function &&
|
||||
getSema().CurContext != E->getParentContext();
|
||||
|
||||
if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
|
||||
|
@ -1293,8 +1293,7 @@ void ASTStmtReader::VisitSourceLocExpr(SourceLocExpr *E) {
|
||||
E->ParentContext = readDeclAs<DeclContext>();
|
||||
E->BuiltinLoc = readSourceLocation();
|
||||
E->RParenLoc = readSourceLocation();
|
||||
E->SourceLocExprBits.Kind =
|
||||
static_cast<SourceLocExpr::IdentKind>(Record.readInt());
|
||||
E->SourceLocExprBits.Kind = Record.readInt();
|
||||
}
|
||||
|
||||
void ASTStmtReader::VisitAddrLabelExpr(AddrLabelExpr *E) {
|
||||
|
@ -1165,7 +1165,7 @@ void ASTStmtWriter::VisitSourceLocExpr(SourceLocExpr *E) {
|
||||
Record.AddDeclRef(cast_or_null<Decl>(E->getParentContext()));
|
||||
Record.AddSourceLocation(E->getBeginLoc());
|
||||
Record.AddSourceLocation(E->getEndLoc());
|
||||
Record.push_back(E->getIdentKind());
|
||||
Record.push_back(llvm::to_underlying(E->getIdentKind()));
|
||||
Code = serialization::EXPR_SOURCE_LOC;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user