diff options
Diffstat (limited to 'include/clang/Parse')
-rw-r--r-- | include/clang/Parse/Action.h | 50 | ||||
-rw-r--r-- | include/clang/Parse/DeclSpec.h | 73 | ||||
-rw-r--r-- | include/clang/Parse/Parser.h | 32 |
3 files changed, 102 insertions, 53 deletions
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index fc56cc6..b7540f9 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -334,6 +334,20 @@ public: bool EnteringContext) { return 0; } + + /// IsInvalidUnlessNestedName - This method is used for error recovery + /// purposes to determine whether the specified identifier is only valid as + /// a nested name specifier, for example a namespace name. It is + /// conservatively correct to always return false from this method. + /// + /// The arguments are the same as those passed to ActOnCXXNestedNameSpecifier. + virtual bool IsInvalidUnlessNestedName(Scope *S, + const CXXScopeSpec &SS, + IdentifierInfo &II, + TypeTy *ObjectType, + bool EnteringContext) { + return false; + } /// ActOnCXXNestedNameSpecifier - Called during parsing of a /// nested-name-specifier that involves a template-id, e.g., @@ -351,8 +365,19 @@ public: return 0; } + /// ShouldEnterDeclaratorScope - Called when a C++ scope specifier + /// is parsed as part of a declarator-id to determine whether a scope + /// should be entered. + /// + /// \param S the current scope + /// \param SS the scope being entered + /// \param isFriendDeclaration whether this is a friend declaration + virtual bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) { + return false; + } + /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global - /// scope or nested-name-specifier) is parsed, part of a declarator-id. + /// scope or nested-name-specifier) is parsed as part of a declarator-id. /// After this method is called, according to [C++ 3.4.3p3], names should be /// looked up in the declarator-id's scope, until the declarator is parsed and /// ActOnCXXExitDeclaratorScope is called. @@ -1250,6 +1275,10 @@ public: /// /// \param AS the currently-active access specifier. /// + /// \param HasUsingKeyword true if this was declared with an + /// explicit 'using' keyword (i.e. if this is technically a using + /// declaration, not an access declaration) + /// /// \param UsingLoc the location of the 'using' keyword. /// /// \param SS the nested-name-specifier that precedes the name. @@ -1267,6 +1296,7 @@ public: /// \returns a representation of the using declaration. virtual DeclPtrTy ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, + bool HasUsingKeyword, SourceLocation UsingLoc, const CXXScopeSpec &SS, UnqualifiedId &Name, @@ -2394,6 +2424,24 @@ public: /// \param S the scope in which the operator keyword occurs. virtual void CodeCompleteOperatorName(Scope *S) { } + /// \brief Code completion after the '@' at the top level. + /// + /// \param S the scope in which the '@' occurs. + /// + /// \param ObjCImpDecl the Objective-C implementation or category + /// implementation. + /// + /// \param InInterface whether we are in an Objective-C interface or + /// protocol. + virtual void CodeCompleteObjCAtDirective(Scope *S, DeclPtrTy ObjCImpDecl, + bool InInterface) { } + + /// \brief Code completion after the '@' in a statement. + virtual void CodeCompleteObjCAtStatement(Scope *S) { } + + /// \brief Code completion after the '@' in an expression. + virtual void CodeCompleteObjCAtExpression(Scope *S) { } + /// \brief Code completion for an ObjC property decl. /// /// This code completion action is invoked when the code-completion token is diff --git a/include/clang/Parse/DeclSpec.h b/include/clang/Parse/DeclSpec.h index fe899b3..b766890 100644 --- a/include/clang/Parse/DeclSpec.h +++ b/include/clang/Parse/DeclSpec.h @@ -27,6 +27,40 @@ namespace clang { class Declarator; struct TemplateIdAnnotation; +/// CXXScopeSpec - Represents a C++ nested-name-specifier or a global scope +/// specifier. +class CXXScopeSpec { + SourceRange Range; + void *ScopeRep; + +public: + CXXScopeSpec() : Range(), ScopeRep() { } + + const SourceRange &getRange() const { return Range; } + void setRange(const SourceRange &R) { Range = R; } + void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); } + void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); } + SourceLocation getBeginLoc() const { return Range.getBegin(); } + SourceLocation getEndLoc() const { return Range.getEnd(); } + + ActionBase::CXXScopeTy *getScopeRep() const { return ScopeRep; } + void setScopeRep(ActionBase::CXXScopeTy *S) { ScopeRep = S; } + + bool isEmpty() const { return !Range.isValid(); } + bool isNotEmpty() const { return !isEmpty(); } + + /// isInvalid - An error occured during parsing of the scope specifier. + bool isInvalid() const { return isNotEmpty() && ScopeRep == 0; } + + /// isSet - A scope specifier was resolved to a valid C++ scope. + bool isSet() const { return ScopeRep != 0; } + + void clear() { + Range = SourceRange(); + ScopeRep = 0; + } +}; + /// DeclSpec - This class captures information about "declaration specifiers", /// which encompasses storage-class-specifiers, type-specifiers, /// type-qualifiers, and function-specifiers. @@ -143,6 +177,9 @@ private: // attributes. AttributeList *AttrList; + // Scope specifier for the type spec, if applicable. + CXXScopeSpec TypeScope; + // List of protocol qualifiers for objective-c classes. Used for // protocol-qualified interfaces "NString<foo>" and protocol-qualified id // "id<foo>". @@ -211,6 +248,8 @@ public: TST getTypeSpecType() const { return (TST)TypeSpecType; } bool isTypeSpecOwned() const { return TypeSpecOwned; } void *getTypeRep() const { return TypeRep; } + CXXScopeSpec &getTypeSpecScope() { return TypeScope; } + const CXXScopeSpec &getTypeSpecScope() const { return TypeScope; } const SourceRange &getSourceRange() const { return Range; } SourceLocation getTypeSpecWidthLoc() const { return TSWLoc; } @@ -436,40 +475,6 @@ private: IdentifierInfo *SetterName; // setter name of NULL if no setter }; -/// CXXScopeSpec - Represents a C++ nested-name-specifier or a global scope -/// specifier. -class CXXScopeSpec { - SourceRange Range; - void *ScopeRep; - -public: - CXXScopeSpec() : Range(), ScopeRep() { } - - const SourceRange &getRange() const { return Range; } - void setRange(const SourceRange &R) { Range = R; } - void setBeginLoc(SourceLocation Loc) { Range.setBegin(Loc); } - void setEndLoc(SourceLocation Loc) { Range.setEnd(Loc); } - SourceLocation getBeginLoc() const { return Range.getBegin(); } - SourceLocation getEndLoc() const { return Range.getEnd(); } - - ActionBase::CXXScopeTy *getScopeRep() const { return ScopeRep; } - void setScopeRep(ActionBase::CXXScopeTy *S) { ScopeRep = S; } - - bool isEmpty() const { return !Range.isValid(); } - bool isNotEmpty() const { return !isEmpty(); } - - /// isInvalid - An error occured during parsing of the scope specifier. - bool isInvalid() const { return isNotEmpty() && ScopeRep == 0; } - - /// isSet - A scope specifier was resolved to a valid C++ scope. - bool isSet() const { return ScopeRep != 0; } - - void clear() { - Range = SourceRange(); - ScopeRep = 0; - } -}; - /// \brief Represents a C++ unqualified-id that has been parsed. class UnqualifiedId { private: diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 81a80eb..e47de50 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -30,6 +30,7 @@ namespace clang { class DiagnosticBuilder; class Parser; class PragmaUnusedHandler; + class ColonProtectionRAIIObject; /// PrettyStackTraceParserEntry - If a crash happens while the parser is active, /// an entry is printed for it. @@ -47,6 +48,7 @@ public: /// class Parser { friend class PragmaUnusedHandler; + friend class ColonProtectionRAIIObject; PrettyStackTraceParserEntry CrashInfo; Preprocessor &PP; @@ -90,26 +92,16 @@ class Parser { /// template argument list, where the '>' closes the template /// argument list. bool GreaterThanIsOperator; + + /// ColonIsSacred - When this is false, we aggressively try to recover from + /// code like "foo : bar" as if it were a typo for "foo :: bar". This is not + /// safe in case statements and a few other things. This is managed by the + /// ColonProtectionRAIIObject RAII object. + bool ColonIsSacred; /// The "depth" of the template parameters currently being parsed. unsigned TemplateParameterDepth; - /// \brief RAII object that makes '>' behave either as an operator - /// or as the closing angle bracket for a template argument list. - struct GreaterThanIsOperatorScope { - bool &GreaterThanIsOperator; - bool OldGreaterThanIsOperator; - - GreaterThanIsOperatorScope(bool >IO, bool Val) - : GreaterThanIsOperator(GTIO), OldGreaterThanIsOperator(GTIO) { - GreaterThanIsOperator = Val; - } - - ~GreaterThanIsOperatorScope() { - GreaterThanIsOperator = OldGreaterThanIsOperator; - } - }; - public: Parser(Preprocessor &PP, Action &Actions); ~Parser(); @@ -759,7 +751,10 @@ private: bool isStartOfFunctionDefinition(); DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(AttributeList *Attr, AccessSpecifier AS = AS_none); - + DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS, + AttributeList *Attr, + AccessSpecifier AS = AS_none); + DeclPtrTy ParseFunctionDefinition(ParsingDeclarator &D, const ParsedTemplateInfo &TemplateInfo = ParsedTemplateInfo()); void ParseKNRParamDeclarations(Declarator &D); @@ -1087,6 +1082,7 @@ private: private: virtual void _anchor(); }; + struct ObjCPropertyCallback; void ParseStructDeclaration(DeclSpec &DS, FieldCallback &Callback); @@ -1288,7 +1284,7 @@ private: tok::TokenKind *After = 0); DeclPtrTy ParseNamespace(unsigned Context, SourceLocation &DeclEnd); - DeclPtrTy ParseLinkage(unsigned Context); + DeclPtrTy ParseLinkage(ParsingDeclSpec &DS, unsigned Context); DeclPtrTy ParseUsingDirectiveOrDeclaration(unsigned Context, SourceLocation &DeclEnd, CXX0XAttributeList Attrs); |