]> granicus.if.org Git - clang/commitdiff
[ms-inline asm] Add the left brace source location and improve the pretty
authorChad Rosier <mcrosier@apple.com>
Wed, 15 Aug 2012 16:53:30 +0000 (16:53 +0000)
committerChad Rosier <mcrosier@apple.com>
Wed, 15 Aug 2012 16:53:30 +0000 (16:53 +0000)
printer.  Patch by Enea Zaffanella <zaffanella@cs.unipr.it>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161958 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Stmt.h
include/clang/Sema/Sema.h
lib/AST/Stmt.cpp
lib/AST/StmtPrinter.cpp
lib/Parse/ParseStmt.cpp
lib/Sema/SemaStmt.cpp
lib/Sema/TreeTransform.h

index 05d054918df43dc90479907fdcb6dfc456153eab..943e005d1f2ba50534a44ea976640c74f0039f4c 100644 (file)
@@ -1620,7 +1620,7 @@ public:
 /// MSAsmStmt - This represents a MS inline-assembly statement extension.
 ///
 class MSAsmStmt : public Stmt {
-  SourceLocation AsmLoc, EndLoc;
+  SourceLocation AsmLoc, LBraceLoc, EndLoc;
   std::string AsmStr;
 
   bool IsSimple;
@@ -1634,15 +1634,20 @@ class MSAsmStmt : public Stmt {
   StringRef *Clobbers;
 
 public:
-  MSAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
-            bool isvolatile, ArrayRef<Token> asmtoks, StringRef asmstr,
-            ArrayRef<StringRef> clobbers, SourceLocation endloc);
+  MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc,
+            bool issimple, bool isvolatile, ArrayRef<Token> asmtoks,
+            StringRef asmstr, ArrayRef<StringRef> clobbers,
+            SourceLocation endloc);
 
   SourceLocation getAsmLoc() const { return AsmLoc; }
   void setAsmLoc(SourceLocation L) { AsmLoc = L; }
+  SourceLocation getLBraceLoc() const { return LBraceLoc; }
+  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
   SourceLocation getEndLoc() const { return EndLoc; }
   void setEndLoc(SourceLocation L) { EndLoc = L; }
 
+  bool hasBraces() const { return LBraceLoc.isValid(); }
+
   unsigned getNumAsmToks() { return NumAsmToks; }
   Token *getAsmToks() { return AsmToks; }
 
index 2cd58279d429a8ac42eabee2a8028d132267d3a0..2966a33ea1d6810e22140d2d89988f40d55cc220 100644 (file)
@@ -2542,6 +2542,7 @@ public:
                           bool MSAsm = false);
 
   StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc,
+                            SourceLocation LBraceLoc,
                             ArrayRef<Token> AsmToks,
                             SourceLocation EndLoc);
 
index 9aa7f5ba55abbd1ae5b30d78f331c347ba8aed4d..680ebc81c8eacc51039526d70f1448851bbc3d44 100644 (file)
@@ -583,11 +583,12 @@ AsmStmt::AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
   std::copy(clobbers, clobbers + NumClobbers, Clobbers);
 }
 
-MSAsmStmt::MSAsmStmt(ASTContext &C, SourceLocation asmloc,
+MSAsmStmt::MSAsmStmt(ASTContext &C,
+                     SourceLocation asmloc, SourceLocation lbraceloc,
                      bool issimple, bool isvolatile, ArrayRef<Token> asmtoks,
                      StringRef asmstr, ArrayRef<StringRef> clobbers,
                      SourceLocation endloc)
-  : Stmt(MSAsmStmtClass), AsmLoc(asmloc), EndLoc(endloc),
+  : Stmt(MSAsmStmtClass), AsmLoc(asmloc), LBraceLoc(lbraceloc), EndLoc(endloc),
     AsmStr(asmstr.str()), IsSimple(issimple), IsVolatile(isvolatile),
     NumAsmToks(asmtoks.size()), NumClobbers(clobbers.size()) {
 
index 2f7cb55c7cc1008adf6aad850d1431dc898d6faa..85d5a79569a60944eff597582354a9c461c5a881 100644 (file)
@@ -432,7 +432,12 @@ void StmtPrinter::VisitAsmStmt(AsmStmt *Node) {
 
 void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) {
   // FIXME: Implement MS style inline asm statement printer.
-  Indent() << "asm ()";
+  Indent() << "__asm ";
+  if (Node->hasBraces())
+    OS << "{\n";
+  OS << *(Node->getAsmString()) << "\n";
+  if (Node->hasBraces())
+    Indent() << "}\n";
 }
 
 void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) {
index 0ff1c8a96a6470050caed96b96672afe8eb8d5a4..0af1d082981393c8142d62b487a5ce240b7d52e8 100644 (file)
@@ -1752,7 +1752,8 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {
   }
 
   // FIXME: We should be passing source locations for better diagnostics.
-  return Actions.ActOnMSAsmStmt(AsmLoc, llvm::makeArrayRef(AsmToks), EndLoc);                               
+  return Actions.ActOnMSAsmStmt(AsmLoc, LBraceLoc,
+                                llvm::makeArrayRef(AsmToks), EndLoc);
 }
 
 /// ParseAsmStatement - Parse a GNU extended asm statement.
index 5bcc33f107c7a39a292a6def1b57f5683b868250..74e8cfed2e5ef321d10ff7f7f48b9fddc79990be 100644 (file)
@@ -2852,6 +2852,7 @@ static std::string buildMSAsmString(Sema &SemaRef,
 }
 
 StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc,
+                                SourceLocation LBraceLoc,
                                 ArrayRef<Token> AsmToks,
                                 SourceLocation EndLoc) {
   // MS-style inline assembly is not fully supported, so emit a warning.
@@ -2862,9 +2863,9 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc,
   if (AsmToks.empty()) {
     StringRef AsmString;
     MSAsmStmt *NS =
-      new (Context) MSAsmStmt(Context, AsmLoc, /* IsSimple */ true,
-                              /* IsVolatile */ true, AsmToks, AsmString,
-                              Clobbers, EndLoc);
+      new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc,
+                              /* IsSimple */ true, /* IsVolatile */ true,
+                              AsmToks, AsmString, Clobbers, EndLoc);
     return Owned(NS);
   }
 
@@ -2888,9 +2889,9 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc,
   // patchMSAsmStrings doesn't correctly patch non-simple asm statements.
   if (!IsSimple) {
     MSAsmStmt *NS =
-      new (Context) MSAsmStmt(Context, AsmLoc, /* IsSimple */ true,
-                              /* IsVolatile */ true, AsmToks, AsmString,
-                              Clobbers, EndLoc);
+      new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc,
+                              /* IsSimple */ true, /* IsVolatile */ true,
+                              AsmToks, AsmString, Clobbers, EndLoc);
     return Owned(NS);
   }
 
@@ -2980,7 +2981,8 @@ StmtResult Sema::ActOnMSAsmStmt(SourceLocation AsmLoc,
   }
 
   MSAsmStmt *NS =
-    new (Context) MSAsmStmt(Context, AsmLoc, IsSimple, /* IsVolatile */ true,
+    new (Context) MSAsmStmt(Context, AsmLoc, LBraceLoc,
+                            IsSimple, /* IsVolatile */ true,
                             AsmToks, AsmString, Clobbers, EndLoc);
 
   return Owned(NS);
index 0516768ac499210c4f4aa363dd7bba9159195655..6c7e9b002522415083f1f875d48110492a9e1b36 100644 (file)
@@ -1185,9 +1185,10 @@ public:
   /// By default, performs semantic analysis to build the new statement.
   /// Subclasses may override this routine to provide different behavior.
   StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc,
+                              SourceLocation LBraceLoc,
                               ArrayRef<Token> AsmToks,
                               SourceLocation EndLoc) {
-    return getSema().ActOnMSAsmStmt(AsmLoc, AsmToks, EndLoc);
+    return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc);
   }
 
   /// \brief Build a new Objective-C \@try statement.
@@ -5610,7 +5611,8 @@ TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
   ArrayRef<Token> AsmToks =
     llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
 
-  return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), AsmToks, S->getEndLoc());
+  return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
+                                       AsmToks, S->getEndLoc());
 }
 
 template<typename Derived>