[cfe-commits] r161342 - in /cfe/trunk: include/clang/AST/Stmt.h include/clang/Sema/Sema.h lib/AST/Stmt.cpp lib/Parse/ParseStmt.cpp lib/Sema/SemaStmt.cpp lib/Sema/TreeTransform.h

Chad Rosier mcrosier at apple.com
Mon Aug 6 13:03:45 PDT 2012


Author: mcrosier
Date: Mon Aug  6 15:03:45 2012
New Revision: 161342

URL: http://llvm.org/viewvc/llvm-project?rev=161342&view=rev
Log:
[ms-inline asm] Pass Tokens to Sema and store them in the AST.  No functional
change intended.  No test case as there's no real way to test at this time.

Modified:
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/AST/Stmt.cpp
    cfe/trunk/lib/Parse/ParseStmt.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/lib/Sema/TreeTransform.h

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=161342&r1=161341&r2=161342&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Mon Aug  6 15:03:45 2012
@@ -20,6 +20,7 @@
 #include "clang/AST/StmtIterator.h"
 #include "clang/AST/DeclGroup.h"
 #include "clang/AST/Attr.h"
+#include "clang/Lex/Token.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
@@ -1620,6 +1621,7 @@
 ///
 class MSAsmStmt : public Stmt {
   SourceLocation AsmLoc, EndLoc;
+  SmallVector<Token, 4> AsmToks;
   std::string AsmStr;
 
   bool IsSimple;
@@ -1628,7 +1630,8 @@
   Stmt **Exprs;
 
 public:
-  MSAsmStmt(ASTContext &C, SourceLocation asmloc, std::string &asmstr,
+  MSAsmStmt(ASTContext &C, SourceLocation asmloc,
+            SmallVectorImpl<Token> &asmtoks, std::string &asmstr,
             SourceLocation endloc);
 
   SourceLocation getAsmLoc() const { return AsmLoc; }
@@ -1636,6 +1639,8 @@
   SourceLocation getEndLoc() const { return EndLoc; }
   void setEndLoc(SourceLocation L) { EndLoc = L; }
 
+  SmallVectorImpl<Token> &getAsmToks() { return AsmToks; }
+
   bool isVolatile() const { return IsVolatile; }
   void setVolatile(bool V) { IsVolatile = V; }
   bool isSimple() const { return IsSimple; }

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=161342&r1=161341&r2=161342&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Aug  6 15:03:45 2012
@@ -2543,6 +2543,7 @@
                           bool MSAsm = false);
 
   StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc,
+                            SmallVectorImpl<Token> &AsmToks,
                             std::string &AsmString,
                             SourceLocation EndLoc);
 

Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=161342&r1=161341&r2=161342&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Mon Aug  6 15:03:45 2012
@@ -583,10 +583,14 @@
   std::copy(clobbers, clobbers + NumClobbers, Clobbers);
 }
 
-MSAsmStmt::MSAsmStmt(ASTContext &C, SourceLocation asmloc, std::string &asmstr,
-                     SourceLocation endloc)
-  : Stmt(MSAsmStmtClass), AsmLoc(asmloc), EndLoc(endloc), AsmStr(asmstr),
+MSAsmStmt::MSAsmStmt(ASTContext &C, SourceLocation asmloc,
+                     SmallVectorImpl<Token> &asmtoks,
+                     std::string &asmstr, SourceLocation endloc)
+  : Stmt(MSAsmStmtClass), AsmLoc(asmloc), EndLoc(endloc),
+    AsmToks(asmtoks.size()), AsmStr(asmstr),
     IsSimple(true), IsVolatile(true) {
+  for (unsigned i = 0, e = asmtoks.size(); i != e; ++i)
+    AsmToks.push_back(asmtoks[i]);
 }
 
 ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,

Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=161342&r1=161341&r2=161342&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Mon Aug  6 15:03:45 2012
@@ -1816,12 +1816,9 @@
     }
   }
 
-  // FIXME: We should be passing the tokens and source locations, rather than
-  // (or possibly in addition to the) AsmString.  Sema is going to interact with
-  // MC to determine Constraints, Clobbers, etc., which would be simplest to
-  // do with the tokens.
+  // FIXME: We should be passing source locations for better diagnostics.
   std::string AsmString = Asm.c_str();
-  return Actions.ActOnMSAsmStmt(AsmLoc, AsmString, EndLoc);
+  return Actions.ActOnMSAsmStmt(AsmLoc, AsmToks, AsmString, EndLoc);
 }
 
 /// ParseAsmStatement - Parse a GNU extended asm statement.

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=161342&r1=161341&r2=161342&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Aug  6 15:03:45 2012
@@ -2748,13 +2748,14 @@
 }
 
 StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc,
+                                SmallVectorImpl<Token> &AsmToks,
                                 std::string &AsmString,
                                 SourceLocation EndLoc) {
   // MS-style inline assembly is not fully supported, so emit a warning.
   Diag(AsmLoc, diag::warn_unsupported_msasm);
 
   MSAsmStmt *NS =
-    new (Context) MSAsmStmt(Context, AsmLoc, AsmString, EndLoc);
+    new (Context) MSAsmStmt(Context, AsmLoc, AsmToks, AsmString, EndLoc);
 
   return Owned(NS);
 }

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=161342&r1=161341&r2=161342&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Mon Aug  6 15:03:45 2012
@@ -1185,9 +1185,10 @@
   /// By default, performs semantic analysis to build the new statement.
   /// Subclasses may override this routine to provide different behavior.
   StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc,
+                              SmallVectorImpl<Token> &AsmToks,
                               std::string &AsmString,
                               SourceLocation EndLoc) {
-    return getSema().ActOnMSAsmStmt(AsmLoc, AsmString, EndLoc);
+    return getSema().ActOnMSAsmStmt(AsmLoc, AsmToks, AsmString, EndLoc);
   }
 
   /// \brief Build a new Objective-C \@try statement.
@@ -5611,6 +5612,7 @@
 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
   // No need to transform the asm string literal.
   return getDerived().RebuildMSAsmStmt(S->getAsmLoc(),
+                                       S->getAsmToks(),
                                        *S->getAsmString(),
                                        S->getEndLoc());
 }





More information about the cfe-commits mailing list