diff options
author | dim <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2013-04-08 18:45:10 +0000 |
commit | c72c57c9e9b69944e3e009cd5e209634839581d3 (patch) | |
tree | 4fc2f184c499d106f29a386c452b49e5197bf63d /lib/Lex/MacroInfo.cpp | |
parent | 5b20025c30d23d521e12c1f33ec8fa6b821952cd (diff) | |
download | FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.zip FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.tar.gz |
Vendor import of clang trunk r178860:
http://llvm.org/svn/llvm-project/cfe/trunk@178860
Diffstat (limited to 'lib/Lex/MacroInfo.cpp')
-rw-r--r-- | lib/Lex/MacroInfo.cpp | 119 |
1 files changed, 66 insertions, 53 deletions
diff --git a/lib/Lex/MacroInfo.cpp b/lib/Lex/MacroInfo.cpp index 904f04e..b61ff71 100644 --- a/lib/Lex/MacroInfo.cpp +++ b/lib/Lex/MacroInfo.cpp @@ -17,7 +17,6 @@ using namespace clang; MacroInfo::MacroInfo(SourceLocation DefLoc) : Location(DefLoc), - PreviousDefinition(0), ArgumentList(0), NumArguments(0), IsDefinitionLengthCached(false), @@ -25,53 +24,12 @@ MacroInfo::MacroInfo(SourceLocation DefLoc) IsC99Varargs(false), IsGNUVarargs(false), IsBuiltinMacro(false), - IsFromAST(false), - ChangedAfterLoad(false), + HasCommaPasting(false), IsDisabled(false), IsUsed(false), IsAllowRedefinitionsWithoutWarning(false), IsWarnIfUnused(false), - IsPublic(true), - IsHidden(false), - IsAmbiguous(false) { -} - -MacroInfo::MacroInfo(const MacroInfo &MI, llvm::BumpPtrAllocator &PPAllocator) - : Location(MI.Location), - EndLocation(MI.EndLocation), - UndefLocation(MI.UndefLocation), - PreviousDefinition(0), - ArgumentList(0), - NumArguments(0), - ReplacementTokens(MI.ReplacementTokens), - DefinitionLength(MI.DefinitionLength), - IsDefinitionLengthCached(MI.IsDefinitionLengthCached), - IsFunctionLike(MI.IsFunctionLike), - IsC99Varargs(MI.IsC99Varargs), - IsGNUVarargs(MI.IsGNUVarargs), - IsBuiltinMacro(MI.IsBuiltinMacro), - IsFromAST(MI.IsFromAST), - ChangedAfterLoad(MI.ChangedAfterLoad), - IsDisabled(MI.IsDisabled), - IsUsed(MI.IsUsed), - IsAllowRedefinitionsWithoutWarning(MI.IsAllowRedefinitionsWithoutWarning), - IsWarnIfUnused(MI.IsWarnIfUnused), - IsPublic(MI.IsPublic), - IsHidden(MI.IsHidden), - IsAmbiguous(MI.IsAmbiguous) { - setArgumentList(MI.ArgumentList, MI.NumArguments, PPAllocator); -} - -const MacroInfo *MacroInfo::findDefinitionAtLoc(SourceLocation L, - SourceManager &SM) const { - assert(L.isValid() && "SourceLocation is invalid."); - for (const MacroInfo *MI = this; MI; MI = MI->PreviousDefinition) { - if (MI->Location.isInvalid() || // For macros defined on the command line. - SM.isBeforeInTranslationUnit(MI->Location, L)) - return (MI->UndefLocation.isInvalid() || - SM.isBeforeInTranslationUnit(L, MI->UndefLocation)) ? MI : NULL; - } - return NULL; + FromASTFile(false) { } unsigned MacroInfo::getDefinitionLengthSlow(SourceManager &SM) const { @@ -103,11 +61,17 @@ unsigned MacroInfo::getDefinitionLengthSlow(SourceManager &SM) const { return DefinitionLength; } -/// isIdenticalTo - Return true if the specified macro definition is equal to -/// this macro in spelling, arguments, and whitespace. This is used to emit -/// duplicate definition warnings. This implements the rules in C99 6.10.3. +/// \brief Return true if the specified macro definition is equal to +/// this macro in spelling, arguments, and whitespace. /// -bool MacroInfo::isIdenticalTo(const MacroInfo &Other, Preprocessor &PP) const { +/// \param Syntactically if true, the macro definitions can be identical even +/// if they use different identifiers for the function macro parameters. +/// Otherwise the comparison is lexical and this implements the rules in +/// C99 6.10.3. +bool MacroInfo::isIdenticalTo(const MacroInfo &Other, Preprocessor &PP, + bool Syntactically) const { + bool Lexically = !Syntactically; + // Check # tokens in replacement, number of args, and various flags all match. if (ReplacementTokens.size() != Other.ReplacementTokens.size() || getNumArgs() != Other.getNumArgs() || @@ -116,10 +80,12 @@ bool MacroInfo::isIdenticalTo(const MacroInfo &Other, Preprocessor &PP) const { isGNUVarargs() != Other.isGNUVarargs()) return false; - // Check arguments. - for (arg_iterator I = arg_begin(), OI = Other.arg_begin(), E = arg_end(); - I != E; ++I, ++OI) - if (*I != *OI) return false; + if (Lexically) { + // Check arguments. + for (arg_iterator I = arg_begin(), OI = Other.arg_begin(), E = arg_end(); + I != E; ++I, ++OI) + if (*I != *OI) return false; + } // Check all the tokens. for (unsigned i = 0, e = ReplacementTokens.size(); i != e; ++i) { @@ -137,7 +103,16 @@ bool MacroInfo::isIdenticalTo(const MacroInfo &Other, Preprocessor &PP) const { // If this is an identifier, it is easy. if (A.getIdentifierInfo() || B.getIdentifierInfo()) { - if (A.getIdentifierInfo() != B.getIdentifierInfo()) + if (A.getIdentifierInfo() == B.getIdentifierInfo()) + continue; + if (Lexically) + return false; + // With syntactic equivalence the parameter names can be different as long + // as they are used in the same place. + int AArgNum = getArgumentNum(A.getIdentifierInfo()); + if (AArgNum == -1) + return false; + if (AArgNum != Other.getArgumentNum(B.getIdentifierInfo())) return false; continue; } @@ -149,3 +124,41 @@ bool MacroInfo::isIdenticalTo(const MacroInfo &Other, Preprocessor &PP) const { return true; } + +MacroDirective::DefInfo MacroDirective::getDefinition(bool AllowHidden) { + MacroDirective *MD = this; + SourceLocation UndefLoc; + Optional<bool> isPublic; + for (; MD; MD = MD->getPrevious()) { + if (!AllowHidden && MD->isHidden()) + continue; + + if (DefMacroDirective *DefMD = dyn_cast<DefMacroDirective>(MD)) + return DefInfo(DefMD, UndefLoc, + !isPublic.hasValue() || isPublic.getValue()); + + if (UndefMacroDirective *UndefMD = dyn_cast<UndefMacroDirective>(MD)) { + UndefLoc = UndefMD->getLocation(); + continue; + } + + VisibilityMacroDirective *VisMD = cast<VisibilityMacroDirective>(MD); + if (!isPublic.hasValue()) + isPublic = VisMD->isPublic(); + } + + return DefInfo(); +} + +const MacroDirective::DefInfo +MacroDirective::findDirectiveAtLoc(SourceLocation L, SourceManager &SM) const { + assert(L.isValid() && "SourceLocation is invalid."); + for (DefInfo Def = getDefinition(); Def; Def = Def.getPreviousDefinition()) { + if (Def.getLocation().isInvalid() || // For macros defined on the command line. + SM.isBeforeInTranslationUnit(Def.getLocation(), L)) + return (!Def.isUndefined() || + SM.isBeforeInTranslationUnit(L, Def.getUndefLocation())) + ? Def : DefInfo(); + } + return DefInfo(); +} |