diff options
Diffstat (limited to 'clang/include/clang/Parse/Parser.h')
-rw-r--r-- | clang/include/clang/Parse/Parser.h | 121 |
1 files changed, 88 insertions, 33 deletions
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 3b6aceb5cd4..db4d1b7a4b7 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -920,14 +920,17 @@ private: //===--------------------------------------------------------------------===// // C99 6.9: External Definitions. - DeclGroupPtrTy ParseExternalDeclaration(CXX0XAttributeList Attr, + struct ParsedAttributesWithRange : ParsedAttributes { + SourceRange Range; + }; + + DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs, ParsingDeclSpec *DS = 0); bool isDeclarationAfterDeclarator() const; bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator); - DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(AttributeList *Attr, - AccessSpecifier AS = AS_none); + DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsedAttributes &attrs, + AccessSpecifier AS = AS_none); DeclGroupPtrTy ParseDeclarationOrFunctionDefinition(ParsingDeclSpec &DS, - AttributeList *Attr, AccessSpecifier AS = AS_none); Decl *ParseFunctionDefinition(ParsingDeclarator &D, @@ -942,7 +945,7 @@ private: Decl *ParseObjCAtDirectives(); Decl *ParseObjCAtClassDeclaration(SourceLocation atLoc); Decl *ParseObjCAtInterfaceDeclaration(SourceLocation atLoc, - AttributeList *prefixAttrs = 0); + ParsedAttributes &prefixAttrs); void ParseObjCClassInstanceVariables(Decl *interfaceDecl, tok::ObjCKeywordKind visibility, SourceLocation atLoc); @@ -955,7 +958,7 @@ private: void ParseObjCInterfaceDeclList(Decl *interfaceDecl, tok::ObjCKeywordKind contextKey); Decl *ParseObjCAtProtocolDeclaration(SourceLocation atLoc, - AttributeList *prefixAttrs = 0); + ParsedAttributes &prefixAttrs); Decl *ObjCImpDecl; llvm::SmallVector<Decl *, 4> PendingObjCImpDecl; @@ -1189,25 +1192,25 @@ private: } StmtResult ParseStatementOrDeclaration(StmtVector& Stmts, bool OnlyStatement = false); - StmtResult ParseLabeledStatement(AttributeList *Attr); - StmtResult ParseCaseStatement(AttributeList *Attr); - StmtResult ParseDefaultStatement(AttributeList *Attr); - StmtResult ParseCompoundStatement(AttributeList *Attr, + StmtResult ParseLabeledStatement(ParsedAttributes &Attr); + StmtResult ParseCaseStatement(ParsedAttributes &Attr); + StmtResult ParseDefaultStatement(ParsedAttributes &Attr); + StmtResult ParseCompoundStatement(ParsedAttributes &Attr, bool isStmtExpr = false); StmtResult ParseCompoundStatementBody(bool isStmtExpr = false); bool ParseParenExprOrCondition(ExprResult &ExprResult, Decl *&DeclResult, SourceLocation Loc, bool ConvertToBoolean); - StmtResult ParseIfStatement(AttributeList *Attr); - StmtResult ParseSwitchStatement(AttributeList *Attr); - StmtResult ParseWhileStatement(AttributeList *Attr); - StmtResult ParseDoStatement(AttributeList *Attr); - StmtResult ParseForStatement(AttributeList *Attr); - StmtResult ParseGotoStatement(AttributeList *Attr); - StmtResult ParseContinueStatement(AttributeList *Attr); - StmtResult ParseBreakStatement(AttributeList *Attr); - StmtResult ParseReturnStatement(AttributeList *Attr); + StmtResult ParseIfStatement(ParsedAttributes &Attr); + StmtResult ParseSwitchStatement(ParsedAttributes &Attr); + StmtResult ParseWhileStatement(ParsedAttributes &Attr); + StmtResult ParseDoStatement(ParsedAttributes &Attr); + StmtResult ParseForStatement(ParsedAttributes &Attr); + StmtResult ParseGotoStatement(ParsedAttributes &Attr); + StmtResult ParseContinueStatement(ParsedAttributes &Attr); + StmtResult ParseBreakStatement(ParsedAttributes &Attr); + StmtResult ParseReturnStatement(ParsedAttributes &Attr); StmtResult ParseAsmStatement(bool &msAsm); StmtResult FuzzyParseMicrosoftAsmStatement(SourceLocation AsmLoc); bool ParseAsmOperandsOpt(llvm::SmallVectorImpl<IdentifierInfo *> &Names, @@ -1217,7 +1220,7 @@ private: //===--------------------------------------------------------------------===// // C++ 6: Statements and Blocks - StmtResult ParseCXXTryBlock(AttributeList *Attr); + StmtResult ParseCXXTryBlock(ParsedAttributes &Attr); StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc); StmtResult ParseCXXCatchBlock(); @@ -1244,11 +1247,11 @@ private: DeclGroupPtrTy ParseDeclaration(StmtVector &Stmts, unsigned Context, SourceLocation &DeclEnd, - CXX0XAttributeList Attr); + ParsedAttributesWithRange &attrs); DeclGroupPtrTy ParseSimpleDeclaration(StmtVector &Stmts, unsigned Context, SourceLocation &DeclEnd, - AttributeList *Attr, + ParsedAttributes &attrs, bool RequireSemi); DeclGroupPtrTy ParseDeclGroup(ParsingDeclSpec &DS, unsigned Context, bool AllowFunctionDefinitions, @@ -1447,14 +1450,64 @@ private: TypeResult ParseTypeName(SourceRange *Range = 0); void ParseBlockId(); - // EndLoc, if non-NULL, is filled with the location of the last token of - // the attribute list. - CXX0XAttributeList ParseCXX0XAttributes(SourceLocation *EndLoc = 0); - void ParseMicrosoftAttributes(); - AttributeList *ParseGNUAttributes(SourceLocation *EndLoc = 0); - AttributeList *ParseMicrosoftDeclSpec(AttributeList* CurrAttr = 0); - AttributeList *ParseMicrosoftTypeAttributes(AttributeList* CurrAttr = 0); - AttributeList *ParseBorlandTypeAttributes(AttributeList* CurrAttr = 0); + + void ProhibitAttributes(ParsedAttributesWithRange &attrs) { + if (!attrs.Range.isValid()) return; + DiagnoseProhibitedAttributes(attrs); + } + void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs); + + void MaybeParseGNUAttributes(Declarator &D) { + if (Tok.is(tok::kw___attribute)) { + ParsedAttributes attrs; + SourceLocation endLoc; + ParseGNUAttributes(attrs, &endLoc); + D.addAttributes(attrs.getList(), endLoc); + } + } + void MaybeParseGNUAttributes(ParsedAttributes &attrs, + SourceLocation *endLoc = 0) { + if (Tok.is(tok::kw___attribute)) + ParseGNUAttributes(attrs, endLoc); + } + void ParseGNUAttributes(ParsedAttributes &attrs, + SourceLocation *endLoc = 0); + + void MaybeParseCXX0XAttributes(Declarator &D) { + if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) { + ParsedAttributesWithRange attrs; + SourceLocation endLoc; + ParseCXX0XAttributes(attrs, &endLoc); + D.addAttributes(attrs.getList(), endLoc); + } + } + void MaybeParseCXX0XAttributes(ParsedAttributes &attrs, + SourceLocation *endLoc = 0) { + if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) { + ParsedAttributesWithRange attrsWithRange; + ParseCXX0XAttributes(attrsWithRange, endLoc); + attrs.append(attrsWithRange.getList()); + } + } + void MaybeParseCXX0XAttributes(ParsedAttributesWithRange &attrs, + SourceLocation *endLoc = 0) { + if (getLang().CPlusPlus0x && isCXX0XAttributeSpecifier()) + ParseCXX0XAttributes(attrs, endLoc); + } + void ParseCXX0XAttributes(ParsedAttributesWithRange &attrs, + SourceLocation *EndLoc = 0); + + void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs, + SourceLocation *endLoc = 0) { + if (getLang().Microsoft && Tok.is(tok::l_square)) + ParseMicrosoftAttributes(attrs, endLoc); + } + void ParseMicrosoftAttributes(ParsedAttributes &attrs, + SourceLocation *endLoc = 0); + void ParseMicrosoftDeclSpec(ParsedAttributes &attrs); + void ParseMicrosoftTypeAttributes(ParsedAttributes &attrs); + void ParseBorlandTypeAttributes(ParsedAttributes &attrs); + void ParseTypeofSpecifier(DeclSpec &DS); void ParseDecltypeSpecifier(DeclSpec &DS); @@ -1499,12 +1552,13 @@ private: typedef void (Parser::*DirectDeclParseFunction)(Declarator&); void ParseDeclaratorInternal(Declarator &D, DirectDeclParseFunction DirectDeclParser); + void ParseTypeQualifierListOpt(DeclSpec &DS, bool GNUAttributesAllowed = true, bool CXX0XAttributesAllowed = true); void ParseDirectDeclarator(Declarator &D); void ParseParenDeclarator(Declarator &D); void ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D, - AttributeList *AttrList = 0, + ParsedAttributes &attrs, bool RequiresArg = false); void ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc, IdentifierInfo *FirstIdent, @@ -1524,10 +1578,11 @@ private: Decl *ParseUsingDirectiveOrDeclaration(unsigned Context, const ParsedTemplateInfo &TemplateInfo, SourceLocation &DeclEnd, - CXX0XAttributeList Attrs); + ParsedAttributesWithRange &attrs); Decl *ParseUsingDirective(unsigned Context, SourceLocation UsingLoc, - SourceLocation &DeclEnd, AttributeList *Attr); + SourceLocation &DeclEnd, + ParsedAttributes &attrs); Decl *ParseUsingDeclaration(unsigned Context, const ParsedTemplateInfo &TemplateInfo, SourceLocation UsingLoc, |