summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-04-14 00:33:13 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-04-14 00:33:13 +0000
commit534986f2b21e6050bf00163cd6423fd92155a6ed (patch)
treea8e8a492336134952e331deec690f010f5c7b71f /include
parent9cdd1e3450a07c1bafc32c96f1db88084497f282 (diff)
Add an AttributedStmt type to represent a statement with C++11 attributes
attached. Since we do not support any attributes which appertain to a statement (yet), testing of this is necessarily quite minimal. Patch by Alexander Kornienko! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154723 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/clang/AST/DeclBase.h1
-rw-r--r--include/clang/AST/RecursiveASTVisitor.h1
-rw-r--r--include/clang/AST/Stmt.h42
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--include/clang/Basic/StmtNodes.td1
-rw-r--r--include/clang/Parse/Parser.h57
-rw-r--r--include/clang/Sema/Sema.h7
-rw-r--r--include/clang/Serialization/ASTBitCodes.h2
-rw-r--r--include/clang/Serialization/ASTWriter.h1
9 files changed, 85 insertions, 30 deletions
diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h
index 4c675aed8f..223289123e 100644
--- a/include/clang/AST/DeclBase.h
+++ b/include/clang/AST/DeclBase.h
@@ -861,7 +861,6 @@ public:
void dumpXML(raw_ostream &OS) const;
private:
- const Attr *getAttrsImpl() const;
void setAttrsImpl(const AttrVec& Attrs, ASTContext &Ctx);
void setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,
ASTContext &Ctx);
diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h
index a4ad525701..f1b5171021 100644
--- a/include/clang/AST/RecursiveASTVisitor.h
+++ b/include/clang/AST/RecursiveASTVisitor.h
@@ -1870,6 +1870,7 @@ DEF_TRAVERSE_STMT(GotoStmt, { })
DEF_TRAVERSE_STMT(IfStmt, { })
DEF_TRAVERSE_STMT(IndirectGotoStmt, { })
DEF_TRAVERSE_STMT(LabelStmt, { })
+DEF_TRAVERSE_STMT(AttributedStmt, { })
DEF_TRAVERSE_STMT(NullStmt, { })
DEF_TRAVERSE_STMT(ObjCAtCatchStmt, { })
DEF_TRAVERSE_STMT(ObjCAtFinallyStmt, { })
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index 84bdfb89ca..1b0f576e27 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -20,6 +20,7 @@
#include "clang/AST/StmtIterator.h"
#include "clang/AST/DeclGroup.h"
#include "clang/AST/ASTContext.h"
+#include "clang/AST/Attr.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
@@ -794,6 +795,47 @@ public:
};
+/// \brief Represents an attribute applied to a statement.
+///
+/// Represents an attribute applied to a statement. For example:
+/// [[omp::for(...)]] for (...) { ... }
+///
+class AttributedStmt : public Stmt {
+ Stmt *SubStmt;
+ SourceLocation AttrLoc;
+ AttrVec Attrs;
+ // TODO: It can be done as Attr *Attrs[1]; and variable size array as in
+ // StringLiteral
+
+ friend class ASTStmtReader;
+
+public:
+ AttributedStmt(SourceLocation loc, const AttrVec &attrs, Stmt *substmt)
+ : Stmt(AttributedStmtClass), SubStmt(substmt), AttrLoc(loc), Attrs(attrs) {
+ }
+
+ // \brief Build an empty attributed statement.
+ explicit AttributedStmt(EmptyShell Empty)
+ : Stmt(AttributedStmtClass, Empty) {
+ }
+
+ SourceLocation getAttrLoc() const { return AttrLoc; }
+ const AttrVec &getAttrs() const { return Attrs; }
+ Stmt *getSubStmt() { return SubStmt; }
+ const Stmt *getSubStmt() const { return SubStmt; }
+
+ SourceRange getSourceRange() const LLVM_READONLY {
+ return SourceRange(AttrLoc, SubStmt->getLocEnd());
+ }
+ child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == AttributedStmtClass;
+ }
+ static bool classof(const AttributedStmt *) { return true; }
+};
+
+
/// IfStmt - This represents an if/then/else.
///
class IfStmt : public Stmt {
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index e553740ab1..b6b6398da9 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1563,6 +1563,9 @@ def warn_redeclaration_without_attribute_prev_attribute_ignored : Warning<
def warn_attribute_ignored : Warning<"%0 attribute ignored">;
def warn_unknown_attribute_ignored : Warning<
"unknown attribute %0 ignored">, InGroup<UnknownAttributes>;
+def warn_attribute_invalid_on_stmt : Warning<
+ "attribute %0 cannot be specified on a statement">,
+ InGroup<IgnoredAttributes>;
def warn_declspec_attribute_ignored : Warning<
"attribute %0 is ignored, place it after \"%select{class|struct|union|enum}1\" to apply attribute to type declaration">, InGroup<IgnoredAttributes>;
def warn_attribute_precede_definition : Warning<
diff --git a/include/clang/Basic/StmtNodes.td b/include/clang/Basic/StmtNodes.td
index 67d71e44c0..e7718cd80c 100644
--- a/include/clang/Basic/StmtNodes.td
+++ b/include/clang/Basic/StmtNodes.td
@@ -12,6 +12,7 @@ class DStmt<Stmt base, bit abstract = 0> : Stmt<abstract> {
def NullStmt : Stmt;
def CompoundStmt : Stmt;
def LabelStmt : Stmt;
+def AttributedStmt : Stmt;
def IfStmt : Stmt;
def SwitchStmt : Stmt;
def WhileStmt : Stmt;
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index 0e5e8c7d88..a9e7a74d69 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -1517,42 +1517,40 @@ private:
//===--------------------------------------------------------------------===//
// C99 6.8: Statements and Blocks.
- StmtResult ParseStatement(SourceLocation *TrailingElseLoc = NULL) {
+ StmtResult ParseStatement(SourceLocation *TrailingElseLoc = 0) {
StmtVector Stmts(Actions);
return ParseStatementOrDeclaration(Stmts, true, TrailingElseLoc);
}
- StmtResult ParseStatementOrDeclaration(StmtVector& Stmts,
+ StmtResult ParseStatementOrDeclaration(StmtVector &Stmts,
bool OnlyStatement,
- SourceLocation *TrailingElseLoc = NULL);
- StmtResult ParseExprStatement(ParsedAttributes &Attrs);
- StmtResult ParseLabeledStatement(ParsedAttributes &Attr);
- StmtResult ParseCaseStatement(ParsedAttributes &Attr,
- bool MissingCase = false,
+ SourceLocation *TrailingElseLoc = 0);
+ StmtResult ParseStatementOrDeclarationAfterAttributes(
+ StmtVector &Stmts,
+ bool OnlyStatement,
+ SourceLocation *TrailingElseLoc,
+ ParsedAttributesWithRange &Attrs);
+ StmtResult ParseExprStatement();
+ StmtResult ParseLabeledStatement(ParsedAttributesWithRange &attrs);
+ StmtResult ParseCaseStatement(bool MissingCase = false,
ExprResult Expr = ExprResult());
- StmtResult ParseDefaultStatement(ParsedAttributes &Attr);
- StmtResult ParseCompoundStatement(ParsedAttributes &Attr,
- bool isStmtExpr = false);
- StmtResult ParseCompoundStatement(ParsedAttributes &Attr,
- bool isStmtExpr,
+ StmtResult ParseDefaultStatement();
+ StmtResult ParseCompoundStatement(bool isStmtExpr = false);
+ StmtResult ParseCompoundStatement(bool isStmtExpr,
unsigned ScopeFlags);
StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
bool ParseParenExprOrCondition(ExprResult &ExprResult,
Decl *&DeclResult,
SourceLocation Loc,
bool ConvertToBoolean);
- StmtResult ParseIfStatement(ParsedAttributes &Attr,
- SourceLocation *TrailingElseLoc);
- StmtResult ParseSwitchStatement(ParsedAttributes &Attr,
- SourceLocation *TrailingElseLoc);
- StmtResult ParseWhileStatement(ParsedAttributes &Attr,
- SourceLocation *TrailingElseLoc);
- StmtResult ParseDoStatement(ParsedAttributes &Attr);
- StmtResult ParseForStatement(ParsedAttributes &Attr,
- SourceLocation *TrailingElseLoc);
- StmtResult ParseGotoStatement(ParsedAttributes &Attr);
- StmtResult ParseContinueStatement(ParsedAttributes &Attr);
- StmtResult ParseBreakStatement(ParsedAttributes &Attr);
- StmtResult ParseReturnStatement(ParsedAttributes &Attr);
+ StmtResult ParseIfStatement(SourceLocation *TrailingElseLoc);
+ StmtResult ParseSwitchStatement(SourceLocation *TrailingElseLoc);
+ StmtResult ParseWhileStatement(SourceLocation *TrailingElseLoc);
+ StmtResult ParseDoStatement();
+ StmtResult ParseForStatement(SourceLocation *TrailingElseLoc);
+ StmtResult ParseGotoStatement();
+ StmtResult ParseContinueStatement();
+ StmtResult ParseBreakStatement();
+ StmtResult ParseReturnStatement();
StmtResult ParseAsmStatement(bool &msAsm);
StmtResult ParseMicrosoftAsmStatement(SourceLocation AsmLoc);
@@ -1586,7 +1584,7 @@ private:
/// \brief The behavior of this __if_exists or __if_not_exists block
/// should.
IfExistsBehavior Behavior;
-};
+ };
bool ParseMicrosoftIfExistsCondition(IfExistsCondition& Result);
void ParseMicrosoftIfExistsStatement(StmtVector &Stmts);
@@ -1602,14 +1600,14 @@ private:
//===--------------------------------------------------------------------===//
// C++ 6: Statements and Blocks
- StmtResult ParseCXXTryBlock(ParsedAttributes &Attr);
+ StmtResult ParseCXXTryBlock();
StmtResult ParseCXXTryBlockCommon(SourceLocation TryLoc);
StmtResult ParseCXXCatchBlock();
//===--------------------------------------------------------------------===//
// MS: SEH Statements and Blocks
- StmtResult ParseSEHTryBlock(ParsedAttributes &Attr);
+ StmtResult ParseSEHTryBlock();
StmtResult ParseSEHTryBlockCommon(SourceLocation Loc);
StmtResult ParseSEHExceptBlock(SourceLocation Loc);
StmtResult ParseSEHFinallyBlock(SourceLocation Loc);
@@ -1883,6 +1881,7 @@ private:
void ProhibitAttributes(ParsedAttributesWithRange &attrs) {
if (!attrs.Range.isValid()) return;
DiagnoseProhibitedAttributes(attrs);
+ attrs.clear();
}
void DiagnoseProhibitedAttributes(ParsedAttributesWithRange &attrs);
@@ -1967,7 +1966,7 @@ private:
void ParseTypeofSpecifier(DeclSpec &DS);
SourceLocation ParseDecltypeSpecifier(DeclSpec &DS);
- void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS,
+ void AnnotateExistingDecltypeSpecifier(const DeclSpec &DS,
SourceLocation StartLoc,
SourceLocation EndLoc);
void ParseUnderlyingTypeSpecifier(DeclSpec &DS);
diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h
index 31c410a9f9..e8a9ff6971 100644
--- a/include/clang/Sema/Sema.h
+++ b/include/clang/Sema/Sema.h
@@ -1974,6 +1974,10 @@ public:
bool CheckCallingConvAttr(const AttributeList &attr, CallingConv &CC);
bool CheckNoReturnAttr(const AttributeList &attr);
+ /// \brief Stmt attributes - this routine is the top level dispatcher.
+ StmtResult ProcessStmtAttributes(Stmt *Stmt, AttributeList *Attrs,
+ SourceRange Range);
+
void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
bool &IncompleteImpl, unsigned DiagID);
void WarnConflictingTypedMethods(ObjCMethodDecl *Method,
@@ -2251,6 +2255,9 @@ public:
StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl,
SourceLocation ColonLoc, Stmt *SubStmt);
+ StmtResult ActOnAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs,
+ Stmt *SubStmt);
+
StmtResult ActOnIfStmt(SourceLocation IfLoc,
FullExprArg CondVal, Decl *CondVar,
Stmt *ThenVal,
diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h
index 4591630357..f9bb8928a3 100644
--- a/include/clang/Serialization/ASTBitCodes.h
+++ b/include/clang/Serialization/ASTBitCodes.h
@@ -964,6 +964,8 @@ namespace clang {
STMT_DEFAULT,
/// \brief A LabelStmt record.
STMT_LABEL,
+ /// \brief An AttributedStmt record.
+ STMT_ATTRIBUTED,
/// \brief An IfStmt record.
STMT_IF,
/// \brief A SwitchStmt record.
diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h
index 4c62385cf2..e693f17593 100644
--- a/include/clang/Serialization/ASTWriter.h
+++ b/include/clang/Serialization/ASTWriter.h
@@ -76,6 +76,7 @@ public:
typedef SmallVectorImpl<uint64_t> RecordDataImpl;
friend class ASTDeclWriter;
+ friend class ASTStmtWriter;
private:
/// \brief Map that provides the ID numbers of each type within the
/// output stream, plus those deserialized from a chained PCH.