| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | #ifndef LLVM_CLANG_SEMA_PARSEDTEMPLATE_H |
| 15 | #define LLVM_CLANG_SEMA_PARSEDTEMPLATE_H |
| 16 | |
| 17 | #include "clang/Basic/OperatorKinds.h" |
| 18 | #include "clang/Basic/SourceLocation.h" |
| 19 | #include "clang/Basic/TemplateKinds.h" |
| 20 | #include "clang/Sema/DeclSpec.h" |
| 21 | #include "clang/Sema/Ownership.h" |
| 22 | #include "llvm/ADT/SmallVector.h" |
| 23 | #include <cassert> |
| 24 | #include <cstdlib> |
| 25 | #include <new> |
| 26 | |
| 27 | namespace clang { |
| 28 | |
| 29 | class ParsedTemplateArgument { |
| 30 | public: |
| 31 | |
| 32 | enum KindType { |
| 33 | |
| 34 | Type, |
| 35 | |
| 36 | NonType, |
| 37 | |
| 38 | Template |
| 39 | }; |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | ParsedTemplateArgument() : Kind(Type), Arg(nullptr) { } |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | ParsedTemplateArgument(KindType Kind, void *Arg, SourceLocation Loc) |
| 51 | : Kind(Kind), Arg(Arg), Loc(Loc) { } |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | ParsedTemplateArgument(const CXXScopeSpec &SS, |
| 63 | ParsedTemplateTy Template, |
| 64 | SourceLocation TemplateLoc) |
| 65 | : Kind(ParsedTemplateArgument::Template), |
| 66 | Arg(Template.getAsOpaquePtr()), |
| 67 | SS(SS), Loc(TemplateLoc), EllipsisLoc() { } |
| 68 | |
| 69 | |
| 70 | bool isInvalid() const { return Arg == nullptr; } |
| 71 | |
| 72 | |
| 73 | KindType getKind() const { return Kind; } |
| 74 | |
| 75 | |
| 76 | ParsedType getAsType() const { |
| 77 | (0) . __assert_fail ("Kind == Type && \"Not a template type argument\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/ParsedTemplate.h", 77, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Kind == Type && "Not a template type argument"); |
| 78 | return ParsedType::getFromOpaquePtr(Arg); |
| 79 | } |
| 80 | |
| 81 | |
| 82 | Expr *getAsExpr() const { |
| 83 | (0) . __assert_fail ("Kind == NonType && \"Not a non-type template argument\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/ParsedTemplate.h", 83, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Kind == NonType && "Not a non-type template argument"); |
| 84 | return static_cast<Expr*>(Arg); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | ParsedTemplateTy getAsTemplate() const { |
| 89 | (0) . __assert_fail ("Kind == Template && \"Not a template template argument\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/ParsedTemplate.h", 89, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Kind == Template && "Not a template template argument"); |
| 90 | return ParsedTemplateTy::getFromOpaquePtr(Arg); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | SourceLocation getLocation() const { return Loc; } |
| 95 | |
| 96 | |
| 97 | |
| 98 | const CXXScopeSpec &getScopeSpec() const { |
| 99 | (0) . __assert_fail ("Kind == Template && \"Only template template arguments can have a scope specifier\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/ParsedTemplate.h", 100, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Kind == Template && |
| 100 | (0) . __assert_fail ("Kind == Template && \"Only template template arguments can have a scope specifier\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/ParsedTemplate.h", 100, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Only template template arguments can have a scope specifier"); |
| 101 | return SS; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | |
| 106 | SourceLocation getEllipsisLoc() const { |
| 107 | (0) . __assert_fail ("Kind == Template && \"Only template template arguments can have an ellipsis\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/ParsedTemplate.h", 108, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true">assert(Kind == Template && |
| 108 | (0) . __assert_fail ("Kind == Template && \"Only template template arguments can have an ellipsis\"", "/home/seafit/code_projects/clang_source/clang/include/clang/Sema/ParsedTemplate.h", 108, __PRETTY_FUNCTION__))" file_link="../../../../include/assert.h.html#88" macro="true"> "Only template template arguments can have an ellipsis"); |
| 109 | return EllipsisLoc; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | ParsedTemplateArgument getTemplatePackExpansion( |
| 117 | SourceLocation EllipsisLoc) const; |
| 118 | |
| 119 | private: |
| 120 | KindType Kind; |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | void *Arg; |
| 126 | |
| 127 | |
| 128 | |
| 129 | CXXScopeSpec SS; |
| 130 | |
| 131 | |
| 132 | SourceLocation Loc; |
| 133 | |
| 134 | |
| 135 | |
| 136 | SourceLocation EllipsisLoc; |
| 137 | }; |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | struct TemplateIdAnnotation final |
| 148 | : private llvm::TrailingObjects<TemplateIdAnnotation, |
| 149 | ParsedTemplateArgument> { |
| 150 | friend TrailingObjects; |
| 151 | |
| 152 | CXXScopeSpec SS; |
| 153 | |
| 154 | |
| 155 | |
| 156 | SourceLocation TemplateKWLoc; |
| 157 | |
| 158 | |
| 159 | |
| 160 | SourceLocation TemplateNameLoc; |
| 161 | |
| 162 | |
| 163 | IdentifierInfo *Name; |
| 164 | |
| 165 | |
| 166 | OverloadedOperatorKind Operator; |
| 167 | |
| 168 | |
| 169 | |
| 170 | ParsedTemplateTy Template; |
| 171 | |
| 172 | |
| 173 | TemplateNameKind Kind; |
| 174 | |
| 175 | |
| 176 | |
| 177 | SourceLocation LAngleLoc; |
| 178 | |
| 179 | |
| 180 | |
| 181 | SourceLocation RAngleLoc; |
| 182 | |
| 183 | |
| 184 | unsigned NumArgs; |
| 185 | |
| 186 | |
| 187 | ParsedTemplateArgument *getTemplateArgs() { |
| 188 | return getTrailingObjects<ParsedTemplateArgument>(); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | |
| 193 | static TemplateIdAnnotation * |
| 194 | Create(CXXScopeSpec SS, SourceLocation TemplateKWLoc, |
| 195 | SourceLocation TemplateNameLoc, IdentifierInfo *Name, |
| 196 | OverloadedOperatorKind OperatorKind, |
| 197 | ParsedTemplateTy OpaqueTemplateName, TemplateNameKind TemplateKind, |
| 198 | SourceLocation LAngleLoc, SourceLocation RAngleLoc, |
| 199 | ArrayRef<ParsedTemplateArgument> TemplateArgs, |
| 200 | SmallVectorImpl<TemplateIdAnnotation *> &CleanupList) { |
| 201 | TemplateIdAnnotation *TemplateId = new (llvm::safe_malloc( |
| 202 | totalSizeToAlloc<ParsedTemplateArgument>(TemplateArgs.size()))) |
| 203 | TemplateIdAnnotation(SS, TemplateKWLoc, TemplateNameLoc, Name, |
| 204 | OperatorKind, OpaqueTemplateName, TemplateKind, |
| 205 | LAngleLoc, RAngleLoc, TemplateArgs); |
| 206 | CleanupList.push_back(TemplateId); |
| 207 | return TemplateId; |
| 208 | } |
| 209 | |
| 210 | void Destroy() { |
| 211 | std::for_each( |
| 212 | getTemplateArgs(), getTemplateArgs() + NumArgs, |
| 213 | [](ParsedTemplateArgument &A) { A.~ParsedTemplateArgument(); }); |
| 214 | this->~TemplateIdAnnotation(); |
| 215 | free(this); |
| 216 | } |
| 217 | private: |
| 218 | TemplateIdAnnotation(const TemplateIdAnnotation &) = delete; |
| 219 | |
| 220 | TemplateIdAnnotation(CXXScopeSpec SS, SourceLocation TemplateKWLoc, |
| 221 | SourceLocation TemplateNameLoc, IdentifierInfo *Name, |
| 222 | OverloadedOperatorKind OperatorKind, |
| 223 | ParsedTemplateTy OpaqueTemplateName, |
| 224 | TemplateNameKind TemplateKind, |
| 225 | SourceLocation LAngleLoc, SourceLocation RAngleLoc, |
| 226 | ArrayRef<ParsedTemplateArgument> TemplateArgs) noexcept |
| 227 | : SS(SS), TemplateKWLoc(TemplateKWLoc), |
| 228 | TemplateNameLoc(TemplateNameLoc), Name(Name), Operator(OperatorKind), |
| 229 | Template(OpaqueTemplateName), Kind(TemplateKind), |
| 230 | LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc), |
| 231 | NumArgs(TemplateArgs.size()) { |
| 232 | |
| 233 | std::uninitialized_copy(TemplateArgs.begin(), TemplateArgs.end(), |
| 234 | getTemplateArgs()); |
| 235 | } |
| 236 | ~TemplateIdAnnotation() = default; |
| 237 | }; |
| 238 | |
| 239 | |
| 240 | SourceRange getTemplateParamsRange(TemplateParameterList const *const *Params, |
| 241 | unsigned NumParams); |
| 242 | } |
| 243 | |
| 244 | #endif |
| 245 | |