[cfe-commits] r162691 - in /cfe/trunk: include/clang/AST/Stmt.h include/clang/Basic/StmtNodes.td lib/AST/Stmt.cpp

Chad Rosier mcrosier at apple.com
Mon Aug 27 11:56:37 PDT 2012


Author: mcrosier
Date: Mon Aug 27 13:56:36 2012
New Revision: 162691

URL: http://llvm.org/viewvc/llvm-project?rev=162691&view=rev
Log:
[ms-inline asm] Add a new base class, AsmStmt, for the GCCAsmStmt and MSAsmStmt
classes.

Modified:
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/include/clang/Basic/StmtNodes.td
    cfe/trunk/lib/AST/Stmt.cpp

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=162691&r1=162690&r2=162691&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Mon Aug 27 13:56:36 2012
@@ -1363,15 +1363,42 @@
   }
 };
 
+/// 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 @@
              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 @@
   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 @@
 
 /// 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 @@
             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 @@
   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; }

Modified: cfe/trunk/include/clang/Basic/StmtNodes.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/StmtNodes.td?rev=162691&r1=162690&r2=162691&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/StmtNodes.td (original)
+++ cfe/trunk/include/clang/Basic/StmtNodes.td Mon Aug 27 13:56:36 2012
@@ -28,11 +28,10 @@
 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;

Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=162691&r1=162690&r2=162691&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Mon Aug 27 13:56:36 2012
@@ -596,8 +596,8 @@
                        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 @@
                      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!");





More information about the cfe-commits mailing list