r179882 - [ms-inline asm] The parsing of C++ identifiers is a task of the front-end parser,

Chad Rosier mcrosier at apple.com
Fri Apr 19 13:37:49 PDT 2013


Author: mcrosier
Date: Fri Apr 19 15:37:49 2013
New Revision: 179882

URL: http://llvm.org/viewvc/llvm-project?rev=179882&view=rev
Log:
[ms-inline asm] The parsing of C++ identifiers is a task of the front-end parser,
not the asm parser.  As such, begin moving the parsing logic in that direction.
This patch is just a temporary hack until the real frontend parser can be hooked
up.  Part of rdar://13663589

Modified:
    cfe/trunk/lib/Sema/SemaStmtAsm.cpp

Modified: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAsm.cpp?rev=179882&r1=179881&r2=179882&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp Fri Apr 19 15:37:49 2013
@@ -494,9 +494,40 @@ public:
 
 }
 
+// FIXME: Temporary hack until the frontend parser is hooked up to parse 
+// variables.
+static bool isIdentifierChar(char c) {
+  return isalnum(c) || c == '_' || c == '$' || c == '.' || c == '@';
+}
+
+static void lexIdentifier(const char *&CurPtr) {
+  while (isIdentifierChar(*CurPtr))
+    ++CurPtr;
+}
+
+static StringRef parseIdentifier(StringRef Identifier) {
+  const char *StartPtr = Identifier.data(), *EndPtr, *CurPtr;
+  EndPtr = StartPtr + Identifier.size();
+  CurPtr = StartPtr;
+  while(CurPtr <= EndPtr) {
+    if (isIdentifierChar(*CurPtr))
+      lexIdentifier(CurPtr);
+    else if (CurPtr[0] == ':' && CurPtr[1] == ':')
+      CurPtr += 2;
+    else
+      break;
+  }
+  return StringRef(StartPtr, CurPtr - StartPtr);
+}
+
 NamedDecl *Sema::LookupInlineAsmIdentifier(StringRef Name, SourceLocation Loc,
                                            unsigned &Length, unsigned &Size, 
                                            unsigned &Type, bool &IsVarDecl) {
+  // FIXME: Temporary hack until the frontend parser is hooked up to parse 
+  // variables.
+  StringRef ParsedName = parseIdentifier(Name);
+  assert (ParsedName == Name && "Identifier not parsed correctly!");
+
   Length = 1;
   Size = 0;
   Type = 0;





More information about the cfe-commits mailing list