aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@apple.com>2012-08-27 18:56:36 +0000
committerChad Rosier <mcrosier@apple.com>2012-08-27 18:56:36 +0000
commit728581e7702cafe32cc9e1b5b61a15f5042ce189 (patch)
tree4073793bb380155abba6870229e2e81d1177c59a
parent95a58d2f6ef9149dd50d679a7ee70d0685c38d27 (diff)
[ms-inline asm] Add a new base class, AsmStmt, for the GCCAsmStmt and MSAsmStmt
classes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162691 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/Stmt.h54
-rw-r--r--include/clang/Basic/StmtNodes.td9
-rw-r--r--lib/AST/Stmt.cpp8
3 files changed, 42 insertions, 29 deletions
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index fa068bb8ff..dd26732ef9 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -1363,15 +1363,42 @@ public:
}
};
+/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
+///
+class AsmStmt : public Stmt {
+protected:
+ bool IsSimple;
+ bool IsVolatile;
+
+ AsmStmt(StmtClass SC, bool issimple, bool isvolatile) :
+ Stmt (SC), IsSimple(issimple), IsVolatile(isvolatile) { }
+
+public:
+ /// \brief Build an empty inline-assembly statement.
+ explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
+ Stmt(SC, Empty) { }
+
+ bool isSimple() const { return IsSimple; }
+ void setSimple(bool V) { IsSimple = V; }
+
+ bool isVolatile() const { return IsVolatile; }
+ void setVolatile(bool V) { IsVolatile = V; }
+
+ SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == GCCAsmStmtClass ||
+ T->getStmtClass() == MSAsmStmtClass;
+ }
+ static bool classof(const AsmStmt *) { return true; }
+};
+
/// This represents a GCC inline-assembly statement extension.
///
-class GCCAsmStmt : public Stmt {
+class GCCAsmStmt : public AsmStmt {
SourceLocation AsmLoc, RParenLoc;
StringLiteral *AsmStr;
- bool IsSimple;
- bool IsVolatile;
-
unsigned NumOutputs;
unsigned NumInputs;
unsigned NumClobbers;
@@ -1390,7 +1417,7 @@ public:
StringLiteral **clobbers, SourceLocation rparenloc);
/// \brief Build an empty inline-assembly statement.
- explicit GCCAsmStmt(EmptyShell Empty) : Stmt(GCCAsmStmtClass, Empty),
+ explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
Names(0), Constraints(0), Exprs(0), Clobbers(0) { }
SourceLocation getAsmLoc() const { return AsmLoc; }
@@ -1398,11 +1425,6 @@ public:
SourceLocation getRParenLoc() const { return RParenLoc; }
void setRParenLoc(SourceLocation L) { RParenLoc = L; }
- bool isVolatile() const { return IsVolatile; }
- void setVolatile(bool V) { IsVolatile = V; }
- bool isSimple() const { return IsSimple; }
- void setSimple(bool V) { IsSimple = V; }
-
//===--- Asm String Analysis ---===//
const StringLiteral *getAsmString() const { return AsmStr; }
@@ -1614,13 +1636,10 @@ public:
/// This represents a Microsoft inline-assembly statement extension.
///
-class MSAsmStmt : public Stmt {
+class MSAsmStmt : public AsmStmt {
SourceLocation AsmLoc, LBraceLoc, EndLoc;
std::string AsmStr;
- bool IsSimple;
- bool IsVolatile;
-
unsigned NumAsmToks;
unsigned NumInputs;
unsigned NumOutputs;
@@ -1640,7 +1659,7 @@ public:
SourceLocation endloc);
/// \brief Build an empty MS-style inline-assembly statement.
- explicit MSAsmStmt(EmptyShell Empty) : Stmt(MSAsmStmtClass, Empty),
+ explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
NumAsmToks(0), NumInputs(0), NumOutputs(0), NumClobbers(0), AsmToks(0),
Names(0), Exprs(0), Clobbers(0) { }
@@ -1656,11 +1675,6 @@ public:
unsigned getNumAsmToks() { return NumAsmToks; }
Token *getAsmToks() { return AsmToks; }
- bool isVolatile() const { return IsVolatile; }
- void setVolatile(bool V) { IsVolatile = V; }
- bool isSimple() const { return IsSimple; }
- void setSimple(bool V) { IsSimple = V; }
-
//===--- Asm String Analysis ---===//
const std::string *getAsmString() const { return &AsmStr; }
diff --git a/include/clang/Basic/StmtNodes.td b/include/clang/Basic/StmtNodes.td
index a4d09f21cd..06da94708f 100644
--- a/include/clang/Basic/StmtNodes.td
+++ b/include/clang/Basic/StmtNodes.td
@@ -28,11 +28,10 @@ def SwitchCase : Stmt<1>;
def CaseStmt : DStmt<SwitchCase>;
def DefaultStmt : DStmt<SwitchCase>;
-// GNU Extensions
-def GCCAsmStmt : Stmt;
-
-// MS Extensions
-def MSAsmStmt : Stmt;
+// Asm statements
+def AsmStmt : Stmt<1>;
+def GCCAsmStmt : DStmt<AsmStmt>;
+def MSAsmStmt : DStmt<AsmStmt>;
// Obj-C statements
def ObjCAtTryStmt : Stmt;
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index 68e53cc901..8c76a9c1a7 100644
--- a/lib/AST/Stmt.cpp
+++ b/lib/AST/Stmt.cpp
@@ -596,8 +596,8 @@ GCCAsmStmt::GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
Expr **exprs, StringLiteral *asmstr,
unsigned numclobbers, StringLiteral **clobbers,
SourceLocation rparenloc)
- : Stmt(GCCAsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr)
- , IsSimple(issimple), IsVolatile(isvolatile), NumOutputs(numoutputs)
+ : AsmStmt(GCCAsmStmtClass, issimple, isvolatile), AsmLoc(asmloc)
+ , RParenLoc(rparenloc), AsmStr(asmstr), NumOutputs(numoutputs)
, NumInputs(numinputs), NumClobbers(numclobbers) {
unsigned NumExprs = NumOutputs + NumInputs;
@@ -622,8 +622,8 @@ MSAsmStmt::MSAsmStmt(ASTContext &C, SourceLocation asmloc,
ArrayRef<Expr*> inputexprs, ArrayRef<Expr*> outputexprs,
StringRef asmstr, ArrayRef<StringRef> clobbers,
SourceLocation endloc)
- : Stmt(MSAsmStmtClass), AsmLoc(asmloc), LBraceLoc(lbraceloc), EndLoc(endloc),
- AsmStr(asmstr.str()), IsSimple(issimple), IsVolatile(isvolatile),
+ : AsmStmt(MSAsmStmtClass, issimple, isvolatile), AsmLoc(asmloc),
+ LBraceLoc(lbraceloc), EndLoc(endloc), AsmStr(asmstr.str()),
NumAsmToks(asmtoks.size()), NumInputs(inputs.size()),
NumOutputs(outputs.size()), NumClobbers(clobbers.size()) {
assert (inputs.size() == inputexprs.size() && "Input expr size mismatch!");