Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 1 | //===- ClangAttrEmitter.cpp - Generate Clang attribute handling =-*- C++ -*--=// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // These tablegen backends emit Clang attribute processing code |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Sean Hunt | 93f95f2 | 2012-06-18 16:13:52 +0000 | [diff] [blame^] | 14 | #include "llvm/ADT/SmallString.h" |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/StringSwitch.h" |
| 16 | #include "llvm/TableGen/Record.h" |
Douglas Gregor | 0c19b3c | 2012-05-02 17:33:51 +0000 | [diff] [blame] | 17 | #include "llvm/TableGen/StringMatcher.h" |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 18 | #include "llvm/TableGen/TableGenBackend.h" |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 19 | #include <algorithm> |
| 20 | #include <cctype> |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 21 | #include <set> |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace llvm; |
| 24 | |
| 25 | static const std::vector<StringRef> |
| 26 | getValueAsListOfStrings(Record &R, StringRef FieldName) { |
| 27 | ListInit *List = R.getValueAsListInit(FieldName); |
| 28 | assert (List && "Got a null ListInit"); |
| 29 | |
| 30 | std::vector<StringRef> Strings; |
| 31 | Strings.reserve(List->getSize()); |
| 32 | |
| 33 | for (ListInit::const_iterator i = List->begin(), e = List->end(); |
| 34 | i != e; |
| 35 | ++i) { |
| 36 | assert(*i && "Got a null element in a ListInit"); |
| 37 | if (StringInit *S = dynamic_cast<StringInit *>(*i)) |
| 38 | Strings.push_back(S->getValue()); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 39 | else |
| 40 | assert(false && "Got a non-string, non-code element in a ListInit"); |
| 41 | } |
| 42 | |
| 43 | return Strings; |
| 44 | } |
| 45 | |
| 46 | static std::string ReadPCHRecord(StringRef type) { |
| 47 | return StringSwitch<std::string>(type) |
| 48 | .EndsWith("Decl *", "GetLocalDeclAs<" |
| 49 | + std::string(type, 0, type.size()-1) + ">(F, Record[Idx++])") |
| 50 | .Case("QualType", "getLocalType(F, Record[Idx++])") |
| 51 | .Case("Expr *", "ReadSubExpr()") |
| 52 | .Case("IdentifierInfo *", "GetIdentifierInfo(F, Record, Idx)") |
| 53 | .Case("SourceLocation", "ReadSourceLocation(F, Record, Idx)") |
| 54 | .Default("Record[Idx++]"); |
| 55 | } |
| 56 | |
| 57 | // Assumes that the way to get the value is SA->getname() |
| 58 | static std::string WritePCHRecord(StringRef type, StringRef name) { |
| 59 | return StringSwitch<std::string>(type) |
| 60 | .EndsWith("Decl *", "AddDeclRef(" + std::string(name) + |
| 61 | ", Record);\n") |
| 62 | .Case("QualType", "AddTypeRef(" + std::string(name) + ", Record);\n") |
| 63 | .Case("Expr *", "AddStmt(" + std::string(name) + ");\n") |
| 64 | .Case("IdentifierInfo *", |
| 65 | "AddIdentifierRef(" + std::string(name) + ", Record);\n") |
| 66 | .Case("SourceLocation", |
| 67 | "AddSourceLocation(" + std::string(name) + ", Record);\n") |
| 68 | .Default("Record.push_back(" + std::string(name) + ");\n"); |
| 69 | } |
| 70 | |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 71 | // Normalize attribute name by removing leading and trailing |
| 72 | // underscores. For example, __foo, foo__, __foo__ would |
| 73 | // become foo. |
| 74 | static StringRef NormalizeAttrName(StringRef AttrName) { |
| 75 | if (AttrName.startswith("__")) |
| 76 | AttrName = AttrName.substr(2, AttrName.size()); |
| 77 | |
| 78 | if (AttrName.endswith("__")) |
| 79 | AttrName = AttrName.substr(0, AttrName.size() - 2); |
| 80 | |
| 81 | return AttrName; |
| 82 | } |
| 83 | |
| 84 | // Normalize attribute spelling only if the spelling has both leading |
| 85 | // and trailing underscores. For example, __ms_struct__ will be |
| 86 | // normalized to "ms_struct"; __cdecl will remain intact. |
| 87 | static StringRef NormalizeAttrSpelling(StringRef AttrSpelling) { |
| 88 | if (AttrSpelling.startswith("__") && AttrSpelling.endswith("__")) { |
| 89 | AttrSpelling = AttrSpelling.substr(2, AttrSpelling.size() - 4); |
| 90 | } |
| 91 | |
| 92 | return AttrSpelling; |
| 93 | } |
| 94 | |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 95 | namespace { |
| 96 | class Argument { |
| 97 | std::string lowerName, upperName; |
| 98 | StringRef attrName; |
| 99 | |
| 100 | public: |
| 101 | Argument(Record &Arg, StringRef Attr) |
| 102 | : lowerName(Arg.getValueAsString("Name")), upperName(lowerName), |
| 103 | attrName(Attr) { |
| 104 | if (!lowerName.empty()) { |
| 105 | lowerName[0] = std::tolower(lowerName[0]); |
| 106 | upperName[0] = std::toupper(upperName[0]); |
| 107 | } |
| 108 | } |
| 109 | virtual ~Argument() {} |
| 110 | |
| 111 | StringRef getLowerName() const { return lowerName; } |
| 112 | StringRef getUpperName() const { return upperName; } |
| 113 | StringRef getAttrName() const { return attrName; } |
| 114 | |
| 115 | // These functions print the argument contents formatted in different ways. |
| 116 | virtual void writeAccessors(raw_ostream &OS) const = 0; |
| 117 | virtual void writeAccessorDefinitions(raw_ostream &OS) const {} |
| 118 | virtual void writeCloneArgs(raw_ostream &OS) const = 0; |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 119 | virtual void writeTemplateInstantiationArgs(raw_ostream &OS) const = 0; |
Daniel Dunbar | b880609 | 2012-02-10 06:00:29 +0000 | [diff] [blame] | 120 | virtual void writeTemplateInstantiation(raw_ostream &OS) const {} |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 121 | virtual void writeCtorBody(raw_ostream &OS) const {} |
| 122 | virtual void writeCtorInitializers(raw_ostream &OS) const = 0; |
| 123 | virtual void writeCtorParameters(raw_ostream &OS) const = 0; |
| 124 | virtual void writeDeclarations(raw_ostream &OS) const = 0; |
| 125 | virtual void writePCHReadArgs(raw_ostream &OS) const = 0; |
| 126 | virtual void writePCHReadDecls(raw_ostream &OS) const = 0; |
| 127 | virtual void writePCHWrite(raw_ostream &OS) const = 0; |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 128 | virtual void writeValue(raw_ostream &OS) const = 0; |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | class SimpleArgument : public Argument { |
| 132 | std::string type; |
| 133 | |
| 134 | public: |
| 135 | SimpleArgument(Record &Arg, StringRef Attr, std::string T) |
| 136 | : Argument(Arg, Attr), type(T) |
| 137 | {} |
| 138 | |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 139 | std::string getType() const { return type; } |
| 140 | |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 141 | void writeAccessors(raw_ostream &OS) const { |
| 142 | OS << " " << type << " get" << getUpperName() << "() const {\n"; |
| 143 | OS << " return " << getLowerName() << ";\n"; |
| 144 | OS << " }"; |
| 145 | } |
| 146 | void writeCloneArgs(raw_ostream &OS) const { |
| 147 | OS << getLowerName(); |
| 148 | } |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 149 | void writeTemplateInstantiationArgs(raw_ostream &OS) const { |
| 150 | OS << "A->get" << getUpperName() << "()"; |
| 151 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 152 | void writeCtorInitializers(raw_ostream &OS) const { |
| 153 | OS << getLowerName() << "(" << getUpperName() << ")"; |
| 154 | } |
| 155 | void writeCtorParameters(raw_ostream &OS) const { |
| 156 | OS << type << " " << getUpperName(); |
| 157 | } |
| 158 | void writeDeclarations(raw_ostream &OS) const { |
| 159 | OS << type << " " << getLowerName() << ";"; |
| 160 | } |
| 161 | void writePCHReadDecls(raw_ostream &OS) const { |
| 162 | std::string read = ReadPCHRecord(type); |
| 163 | OS << " " << type << " " << getLowerName() << " = " << read << ";\n"; |
| 164 | } |
| 165 | void writePCHReadArgs(raw_ostream &OS) const { |
| 166 | OS << getLowerName(); |
| 167 | } |
| 168 | void writePCHWrite(raw_ostream &OS) const { |
| 169 | OS << " " << WritePCHRecord(type, "SA->get" + |
| 170 | std::string(getUpperName()) + "()"); |
| 171 | } |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 172 | void writeValue(raw_ostream &OS) const { |
| 173 | if (type == "FunctionDecl *") { |
| 174 | OS << "\" << get" << getUpperName() << "()->getNameInfo().getAsString() << \""; |
| 175 | } else if (type == "IdentifierInfo *") { |
| 176 | OS << "\" << get" << getUpperName() << "()->getName() << \""; |
| 177 | } else if (type == "QualType") { |
| 178 | OS << "\" << get" << getUpperName() << "().getAsString() << \""; |
| 179 | } else if (type == "SourceLocation") { |
| 180 | OS << "\" << get" << getUpperName() << "().getRawEncoding() << \""; |
| 181 | } else { |
| 182 | OS << "\" << get" << getUpperName() << "() << \""; |
| 183 | } |
| 184 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | class StringArgument : public Argument { |
| 188 | public: |
| 189 | StringArgument(Record &Arg, StringRef Attr) |
| 190 | : Argument(Arg, Attr) |
| 191 | {} |
| 192 | |
| 193 | void writeAccessors(raw_ostream &OS) const { |
| 194 | OS << " llvm::StringRef get" << getUpperName() << "() const {\n"; |
| 195 | OS << " return llvm::StringRef(" << getLowerName() << ", " |
| 196 | << getLowerName() << "Length);\n"; |
| 197 | OS << " }\n"; |
| 198 | OS << " unsigned get" << getUpperName() << "Length() const {\n"; |
| 199 | OS << " return " << getLowerName() << "Length;\n"; |
| 200 | OS << " }\n"; |
| 201 | OS << " void set" << getUpperName() |
| 202 | << "(ASTContext &C, llvm::StringRef S) {\n"; |
| 203 | OS << " " << getLowerName() << "Length = S.size();\n"; |
| 204 | OS << " this->" << getLowerName() << " = new (C, 1) char [" |
| 205 | << getLowerName() << "Length];\n"; |
| 206 | OS << " std::memcpy(this->" << getLowerName() << ", S.data(), " |
| 207 | << getLowerName() << "Length);\n"; |
| 208 | OS << " }"; |
| 209 | } |
| 210 | void writeCloneArgs(raw_ostream &OS) const { |
| 211 | OS << "get" << getUpperName() << "()"; |
| 212 | } |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 213 | void writeTemplateInstantiationArgs(raw_ostream &OS) const { |
| 214 | OS << "A->get" << getUpperName() << "()"; |
| 215 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 216 | void writeCtorBody(raw_ostream &OS) const { |
| 217 | OS << " std::memcpy(" << getLowerName() << ", " << getUpperName() |
| 218 | << ".data(), " << getLowerName() << "Length);"; |
| 219 | } |
| 220 | void writeCtorInitializers(raw_ostream &OS) const { |
| 221 | OS << getLowerName() << "Length(" << getUpperName() << ".size())," |
| 222 | << getLowerName() << "(new (Ctx, 1) char[" << getLowerName() |
| 223 | << "Length])"; |
| 224 | } |
| 225 | void writeCtorParameters(raw_ostream &OS) const { |
| 226 | OS << "llvm::StringRef " << getUpperName(); |
| 227 | } |
| 228 | void writeDeclarations(raw_ostream &OS) const { |
| 229 | OS << "unsigned " << getLowerName() << "Length;\n"; |
| 230 | OS << "char *" << getLowerName() << ";"; |
| 231 | } |
| 232 | void writePCHReadDecls(raw_ostream &OS) const { |
| 233 | OS << " std::string " << getLowerName() |
| 234 | << "= ReadString(Record, Idx);\n"; |
| 235 | } |
| 236 | void writePCHReadArgs(raw_ostream &OS) const { |
| 237 | OS << getLowerName(); |
| 238 | } |
| 239 | void writePCHWrite(raw_ostream &OS) const { |
| 240 | OS << " AddString(SA->get" << getUpperName() << "(), Record);\n"; |
| 241 | } |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 242 | void writeValue(raw_ostream &OS) const { |
| 243 | OS << "\\\"\" << get" << getUpperName() << "() << \"\\\""; |
| 244 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | class AlignedArgument : public Argument { |
| 248 | public: |
| 249 | AlignedArgument(Record &Arg, StringRef Attr) |
| 250 | : Argument(Arg, Attr) |
| 251 | {} |
| 252 | |
| 253 | void writeAccessors(raw_ostream &OS) const { |
| 254 | OS << " bool is" << getUpperName() << "Dependent() const;\n"; |
| 255 | |
| 256 | OS << " unsigned get" << getUpperName() << "(ASTContext &Ctx) const;\n"; |
| 257 | |
| 258 | OS << " bool is" << getUpperName() << "Expr() const {\n"; |
| 259 | OS << " return is" << getLowerName() << "Expr;\n"; |
| 260 | OS << " }\n"; |
| 261 | |
| 262 | OS << " Expr *get" << getUpperName() << "Expr() const {\n"; |
| 263 | OS << " assert(is" << getLowerName() << "Expr);\n"; |
| 264 | OS << " return " << getLowerName() << "Expr;\n"; |
| 265 | OS << " }\n"; |
| 266 | |
| 267 | OS << " TypeSourceInfo *get" << getUpperName() << "Type() const {\n"; |
| 268 | OS << " assert(!is" << getLowerName() << "Expr);\n"; |
| 269 | OS << " return " << getLowerName() << "Type;\n"; |
| 270 | OS << " }"; |
| 271 | } |
| 272 | void writeAccessorDefinitions(raw_ostream &OS) const { |
| 273 | OS << "bool " << getAttrName() << "Attr::is" << getUpperName() |
| 274 | << "Dependent() const {\n"; |
| 275 | OS << " if (is" << getLowerName() << "Expr)\n"; |
| 276 | OS << " return " << getLowerName() << "Expr && (" << getLowerName() |
| 277 | << "Expr->isValueDependent() || " << getLowerName() |
| 278 | << "Expr->isTypeDependent());\n"; |
| 279 | OS << " else\n"; |
| 280 | OS << " return " << getLowerName() |
| 281 | << "Type->getType()->isDependentType();\n"; |
| 282 | OS << "}\n"; |
| 283 | |
| 284 | // FIXME: Do not do the calculation here |
| 285 | // FIXME: Handle types correctly |
| 286 | // A null pointer means maximum alignment |
| 287 | // FIXME: Load the platform-specific maximum alignment, rather than |
| 288 | // 16, the x86 max. |
| 289 | OS << "unsigned " << getAttrName() << "Attr::get" << getUpperName() |
| 290 | << "(ASTContext &Ctx) const {\n"; |
| 291 | OS << " assert(!is" << getUpperName() << "Dependent());\n"; |
| 292 | OS << " if (is" << getLowerName() << "Expr)\n"; |
| 293 | OS << " return (" << getLowerName() << "Expr ? " << getLowerName() |
Richard Smith | a6b8b2c | 2011-10-10 18:28:20 +0000 | [diff] [blame] | 294 | << "Expr->EvaluateKnownConstInt(Ctx).getZExtValue() : 16)" |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 295 | << "* Ctx.getCharWidth();\n"; |
| 296 | OS << " else\n"; |
| 297 | OS << " return 0; // FIXME\n"; |
| 298 | OS << "}\n"; |
| 299 | } |
| 300 | void writeCloneArgs(raw_ostream &OS) const { |
| 301 | OS << "is" << getLowerName() << "Expr, is" << getLowerName() |
| 302 | << "Expr ? static_cast<void*>(" << getLowerName() |
| 303 | << "Expr) : " << getLowerName() |
| 304 | << "Type"; |
| 305 | } |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 306 | void writeTemplateInstantiationArgs(raw_ostream &OS) const { |
| 307 | // FIXME: move the definition in Sema::InstantiateAttrs to here. |
| 308 | // In the meantime, aligned attributes are cloned. |
| 309 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 310 | void writeCtorBody(raw_ostream &OS) const { |
| 311 | OS << " if (is" << getLowerName() << "Expr)\n"; |
| 312 | OS << " " << getLowerName() << "Expr = reinterpret_cast<Expr *>(" |
| 313 | << getUpperName() << ");\n"; |
| 314 | OS << " else\n"; |
| 315 | OS << " " << getLowerName() |
| 316 | << "Type = reinterpret_cast<TypeSourceInfo *>(" << getUpperName() |
| 317 | << ");"; |
| 318 | } |
| 319 | void writeCtorInitializers(raw_ostream &OS) const { |
| 320 | OS << "is" << getLowerName() << "Expr(Is" << getUpperName() << "Expr)"; |
| 321 | } |
| 322 | void writeCtorParameters(raw_ostream &OS) const { |
| 323 | OS << "bool Is" << getUpperName() << "Expr, void *" << getUpperName(); |
| 324 | } |
| 325 | void writeDeclarations(raw_ostream &OS) const { |
| 326 | OS << "bool is" << getLowerName() << "Expr;\n"; |
| 327 | OS << "union {\n"; |
| 328 | OS << "Expr *" << getLowerName() << "Expr;\n"; |
| 329 | OS << "TypeSourceInfo *" << getLowerName() << "Type;\n"; |
| 330 | OS << "};"; |
| 331 | } |
| 332 | void writePCHReadArgs(raw_ostream &OS) const { |
| 333 | OS << "is" << getLowerName() << "Expr, " << getLowerName() << "Ptr"; |
| 334 | } |
| 335 | void writePCHReadDecls(raw_ostream &OS) const { |
| 336 | OS << " bool is" << getLowerName() << "Expr = Record[Idx++];\n"; |
| 337 | OS << " void *" << getLowerName() << "Ptr;\n"; |
| 338 | OS << " if (is" << getLowerName() << "Expr)\n"; |
| 339 | OS << " " << getLowerName() << "Ptr = ReadExpr(F);\n"; |
| 340 | OS << " else\n"; |
| 341 | OS << " " << getLowerName() |
| 342 | << "Ptr = GetTypeSourceInfo(F, Record, Idx);\n"; |
| 343 | } |
| 344 | void writePCHWrite(raw_ostream &OS) const { |
| 345 | OS << " Record.push_back(SA->is" << getUpperName() << "Expr());\n"; |
| 346 | OS << " if (SA->is" << getUpperName() << "Expr())\n"; |
| 347 | OS << " AddStmt(SA->get" << getUpperName() << "Expr());\n"; |
| 348 | OS << " else\n"; |
| 349 | OS << " AddTypeSourceInfo(SA->get" << getUpperName() |
| 350 | << "Type(), Record);\n"; |
| 351 | } |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 352 | void writeValue(raw_ostream &OS) const { |
| 353 | OS << "\" << get" << getUpperName() << "(Ctx) << \""; |
| 354 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | class VariadicArgument : public Argument { |
| 358 | std::string type; |
| 359 | |
| 360 | public: |
| 361 | VariadicArgument(Record &Arg, StringRef Attr, std::string T) |
| 362 | : Argument(Arg, Attr), type(T) |
| 363 | {} |
| 364 | |
| 365 | std::string getType() const { return type; } |
| 366 | |
| 367 | void writeAccessors(raw_ostream &OS) const { |
| 368 | OS << " typedef " << type << "* " << getLowerName() << "_iterator;\n"; |
| 369 | OS << " " << getLowerName() << "_iterator " << getLowerName() |
| 370 | << "_begin() const {\n"; |
| 371 | OS << " return " << getLowerName() << ";\n"; |
| 372 | OS << " }\n"; |
| 373 | OS << " " << getLowerName() << "_iterator " << getLowerName() |
| 374 | << "_end() const {\n"; |
| 375 | OS << " return " << getLowerName() << " + " << getLowerName() |
| 376 | << "Size;\n"; |
| 377 | OS << " }\n"; |
| 378 | OS << " unsigned " << getLowerName() << "_size() const {\n" |
DeLesley Hutchins | 23323e0 | 2012-01-20 22:50:54 +0000 | [diff] [blame] | 379 | << " return " << getLowerName() << "Size;\n"; |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 380 | OS << " }"; |
| 381 | } |
| 382 | void writeCloneArgs(raw_ostream &OS) const { |
| 383 | OS << getLowerName() << ", " << getLowerName() << "Size"; |
| 384 | } |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 385 | void writeTemplateInstantiationArgs(raw_ostream &OS) const { |
| 386 | // This isn't elegant, but we have to go through public methods... |
| 387 | OS << "A->" << getLowerName() << "_begin(), " |
| 388 | << "A->" << getLowerName() << "_size()"; |
| 389 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 390 | void writeCtorBody(raw_ostream &OS) const { |
| 391 | // FIXME: memcpy is not safe on non-trivial types. |
| 392 | OS << " std::memcpy(" << getLowerName() << ", " << getUpperName() |
| 393 | << ", " << getLowerName() << "Size * sizeof(" << getType() << "));\n"; |
| 394 | } |
| 395 | void writeCtorInitializers(raw_ostream &OS) const { |
| 396 | OS << getLowerName() << "Size(" << getUpperName() << "Size), " |
| 397 | << getLowerName() << "(new (Ctx, 16) " << getType() << "[" |
| 398 | << getLowerName() << "Size])"; |
| 399 | } |
| 400 | void writeCtorParameters(raw_ostream &OS) const { |
| 401 | OS << getType() << " *" << getUpperName() << ", unsigned " |
| 402 | << getUpperName() << "Size"; |
| 403 | } |
| 404 | void writeDeclarations(raw_ostream &OS) const { |
| 405 | OS << " unsigned " << getLowerName() << "Size;\n"; |
| 406 | OS << " " << getType() << " *" << getLowerName() << ";"; |
| 407 | } |
| 408 | void writePCHReadDecls(raw_ostream &OS) const { |
| 409 | OS << " unsigned " << getLowerName() << "Size = Record[Idx++];\n"; |
| 410 | OS << " llvm::SmallVector<" << type << ", 4> " << getLowerName() |
| 411 | << ";\n"; |
| 412 | OS << " " << getLowerName() << ".reserve(" << getLowerName() |
| 413 | << "Size);\n"; |
| 414 | OS << " for (unsigned i = " << getLowerName() << "Size; i; --i)\n"; |
| 415 | |
| 416 | std::string read = ReadPCHRecord(type); |
| 417 | OS << " " << getLowerName() << ".push_back(" << read << ");\n"; |
| 418 | } |
| 419 | void writePCHReadArgs(raw_ostream &OS) const { |
| 420 | OS << getLowerName() << ".data(), " << getLowerName() << "Size"; |
| 421 | } |
| 422 | void writePCHWrite(raw_ostream &OS) const{ |
| 423 | OS << " Record.push_back(SA->" << getLowerName() << "_size());\n"; |
| 424 | OS << " for (" << getAttrName() << "Attr::" << getLowerName() |
| 425 | << "_iterator i = SA->" << getLowerName() << "_begin(), e = SA->" |
| 426 | << getLowerName() << "_end(); i != e; ++i)\n"; |
| 427 | OS << " " << WritePCHRecord(type, "(*i)"); |
| 428 | } |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 429 | void writeValue(raw_ostream &OS) const { |
| 430 | OS << "\";\n"; |
| 431 | OS << " bool isFirst = true;\n" |
| 432 | << " for (" << getAttrName() << "Attr::" << getLowerName() |
| 433 | << "_iterator i = " << getLowerName() << "_begin(), e = " |
| 434 | << getLowerName() << "_end(); i != e; ++i) {\n" |
| 435 | << " if (isFirst) isFirst = false;\n" |
| 436 | << " else OS << \", \";\n" |
| 437 | << " OS << *i;\n" |
| 438 | << " }\n"; |
| 439 | OS << " OS << \""; |
| 440 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 441 | }; |
| 442 | |
| 443 | class EnumArgument : public Argument { |
| 444 | std::string type; |
| 445 | std::vector<StringRef> values, enums; |
| 446 | public: |
| 447 | EnumArgument(Record &Arg, StringRef Attr) |
| 448 | : Argument(Arg, Attr), type(Arg.getValueAsString("Type")), |
| 449 | values(getValueAsListOfStrings(Arg, "Values")), |
| 450 | enums(getValueAsListOfStrings(Arg, "Enums")) |
| 451 | {} |
| 452 | |
| 453 | void writeAccessors(raw_ostream &OS) const { |
| 454 | OS << " " << type << " get" << getUpperName() << "() const {\n"; |
| 455 | OS << " return " << getLowerName() << ";\n"; |
| 456 | OS << " }"; |
| 457 | } |
| 458 | void writeCloneArgs(raw_ostream &OS) const { |
| 459 | OS << getLowerName(); |
| 460 | } |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 461 | void writeTemplateInstantiationArgs(raw_ostream &OS) const { |
| 462 | OS << "A->get" << getUpperName() << "()"; |
| 463 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 464 | void writeCtorInitializers(raw_ostream &OS) const { |
| 465 | OS << getLowerName() << "(" << getUpperName() << ")"; |
| 466 | } |
| 467 | void writeCtorParameters(raw_ostream &OS) const { |
| 468 | OS << type << " " << getUpperName(); |
| 469 | } |
| 470 | void writeDeclarations(raw_ostream &OS) const { |
| 471 | // Calculate the various enum values |
| 472 | std::vector<StringRef> uniques(enums); |
| 473 | std::sort(uniques.begin(), uniques.end()); |
| 474 | uniques.erase(std::unique(uniques.begin(), uniques.end()), |
| 475 | uniques.end()); |
| 476 | // FIXME: Emit a proper error |
| 477 | assert(!uniques.empty()); |
| 478 | |
| 479 | std::vector<StringRef>::iterator i = uniques.begin(), |
| 480 | e = uniques.end(); |
| 481 | // The last one needs to not have a comma. |
| 482 | --e; |
| 483 | |
| 484 | OS << "public:\n"; |
| 485 | OS << " enum " << type << " {\n"; |
| 486 | for (; i != e; ++i) |
| 487 | OS << " " << *i << ",\n"; |
| 488 | OS << " " << *e << "\n"; |
| 489 | OS << " };\n"; |
| 490 | OS << "private:\n"; |
| 491 | OS << " " << type << " " << getLowerName() << ";"; |
| 492 | } |
| 493 | void writePCHReadDecls(raw_ostream &OS) const { |
| 494 | OS << " " << getAttrName() << "Attr::" << type << " " << getLowerName() |
| 495 | << "(static_cast<" << getAttrName() << "Attr::" << type |
| 496 | << ">(Record[Idx++]));\n"; |
| 497 | } |
| 498 | void writePCHReadArgs(raw_ostream &OS) const { |
| 499 | OS << getLowerName(); |
| 500 | } |
| 501 | void writePCHWrite(raw_ostream &OS) const { |
| 502 | OS << "Record.push_back(SA->get" << getUpperName() << "());\n"; |
| 503 | } |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 504 | void writeValue(raw_ostream &OS) const { |
| 505 | OS << "\" << get" << getUpperName() << "() << \""; |
| 506 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 507 | }; |
| 508 | |
| 509 | class VersionArgument : public Argument { |
| 510 | public: |
| 511 | VersionArgument(Record &Arg, StringRef Attr) |
| 512 | : Argument(Arg, Attr) |
| 513 | {} |
| 514 | |
| 515 | void writeAccessors(raw_ostream &OS) const { |
| 516 | OS << " VersionTuple get" << getUpperName() << "() const {\n"; |
| 517 | OS << " return " << getLowerName() << ";\n"; |
| 518 | OS << " }\n"; |
| 519 | OS << " void set" << getUpperName() |
| 520 | << "(ASTContext &C, VersionTuple V) {\n"; |
| 521 | OS << " " << getLowerName() << " = V;\n"; |
| 522 | OS << " }"; |
| 523 | } |
| 524 | void writeCloneArgs(raw_ostream &OS) const { |
| 525 | OS << "get" << getUpperName() << "()"; |
| 526 | } |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 527 | void writeTemplateInstantiationArgs(raw_ostream &OS) const { |
| 528 | OS << "A->get" << getUpperName() << "()"; |
| 529 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 530 | void writeCtorBody(raw_ostream &OS) const { |
| 531 | } |
| 532 | void writeCtorInitializers(raw_ostream &OS) const { |
| 533 | OS << getLowerName() << "(" << getUpperName() << ")"; |
| 534 | } |
| 535 | void writeCtorParameters(raw_ostream &OS) const { |
| 536 | OS << "VersionTuple " << getUpperName(); |
| 537 | } |
| 538 | void writeDeclarations(raw_ostream &OS) const { |
| 539 | OS << "VersionTuple " << getLowerName() << ";\n"; |
| 540 | } |
| 541 | void writePCHReadDecls(raw_ostream &OS) const { |
| 542 | OS << " VersionTuple " << getLowerName() |
| 543 | << "= ReadVersionTuple(Record, Idx);\n"; |
| 544 | } |
| 545 | void writePCHReadArgs(raw_ostream &OS) const { |
| 546 | OS << getLowerName(); |
| 547 | } |
| 548 | void writePCHWrite(raw_ostream &OS) const { |
| 549 | OS << " AddVersionTuple(SA->get" << getUpperName() << "(), Record);\n"; |
| 550 | } |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 551 | void writeValue(raw_ostream &OS) const { |
| 552 | OS << getLowerName() << "=\" << get" << getUpperName() << "() << \""; |
| 553 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 554 | }; |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 555 | |
| 556 | class ExprArgument : public SimpleArgument { |
| 557 | public: |
| 558 | ExprArgument(Record &Arg, StringRef Attr) |
| 559 | : SimpleArgument(Arg, Attr, "Expr *") |
| 560 | {} |
| 561 | |
| 562 | void writeTemplateInstantiationArgs(raw_ostream &OS) const { |
| 563 | OS << "tempInst" << getUpperName(); |
| 564 | } |
| 565 | |
| 566 | void writeTemplateInstantiation(raw_ostream &OS) const { |
| 567 | OS << " " << getType() << " tempInst" << getUpperName() << ";\n"; |
| 568 | OS << " {\n"; |
| 569 | OS << " EnterExpressionEvaluationContext " |
| 570 | << "Unevaluated(S, Sema::Unevaluated);\n"; |
| 571 | OS << " ExprResult " << "Result = S.SubstExpr(" |
| 572 | << "A->get" << getUpperName() << "(), TemplateArgs);\n"; |
| 573 | OS << " tempInst" << getUpperName() << " = " |
| 574 | << "Result.takeAs<Expr>();\n"; |
| 575 | OS << " }\n"; |
| 576 | } |
| 577 | }; |
| 578 | |
| 579 | class VariadicExprArgument : public VariadicArgument { |
| 580 | public: |
| 581 | VariadicExprArgument(Record &Arg, StringRef Attr) |
| 582 | : VariadicArgument(Arg, Attr, "Expr *") |
| 583 | {} |
| 584 | |
| 585 | void writeTemplateInstantiationArgs(raw_ostream &OS) const { |
| 586 | OS << "tempInst" << getUpperName() << ", " |
| 587 | << "A->" << getLowerName() << "_size()"; |
| 588 | } |
| 589 | |
| 590 | void writeTemplateInstantiation(raw_ostream &OS) const { |
| 591 | OS << " " << getType() << " *tempInst" << getUpperName() |
| 592 | << " = new (C, 16) " << getType() |
| 593 | << "[A->" << getLowerName() << "_size()];\n"; |
| 594 | OS << " {\n"; |
| 595 | OS << " EnterExpressionEvaluationContext " |
| 596 | << "Unevaluated(S, Sema::Unevaluated);\n"; |
| 597 | OS << " " << getType() << " *TI = tempInst" << getUpperName() |
| 598 | << ";\n"; |
| 599 | OS << " " << getType() << " *I = A->" << getLowerName() |
| 600 | << "_begin();\n"; |
| 601 | OS << " " << getType() << " *E = A->" << getLowerName() |
| 602 | << "_end();\n"; |
| 603 | OS << " for (; I != E; ++I, ++TI) {\n"; |
| 604 | OS << " ExprResult Result = S.SubstExpr(*I, TemplateArgs);\n"; |
| 605 | OS << " *TI = Result.takeAs<Expr>();\n"; |
| 606 | OS << " }\n"; |
| 607 | OS << " }\n"; |
| 608 | } |
| 609 | }; |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | static Argument *createArgument(Record &Arg, StringRef Attr, |
| 613 | Record *Search = 0) { |
| 614 | if (!Search) |
| 615 | Search = &Arg; |
| 616 | |
| 617 | Argument *Ptr = 0; |
| 618 | llvm::StringRef ArgName = Search->getName(); |
| 619 | |
| 620 | if (ArgName == "AlignedArgument") Ptr = new AlignedArgument(Arg, Attr); |
| 621 | else if (ArgName == "EnumArgument") Ptr = new EnumArgument(Arg, Attr); |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 622 | else if (ArgName == "ExprArgument") Ptr = new ExprArgument(Arg, Attr); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 623 | else if (ArgName == "FunctionArgument") |
| 624 | Ptr = new SimpleArgument(Arg, Attr, "FunctionDecl *"); |
| 625 | else if (ArgName == "IdentifierArgument") |
| 626 | Ptr = new SimpleArgument(Arg, Attr, "IdentifierInfo *"); |
| 627 | else if (ArgName == "BoolArgument") Ptr = new SimpleArgument(Arg, Attr, |
| 628 | "bool"); |
| 629 | else if (ArgName == "IntArgument") Ptr = new SimpleArgument(Arg, Attr, "int"); |
| 630 | else if (ArgName == "StringArgument") Ptr = new StringArgument(Arg, Attr); |
| 631 | else if (ArgName == "TypeArgument") |
| 632 | Ptr = new SimpleArgument(Arg, Attr, "QualType"); |
| 633 | else if (ArgName == "UnsignedArgument") |
| 634 | Ptr = new SimpleArgument(Arg, Attr, "unsigned"); |
| 635 | else if (ArgName == "SourceLocArgument") |
| 636 | Ptr = new SimpleArgument(Arg, Attr, "SourceLocation"); |
| 637 | else if (ArgName == "VariadicUnsignedArgument") |
| 638 | Ptr = new VariadicArgument(Arg, Attr, "unsigned"); |
| 639 | else if (ArgName == "VariadicExprArgument") |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 640 | Ptr = new VariadicExprArgument(Arg, Attr); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 641 | else if (ArgName == "VersionArgument") |
| 642 | Ptr = new VersionArgument(Arg, Attr); |
| 643 | |
| 644 | if (!Ptr) { |
| 645 | std::vector<Record*> Bases = Search->getSuperClasses(); |
| 646 | for (std::vector<Record*>::iterator i = Bases.begin(), e = Bases.end(); |
| 647 | i != e; ++i) { |
| 648 | Ptr = createArgument(Arg, Attr, *i); |
| 649 | if (Ptr) |
| 650 | break; |
| 651 | } |
| 652 | } |
| 653 | return Ptr; |
| 654 | } |
| 655 | |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 656 | static void writeAvailabilityValue(raw_ostream &OS) { |
| 657 | OS << "\" << getPlatform()->getName();\n" |
| 658 | << " if (!getIntroduced().empty()) OS << \", introduced=\" << getIntroduced();\n" |
| 659 | << " if (!getDeprecated().empty()) OS << \", deprecated=\" << getDeprecated();\n" |
| 660 | << " if (!getObsoleted().empty()) OS << \", obsoleted=\" << getObsoleted();\n" |
| 661 | << " if (getUnavailable()) OS << \", unavailable\";\n" |
| 662 | << " OS << \""; |
| 663 | } |
| 664 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 665 | namespace clang { |
| 666 | |
| 667 | // Emits the class definitions for attributes. |
| 668 | void EmitClangAttrClass(RecordKeeper &Records, raw_ostream &OS) { |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 669 | OS << "// This file is generated by TableGen. Do not edit.\n\n"; |
| 670 | OS << "#ifndef LLVM_CLANG_ATTR_CLASSES_INC\n"; |
| 671 | OS << "#define LLVM_CLANG_ATTR_CLASSES_INC\n\n"; |
| 672 | |
| 673 | std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"); |
| 674 | |
| 675 | for (std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end(); |
| 676 | i != e; ++i) { |
| 677 | Record &R = **i; |
Douglas Gregor | 3e7d31a | 2012-05-02 15:56:52 +0000 | [diff] [blame] | 678 | |
| 679 | if (!R.getValueAsBit("ASTNode")) |
| 680 | continue; |
| 681 | |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 682 | const std::string &SuperName = R.getSuperClasses().back()->getName(); |
| 683 | |
| 684 | OS << "class " << R.getName() << "Attr : public " << SuperName << " {\n"; |
| 685 | |
| 686 | std::vector<Record*> ArgRecords = R.getValueAsListOfDefs("Args"); |
| 687 | std::vector<Argument*> Args; |
| 688 | std::vector<Argument*>::iterator ai, ae; |
| 689 | Args.reserve(ArgRecords.size()); |
| 690 | |
| 691 | for (std::vector<Record*>::iterator ri = ArgRecords.begin(), |
| 692 | re = ArgRecords.end(); |
| 693 | ri != re; ++ri) { |
| 694 | Record &ArgRecord = **ri; |
| 695 | Argument *Arg = createArgument(ArgRecord, R.getName()); |
| 696 | assert(Arg); |
| 697 | Args.push_back(Arg); |
| 698 | |
| 699 | Arg->writeDeclarations(OS); |
| 700 | OS << "\n\n"; |
| 701 | } |
| 702 | |
| 703 | ae = Args.end(); |
| 704 | |
| 705 | OS << "\n public:\n"; |
| 706 | OS << " " << R.getName() << "Attr(SourceRange R, ASTContext &Ctx\n"; |
| 707 | |
| 708 | for (ai = Args.begin(); ai != ae; ++ai) { |
| 709 | OS << " , "; |
| 710 | (*ai)->writeCtorParameters(OS); |
| 711 | OS << "\n"; |
| 712 | } |
| 713 | |
| 714 | OS << " )\n"; |
| 715 | OS << " : " << SuperName << "(attr::" << R.getName() << ", R)\n"; |
| 716 | |
| 717 | for (ai = Args.begin(); ai != ae; ++ai) { |
| 718 | OS << " , "; |
| 719 | (*ai)->writeCtorInitializers(OS); |
| 720 | OS << "\n"; |
| 721 | } |
| 722 | |
| 723 | OS << " {\n"; |
| 724 | |
| 725 | for (ai = Args.begin(); ai != ae; ++ai) { |
| 726 | (*ai)->writeCtorBody(OS); |
| 727 | OS << "\n"; |
| 728 | } |
| 729 | OS << " }\n\n"; |
| 730 | |
| 731 | OS << " virtual " << R.getName() << "Attr *clone (ASTContext &C) const;\n"; |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 732 | OS << " virtual void printPretty(llvm::raw_ostream &OS, ASTContext &Ctx) const;\n"; |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 733 | |
| 734 | for (ai = Args.begin(); ai != ae; ++ai) { |
| 735 | (*ai)->writeAccessors(OS); |
| 736 | OS << "\n\n"; |
| 737 | } |
| 738 | |
Jakob Stoklund Olesen | eb66673 | 2012-01-13 04:57:47 +0000 | [diff] [blame] | 739 | OS << R.getValueAsString("AdditionalMembers"); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 740 | OS << "\n\n"; |
| 741 | |
| 742 | OS << " static bool classof(const Attr *A) { return A->getKind() == " |
| 743 | << "attr::" << R.getName() << "; }\n"; |
| 744 | OS << " static bool classof(const " << R.getName() |
| 745 | << "Attr *) { return true; }\n"; |
DeLesley Hutchins | 23323e0 | 2012-01-20 22:50:54 +0000 | [diff] [blame] | 746 | |
| 747 | bool LateParsed = R.getValueAsBit("LateParsed"); |
| 748 | OS << " virtual bool isLateParsed() const { return " |
| 749 | << LateParsed << "; }\n"; |
| 750 | |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 751 | OS << "};\n\n"; |
| 752 | } |
| 753 | |
| 754 | OS << "#endif\n"; |
| 755 | } |
| 756 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 757 | // Emits the class method definitions for attributes. |
| 758 | void EmitClangAttrImpl(RecordKeeper &Records, raw_ostream &OS) { |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 759 | OS << "// This file is generated by TableGen. Do not edit.\n\n"; |
| 760 | |
| 761 | std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"); |
| 762 | std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end(), ri, re; |
| 763 | std::vector<Argument*>::iterator ai, ae; |
| 764 | |
| 765 | for (; i != e; ++i) { |
| 766 | Record &R = **i; |
Douglas Gregor | 3e7d31a | 2012-05-02 15:56:52 +0000 | [diff] [blame] | 767 | |
| 768 | if (!R.getValueAsBit("ASTNode")) |
| 769 | continue; |
| 770 | |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 771 | std::vector<Record*> ArgRecords = R.getValueAsListOfDefs("Args"); |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 772 | std::vector<StringRef> Spellings = getValueAsListOfStrings(R, "Spellings"); |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 773 | std::vector<Argument*> Args; |
| 774 | for (ri = ArgRecords.begin(), re = ArgRecords.end(); ri != re; ++ri) |
| 775 | Args.push_back(createArgument(**ri, R.getName())); |
| 776 | |
| 777 | for (ai = Args.begin(), ae = Args.end(); ai != ae; ++ai) |
| 778 | (*ai)->writeAccessorDefinitions(OS); |
| 779 | |
| 780 | OS << R.getName() << "Attr *" << R.getName() |
| 781 | << "Attr::clone(ASTContext &C) const {\n"; |
| 782 | OS << " return new (C) " << R.getName() << "Attr(getLocation(), C"; |
| 783 | for (ai = Args.begin(); ai != ae; ++ai) { |
| 784 | OS << ", "; |
| 785 | (*ai)->writeCloneArgs(OS); |
| 786 | } |
| 787 | OS << ");\n}\n\n"; |
Douglas Gregor | 1bea880 | 2011-11-19 19:22:57 +0000 | [diff] [blame] | 788 | |
| 789 | OS << "void " << R.getName() << "Attr::printPretty(" |
| 790 | << "llvm::raw_ostream &OS, ASTContext &Ctx) const {\n"; |
| 791 | if (Spellings.begin() != Spellings.end()) { |
| 792 | OS << " OS << \" __attribute__((" << *Spellings.begin(); |
| 793 | if (Args.size()) OS << "("; |
| 794 | if (*Spellings.begin()=="availability") { |
| 795 | writeAvailabilityValue(OS); |
| 796 | } else { |
| 797 | for (ai = Args.begin(); ai != ae; ++ai) { |
| 798 | if (ai!=Args.begin()) OS <<", "; |
| 799 | (*ai)->writeValue(OS); |
| 800 | } |
| 801 | } |
| 802 | if (Args.size()) OS << ")"; |
| 803 | OS << "))\";\n"; |
| 804 | } |
| 805 | OS << "}\n\n"; |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 809 | } // end namespace clang |
| 810 | |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 811 | static void EmitAttrList(raw_ostream &OS, StringRef Class, |
| 812 | const std::vector<Record*> &AttrList) { |
| 813 | std::vector<Record*>::const_iterator i = AttrList.begin(), e = AttrList.end(); |
| 814 | |
| 815 | if (i != e) { |
| 816 | // Move the end iterator back to emit the last attribute. |
Douglas Gregor | 3e7d31a | 2012-05-02 15:56:52 +0000 | [diff] [blame] | 817 | for(--e; i != e; ++i) { |
| 818 | if (!(*i)->getValueAsBit("ASTNode")) |
| 819 | continue; |
| 820 | |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 821 | OS << Class << "(" << (*i)->getName() << ")\n"; |
Douglas Gregor | 3e7d31a | 2012-05-02 15:56:52 +0000 | [diff] [blame] | 822 | } |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 823 | |
| 824 | OS << "LAST_" << Class << "(" << (*i)->getName() << ")\n\n"; |
| 825 | } |
| 826 | } |
| 827 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 828 | namespace clang { |
| 829 | |
| 830 | // Emits the enumeration list for attributes. |
| 831 | void EmitClangAttrList(RecordKeeper &Records, raw_ostream &OS) { |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 832 | OS << "// This file is generated by TableGen. Do not edit.\n\n"; |
| 833 | |
| 834 | OS << "#ifndef LAST_ATTR\n"; |
| 835 | OS << "#define LAST_ATTR(NAME) ATTR(NAME)\n"; |
| 836 | OS << "#endif\n\n"; |
| 837 | |
| 838 | OS << "#ifndef INHERITABLE_ATTR\n"; |
| 839 | OS << "#define INHERITABLE_ATTR(NAME) ATTR(NAME)\n"; |
| 840 | OS << "#endif\n\n"; |
| 841 | |
| 842 | OS << "#ifndef LAST_INHERITABLE_ATTR\n"; |
| 843 | OS << "#define LAST_INHERITABLE_ATTR(NAME) INHERITABLE_ATTR(NAME)\n"; |
| 844 | OS << "#endif\n\n"; |
| 845 | |
| 846 | OS << "#ifndef INHERITABLE_PARAM_ATTR\n"; |
| 847 | OS << "#define INHERITABLE_PARAM_ATTR(NAME) ATTR(NAME)\n"; |
| 848 | OS << "#endif\n\n"; |
| 849 | |
| 850 | OS << "#ifndef LAST_INHERITABLE_PARAM_ATTR\n"; |
| 851 | OS << "#define LAST_INHERITABLE_PARAM_ATTR(NAME)" |
| 852 | " INHERITABLE_PARAM_ATTR(NAME)\n"; |
| 853 | OS << "#endif\n\n"; |
| 854 | |
| 855 | Record *InhClass = Records.getClass("InheritableAttr"); |
| 856 | Record *InhParamClass = Records.getClass("InheritableParamAttr"); |
| 857 | std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"), |
| 858 | NonInhAttrs, InhAttrs, InhParamAttrs; |
| 859 | for (std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end(); |
| 860 | i != e; ++i) { |
Douglas Gregor | 3e7d31a | 2012-05-02 15:56:52 +0000 | [diff] [blame] | 861 | if (!(*i)->getValueAsBit("ASTNode")) |
| 862 | continue; |
| 863 | |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 864 | if ((*i)->isSubClassOf(InhParamClass)) |
| 865 | InhParamAttrs.push_back(*i); |
| 866 | else if ((*i)->isSubClassOf(InhClass)) |
| 867 | InhAttrs.push_back(*i); |
| 868 | else |
| 869 | NonInhAttrs.push_back(*i); |
| 870 | } |
| 871 | |
| 872 | EmitAttrList(OS, "INHERITABLE_PARAM_ATTR", InhParamAttrs); |
| 873 | EmitAttrList(OS, "INHERITABLE_ATTR", InhAttrs); |
| 874 | EmitAttrList(OS, "ATTR", NonInhAttrs); |
| 875 | |
| 876 | OS << "#undef LAST_ATTR\n"; |
| 877 | OS << "#undef INHERITABLE_ATTR\n"; |
| 878 | OS << "#undef LAST_INHERITABLE_ATTR\n"; |
| 879 | OS << "#undef LAST_INHERITABLE_PARAM_ATTR\n"; |
| 880 | OS << "#undef ATTR\n"; |
| 881 | } |
| 882 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 883 | // Emits the code to read an attribute from a precompiled header. |
| 884 | void EmitClangAttrPCHRead(RecordKeeper &Records, raw_ostream &OS) { |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 885 | OS << "// This file is generated by TableGen. Do not edit.\n\n"; |
| 886 | |
| 887 | Record *InhClass = Records.getClass("InheritableAttr"); |
| 888 | std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"), |
| 889 | ArgRecords; |
| 890 | std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end(), ai, ae; |
| 891 | std::vector<Argument*> Args; |
| 892 | std::vector<Argument*>::iterator ri, re; |
| 893 | |
| 894 | OS << " switch (Kind) {\n"; |
| 895 | OS << " default:\n"; |
| 896 | OS << " assert(0 && \"Unknown attribute!\");\n"; |
| 897 | OS << " break;\n"; |
| 898 | for (; i != e; ++i) { |
| 899 | Record &R = **i; |
Douglas Gregor | 3e7d31a | 2012-05-02 15:56:52 +0000 | [diff] [blame] | 900 | if (!R.getValueAsBit("ASTNode")) |
| 901 | continue; |
| 902 | |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 903 | OS << " case attr::" << R.getName() << ": {\n"; |
| 904 | if (R.isSubClassOf(InhClass)) |
| 905 | OS << " bool isInherited = Record[Idx++];\n"; |
| 906 | ArgRecords = R.getValueAsListOfDefs("Args"); |
| 907 | Args.clear(); |
| 908 | for (ai = ArgRecords.begin(), ae = ArgRecords.end(); ai != ae; ++ai) { |
| 909 | Argument *A = createArgument(**ai, R.getName()); |
| 910 | Args.push_back(A); |
| 911 | A->writePCHReadDecls(OS); |
| 912 | } |
| 913 | OS << " New = new (Context) " << R.getName() << "Attr(Range, Context"; |
| 914 | for (ri = Args.begin(), re = Args.end(); ri != re; ++ri) { |
| 915 | OS << ", "; |
| 916 | (*ri)->writePCHReadArgs(OS); |
| 917 | } |
| 918 | OS << ");\n"; |
| 919 | if (R.isSubClassOf(InhClass)) |
| 920 | OS << " cast<InheritableAttr>(New)->setInherited(isInherited);\n"; |
| 921 | OS << " break;\n"; |
| 922 | OS << " }\n"; |
| 923 | } |
| 924 | OS << " }\n"; |
| 925 | } |
| 926 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 927 | // Emits the code to write an attribute to a precompiled header. |
| 928 | void EmitClangAttrPCHWrite(RecordKeeper &Records, raw_ostream &OS) { |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 929 | Record *InhClass = Records.getClass("InheritableAttr"); |
| 930 | std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"), Args; |
| 931 | std::vector<Record*>::iterator i = Attrs.begin(), e = Attrs.end(), ai, ae; |
| 932 | |
| 933 | OS << " switch (A->getKind()) {\n"; |
| 934 | OS << " default:\n"; |
| 935 | OS << " llvm_unreachable(\"Unknown attribute kind!\");\n"; |
| 936 | OS << " break;\n"; |
| 937 | for (; i != e; ++i) { |
| 938 | Record &R = **i; |
Douglas Gregor | 3e7d31a | 2012-05-02 15:56:52 +0000 | [diff] [blame] | 939 | if (!R.getValueAsBit("ASTNode")) |
| 940 | continue; |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 941 | OS << " case attr::" << R.getName() << ": {\n"; |
| 942 | Args = R.getValueAsListOfDefs("Args"); |
| 943 | if (R.isSubClassOf(InhClass) || !Args.empty()) |
| 944 | OS << " const " << R.getName() << "Attr *SA = cast<" << R.getName() |
| 945 | << "Attr>(A);\n"; |
| 946 | if (R.isSubClassOf(InhClass)) |
| 947 | OS << " Record.push_back(SA->isInherited());\n"; |
| 948 | for (ai = Args.begin(), ae = Args.end(); ai != ae; ++ai) |
| 949 | createArgument(**ai, R.getName())->writePCHWrite(OS); |
| 950 | OS << " break;\n"; |
| 951 | OS << " }\n"; |
| 952 | } |
| 953 | OS << " }\n"; |
| 954 | } |
| 955 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 956 | // Emits the list of spellings for attributes. |
| 957 | void EmitClangAttrSpellingList(RecordKeeper &Records, raw_ostream &OS) { |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 958 | OS << "// This file is generated by TableGen. Do not edit.\n\n"; |
| 959 | |
| 960 | std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"); |
| 961 | |
| 962 | for (std::vector<Record*>::iterator I = Attrs.begin(), E = Attrs.end(); I != E; ++I) { |
| 963 | Record &Attr = **I; |
| 964 | |
| 965 | std::vector<StringRef> Spellings = getValueAsListOfStrings(Attr, "Spellings"); |
| 966 | |
| 967 | for (std::vector<StringRef>::const_iterator I = Spellings.begin(), E = Spellings.end(); I != E; ++I) { |
| 968 | StringRef Spelling = *I; |
| 969 | OS << ".Case(\"" << Spelling << "\", true)\n"; |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | } |
| 974 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 975 | // Emits the LateParsed property for attributes. |
| 976 | void EmitClangAttrLateParsedList(RecordKeeper &Records, raw_ostream &OS) { |
Peter Collingbourne | 51d7777 | 2011-10-06 13:03:08 +0000 | [diff] [blame] | 977 | OS << "// This file is generated by TableGen. Do not edit.\n\n"; |
| 978 | |
| 979 | std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"); |
| 980 | |
| 981 | for (std::vector<Record*>::iterator I = Attrs.begin(), E = Attrs.end(); |
| 982 | I != E; ++I) { |
| 983 | Record &Attr = **I; |
| 984 | |
| 985 | bool LateParsed = Attr.getValueAsBit("LateParsed"); |
| 986 | |
| 987 | if (LateParsed) { |
| 988 | std::vector<StringRef> Spellings = |
| 989 | getValueAsListOfStrings(Attr, "Spellings"); |
| 990 | |
| 991 | for (std::vector<StringRef>::const_iterator I = Spellings.begin(), |
| 992 | E = Spellings.end(); I != E; ++I) { |
| 993 | OS << ".Case(\"" << (*I) << "\", " << LateParsed << ")\n"; |
| 994 | } |
| 995 | } |
| 996 | } |
| 997 | } |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 998 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 999 | // Emits code to instantiate dependent attributes on templates. |
| 1000 | void EmitClangAttrTemplateInstantiate(RecordKeeper &Records, raw_ostream &OS) { |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 1001 | OS << "// This file is generated by TableGen. Do not edit.\n\n"; |
| 1002 | |
| 1003 | std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"); |
| 1004 | |
Benjamin Kramer | 5bbc385 | 2012-02-06 11:13:08 +0000 | [diff] [blame] | 1005 | OS << "namespace clang {\n" |
| 1006 | << "namespace sema {\n\n" |
| 1007 | << "Attr *instantiateTemplateAttribute(const Attr *At, ASTContext &C, " |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 1008 | << "Sema &S,\n" |
| 1009 | << " const MultiLevelTemplateArgumentList &TemplateArgs) {\n" |
| 1010 | << " switch (At->getKind()) {\n" |
| 1011 | << " default:\n" |
| 1012 | << " break;\n"; |
| 1013 | |
| 1014 | for (std::vector<Record*>::iterator I = Attrs.begin(), E = Attrs.end(); |
| 1015 | I != E; ++I) { |
| 1016 | Record &R = **I; |
Douglas Gregor | 3e7d31a | 2012-05-02 15:56:52 +0000 | [diff] [blame] | 1017 | if (!R.getValueAsBit("ASTNode")) |
| 1018 | continue; |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 1019 | |
| 1020 | OS << " case attr::" << R.getName() << ": {\n"; |
Rafael Espindola | 31c195a | 2012-05-15 14:09:55 +0000 | [diff] [blame] | 1021 | bool ShouldClone = R.getValueAsBit("Clone"); |
| 1022 | |
| 1023 | if (!ShouldClone) { |
| 1024 | OS << " return NULL;\n"; |
| 1025 | OS << " }\n"; |
| 1026 | continue; |
| 1027 | } |
| 1028 | |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 1029 | OS << " const " << R.getName() << "Attr *A = cast<" |
| 1030 | << R.getName() << "Attr>(At);\n"; |
| 1031 | bool TDependent = R.getValueAsBit("TemplateDependent"); |
| 1032 | |
| 1033 | if (!TDependent) { |
| 1034 | OS << " return A->clone(C);\n"; |
| 1035 | OS << " }\n"; |
| 1036 | continue; |
| 1037 | } |
| 1038 | |
| 1039 | std::vector<Record*> ArgRecords = R.getValueAsListOfDefs("Args"); |
| 1040 | std::vector<Argument*> Args; |
| 1041 | std::vector<Argument*>::iterator ai, ae; |
| 1042 | Args.reserve(ArgRecords.size()); |
| 1043 | |
| 1044 | for (std::vector<Record*>::iterator ri = ArgRecords.begin(), |
| 1045 | re = ArgRecords.end(); |
| 1046 | ri != re; ++ri) { |
| 1047 | Record &ArgRecord = **ri; |
| 1048 | Argument *Arg = createArgument(ArgRecord, R.getName()); |
| 1049 | assert(Arg); |
| 1050 | Args.push_back(Arg); |
| 1051 | } |
| 1052 | ae = Args.end(); |
| 1053 | |
| 1054 | for (ai = Args.begin(); ai != ae; ++ai) { |
| 1055 | (*ai)->writeTemplateInstantiation(OS); |
| 1056 | } |
| 1057 | OS << " return new (C) " << R.getName() << "Attr(A->getLocation(), C"; |
| 1058 | for (ai = Args.begin(); ai != ae; ++ai) { |
| 1059 | OS << ", "; |
| 1060 | (*ai)->writeTemplateInstantiationArgs(OS); |
| 1061 | } |
| 1062 | OS << ");\n }\n"; |
| 1063 | } |
| 1064 | OS << " } // end switch\n" |
| 1065 | << " llvm_unreachable(\"Unknown attribute!\");\n" |
| 1066 | << " return 0;\n" |
Benjamin Kramer | 5bbc385 | 2012-02-06 11:13:08 +0000 | [diff] [blame] | 1067 | << "}\n\n" |
| 1068 | << "} // end namespace sema\n" |
| 1069 | << "} // end namespace clang\n"; |
DeLesley Hutchins | 7b9ff0c | 2012-01-20 22:37:06 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 1072 | // Emits the list of parsed attributes. |
| 1073 | void EmitClangAttrParsedAttrList(RecordKeeper &Records, raw_ostream &OS) { |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 1074 | OS << "// This file is generated by TableGen. Do not edit.\n\n"; |
| 1075 | |
| 1076 | OS << "#ifndef PARSED_ATTR\n"; |
| 1077 | OS << "#define PARSED_ATTR(NAME) NAME\n"; |
| 1078 | OS << "#endif\n\n"; |
| 1079 | |
| 1080 | std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"); |
| 1081 | std::set<StringRef> ProcessedAttrs; |
| 1082 | |
| 1083 | for (std::vector<Record*>::iterator I = Attrs.begin(), E = Attrs.end(); |
| 1084 | I != E; ++I) { |
| 1085 | Record &Attr = **I; |
| 1086 | |
| 1087 | bool SemaHandler = Attr.getValueAsBit("SemaHandler"); |
Douglas Gregor | 703d412 | 2012-05-11 23:37:49 +0000 | [diff] [blame] | 1088 | bool DistinctSpellings = Attr.getValueAsBit("DistinctSpellings"); |
| 1089 | |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 1090 | if (SemaHandler) { |
| 1091 | std::vector<StringRef> Spellings = |
| 1092 | getValueAsListOfStrings(Attr, "Spellings"); |
| 1093 | |
| 1094 | for (std::vector<StringRef>::const_iterator I = Spellings.begin(), |
| 1095 | E = Spellings.end(); I != E; ++I) { |
| 1096 | StringRef AttrName = *I; |
| 1097 | |
| 1098 | AttrName = NormalizeAttrName(AttrName); |
| 1099 | // skip if a normalized version has been processed. |
| 1100 | if (ProcessedAttrs.find(AttrName) != ProcessedAttrs.end()) |
| 1101 | continue; |
| 1102 | else |
| 1103 | ProcessedAttrs.insert(AttrName); |
| 1104 | |
| 1105 | OS << "PARSED_ATTR(" << AttrName << ")\n"; |
Douglas Gregor | 703d412 | 2012-05-11 23:37:49 +0000 | [diff] [blame] | 1106 | |
| 1107 | if (!DistinctSpellings) |
| 1108 | break; |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 1114 | // Emits the kind list of parsed attributes |
| 1115 | void EmitClangAttrParsedAttrKinds(RecordKeeper &Records, raw_ostream &OS) { |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 1116 | OS << "// This file is generated by TableGen. Do not edit.\n\n"; |
Douglas Gregor | 0c19b3c | 2012-05-02 17:33:51 +0000 | [diff] [blame] | 1117 | OS << "\n"; |
| 1118 | |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 1119 | std::vector<Record*> Attrs = Records.getAllDerivedDefinitions("Attr"); |
| 1120 | |
Douglas Gregor | 0c19b3c | 2012-05-02 17:33:51 +0000 | [diff] [blame] | 1121 | std::vector<StringMatcher::StringPair> Matches; |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 1122 | for (std::vector<Record*>::iterator I = Attrs.begin(), E = Attrs.end(); |
| 1123 | I != E; ++I) { |
| 1124 | Record &Attr = **I; |
| 1125 | |
| 1126 | bool SemaHandler = Attr.getValueAsBit("SemaHandler"); |
Douglas Gregor | 331d2ec | 2012-05-02 16:18:45 +0000 | [diff] [blame] | 1127 | bool Ignored = Attr.getValueAsBit("Ignored"); |
Douglas Gregor | 703d412 | 2012-05-11 23:37:49 +0000 | [diff] [blame] | 1128 | bool DistinctSpellings = Attr.getValueAsBit("DistinctSpellings"); |
Douglas Gregor | 331d2ec | 2012-05-02 16:18:45 +0000 | [diff] [blame] | 1129 | if (SemaHandler || Ignored) { |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 1130 | std::vector<StringRef> Spellings = |
| 1131 | getValueAsListOfStrings(Attr, "Spellings"); |
Sean Hunt | 93f95f2 | 2012-06-18 16:13:52 +0000 | [diff] [blame^] | 1132 | std::vector<StringRef> Namespaces = |
| 1133 | getValueAsListOfStrings(Attr, "Namespaces"); |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 1134 | |
| 1135 | for (std::vector<StringRef>::const_iterator I = Spellings.begin(), |
| 1136 | E = Spellings.end(); I != E; ++I) { |
Douglas Gregor | 703d412 | 2012-05-11 23:37:49 +0000 | [diff] [blame] | 1137 | StringRef AttrName = NormalizeAttrName(DistinctSpellings |
| 1138 | ? *I |
| 1139 | : Spellings.front()); |
| 1140 | StringRef Spelling = NormalizeAttrSpelling(*I); |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 1141 | |
Sean Hunt | 93f95f2 | 2012-06-18 16:13:52 +0000 | [diff] [blame^] | 1142 | for (std::vector<StringRef>::const_iterator NI = Namespaces.begin(), |
| 1143 | NE = Namespaces.end(); NI != NE; ++NI) { |
| 1144 | SmallString<64> Buf; |
| 1145 | Buf += *NI; |
| 1146 | Buf += "::"; |
| 1147 | Buf += Spelling; |
| 1148 | |
| 1149 | if (SemaHandler) |
| 1150 | Matches.push_back( |
| 1151 | StringMatcher::StringPair( |
| 1152 | Buf.str(), |
| 1153 | "return AttributeList::AT_" + AttrName.str() + ";")); |
| 1154 | else |
| 1155 | Matches.push_back( |
| 1156 | StringMatcher::StringPair( |
| 1157 | Buf.str(), |
| 1158 | "return AttributeList::IgnoredAttribute;")); |
| 1159 | } |
| 1160 | |
Douglas Gregor | 331d2ec | 2012-05-02 16:18:45 +0000 | [diff] [blame] | 1161 | if (SemaHandler) |
Douglas Gregor | 0c19b3c | 2012-05-02 17:33:51 +0000 | [diff] [blame] | 1162 | Matches.push_back( |
Douglas Gregor | 703d412 | 2012-05-11 23:37:49 +0000 | [diff] [blame] | 1163 | StringMatcher::StringPair( |
| 1164 | Spelling, |
Sean Hunt | 93f95f2 | 2012-06-18 16:13:52 +0000 | [diff] [blame^] | 1165 | "return AttributeList::AT_" + AttrName.str() + ";")); |
Douglas Gregor | 331d2ec | 2012-05-02 16:18:45 +0000 | [diff] [blame] | 1166 | else |
Douglas Gregor | 0c19b3c | 2012-05-02 17:33:51 +0000 | [diff] [blame] | 1167 | Matches.push_back( |
| 1168 | StringMatcher::StringPair( |
| 1169 | Spelling, |
Sean Hunt | 93f95f2 | 2012-06-18 16:13:52 +0000 | [diff] [blame^] | 1170 | "return AttributeList::IgnoredAttribute;")); |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | } |
Douglas Gregor | 0c19b3c | 2012-05-02 17:33:51 +0000 | [diff] [blame] | 1174 | |
| 1175 | OS << "static AttributeList::Kind getAttrKind(StringRef Name) {\n"; |
| 1176 | StringMatcher("Name", Matches, OS).Emit(); |
| 1177 | OS << "return AttributeList::UnknownAttribute;\n" |
| 1178 | << "}\n"; |
Michael Han | e53ac8a | 2012-03-07 00:12:16 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
Jakob Stoklund Olesen | 3cc509b | 2012-06-13 05:12:41 +0000 | [diff] [blame] | 1181 | } // end namespace clang |