Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(610)

Side by Side Diff: utils/TableGen/ClangAttrEmitter.cpp

Issue 5556059: Template instantiation of dependent attributes II
Patch Set: Created 13 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- ClangAttrEmitter.cpp - Generate Clang attribute handling =-*- C++ -*--=// 1 //===- ClangAttrEmitter.cpp - Generate Clang attribute handling =-*- C++ -*--=//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // These tablegen backends emit Clang attribute processing code 10 // These tablegen backends emit Clang attribute processing code
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 virtual ~Argument() {} 84 virtual ~Argument() {}
85 85
86 StringRef getLowerName() const { return lowerName; } 86 StringRef getLowerName() const { return lowerName; }
87 StringRef getUpperName() const { return upperName; } 87 StringRef getUpperName() const { return upperName; }
88 StringRef getAttrName() const { return attrName; } 88 StringRef getAttrName() const { return attrName; }
89 89
90 // These functions print the argument contents formatted in different ways. 90 // These functions print the argument contents formatted in different ways.
91 virtual void writeAccessors(raw_ostream &OS) const = 0; 91 virtual void writeAccessors(raw_ostream &OS) const = 0;
92 virtual void writeAccessorDefinitions(raw_ostream &OS) const {} 92 virtual void writeAccessorDefinitions(raw_ostream &OS) const {}
93 virtual void writeCloneArgs(raw_ostream &OS) const = 0; 93 virtual void writeCloneArgs(raw_ostream &OS) const = 0;
94 virtual void writeTemplateInstantiationArgs(raw_ostream &OS) const = 0;
95 virtual void writeTemplateInstantiation(raw_ostream &OS) const {};
94 virtual void writeCtorBody(raw_ostream &OS) const {} 96 virtual void writeCtorBody(raw_ostream &OS) const {}
95 virtual void writeCtorInitializers(raw_ostream &OS) const = 0; 97 virtual void writeCtorInitializers(raw_ostream &OS) const = 0;
96 virtual void writeCtorParameters(raw_ostream &OS) const = 0; 98 virtual void writeCtorParameters(raw_ostream &OS) const = 0;
97 virtual void writeDeclarations(raw_ostream &OS) const = 0; 99 virtual void writeDeclarations(raw_ostream &OS) const = 0;
98 virtual void writePCHReadArgs(raw_ostream &OS) const = 0; 100 virtual void writePCHReadArgs(raw_ostream &OS) const = 0;
99 virtual void writePCHReadDecls(raw_ostream &OS) const = 0; 101 virtual void writePCHReadDecls(raw_ostream &OS) const = 0;
100 virtual void writePCHWrite(raw_ostream &OS) const = 0; 102 virtual void writePCHWrite(raw_ostream &OS) const = 0;
101 virtual void writeValue(raw_ostream &OS) const = 0; 103 virtual void writeValue(raw_ostream &OS) const = 0;
102 }; 104 };
103 105
104 class SimpleArgument : public Argument { 106 class SimpleArgument : public Argument {
105 std::string type; 107 std::string type;
106 108
107 public: 109 public:
108 SimpleArgument(Record &Arg, StringRef Attr, std::string T) 110 SimpleArgument(Record &Arg, StringRef Attr, std::string T)
109 : Argument(Arg, Attr), type(T) 111 : Argument(Arg, Attr), type(T)
110 {} 112 {}
111 113
114 std::string getType() const { return type; }
115
112 void writeAccessors(raw_ostream &OS) const { 116 void writeAccessors(raw_ostream &OS) const {
113 OS << " " << type << " get" << getUpperName() << "() const {\n"; 117 OS << " " << type << " get" << getUpperName() << "() const {\n";
114 OS << " return " << getLowerName() << ";\n"; 118 OS << " return " << getLowerName() << ";\n";
115 OS << " }"; 119 OS << " }";
116 } 120 }
117 void writeCloneArgs(raw_ostream &OS) const { 121 void writeCloneArgs(raw_ostream &OS) const {
118 OS << getLowerName(); 122 OS << getLowerName();
119 } 123 }
124 void writeTemplateInstantiationArgs(raw_ostream &OS) const {
125 OS << "A->get" << getUpperName() << "()";
126 }
120 void writeCtorInitializers(raw_ostream &OS) const { 127 void writeCtorInitializers(raw_ostream &OS) const {
121 OS << getLowerName() << "(" << getUpperName() << ")"; 128 OS << getLowerName() << "(" << getUpperName() << ")";
122 } 129 }
123 void writeCtorParameters(raw_ostream &OS) const { 130 void writeCtorParameters(raw_ostream &OS) const {
124 OS << type << " " << getUpperName(); 131 OS << type << " " << getUpperName();
125 } 132 }
126 void writeDeclarations(raw_ostream &OS) const { 133 void writeDeclarations(raw_ostream &OS) const {
127 OS << type << " " << getLowerName() << ";"; 134 OS << type << " " << getLowerName() << ";";
128 } 135 }
129 void writePCHReadDecls(raw_ostream &OS) const { 136 void writePCHReadDecls(raw_ostream &OS) const {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 OS << " " << getLowerName() << "Length = S.size();\n"; 178 OS << " " << getLowerName() << "Length = S.size();\n";
172 OS << " this->" << getLowerName() << " = new (C, 1) char [" 179 OS << " this->" << getLowerName() << " = new (C, 1) char ["
173 << getLowerName() << "Length];\n"; 180 << getLowerName() << "Length];\n";
174 OS << " std::memcpy(this->" << getLowerName() << ", S.data(), " 181 OS << " std::memcpy(this->" << getLowerName() << ", S.data(), "
175 << getLowerName() << "Length);\n"; 182 << getLowerName() << "Length);\n";
176 OS << " }"; 183 OS << " }";
177 } 184 }
178 void writeCloneArgs(raw_ostream &OS) const { 185 void writeCloneArgs(raw_ostream &OS) const {
179 OS << "get" << getUpperName() << "()"; 186 OS << "get" << getUpperName() << "()";
180 } 187 }
188 void writeTemplateInstantiationArgs(raw_ostream &OS) const {
189 OS << "A->get" << getUpperName() << "()";
190 }
181 void writeCtorBody(raw_ostream &OS) const { 191 void writeCtorBody(raw_ostream &OS) const {
182 OS << " std::memcpy(" << getLowerName() << ", " << getUpperName() 192 OS << " std::memcpy(" << getLowerName() << ", " << getUpperName()
183 << ".data(), " << getLowerName() << "Length);"; 193 << ".data(), " << getLowerName() << "Length);";
184 } 194 }
185 void writeCtorInitializers(raw_ostream &OS) const { 195 void writeCtorInitializers(raw_ostream &OS) const {
186 OS << getLowerName() << "Length(" << getUpperName() << ".size())," 196 OS << getLowerName() << "Length(" << getUpperName() << ".size()),"
187 << getLowerName() << "(new (Ctx, 1) char[" << getLowerName() 197 << getLowerName() << "(new (Ctx, 1) char[" << getLowerName()
188 << "Length])"; 198 << "Length])";
189 } 199 }
190 void writeCtorParameters(raw_ostream &OS) const { 200 void writeCtorParameters(raw_ostream &OS) const {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 OS << " else\n"; 271 OS << " else\n";
262 OS << " return 0; // FIXME\n"; 272 OS << " return 0; // FIXME\n";
263 OS << "}\n"; 273 OS << "}\n";
264 } 274 }
265 void writeCloneArgs(raw_ostream &OS) const { 275 void writeCloneArgs(raw_ostream &OS) const {
266 OS << "is" << getLowerName() << "Expr, is" << getLowerName() 276 OS << "is" << getLowerName() << "Expr, is" << getLowerName()
267 << "Expr ? static_cast<void*>(" << getLowerName() 277 << "Expr ? static_cast<void*>(" << getLowerName()
268 << "Expr) : " << getLowerName() 278 << "Expr) : " << getLowerName()
269 << "Type"; 279 << "Type";
270 } 280 }
281 void writeTemplateInstantiationArgs(raw_ostream &OS) const {
282 // FIXME: move the definition in Sema::InstantiateAttrs to here.
283 // In the meantime, aligned attributes are cloned.
284 }
271 void writeCtorBody(raw_ostream &OS) const { 285 void writeCtorBody(raw_ostream &OS) const {
272 OS << " if (is" << getLowerName() << "Expr)\n"; 286 OS << " if (is" << getLowerName() << "Expr)\n";
273 OS << " " << getLowerName() << "Expr = reinterpret_cast<Expr *>(" 287 OS << " " << getLowerName() << "Expr = reinterpret_cast<Expr *>("
274 << getUpperName() << ");\n"; 288 << getUpperName() << ");\n";
275 OS << " else\n"; 289 OS << " else\n";
276 OS << " " << getLowerName() 290 OS << " " << getLowerName()
277 << "Type = reinterpret_cast<TypeSourceInfo *>(" << getUpperName() 291 << "Type = reinterpret_cast<TypeSourceInfo *>(" << getUpperName()
278 << ");"; 292 << ");";
279 } 293 }
280 void writeCtorInitializers(raw_ostream &OS) const { 294 void writeCtorInitializers(raw_ostream &OS) const {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 OS << " return " << getLowerName() << " + " << getLowerName() 350 OS << " return " << getLowerName() << " + " << getLowerName()
337 << "Size;\n"; 351 << "Size;\n";
338 OS << " }\n"; 352 OS << " }\n";
339 OS << " unsigned " << getLowerName() << "_size() const {\n" 353 OS << " unsigned " << getLowerName() << "_size() const {\n"
340 << " return " << getLowerName() << "Size;\n;"; 354 << " return " << getLowerName() << "Size;\n;";
341 OS << " }"; 355 OS << " }";
342 } 356 }
343 void writeCloneArgs(raw_ostream &OS) const { 357 void writeCloneArgs(raw_ostream &OS) const {
344 OS << getLowerName() << ", " << getLowerName() << "Size"; 358 OS << getLowerName() << ", " << getLowerName() << "Size";
345 } 359 }
360 void writeTemplateInstantiationArgs(raw_ostream &OS) const {
361 // This isn't elegant, but we have to go through public methods...
362 OS << "A->" << getLowerName() << "_begin(), "
363 << "A->" << getLowerName() << "_size()";
364 }
346 void writeCtorBody(raw_ostream &OS) const { 365 void writeCtorBody(raw_ostream &OS) const {
347 // FIXME: memcpy is not safe on non-trivial types. 366 // FIXME: memcpy is not safe on non-trivial types.
348 OS << " std::memcpy(" << getLowerName() << ", " << getUpperName() 367 OS << " std::memcpy(" << getLowerName() << ", " << getUpperName()
349 << ", " << getLowerName() << "Size * sizeof(" << getType() << "));\n"; 368 << ", " << getLowerName() << "Size * sizeof(" << getType() << "));\n";
350 } 369 }
351 void writeCtorInitializers(raw_ostream &OS) const { 370 void writeCtorInitializers(raw_ostream &OS) const {
352 OS << getLowerName() << "Size(" << getUpperName() << "Size), " 371 OS << getLowerName() << "Size(" << getUpperName() << "Size), "
353 << getLowerName() << "(new (Ctx, 16) " << getType() << "[" 372 << getLowerName() << "(new (Ctx, 16) " << getType() << "["
354 << getLowerName() << "Size])"; 373 << getLowerName() << "Size])";
355 } 374 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 {} 426 {}
408 427
409 void writeAccessors(raw_ostream &OS) const { 428 void writeAccessors(raw_ostream &OS) const {
410 OS << " " << type << " get" << getUpperName() << "() const {\n"; 429 OS << " " << type << " get" << getUpperName() << "() const {\n";
411 OS << " return " << getLowerName() << ";\n"; 430 OS << " return " << getLowerName() << ";\n";
412 OS << " }"; 431 OS << " }";
413 } 432 }
414 void writeCloneArgs(raw_ostream &OS) const { 433 void writeCloneArgs(raw_ostream &OS) const {
415 OS << getLowerName(); 434 OS << getLowerName();
416 } 435 }
436 void writeTemplateInstantiationArgs(raw_ostream &OS) const {
437 OS << "A->get" << getUpperName() << "()";
438 }
417 void writeCtorInitializers(raw_ostream &OS) const { 439 void writeCtorInitializers(raw_ostream &OS) const {
418 OS << getLowerName() << "(" << getUpperName() << ")"; 440 OS << getLowerName() << "(" << getUpperName() << ")";
419 } 441 }
420 void writeCtorParameters(raw_ostream &OS) const { 442 void writeCtorParameters(raw_ostream &OS) const {
421 OS << type << " " << getUpperName(); 443 OS << type << " " << getUpperName();
422 } 444 }
423 void writeDeclarations(raw_ostream &OS) const { 445 void writeDeclarations(raw_ostream &OS) const {
424 // Calculate the various enum values 446 // Calculate the various enum values
425 std::vector<StringRef> uniques(enums); 447 std::vector<StringRef> uniques(enums);
426 std::sort(uniques.begin(), uniques.end()); 448 std::sort(uniques.begin(), uniques.end());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 OS << " return " << getLowerName() << ";\n"; 492 OS << " return " << getLowerName() << ";\n";
471 OS << " }\n"; 493 OS << " }\n";
472 OS << " void set" << getUpperName()· 494 OS << " void set" << getUpperName()·
473 << "(ASTContext &C, VersionTuple V) {\n"; 495 << "(ASTContext &C, VersionTuple V) {\n";
474 OS << " " << getLowerName() << " = V;\n"; 496 OS << " " << getLowerName() << " = V;\n";
475 OS << " }"; 497 OS << " }";
476 } 498 }
477 void writeCloneArgs(raw_ostream &OS) const { 499 void writeCloneArgs(raw_ostream &OS) const {
478 OS << "get" << getUpperName() << "()"; 500 OS << "get" << getUpperName() << "()";
479 } 501 }
502 void writeTemplateInstantiationArgs(raw_ostream &OS) const {
503 OS << "A->get" << getUpperName() << "()";
504 }
480 void writeCtorBody(raw_ostream &OS) const { 505 void writeCtorBody(raw_ostream &OS) const {
481 } 506 }
482 void writeCtorInitializers(raw_ostream &OS) const { 507 void writeCtorInitializers(raw_ostream &OS) const {
483 OS << getLowerName() << "(" << getUpperName() << ")"; 508 OS << getLowerName() << "(" << getUpperName() << ")";
484 } 509 }
485 void writeCtorParameters(raw_ostream &OS) const { 510 void writeCtorParameters(raw_ostream &OS) const {
486 OS << "VersionTuple " << getUpperName(); 511 OS << "VersionTuple " << getUpperName();
487 } 512 }
488 void writeDeclarations(raw_ostream &OS) const { 513 void writeDeclarations(raw_ostream &OS) const {
489 OS << "VersionTuple " << getLowerName() << ";\n"; 514 OS << "VersionTuple " << getLowerName() << ";\n";
490 } 515 }
491 void writePCHReadDecls(raw_ostream &OS) const { 516 void writePCHReadDecls(raw_ostream &OS) const {
492 OS << " VersionTuple " << getLowerName() 517 OS << " VersionTuple " << getLowerName()
493 << "= ReadVersionTuple(Record, Idx);\n"; 518 << "= ReadVersionTuple(Record, Idx);\n";
494 } 519 }
495 void writePCHReadArgs(raw_ostream &OS) const { 520 void writePCHReadArgs(raw_ostream &OS) const {
496 OS << getLowerName(); 521 OS << getLowerName();
497 } 522 }
498 void writePCHWrite(raw_ostream &OS) const { 523 void writePCHWrite(raw_ostream &OS) const {
499 OS << " AddVersionTuple(SA->get" << getUpperName() << "(), Record);\n"; 524 OS << " AddVersionTuple(SA->get" << getUpperName() << "(), Record);\n";
500 } 525 }
501 void writeValue(raw_ostream &OS) const { 526 void writeValue(raw_ostream &OS) const {
502 OS << getLowerName() << "=\" << get" << getUpperName() << "() << \""; 527 OS << getLowerName() << "=\" << get" << getUpperName() << "() << \"";
503 } 528 }
504 }; 529 };
530
531 class ExprArgument : public SimpleArgument {
532 public:
533 ExprArgument(Record &Arg, StringRef Attr)
534 : SimpleArgument(Arg, Attr, "Expr *")
535 {}
536
537 void writeTemplateInstantiationArgs(raw_ostream &OS) const {
538 OS << "tempInst" << getUpperName();
539 }
540
541 void writeTemplateInstantiation(raw_ostream &OS) const {
542 OS << " " << getType() << " tempInst" << getUpperName() << ";\n";
543 OS << " {\n";
544 OS << " EnterExpressionEvaluationContext "
545 << "Unevaluated(S, Sema::Unevaluated);\n";
546 OS << " ExprResult " << "Result = S.SubstExpr("
547 << "A->get" << getUpperName() << "(), TemplateArgs);\n";
548 OS << " tempInst" << getUpperName() << " = "
549 << "Result.takeAs<Expr>();\n";
550 OS << " }\n";
551 }
552 };
553
554 class VariadicExprArgument : public VariadicArgument {
555 public:
556 VariadicExprArgument(Record &Arg, StringRef Attr)
557 : VariadicArgument(Arg, Attr, "Expr *")
558 {}
559
560 void writeTemplateInstantiationArgs(raw_ostream &OS) const {
561 OS << "tempInst" << getUpperName() << ", "
562 << "A->" << getLowerName() << "_size()";
563 }
564
565 void writeTemplateInstantiation(raw_ostream &OS) const {
566 OS << " " << getType() << " *tempInst" << getUpperName()
567 << " = new (C, 16) " << getType()
568 << "[A->" << getLowerName() << "_size()];\n";
569 OS << " {\n";
570 OS << " EnterExpressionEvaluationContext "
571 << "Unevaluated(S, Sema::Unevaluated);\n";
572 OS << " " << getType() << " *TI = tempInst" << getUpperName()
573 << ";\n";
574 OS << " " << getType() << " *I = A->" << getLowerName()
575 << "_begin();\n";
576 OS << " " << getType() << " *E = A->" << getLowerName()
577 << "_end();\n";
578 OS << " for (; I != E; ++I, ++TI) {\n";
579 OS << " ExprResult Result = S.SubstExpr(*I, TemplateArgs);\n";
580 OS << " *TI = Result.takeAs<Expr>();\n";
581 OS << " }\n";
582 OS << " }\n";
583 }
584 };
505 } 585 }
506 586
507 static Argument *createArgument(Record &Arg, StringRef Attr, 587 static Argument *createArgument(Record &Arg, StringRef Attr,
508 Record *Search = 0) { 588 Record *Search = 0) {
509 if (!Search) 589 if (!Search)
510 Search = &Arg; 590 Search = &Arg;
511 591
512 Argument *Ptr = 0; 592 Argument *Ptr = 0;
513 llvm::StringRef ArgName = Search->getName(); 593 llvm::StringRef ArgName = Search->getName();
514 594
515 if (ArgName == "AlignedArgument") Ptr = new AlignedArgument(Arg, Attr); 595 if (ArgName == "AlignedArgument") Ptr = new AlignedArgument(Arg, Attr);
516 else if (ArgName == "EnumArgument") Ptr = new EnumArgument(Arg, Attr); 596 else if (ArgName == "EnumArgument") Ptr = new EnumArgument(Arg, Attr);
517 else if (ArgName == "ExprArgument") Ptr = new SimpleArgument(Arg, Attr, 597 else if (ArgName == "ExprArgument") Ptr = new ExprArgument(Arg, Attr);
518 "Expr *");
519 else if (ArgName == "FunctionArgument") 598 else if (ArgName == "FunctionArgument")
520 Ptr = new SimpleArgument(Arg, Attr, "FunctionDecl *"); 599 Ptr = new SimpleArgument(Arg, Attr, "FunctionDecl *");
521 else if (ArgName == "IdentifierArgument") 600 else if (ArgName == "IdentifierArgument")
522 Ptr = new SimpleArgument(Arg, Attr, "IdentifierInfo *"); 601 Ptr = new SimpleArgument(Arg, Attr, "IdentifierInfo *");
523 else if (ArgName == "BoolArgument") Ptr = new SimpleArgument(Arg, Attr,· 602 else if (ArgName == "BoolArgument") Ptr = new SimpleArgument(Arg, Attr,·
524 "bool"); 603 "bool");
525 else if (ArgName == "IntArgument") Ptr = new SimpleArgument(Arg, Attr, "int"); 604 else if (ArgName == "IntArgument") Ptr = new SimpleArgument(Arg, Attr, "int");
526 else if (ArgName == "StringArgument") Ptr = new StringArgument(Arg, Attr); 605 else if (ArgName == "StringArgument") Ptr = new StringArgument(Arg, Attr);
527 else if (ArgName == "TypeArgument") 606 else if (ArgName == "TypeArgument")
528 Ptr = new SimpleArgument(Arg, Attr, "QualType"); 607 Ptr = new SimpleArgument(Arg, Attr, "QualType");
529 else if (ArgName == "UnsignedArgument") 608 else if (ArgName == "UnsignedArgument")
530 Ptr = new SimpleArgument(Arg, Attr, "unsigned"); 609 Ptr = new SimpleArgument(Arg, Attr, "unsigned");
531 else if (ArgName == "SourceLocArgument") 610 else if (ArgName == "SourceLocArgument")
532 Ptr = new SimpleArgument(Arg, Attr, "SourceLocation"); 611 Ptr = new SimpleArgument(Arg, Attr, "SourceLocation");
533 else if (ArgName == "VariadicUnsignedArgument") 612 else if (ArgName == "VariadicUnsignedArgument")
534 Ptr = new VariadicArgument(Arg, Attr, "unsigned"); 613 Ptr = new VariadicArgument(Arg, Attr, "unsigned");
535 else if (ArgName == "VariadicExprArgument") 614 else if (ArgName == "VariadicExprArgument")
536 Ptr = new VariadicArgument(Arg, Attr, "Expr *"); 615 Ptr = new VariadicExprArgument(Arg, Attr);
537 else if (ArgName == "VersionArgument") 616 else if (ArgName == "VersionArgument")
538 Ptr = new VersionArgument(Arg, Attr); 617 Ptr = new VersionArgument(Arg, Attr);
539 618
540 if (!Ptr) { 619 if (!Ptr) {
541 std::vector<Record*> Bases = Search->getSuperClasses(); 620 std::vector<Record*> Bases = Search->getSuperClasses();
542 for (std::vector<Record*>::iterator i = Bases.begin(), e = Bases.end(); 621 for (std::vector<Record*>::iterator i = Bases.begin(), e = Bases.end();
543 i != e; ++i) { 622 i != e; ++i) {
544 Ptr = createArgument(Arg, Attr, *i); 623 Ptr = createArgument(Arg, Attr, *i);
545 if (Ptr) 624 if (Ptr)
546 break; 625 break;
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 std::vector<StringRef> Spellings = 925 std::vector<StringRef> Spellings =
847 getValueAsListOfStrings(Attr, "Spellings"); 926 getValueAsListOfStrings(Attr, "Spellings");
848 927
849 for (std::vector<StringRef>::const_iterator I = Spellings.begin(), 928 for (std::vector<StringRef>::const_iterator I = Spellings.begin(),
850 E = Spellings.end(); I != E; ++I) { 929 E = Spellings.end(); I != E; ++I) {
851 OS << ".Case(\"" << (*I) << "\", " << LateParsed << ")\n"; 930 OS << ".Case(\"" << (*I) << "\", " << LateParsed << ")\n";
852 } 931 }
853 } 932 }
854 } 933 }
855 } 934 }
935
936
937 void ClangAttrTemplateInstantiateEmitter::run(raw_ostream &OS) {
938 OS << "// This file is generated by TableGen. Do not edit.\n\n";
939
940 std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr");
941
942 OS << "Attr* instantiateTemplateAttribute(const Attr *At, ASTContext &C, "
943 << "Sema &S,\n"
944 << " const MultiLevelTemplateArgumentList &TemplateArgs) {\n"
945 << " switch (At->getKind()) {\n"
946 << " default: {\n"
947 << " assert(0 && \"Unknown attribute!\");\n"
948 << " return 0;\n"
949 << " }\n";
950
951 for (std::vector<Record*>::iterator I = Attrs.begin(), E = Attrs.end();
952 I != E; ++I) {
953 Record &R = **I;
954
955 OS << " case attr::" << R.getName() << ": {\n";
956 OS << " const " << R.getName() << "Attr *A = reinterpret_cast<const "
957 << R.getName() << "Attr*>(At);\n";
958 bool TDependent = R.getValueAsBit("TemplateDependent");
959
960 if (!TDependent) {
961 OS << " return A->clone(C);\n";
962 OS << " }\n";
963 continue;
964 }
965
966 std::vector<Record*> ArgRecords = R.getValueAsListOfDefs("Args");
967 std::vector<Argument*> Args;
968 std::vector<Argument*>::iterator ai, ae;
969 Args.reserve(ArgRecords.size());
970
971 for (std::vector<Record*>::iterator ri = ArgRecords.begin(),
972 re = ArgRecords.end();
973 ri != re; ++ri) {
974 Record &ArgRecord = **ri;
975 Argument *Arg = createArgument(ArgRecord, R.getName());
976 assert(Arg);
977 Args.push_back(Arg);
978 }
979 ae = Args.end();
980
981 for (ai = Args.begin(); ai != ae; ++ai) {
982 (*ai)->writeTemplateInstantiation(OS);
983 }
984 OS << " return new (C) " << R.getName() << "Attr(A->getLocation(), C";
985 for (ai = Args.begin(); ai != ae; ++ai) {
986 OS << ", ";
987 (*ai)->writeTemplateInstantiationArgs(OS);
988 }
989 OS << ");\n }\n";
990 }
991 OS << " } // end switch\n}\n\n";
992 }
993
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b