Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- SemaDeclSpec.cpp - Declaration Specifier Semantic Analysis -------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements semantic analysis for declaration specifiers. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
John McCall | 1951085 | 2010-08-20 18:27:03 +0000 | [diff] [blame] | 14 | #include "clang/Parse/ParseDiagnostic.h" // FIXME: remove this back-dependency! |
| 15 | #include "clang/Sema/DeclSpec.h" |
| 16 | #include "clang/Sema/ParsedTemplate.h" |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame^] | 17 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 18 | #include "clang/AST/NestedNameSpecifier.h" |
| 19 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 20 | #include "clang/Lex/Preprocessor.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | #include "clang/Basic/LangOptions.h" |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/STLExtras.h" |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 24 | #include <cstring> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 25 | using namespace clang; |
| 26 | |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 27 | |
| 28 | static DiagnosticBuilder Diag(Diagnostic &D, SourceLocation Loc, |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 29 | unsigned DiagID) { |
| 30 | return D.Report(Loc, DiagID); |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Douglas Gregor | 314b97f | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 33 | |
| 34 | void UnqualifiedId::setTemplateId(TemplateIdAnnotation *TemplateId) { |
| 35 | assert(TemplateId && "NULL template-id annotation?"); |
| 36 | Kind = IK_TemplateId; |
| 37 | this->TemplateId = TemplateId; |
| 38 | StartLocation = TemplateId->TemplateNameLoc; |
| 39 | EndLocation = TemplateId->RAngleLoc; |
| 40 | } |
| 41 | |
Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 42 | void UnqualifiedId::setConstructorTemplateId(TemplateIdAnnotation *TemplateId) { |
| 43 | assert(TemplateId && "NULL template-id annotation?"); |
| 44 | Kind = IK_ConstructorTemplateId; |
| 45 | this->TemplateId = TemplateId; |
| 46 | StartLocation = TemplateId->TemplateNameLoc; |
| 47 | EndLocation = TemplateId->RAngleLoc; |
| 48 | } |
| 49 | |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame^] | 50 | CXXScopeSpec::CXXScopeSpec(const CXXScopeSpec &Other) |
| 51 | : Range(Other.Range), ScopeRep(Other.ScopeRep), Buffer(0), |
| 52 | BufferSize(Other.BufferSize), BufferCapacity(Other.BufferSize) |
| 53 | { |
| 54 | if (BufferSize) { |
| 55 | Buffer = static_cast<char *>(malloc(BufferSize)); |
| 56 | memcpy(Buffer, Other.Buffer, BufferSize); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | CXXScopeSpec &CXXScopeSpec::operator=(const CXXScopeSpec &Other) { |
| 61 | Range = Other.Range; |
| 62 | ScopeRep = Other.ScopeRep; |
| 63 | if (Buffer && Other.Buffer && BufferCapacity >= Other.BufferSize) { |
| 64 | // Re-use our storage. |
| 65 | BufferSize = Other.BufferSize; |
| 66 | memcpy(Buffer, Other.Buffer, BufferSize); |
| 67 | return *this; |
| 68 | } |
| 69 | |
| 70 | if (BufferCapacity) |
| 71 | free(Buffer); |
| 72 | if (Other.Buffer) { |
| 73 | BufferSize = Other.BufferSize; |
| 74 | BufferCapacity = BufferSize; |
| 75 | Buffer = static_cast<char *>(malloc(BufferSize)); |
| 76 | memcpy(Buffer, Other.Buffer, BufferSize); |
| 77 | } else { |
| 78 | Buffer = 0; |
| 79 | BufferSize = 0; |
| 80 | BufferCapacity = 0; |
| 81 | } |
| 82 | return *this; |
| 83 | } |
| 84 | |
| 85 | CXXScopeSpec::~CXXScopeSpec() { |
| 86 | if (BufferCapacity) |
| 87 | free(Buffer); |
| 88 | } |
| 89 | |
| 90 | namespace { |
| 91 | void Append(char *Start, char *End, char *&Buffer, unsigned &BufferSize, |
| 92 | unsigned &BufferCapacity) { |
| 93 | if (BufferSize + (End - Start) > BufferCapacity) { |
| 94 | // Reallocate the buffer. |
| 95 | unsigned NewCapacity |
| 96 | = std::max((unsigned)(BufferCapacity? BufferCapacity * 2 |
| 97 | : sizeof(void*) * 2), |
| 98 | (unsigned)(BufferSize + (End - Start))); |
| 99 | char *NewBuffer = static_cast<char *>(malloc(NewCapacity)); |
| 100 | memcpy(NewBuffer, Buffer, BufferSize); |
| 101 | |
| 102 | if (BufferCapacity) |
| 103 | free(Buffer); |
| 104 | Buffer = NewBuffer; |
| 105 | BufferCapacity = NewCapacity; |
| 106 | } |
| 107 | |
| 108 | memcpy(Buffer + BufferSize, Start, End - Start); |
| 109 | BufferSize += End-Start; |
| 110 | } |
| 111 | |
| 112 | /// \brief Save a source location to the given buffer. |
| 113 | void SaveSourceLocation(SourceLocation Loc, char *&Buffer, |
| 114 | unsigned &BufferSize, unsigned &BufferCapacity) { |
| 115 | unsigned Raw = Loc.getRawEncoding(); |
| 116 | Append(reinterpret_cast<char *>(&Raw), |
| 117 | reinterpret_cast<char *>(&Raw) + sizeof(unsigned), |
| 118 | Buffer, BufferSize, BufferCapacity); |
| 119 | } |
| 120 | |
| 121 | /// \brief Save a pointer to the given buffer. |
| 122 | void SavePointer(void *Ptr, char *&Buffer, unsigned &BufferSize, |
| 123 | unsigned &BufferCapacity) { |
| 124 | Append(reinterpret_cast<char *>(&Ptr), |
| 125 | reinterpret_cast<char *>(&Ptr) + sizeof(void *), |
| 126 | Buffer, BufferSize, BufferCapacity); |
| 127 | } |
| 128 | } |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 129 | void CXXScopeSpec::Extend(ASTContext &Context, SourceLocation TemplateKWLoc, |
| 130 | TypeLoc TL, SourceLocation ColonColonLoc) { |
| 131 | ScopeRep = NestedNameSpecifier::Create(Context, ScopeRep, |
| 132 | TemplateKWLoc.isValid(), |
| 133 | TL.getTypePtr()); |
| 134 | if (Range.getBegin().isInvalid()) |
| 135 | Range.setBegin(TL.getBeginLoc()); |
| 136 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame^] | 137 | |
| 138 | // Push source-location info into the buffer. |
| 139 | SavePointer(TL.getOpaqueData(), Buffer, BufferSize, BufferCapacity); |
| 140 | SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity); |
| 141 | |
| 142 | assert(Range == NestedNameSpecifierLoc(ScopeRep, Buffer).getSourceRange() && |
| 143 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void CXXScopeSpec::Extend(ASTContext &Context, IdentifierInfo *Identifier, |
| 147 | SourceLocation IdentifierLoc, |
| 148 | SourceLocation ColonColonLoc) { |
| 149 | ScopeRep = NestedNameSpecifier::Create(Context, ScopeRep, Identifier); |
| 150 | if (Range.getBegin().isInvalid()) |
| 151 | Range.setBegin(IdentifierLoc); |
| 152 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame^] | 153 | |
| 154 | // Push source-location info into the buffer. |
| 155 | SaveSourceLocation(IdentifierLoc, Buffer, BufferSize, BufferCapacity); |
| 156 | SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity); |
| 157 | |
| 158 | assert(Range == NestedNameSpecifierLoc(ScopeRep, Buffer).getSourceRange() && |
| 159 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | void CXXScopeSpec::Extend(ASTContext &Context, NamespaceDecl *Namespace, |
| 163 | SourceLocation NamespaceLoc, |
| 164 | SourceLocation ColonColonLoc) { |
| 165 | ScopeRep = NestedNameSpecifier::Create(Context, ScopeRep, Namespace); |
| 166 | if (Range.getBegin().isInvalid()) |
| 167 | Range.setBegin(NamespaceLoc); |
| 168 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame^] | 169 | |
| 170 | // Push source-location info into the buffer. |
| 171 | SaveSourceLocation(NamespaceLoc, Buffer, BufferSize, BufferCapacity); |
| 172 | SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity); |
| 173 | |
| 174 | assert(Range == NestedNameSpecifierLoc(ScopeRep, Buffer).getSourceRange() && |
| 175 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 178 | void CXXScopeSpec::Extend(ASTContext &Context, NamespaceAliasDecl *Alias, |
| 179 | SourceLocation AliasLoc, |
| 180 | SourceLocation ColonColonLoc) { |
| 181 | ScopeRep = NestedNameSpecifier::Create(Context, ScopeRep, Alias); |
| 182 | if (Range.getBegin().isInvalid()) |
| 183 | Range.setBegin(AliasLoc); |
| 184 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame^] | 185 | |
| 186 | // Push source-location info into the buffer. |
| 187 | SaveSourceLocation(AliasLoc, Buffer, BufferSize, BufferCapacity); |
| 188 | SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity); |
| 189 | |
| 190 | assert(Range == NestedNameSpecifierLoc(ScopeRep, Buffer).getSourceRange() && |
| 191 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 194 | void CXXScopeSpec::MakeGlobal(ASTContext &Context, |
| 195 | SourceLocation ColonColonLoc) { |
| 196 | assert(!ScopeRep && "Already have a nested-name-specifier!?"); |
| 197 | ScopeRep = NestedNameSpecifier::GlobalSpecifier(Context); |
| 198 | Range = SourceRange(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame^] | 199 | |
| 200 | // Push source-location info into the buffer. |
| 201 | SaveSourceLocation(ColonColonLoc, Buffer, BufferSize, BufferCapacity); |
| 202 | |
| 203 | assert(Range == NestedNameSpecifierLoc(ScopeRep, Buffer).getSourceRange() && |
| 204 | "NestedNameSpecifierLoc range computation incorrect"); |
| 205 | } |
| 206 | |
| 207 | void CXXScopeSpec::MakeTrivial(ASTContext &Context, |
| 208 | NestedNameSpecifier *Qualifier, SourceRange R) { |
| 209 | ScopeRep = Qualifier; |
| 210 | Range = R; |
| 211 | |
| 212 | // Construct bogus (but well-formed) source information for the |
| 213 | // nested-name-specifier. |
| 214 | BufferSize = 0; |
| 215 | llvm::SmallVector<NestedNameSpecifier *, 4> Stack; |
| 216 | for (NestedNameSpecifier *NNS = Qualifier; NNS; NNS = NNS->getPrefix()) |
| 217 | Stack.push_back(NNS); |
| 218 | while (!Stack.empty()) { |
| 219 | NestedNameSpecifier *NNS = Stack.back(); |
| 220 | Stack.pop_back(); |
| 221 | switch (NNS->getKind()) { |
| 222 | case NestedNameSpecifier::Identifier: |
| 223 | case NestedNameSpecifier::Namespace: |
| 224 | case NestedNameSpecifier::NamespaceAlias: |
| 225 | SaveSourceLocation(R.getBegin(), Buffer, BufferSize, BufferCapacity); |
| 226 | break; |
| 227 | |
| 228 | case NestedNameSpecifier::TypeSpec: |
| 229 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 230 | TypeSourceInfo *TSInfo |
| 231 | = Context.getTrivialTypeSourceInfo(QualType(NNS->getAsType(), 0), |
| 232 | R.getBegin()); |
| 233 | SavePointer(TSInfo->getTypeLoc().getOpaqueData(), Buffer, BufferSize, |
| 234 | BufferCapacity); |
| 235 | break; |
| 236 | } |
| 237 | |
| 238 | case NestedNameSpecifier::Global: |
| 239 | break; |
| 240 | } |
| 241 | |
| 242 | // Save the location of the '::'. |
| 243 | SaveSourceLocation(Stack.empty()? R.getEnd() : R.getBegin(), |
| 244 | Buffer, BufferSize, BufferCapacity); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | void CXXScopeSpec::Adopt(NestedNameSpecifierLoc Other) { |
| 249 | if (!Other) { |
| 250 | Range = SourceRange(); |
| 251 | ScopeRep = 0; |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | if (BufferCapacity) |
| 256 | free(Buffer); |
| 257 | |
| 258 | // Rather than copying the data (which is wasteful), "adopt" the |
| 259 | // pointer (which points into the ASTContext) but set the capacity to zero to |
| 260 | // indicate that we don't own it. |
| 261 | Range = Other.getSourceRange(); |
| 262 | ScopeRep = Other.getNestedNameSpecifier(); |
| 263 | Buffer = static_cast<char *>(Other.getOpaqueData()); |
| 264 | BufferSize = Other.getDataLength(); |
| 265 | BufferCapacity = 0; |
| 266 | } |
| 267 | |
| 268 | NestedNameSpecifierLoc CXXScopeSpec::getWithLocInContext(ASTContext &Context) { |
| 269 | if (isEmpty() || isInvalid()) |
| 270 | return NestedNameSpecifierLoc(); |
| 271 | |
| 272 | // If we adopted our data pointer from elsewhere in the AST context, there's |
| 273 | // no need to copy the memory. |
| 274 | if (BufferCapacity == 0) |
| 275 | return NestedNameSpecifierLoc(ScopeRep, Buffer); |
| 276 | |
| 277 | void *Mem = Context.Allocate(BufferSize, llvm::alignOf<void *>()); |
| 278 | memcpy(Mem, Buffer, BufferSize); |
| 279 | return NestedNameSpecifierLoc(ScopeRep, Mem); |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 282 | /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. |
| 283 | /// "TheDeclarator" is the declarator that this will be added to. |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 284 | DeclaratorChunk DeclaratorChunk::getFunction(const ParsedAttributes &attrs, |
| 285 | bool hasProto, bool isVariadic, |
Douglas Gregor | 965acbb | 2009-02-18 07:07:28 +0000 | [diff] [blame] | 286 | SourceLocation EllipsisLoc, |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 287 | ParamInfo *ArgInfo, |
| 288 | unsigned NumArgs, |
| 289 | unsigned TypeQuals, |
Douglas Gregor | 83f5172 | 2011-01-26 03:43:54 +0000 | [diff] [blame] | 290 | bool RefQualifierIsLvalueRef, |
| 291 | SourceLocation RefQualifierLoc, |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 292 | bool hasExceptionSpec, |
Sebastian Redl | 3cc9726 | 2009-05-31 11:47:27 +0000 | [diff] [blame] | 293 | SourceLocation ThrowLoc, |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 294 | bool hasAnyExceptionSpec, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 295 | ParsedType *Exceptions, |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 296 | SourceRange *ExceptionRanges, |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 297 | unsigned NumExceptions, |
Argyrios Kyrtzidis | 82bf010 | 2009-08-19 23:14:54 +0000 | [diff] [blame] | 298 | SourceLocation LPLoc, |
| 299 | SourceLocation RPLoc, |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 300 | Declarator &TheDeclarator, |
| 301 | ParsedType TrailingReturnType) { |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 302 | DeclaratorChunk I; |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 303 | I.Kind = Function; |
Argyrios Kyrtzidis | 82bf010 | 2009-08-19 23:14:54 +0000 | [diff] [blame] | 304 | I.Loc = LPLoc; |
| 305 | I.EndLoc = RPLoc; |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 306 | I.Fun.AttrList = attrs.getList(); |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 307 | I.Fun.hasPrototype = hasProto; |
| 308 | I.Fun.isVariadic = isVariadic; |
| 309 | I.Fun.EllipsisLoc = EllipsisLoc.getRawEncoding(); |
| 310 | I.Fun.DeleteArgInfo = false; |
| 311 | I.Fun.TypeQuals = TypeQuals; |
| 312 | I.Fun.NumArgs = NumArgs; |
| 313 | I.Fun.ArgInfo = 0; |
Douglas Gregor | 83f5172 | 2011-01-26 03:43:54 +0000 | [diff] [blame] | 314 | I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef; |
| 315 | I.Fun.RefQualifierLoc = RefQualifierLoc.getRawEncoding(); |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 316 | I.Fun.hasExceptionSpec = hasExceptionSpec; |
Sebastian Redl | 3cc9726 | 2009-05-31 11:47:27 +0000 | [diff] [blame] | 317 | I.Fun.ThrowLoc = ThrowLoc.getRawEncoding(); |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 318 | I.Fun.hasAnyExceptionSpec = hasAnyExceptionSpec; |
| 319 | I.Fun.NumExceptions = NumExceptions; |
| 320 | I.Fun.Exceptions = 0; |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 321 | I.Fun.TrailingReturnType = TrailingReturnType.getAsOpaquePtr(); |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 322 | |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 323 | // new[] an argument array if needed. |
| 324 | if (NumArgs) { |
| 325 | // If the 'InlineParams' in Declarator is unused and big enough, put our |
| 326 | // parameter list there (in an effort to avoid new/delete traffic). If it |
| 327 | // is already used (consider a function returning a function pointer) or too |
| 328 | // small (function taking too many arguments), go to the heap. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 329 | if (!TheDeclarator.InlineParamsUsed && |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 330 | NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) { |
| 331 | I.Fun.ArgInfo = TheDeclarator.InlineParams; |
| 332 | I.Fun.DeleteArgInfo = false; |
| 333 | TheDeclarator.InlineParamsUsed = true; |
| 334 | } else { |
| 335 | I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs]; |
| 336 | I.Fun.DeleteArgInfo = true; |
| 337 | } |
| 338 | memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs); |
| 339 | } |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 340 | // new[] an exception array if needed |
| 341 | if (NumExceptions) { |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 342 | I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions]; |
| 343 | for (unsigned i = 0; i != NumExceptions; ++i) { |
| 344 | I.Fun.Exceptions[i].Ty = Exceptions[i]; |
| 345 | I.Fun.Exceptions[i].Range = ExceptionRanges[i]; |
| 346 | } |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 347 | } |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 348 | return I; |
| 349 | } |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 350 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 351 | /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this |
Chris Lattner | 2a327d1 | 2009-02-27 18:35:46 +0000 | [diff] [blame] | 352 | /// declaration specifier includes. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 353 | /// |
| 354 | unsigned DeclSpec::getParsedSpecifiers() const { |
| 355 | unsigned Res = 0; |
| 356 | if (StorageClassSpec != SCS_unspecified || |
| 357 | SCS_thread_specified) |
| 358 | Res |= PQ_StorageClassSpecifier; |
Mike Stump | d420433 | 2008-06-19 19:52:46 +0000 | [diff] [blame] | 359 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 360 | if (TypeQualifiers != TQ_unspecified) |
| 361 | Res |= PQ_TypeQualifier; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 362 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 363 | if (hasTypeSpecifier()) |
| 364 | Res |= PQ_TypeSpecifier; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 366 | if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 367 | Res |= PQ_FunctionSpecifier; |
| 368 | return Res; |
| 369 | } |
| 370 | |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 371 | template <class T> static bool BadSpecifier(T TNew, T TPrev, |
| 372 | const char *&PrevSpec, |
| 373 | unsigned &DiagID) { |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 374 | PrevSpec = DeclSpec::getSpecifierName(TPrev); |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 375 | DiagID = (TNew == TPrev ? diag::ext_duplicate_declspec |
| 376 | : diag::err_invalid_decl_spec_combination); |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 377 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 378 | } |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 379 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 380 | const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) { |
| 381 | switch (S) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 382 | case DeclSpec::SCS_unspecified: return "unspecified"; |
| 383 | case DeclSpec::SCS_typedef: return "typedef"; |
| 384 | case DeclSpec::SCS_extern: return "extern"; |
| 385 | case DeclSpec::SCS_static: return "static"; |
| 386 | case DeclSpec::SCS_auto: return "auto"; |
| 387 | case DeclSpec::SCS_register: return "register"; |
Eli Friedman | 63054b3 | 2009-04-19 20:27:55 +0000 | [diff] [blame] | 388 | case DeclSpec::SCS_private_extern: return "__private_extern__"; |
Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 389 | case DeclSpec::SCS_mutable: return "mutable"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 390 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 391 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 392 | } |
| 393 | |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 394 | const char *DeclSpec::getSpecifierName(TSW W) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 395 | switch (W) { |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 396 | case TSW_unspecified: return "unspecified"; |
| 397 | case TSW_short: return "short"; |
| 398 | case TSW_long: return "long"; |
| 399 | case TSW_longlong: return "long long"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 400 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 401 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 402 | } |
| 403 | |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 404 | const char *DeclSpec::getSpecifierName(TSC C) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 405 | switch (C) { |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 406 | case TSC_unspecified: return "unspecified"; |
| 407 | case TSC_imaginary: return "imaginary"; |
| 408 | case TSC_complex: return "complex"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 409 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 410 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 414 | const char *DeclSpec::getSpecifierName(TSS S) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 415 | switch (S) { |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 416 | case TSS_unspecified: return "unspecified"; |
| 417 | case TSS_signed: return "signed"; |
| 418 | case TSS_unsigned: return "unsigned"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 419 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 420 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | const char *DeclSpec::getSpecifierName(DeclSpec::TST T) { |
| 424 | switch (T) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 425 | case DeclSpec::TST_unspecified: return "unspecified"; |
| 426 | case DeclSpec::TST_void: return "void"; |
| 427 | case DeclSpec::TST_char: return "char"; |
Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 428 | case DeclSpec::TST_wchar: return "wchar_t"; |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 429 | case DeclSpec::TST_char16: return "char16_t"; |
| 430 | case DeclSpec::TST_char32: return "char32_t"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 431 | case DeclSpec::TST_int: return "int"; |
| 432 | case DeclSpec::TST_float: return "float"; |
| 433 | case DeclSpec::TST_double: return "double"; |
| 434 | case DeclSpec::TST_bool: return "_Bool"; |
| 435 | case DeclSpec::TST_decimal32: return "_Decimal32"; |
| 436 | case DeclSpec::TST_decimal64: return "_Decimal64"; |
| 437 | case DeclSpec::TST_decimal128: return "_Decimal128"; |
| 438 | case DeclSpec::TST_enum: return "enum"; |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 439 | case DeclSpec::TST_class: return "class"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 440 | case DeclSpec::TST_union: return "union"; |
| 441 | case DeclSpec::TST_struct: return "struct"; |
Douglas Gregor | 1a51b4a | 2009-02-09 15:09:02 +0000 | [diff] [blame] | 442 | case DeclSpec::TST_typename: return "type-name"; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 443 | case DeclSpec::TST_typeofType: |
| 444 | case DeclSpec::TST_typeofExpr: return "typeof"; |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 445 | case DeclSpec::TST_auto: return "auto"; |
| 446 | case DeclSpec::TST_decltype: return "(decltype)"; |
| 447 | case DeclSpec::TST_error: return "(error)"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 448 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 449 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 450 | } |
| 451 | |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 452 | const char *DeclSpec::getSpecifierName(TQ T) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 453 | switch (T) { |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 454 | case DeclSpec::TQ_unspecified: return "unspecified"; |
| 455 | case DeclSpec::TQ_const: return "const"; |
| 456 | case DeclSpec::TQ_restrict: return "restrict"; |
| 457 | case DeclSpec::TQ_volatile: return "volatile"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 458 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 459 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | bool DeclSpec::SetStorageClassSpec(SCS S, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 463 | const char *&PrevSpec, |
Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 464 | unsigned &DiagID, |
| 465 | const LangOptions &Lang) { |
| 466 | // OpenCL prohibits extern, auto, register, and static |
| 467 | // It seems sensible to prohibit private_extern too |
| 468 | if (Lang.OpenCL) { |
| 469 | switch (S) { |
| 470 | case SCS_extern: |
| 471 | case SCS_private_extern: |
| 472 | case SCS_auto: |
| 473 | case SCS_register: |
| 474 | case SCS_static: |
| 475 | DiagID = diag::err_not_opencl_storage_class_specifier; |
| 476 | PrevSpec = getSpecifierName(S); |
| 477 | return true; |
| 478 | default: |
| 479 | break; |
| 480 | } |
| 481 | } |
| 482 | |
Abramo Bagnara | 35f9a19 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 483 | if (StorageClassSpec != SCS_unspecified) { |
| 484 | // Changing storage class is allowed only if the previous one |
| 485 | // was the 'extern' that is part of a linkage specification and |
| 486 | // the new storage class is 'typedef'. |
| 487 | if (!(SCS_extern_in_linkage_spec && |
| 488 | StorageClassSpec == SCS_extern && |
| 489 | S == SCS_typedef)) |
| 490 | return BadSpecifier(S, (SCS)StorageClassSpec, PrevSpec, DiagID); |
| 491 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 492 | StorageClassSpec = S; |
| 493 | StorageClassSpecLoc = Loc; |
Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 494 | assert((unsigned)S == StorageClassSpec && "SCS constants overflow bitfield"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 495 | return false; |
| 496 | } |
| 497 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 498 | bool DeclSpec::SetStorageClassSpecThread(SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 499 | const char *&PrevSpec, |
| 500 | unsigned &DiagID) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 501 | if (SCS_thread_specified) { |
| 502 | PrevSpec = "__thread"; |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 503 | DiagID = diag::ext_duplicate_declspec; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 504 | return true; |
| 505 | } |
| 506 | SCS_thread_specified = true; |
| 507 | SCS_threadLoc = Loc; |
| 508 | return false; |
| 509 | } |
| 510 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 511 | /// These methods set the specified attribute of the DeclSpec, but return true |
| 512 | /// and ignore the request if invalid (e.g. "extern" then "auto" is |
| 513 | /// specified). |
| 514 | bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 515 | const char *&PrevSpec, |
| 516 | unsigned &DiagID) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 517 | if (TypeSpecWidth != TSW_unspecified && |
| 518 | // Allow turning long -> long long. |
| 519 | (W != TSW_longlong || TypeSpecWidth != TSW_long)) |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 520 | return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 521 | TypeSpecWidth = W; |
| 522 | TSWLoc = Loc; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 523 | if (TypeAltiVecVector && !TypeAltiVecBool && |
| 524 | ((TypeSpecWidth == TSW_long) || (TypeSpecWidth == TSW_longlong))) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 525 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 526 | DiagID = diag::warn_vector_long_decl_spec_combination; |
| 527 | return true; |
| 528 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 529 | return false; |
| 530 | } |
| 531 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 532 | bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 533 | const char *&PrevSpec, |
| 534 | unsigned &DiagID) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 535 | if (TypeSpecComplex != TSC_unspecified) |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 536 | return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 537 | TypeSpecComplex = C; |
| 538 | TSCLoc = Loc; |
| 539 | return false; |
| 540 | } |
| 541 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 543 | const char *&PrevSpec, |
| 544 | unsigned &DiagID) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 545 | if (TypeSpecSign != TSS_unspecified) |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 546 | return BadSpecifier(S, (TSS)TypeSpecSign, PrevSpec, DiagID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 547 | TypeSpecSign = S; |
| 548 | TSSLoc = Loc; |
| 549 | return false; |
| 550 | } |
| 551 | |
| 552 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 553 | const char *&PrevSpec, |
| 554 | unsigned &DiagID, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 555 | ParsedType Rep) { |
| 556 | assert(isTypeRep(T) && "T does not store a type"); |
| 557 | assert(Rep && "no type provided!"); |
| 558 | if (TypeSpecType != TST_unspecified) { |
| 559 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 560 | DiagID = diag::err_invalid_decl_spec_combination; |
| 561 | return true; |
| 562 | } |
| 563 | TypeSpecType = T; |
| 564 | TypeRep = Rep; |
| 565 | TSTLoc = Loc; |
| 566 | TypeSpecOwned = false; |
| 567 | return false; |
| 568 | } |
| 569 | |
| 570 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
| 571 | const char *&PrevSpec, |
| 572 | unsigned &DiagID, |
| 573 | Expr *Rep) { |
| 574 | assert(isExprRep(T) && "T does not store an expr"); |
| 575 | assert(Rep && "no expression provided!"); |
| 576 | if (TypeSpecType != TST_unspecified) { |
| 577 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 578 | DiagID = diag::err_invalid_decl_spec_combination; |
| 579 | return true; |
| 580 | } |
| 581 | TypeSpecType = T; |
| 582 | ExprRep = Rep; |
| 583 | TSTLoc = Loc; |
| 584 | TypeSpecOwned = false; |
| 585 | return false; |
| 586 | } |
| 587 | |
| 588 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
| 589 | const char *&PrevSpec, |
| 590 | unsigned &DiagID, |
| 591 | Decl *Rep, bool Owned) { |
| 592 | assert(isDeclRep(T) && "T does not store a decl"); |
| 593 | // Unlike the other cases, we don't assert that we actually get a decl. |
| 594 | |
| 595 | if (TypeSpecType != TST_unspecified) { |
| 596 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 597 | DiagID = diag::err_invalid_decl_spec_combination; |
| 598 | return true; |
| 599 | } |
| 600 | TypeSpecType = T; |
| 601 | DeclRep = Rep; |
| 602 | TSTLoc = Loc; |
| 603 | TypeSpecOwned = Owned; |
| 604 | return false; |
| 605 | } |
| 606 | |
| 607 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
| 608 | const char *&PrevSpec, |
| 609 | unsigned &DiagID) { |
| 610 | assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) && |
| 611 | "rep required for these type-spec kinds!"); |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 612 | if (TypeSpecType != TST_unspecified) { |
| 613 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 614 | DiagID = diag::err_invalid_decl_spec_combination; |
| 615 | return true; |
| 616 | } |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 617 | if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) { |
| 618 | TypeAltiVecBool = true; |
| 619 | TSTLoc = Loc; |
| 620 | return false; |
| 621 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 622 | TypeSpecType = T; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 623 | TSTLoc = Loc; |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 624 | TypeSpecOwned = false; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 625 | if (TypeAltiVecVector && !TypeAltiVecBool && (TypeSpecType == TST_double)) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 626 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 627 | DiagID = diag::err_invalid_vector_decl_spec; |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 628 | return true; |
| 629 | } |
| 630 | return false; |
| 631 | } |
| 632 | |
| 633 | bool DeclSpec::SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, |
| 634 | const char *&PrevSpec, unsigned &DiagID) { |
| 635 | if (TypeSpecType != TST_unspecified) { |
| 636 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 637 | DiagID = diag::err_invalid_vector_decl_spec_combination; |
| 638 | return true; |
| 639 | } |
| 640 | TypeAltiVecVector = isAltiVecVector; |
| 641 | AltiVecLoc = Loc; |
| 642 | return false; |
| 643 | } |
| 644 | |
| 645 | bool DeclSpec::SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, |
| 646 | const char *&PrevSpec, unsigned &DiagID) { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 647 | if (!TypeAltiVecVector || TypeAltiVecPixel || |
| 648 | (TypeSpecType != TST_unspecified)) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 649 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 650 | DiagID = diag::err_invalid_pixel_decl_spec_combination; |
| 651 | return true; |
| 652 | } |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 653 | TypeAltiVecPixel = isAltiVecPixel; |
| 654 | TSTLoc = Loc; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 655 | return false; |
| 656 | } |
| 657 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 658 | bool DeclSpec::SetTypeSpecError() { |
| 659 | TypeSpecType = TST_error; |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 660 | TypeSpecOwned = false; |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 661 | TSTLoc = SourceLocation(); |
| 662 | return false; |
| 663 | } |
| 664 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 665 | bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 666 | unsigned &DiagID, const LangOptions &Lang) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 667 | // Duplicates turn into warnings pre-C99. |
| 668 | if ((TypeQualifiers & T) && !Lang.C99) |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 669 | return BadSpecifier(T, T, PrevSpec, DiagID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 670 | TypeQualifiers |= T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 671 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 672 | switch (T) { |
| 673 | default: assert(0 && "Unknown type qualifier!"); |
| 674 | case TQ_const: TQ_constLoc = Loc; break; |
| 675 | case TQ_restrict: TQ_restrictLoc = Loc; break; |
| 676 | case TQ_volatile: TQ_volatileLoc = Loc; break; |
| 677 | } |
| 678 | return false; |
| 679 | } |
| 680 | |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 681 | bool DeclSpec::SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, |
| 682 | unsigned &DiagID) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 683 | // 'inline inline' is ok. |
| 684 | FS_inline_specified = true; |
| 685 | FS_inlineLoc = Loc; |
| 686 | return false; |
| 687 | } |
| 688 | |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 689 | bool DeclSpec::SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, |
| 690 | unsigned &DiagID) { |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 691 | // 'virtual virtual' is ok. |
| 692 | FS_virtual_specified = true; |
| 693 | FS_virtualLoc = Loc; |
| 694 | return false; |
| 695 | } |
| 696 | |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 697 | bool DeclSpec::SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, |
| 698 | unsigned &DiagID) { |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 699 | // 'explicit explicit' is ok. |
| 700 | FS_explicit_specified = true; |
| 701 | FS_explicitLoc = Loc; |
| 702 | return false; |
| 703 | } |
| 704 | |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 705 | bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, |
| 706 | unsigned &DiagID) { |
Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 707 | if (Friend_specified) { |
| 708 | PrevSpec = "friend"; |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 709 | DiagID = diag::ext_duplicate_declspec; |
Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 710 | return true; |
| 711 | } |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 712 | |
Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 713 | Friend_specified = true; |
| 714 | FriendLoc = Loc; |
| 715 | return false; |
| 716 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 717 | |
Sebastian Redl | 2ac6723 | 2009-11-05 15:47:02 +0000 | [diff] [blame] | 718 | bool DeclSpec::SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec, |
| 719 | unsigned &DiagID) { |
| 720 | // 'constexpr constexpr' is ok. |
| 721 | Constexpr_specified = true; |
| 722 | ConstexprLoc = Loc; |
| 723 | return false; |
| 724 | } |
| 725 | |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 726 | void DeclSpec::setProtocolQualifiers(Decl * const *Protos, |
Argyrios Kyrtzidis | e3a535b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 727 | unsigned NP, |
| 728 | SourceLocation *ProtoLocs, |
| 729 | SourceLocation LAngleLoc) { |
| 730 | if (NP == 0) return; |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 731 | ProtocolQualifiers = new Decl*[NP]; |
Argyrios Kyrtzidis | e3a535b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 732 | ProtocolLocs = new SourceLocation[NP]; |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 733 | memcpy((void*)ProtocolQualifiers, Protos, sizeof(Decl*)*NP); |
Argyrios Kyrtzidis | e3a535b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 734 | memcpy(ProtocolLocs, ProtoLocs, sizeof(SourceLocation)*NP); |
| 735 | NumProtocolQualifiers = NP; |
| 736 | ProtocolLAngleLoc = LAngleLoc; |
| 737 | } |
| 738 | |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 739 | void DeclSpec::SaveWrittenBuiltinSpecs() { |
| 740 | writtenBS.Sign = getTypeSpecSign(); |
| 741 | writtenBS.Width = getTypeSpecWidth(); |
| 742 | writtenBS.Type = getTypeSpecType(); |
| 743 | // Search the list of attributes for the presence of a mode attribute. |
| 744 | writtenBS.ModeAttr = false; |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 745 | AttributeList* attrs = getAttributes().getList(); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 746 | while (attrs) { |
| 747 | if (attrs->getKind() == AttributeList::AT_mode) { |
| 748 | writtenBS.ModeAttr = true; |
| 749 | break; |
| 750 | } |
| 751 | attrs = attrs->getNext(); |
| 752 | } |
| 753 | } |
| 754 | |
Abramo Bagnara | 35f9a19 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 755 | void DeclSpec::SaveStorageSpecifierAsWritten() { |
| 756 | if (SCS_extern_in_linkage_spec && StorageClassSpec == SCS_extern) |
| 757 | // If 'extern' is part of a linkage specification, |
| 758 | // then it is not a storage class "as written". |
| 759 | StorageClassSpecAsWritten = SCS_unspecified; |
| 760 | else |
| 761 | StorageClassSpecAsWritten = StorageClassSpec; |
| 762 | } |
| 763 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 764 | /// Finish - This does final analysis of the declspec, rejecting things like |
| 765 | /// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or |
| 766 | /// diag::NUM_DIAGNOSTICS if there is no error. After calling this method, |
| 767 | /// DeclSpec is guaranteed self-consistent, even if an error occurred. |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 768 | void DeclSpec::Finish(Diagnostic &D, Preprocessor &PP) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 769 | // Before possibly changing their values, save specs as written. |
| 770 | SaveWrittenBuiltinSpecs(); |
Douglas Gregor | 16573fa | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 771 | SaveStorageSpecifierAsWritten(); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 772 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 773 | // Check the type specifier components first. |
| 774 | |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 775 | // Validate and finalize AltiVec vector declspec. |
| 776 | if (TypeAltiVecVector) { |
| 777 | if (TypeAltiVecBool) { |
| 778 | // Sign specifiers are not allowed with vector bool. (PIM 2.1) |
| 779 | if (TypeSpecSign != TSS_unspecified) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 780 | Diag(D, TSSLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 781 | << getSpecifierName((TSS)TypeSpecSign); |
| 782 | } |
| 783 | |
| 784 | // Only char/int are valid with vector bool. (PIM 2.1) |
Duncan Sands | 2e964a92 | 2010-06-23 19:34:52 +0000 | [diff] [blame] | 785 | if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) && |
| 786 | (TypeSpecType != TST_int)) || TypeAltiVecPixel) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 787 | Diag(D, TSTLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 788 | << (TypeAltiVecPixel ? "__pixel" : |
| 789 | getSpecifierName((TST)TypeSpecType)); |
| 790 | } |
| 791 | |
| 792 | // Only 'short' is valid with vector bool. (PIM 2.1) |
| 793 | if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short)) |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 794 | Diag(D, TSWLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 795 | << getSpecifierName((TSW)TypeSpecWidth); |
| 796 | |
| 797 | // Elements of vector bool are interpreted as unsigned. (PIM 2.1) |
| 798 | if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) || |
| 799 | (TypeSpecWidth != TSW_unspecified)) |
| 800 | TypeSpecSign = TSS_unsigned; |
| 801 | } |
| 802 | |
| 803 | if (TypeAltiVecPixel) { |
| 804 | //TODO: perform validation |
| 805 | TypeSpecType = TST_int; |
| 806 | TypeSpecSign = TSS_unsigned; |
| 807 | TypeSpecWidth = TSW_short; |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 808 | TypeSpecOwned = false; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 809 | } |
| 810 | } |
| 811 | |
Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 812 | // signed/unsigned are only valid with int/char/wchar_t. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 813 | if (TypeSpecSign != TSS_unspecified) { |
| 814 | if (TypeSpecType == TST_unspecified) |
| 815 | TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int. |
Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 816 | else if (TypeSpecType != TST_int && |
| 817 | TypeSpecType != TST_char && TypeSpecType != TST_wchar) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 818 | Diag(D, TSSLoc, diag::err_invalid_sign_spec) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 819 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 820 | // signed double -> double. |
| 821 | TypeSpecSign = TSS_unspecified; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | // Validate the width of the type. |
| 826 | switch (TypeSpecWidth) { |
| 827 | case TSW_unspecified: break; |
| 828 | case TSW_short: // short int |
| 829 | case TSW_longlong: // long long int |
| 830 | if (TypeSpecType == TST_unspecified) |
| 831 | TypeSpecType = TST_int; // short -> short int, long long -> long long int. |
| 832 | else if (TypeSpecType != TST_int) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 833 | Diag(D, TSWLoc, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 834 | TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 835 | : diag::err_invalid_longlong_spec) |
| 836 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 837 | TypeSpecType = TST_int; |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 838 | TypeSpecOwned = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 839 | } |
| 840 | break; |
| 841 | case TSW_long: // long double, long int |
| 842 | if (TypeSpecType == TST_unspecified) |
| 843 | TypeSpecType = TST_int; // long -> long int. |
| 844 | else if (TypeSpecType != TST_int && TypeSpecType != TST_double) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 845 | Diag(D, TSWLoc, diag::err_invalid_long_spec) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 846 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 847 | TypeSpecType = TST_int; |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 848 | TypeSpecOwned = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 849 | } |
| 850 | break; |
| 851 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 852 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 853 | // TODO: if the implementation does not implement _Complex or _Imaginary, |
| 854 | // disallow their use. Need information about the backend. |
| 855 | if (TypeSpecComplex != TSC_unspecified) { |
| 856 | if (TypeSpecType == TST_unspecified) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 857 | Diag(D, TSCLoc, diag::ext_plain_complex) |
Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 858 | << FixItHint::CreateInsertion( |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 859 | PP.getLocForEndOfToken(getTypeSpecComplexLoc()), |
| 860 | " double"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 861 | TypeSpecType = TST_double; // _Complex -> _Complex double. |
| 862 | } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) { |
| 863 | // Note that this intentionally doesn't include _Complex _Bool. |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 864 | Diag(D, TSTLoc, diag::ext_integer_complex); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 865 | } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 866 | Diag(D, TSCLoc, diag::err_invalid_complex_spec) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 867 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 868 | TypeSpecComplex = TSC_unspecified; |
| 869 | } |
| 870 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 871 | |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 872 | // C++ [class.friend]p6: |
| 873 | // No storage-class-specifier shall appear in the decl-specifier-seq |
| 874 | // of a friend declaration. |
| 875 | if (isFriendSpecified() && getStorageClassSpec()) { |
| 876 | DeclSpec::SCS SC = getStorageClassSpec(); |
| 877 | const char *SpecName = getSpecifierName(SC); |
| 878 | |
| 879 | SourceLocation SCLoc = getStorageClassSpecLoc(); |
| 880 | SourceLocation SCEndLoc = SCLoc.getFileLocWithOffset(strlen(SpecName)); |
| 881 | |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 882 | Diag(D, SCLoc, diag::err_friend_storage_spec) |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 883 | << SpecName |
Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 884 | << FixItHint::CreateRemoval(SourceRange(SCLoc, SCEndLoc)); |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 885 | |
| 886 | ClearStorageClassSpecs(); |
| 887 | } |
| 888 | |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 889 | assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType)); |
| 890 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 891 | // Okay, now we can infer the real type. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 892 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 893 | // TODO: return "auto function" and other bad things based on the real type. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 894 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 895 | // 'data definition has no type or storage class'? |
| 896 | } |
Daniel Dunbar | e4858a6 | 2008-08-11 03:45:03 +0000 | [diff] [blame] | 897 | |
Sebastian Redl | a4ed0d8 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 898 | bool DeclSpec::isMissingDeclaratorOk() { |
| 899 | TST tst = getTypeSpecType(); |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 900 | return isDeclRep(tst) && getRepAsDecl() != 0 && |
| 901 | StorageClassSpec != DeclSpec::SCS_typedef; |
Sebastian Redl | a4ed0d8 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 902 | } |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 903 | |
| 904 | void UnqualifiedId::clear() { |
| 905 | if (Kind == IK_TemplateId) |
| 906 | TemplateId->Destroy(); |
| 907 | |
| 908 | Kind = IK_Identifier; |
| 909 | Identifier = 0; |
| 910 | StartLocation = SourceLocation(); |
| 911 | EndLocation = SourceLocation(); |
| 912 | } |
| 913 | |
| 914 | void UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc, |
| 915 | OverloadedOperatorKind Op, |
| 916 | SourceLocation SymbolLocations[3]) { |
| 917 | Kind = IK_OperatorFunctionId; |
| 918 | StartLocation = OperatorLoc; |
| 919 | EndLocation = OperatorLoc; |
| 920 | OperatorFunctionId.Operator = Op; |
| 921 | for (unsigned I = 0; I != 3; ++I) { |
| 922 | OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I].getRawEncoding(); |
| 923 | |
| 924 | if (SymbolLocations[I].isValid()) |
| 925 | EndLocation = SymbolLocations[I]; |
| 926 | } |
| 927 | } |
Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 928 | |
Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 929 | bool VirtSpecifiers::SetSpecifier(Specifier VS, SourceLocation Loc, |
Anders Carlsson | 46127a9 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 930 | const char *&PrevSpec) { |
Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 931 | if (Specifiers & VS) { |
| 932 | PrevSpec = getSpecifierName(VS); |
| 933 | return true; |
| 934 | } |
| 935 | |
| 936 | Specifiers |= VS; |
| 937 | |
| 938 | switch (VS) { |
| 939 | default: assert(0 && "Unknown specifier!"); |
| 940 | case VS_Override: VS_overrideLoc = Loc; break; |
| 941 | case VS_Final: VS_finalLoc = Loc; break; |
| 942 | case VS_New: VS_newLoc = Loc; break; |
| 943 | } |
Anders Carlsson | 46127a9 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 944 | |
Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 945 | return false; |
| 946 | } |
| 947 | |
Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 948 | const char *VirtSpecifiers::getSpecifierName(Specifier VS) { |
Anders Carlsson | c46bb7d | 2011-01-22 15:11:37 +0000 | [diff] [blame] | 949 | switch (VS) { |
| 950 | default: assert(0 && "Unknown specifier"); |
| 951 | case VS_Override: return "override"; |
| 952 | case VS_Final: return "final"; |
| 953 | case VS_New: return "new"; |
| 954 | } |
| 955 | } |
Anders Carlsson | 46127a9 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 956 | |
Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 957 | bool ClassVirtSpecifiers::SetSpecifier(Specifier CVS, SourceLocation Loc, |
Anders Carlsson | 46127a9 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 958 | const char *&PrevSpec) { |
| 959 | if (Specifiers & CVS) { |
| 960 | PrevSpec = getSpecifierName(CVS); |
| 961 | return true; |
| 962 | } |
| 963 | |
| 964 | Specifiers |= CVS; |
| 965 | |
| 966 | switch (CVS) { |
| 967 | default: assert(0 && "Unknown specifier!"); |
| 968 | case CVS_Final: CVS_finalLoc = Loc; break; |
| 969 | case CVS_Explicit: CVS_explicitLoc = Loc; break; |
| 970 | } |
| 971 | |
| 972 | return false; |
| 973 | } |
| 974 | |
Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 975 | const char *ClassVirtSpecifiers::getSpecifierName(Specifier CVS) { |
Anders Carlsson | 46127a9 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 976 | switch (CVS) { |
| 977 | default: assert(0 && "Unknown specifier"); |
| 978 | case CVS_Final: return "final"; |
| 979 | case CVS_Explicit: return "explicit"; |
| 980 | } |
| 981 | } |
| 982 | |