implement support for C-style string literal concatenation in td files.
authorChris Lattner <sabre@nondot.org>
Wed, 11 Mar 2009 17:08:13 +0000 (17:08 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 11 Mar 2009 17:08:13 +0000 (17:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66663 91177308-0d34-0410-b5e6-96231b3b80d8

test/TableGen/strconcat.td
utils/TableGen/TGParser.cpp

index cdf3928f04d659ec270789830896b84ab2e6c836..fc0d80596c92584ddeb068288c85f4aea5e1d0ca 100644 (file)
@@ -2,6 +2,9 @@
 
 class Y<string S> {
   string T = !strconcat(S, "foo");
+
+  // String values concatenate lexically, as in C.
+  string S = "foo" "bar";
 }
 
 def Z : Y<"fu">;
index 1ea6b9816f6d34a3dac6451152a3ddb0939d6cf1..d31e2a50ee265bc090db904331f6354b6a89cbb2 100644 (file)
@@ -505,7 +505,7 @@ Init *TGParser::ParseIDValue(Record *CurRec,
 ///
 ///   SimpleValue ::= IDValue
 ///   SimpleValue ::= INTVAL
-///   SimpleValue ::= STRVAL
+///   SimpleValue ::= STRVAL+
 ///   SimpleValue ::= CODEFRAGMENT
 ///   SimpleValue ::= '?'
 ///   SimpleValue ::= '{' ValueList '}'
@@ -523,7 +523,19 @@ Init *TGParser::ParseSimpleValue(Record *CurRec) {
   switch (Lex.getCode()) {
   default: TokError("Unknown token when parsing a value"); break;
   case tgtok::IntVal: R = new IntInit(Lex.getCurIntVal()); Lex.Lex(); break;
-  case tgtok::StrVal: R = new StringInit(Lex.getCurStrVal()); Lex.Lex(); break;
+  case tgtok::StrVal: {
+    std::string Val = Lex.getCurStrVal();
+    Lex.Lex();
+    
+    // Handle multiple consequtive concatenated strings.
+    while (Lex.getCode() == tgtok::StrVal) {
+      Val += Lex.getCurStrVal();
+      Lex.Lex();
+    }
+    
+    R = new StringInit(Val);
+    break;
+  }
   case tgtok::CodeFragment:
       R = new CodeInit(Lex.getCurStrVal()); Lex.Lex(); break;
   case tgtok::question: R = new UnsetInit(); Lex.Lex(); break;