Chris Lattner | 289ab7b | 2006-11-08 06:54:53 +0000 | [diff] [blame] | 1 | //===--- SemaDeclSpec.cpp - Declaration Specifier Semantic Analysis -------===// |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 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. |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | 289ab7b | 2006-11-08 06:54:53 +0000 | [diff] [blame] | 10 | // This file implements semantic analysis for declaration specifiers. |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
John McCall | 8b0666c | 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 | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 18 | #include "clang/AST/NestedNameSpecifier.h" |
| 19 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | e3e01a2 | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 20 | #include "clang/Lex/Preprocessor.h" |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 21 | #include "clang/Basic/LangOptions.h" |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/STLExtras.h" |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 23 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 5253768 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 24 | #include <cstring> |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 25 | using namespace clang; |
| 26 | |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 27 | |
| 28 | static DiagnosticBuilder Diag(Diagnostic &D, SourceLocation Loc, |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 29 | unsigned DiagID) { |
| 30 | return D.Report(Loc, DiagID); |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Douglas Gregor | b53edfb | 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 | 9de54ea | 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 | 869ad45 | 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 | 90c9972 | 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 | 869ad45 | 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 | 90c9972 | 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 | 869ad45 | 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 | 90c9972 | 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 | 869ad45 | 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 | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Douglas Gregor | 7b26ff9 | 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 | 869ad45 | 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 | 7b26ff9 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Douglas Gregor | 90c9972 | 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 | 869ad45 | 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 | |
Douglas Gregor | 1445480 | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 268 | NestedNameSpecifierLoc |
| 269 | CXXScopeSpec::getWithLocInContext(ASTContext &Context) const { |
Douglas Gregor | 869ad45 | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 270 | if (isEmpty() || isInvalid()) |
| 271 | return NestedNameSpecifierLoc(); |
| 272 | |
| 273 | // If we adopted our data pointer from elsewhere in the AST context, there's |
| 274 | // no need to copy the memory. |
| 275 | if (BufferCapacity == 0) |
| 276 | return NestedNameSpecifierLoc(ScopeRep, Buffer); |
| 277 | |
| 278 | void *Mem = Context.Allocate(BufferSize, llvm::alignOf<void *>()); |
| 279 | memcpy(Mem, Buffer, BufferSize); |
| 280 | return NestedNameSpecifierLoc(ScopeRep, Mem); |
Douglas Gregor | 90c9972 | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 283 | /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. |
| 284 | /// "TheDeclarator" is the declarator that this will be added to. |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 285 | DeclaratorChunk DeclaratorChunk::getFunction(const ParsedAttributes &attrs, |
| 286 | bool hasProto, bool isVariadic, |
Douglas Gregor | 94349fd | 2009-02-18 07:07:28 +0000 | [diff] [blame] | 287 | SourceLocation EllipsisLoc, |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 288 | ParamInfo *ArgInfo, |
| 289 | unsigned NumArgs, |
| 290 | unsigned TypeQuals, |
Douglas Gregor | 5499235 | 2011-01-26 03:43:54 +0000 | [diff] [blame] | 291 | bool RefQualifierIsLvalueRef, |
| 292 | SourceLocation RefQualifierLoc, |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 293 | bool hasExceptionSpec, |
Sebastian Redl | fb3f179 | 2009-05-31 11:47:27 +0000 | [diff] [blame] | 294 | SourceLocation ThrowLoc, |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 295 | bool hasAnyExceptionSpec, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 296 | ParsedType *Exceptions, |
Sebastian Redl | d643456 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 297 | SourceRange *ExceptionRanges, |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 298 | unsigned NumExceptions, |
Argyrios Kyrtzidis | 20cf191 | 2009-08-19 23:14:54 +0000 | [diff] [blame] | 299 | SourceLocation LPLoc, |
| 300 | SourceLocation RPLoc, |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 301 | Declarator &TheDeclarator, |
| 302 | ParsedType TrailingReturnType) { |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 303 | DeclaratorChunk I; |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 304 | I.Kind = Function; |
Argyrios Kyrtzidis | 20cf191 | 2009-08-19 23:14:54 +0000 | [diff] [blame] | 305 | I.Loc = LPLoc; |
| 306 | I.EndLoc = RPLoc; |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 307 | I.Fun.AttrList = attrs.getList(); |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 308 | I.Fun.hasPrototype = hasProto; |
| 309 | I.Fun.isVariadic = isVariadic; |
| 310 | I.Fun.EllipsisLoc = EllipsisLoc.getRawEncoding(); |
| 311 | I.Fun.DeleteArgInfo = false; |
| 312 | I.Fun.TypeQuals = TypeQuals; |
| 313 | I.Fun.NumArgs = NumArgs; |
| 314 | I.Fun.ArgInfo = 0; |
Douglas Gregor | 5499235 | 2011-01-26 03:43:54 +0000 | [diff] [blame] | 315 | I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef; |
| 316 | I.Fun.RefQualifierLoc = RefQualifierLoc.getRawEncoding(); |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 317 | I.Fun.hasExceptionSpec = hasExceptionSpec; |
Sebastian Redl | fb3f179 | 2009-05-31 11:47:27 +0000 | [diff] [blame] | 318 | I.Fun.ThrowLoc = ThrowLoc.getRawEncoding(); |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 319 | I.Fun.hasAnyExceptionSpec = hasAnyExceptionSpec; |
| 320 | I.Fun.NumExceptions = NumExceptions; |
| 321 | I.Fun.Exceptions = 0; |
Douglas Gregor | 7fb2541 | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 322 | I.Fun.TrailingReturnType = TrailingReturnType.getAsOpaquePtr(); |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 323 | |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 324 | // new[] an argument array if needed. |
| 325 | if (NumArgs) { |
| 326 | // If the 'InlineParams' in Declarator is unused and big enough, put our |
| 327 | // parameter list there (in an effort to avoid new/delete traffic). If it |
| 328 | // is already used (consider a function returning a function pointer) or too |
| 329 | // small (function taking too many arguments), go to the heap. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 330 | if (!TheDeclarator.InlineParamsUsed && |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 331 | NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) { |
| 332 | I.Fun.ArgInfo = TheDeclarator.InlineParams; |
| 333 | I.Fun.DeleteArgInfo = false; |
| 334 | TheDeclarator.InlineParamsUsed = true; |
| 335 | } else { |
| 336 | I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs]; |
| 337 | I.Fun.DeleteArgInfo = true; |
| 338 | } |
| 339 | memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs); |
| 340 | } |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 341 | // new[] an exception array if needed |
| 342 | if (NumExceptions) { |
Sebastian Redl | d643456 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 343 | I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions]; |
| 344 | for (unsigned i = 0; i != NumExceptions; ++i) { |
| 345 | I.Fun.Exceptions[i].Ty = Exceptions[i]; |
| 346 | I.Fun.Exceptions[i].Range = ExceptionRanges[i]; |
| 347 | } |
Sebastian Redl | 2b9cacb | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 348 | } |
Chris Lattner | 1ce41ed | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 349 | return I; |
| 350 | } |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 351 | |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 352 | /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this |
Chris Lattner | e0c5116 | 2009-02-27 18:35:46 +0000 | [diff] [blame] | 353 | /// declaration specifier includes. |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 354 | /// |
| 355 | unsigned DeclSpec::getParsedSpecifiers() const { |
| 356 | unsigned Res = 0; |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 357 | if (StorageClassSpec != SCS_unspecified || |
| 358 | SCS_thread_specified) |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 359 | Res |= PQ_StorageClassSpecifier; |
Mike Stump | 65643c6 | 2008-06-19 19:52:46 +0000 | [diff] [blame] | 360 | |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 361 | if (TypeQualifiers != TQ_unspecified) |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 362 | Res |= PQ_TypeQualifier; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | |
Chris Lattner | f055d43 | 2006-11-28 04:28:12 +0000 | [diff] [blame] | 364 | if (hasTypeSpecifier()) |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 365 | Res |= PQ_TypeSpecifier; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 366 | |
Douglas Gregor | 61956c4 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 367 | if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified) |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 368 | Res |= PQ_FunctionSpecifier; |
| 369 | return Res; |
| 370 | } |
| 371 | |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 372 | template <class T> static bool BadSpecifier(T TNew, T TPrev, |
| 373 | const char *&PrevSpec, |
| 374 | unsigned &DiagID) { |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 375 | PrevSpec = DeclSpec::getSpecifierName(TPrev); |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 376 | DiagID = (TNew == TPrev ? diag::ext_duplicate_declspec |
| 377 | : diag::err_invalid_decl_spec_combination); |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 378 | return true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 379 | } |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 380 | |
Chris Lattner | 7bd11fe | 2007-01-23 04:35:33 +0000 | [diff] [blame] | 381 | const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) { |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 382 | switch (S) { |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 383 | case DeclSpec::SCS_unspecified: return "unspecified"; |
| 384 | case DeclSpec::SCS_typedef: return "typedef"; |
| 385 | case DeclSpec::SCS_extern: return "extern"; |
| 386 | case DeclSpec::SCS_static: return "static"; |
| 387 | case DeclSpec::SCS_auto: return "auto"; |
| 388 | case DeclSpec::SCS_register: return "register"; |
Eli Friedman | d5c0eed | 2009-04-19 20:27:55 +0000 | [diff] [blame] | 389 | case DeclSpec::SCS_private_extern: return "__private_extern__"; |
Sebastian Redl | ccdfaba | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 390 | case DeclSpec::SCS_mutable: return "mutable"; |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 391 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 392 | llvm_unreachable("Unknown typespec!"); |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 393 | } |
| 394 | |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 395 | const char *DeclSpec::getSpecifierName(TSW W) { |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 396 | switch (W) { |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 397 | case TSW_unspecified: return "unspecified"; |
| 398 | case TSW_short: return "short"; |
| 399 | case TSW_long: return "long"; |
| 400 | case TSW_longlong: return "long long"; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 401 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 402 | llvm_unreachable("Unknown typespec!"); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 403 | } |
| 404 | |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 405 | const char *DeclSpec::getSpecifierName(TSC C) { |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 406 | switch (C) { |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 407 | case TSC_unspecified: return "unspecified"; |
| 408 | case TSC_imaginary: return "imaginary"; |
| 409 | case TSC_complex: return "complex"; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 410 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 411 | llvm_unreachable("Unknown typespec!"); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 415 | const char *DeclSpec::getSpecifierName(TSS S) { |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 416 | switch (S) { |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 417 | case TSS_unspecified: return "unspecified"; |
| 418 | case TSS_signed: return "signed"; |
| 419 | case TSS_unsigned: return "unsigned"; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 420 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 421 | llvm_unreachable("Unknown typespec!"); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 422 | } |
| 423 | |
Chris Lattner | 69680ea | 2007-01-23 04:34:43 +0000 | [diff] [blame] | 424 | const char *DeclSpec::getSpecifierName(DeclSpec::TST T) { |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 425 | switch (T) { |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 426 | case DeclSpec::TST_unspecified: return "unspecified"; |
| 427 | case DeclSpec::TST_void: return "void"; |
| 428 | case DeclSpec::TST_char: return "char"; |
Argyrios Kyrtzidis | 40e9e48 | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 429 | case DeclSpec::TST_wchar: return "wchar_t"; |
Alisdair Meredith | a9ad47d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 430 | case DeclSpec::TST_char16: return "char16_t"; |
| 431 | case DeclSpec::TST_char32: return "char32_t"; |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 432 | case DeclSpec::TST_int: return "int"; |
| 433 | case DeclSpec::TST_float: return "float"; |
| 434 | case DeclSpec::TST_double: return "double"; |
| 435 | case DeclSpec::TST_bool: return "_Bool"; |
| 436 | case DeclSpec::TST_decimal32: return "_Decimal32"; |
| 437 | case DeclSpec::TST_decimal64: return "_Decimal64"; |
| 438 | case DeclSpec::TST_decimal128: return "_Decimal128"; |
Chris Lattner | da72c82 | 2006-08-13 22:16:42 +0000 | [diff] [blame] | 439 | case DeclSpec::TST_enum: return "enum"; |
Chris Lattner | 861a226 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 440 | case DeclSpec::TST_class: return "class"; |
Chris Lattner | da72c82 | 2006-08-13 22:16:42 +0000 | [diff] [blame] | 441 | case DeclSpec::TST_union: return "union"; |
| 442 | case DeclSpec::TST_struct: return "struct"; |
Douglas Gregor | 9817f4a | 2009-02-09 15:09:02 +0000 | [diff] [blame] | 443 | case DeclSpec::TST_typename: return "type-name"; |
Steve Naroff | ad373bd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 444 | case DeclSpec::TST_typeofType: |
| 445 | case DeclSpec::TST_typeofExpr: return "typeof"; |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 446 | case DeclSpec::TST_auto: return "auto"; |
| 447 | case DeclSpec::TST_decltype: return "(decltype)"; |
| 448 | case DeclSpec::TST_error: return "(error)"; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 449 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 450 | llvm_unreachable("Unknown typespec!"); |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 451 | } |
| 452 | |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 453 | const char *DeclSpec::getSpecifierName(TQ T) { |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 454 | switch (T) { |
John McCall | 898cd0f | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 455 | case DeclSpec::TQ_unspecified: return "unspecified"; |
| 456 | case DeclSpec::TQ_const: return "const"; |
| 457 | case DeclSpec::TQ_restrict: return "restrict"; |
| 458 | case DeclSpec::TQ_volatile: return "volatile"; |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 459 | } |
Jeffrey Yasskin | 1615d45 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 460 | llvm_unreachable("Unknown typespec!"); |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 461 | } |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 462 | |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 463 | bool DeclSpec::SetStorageClassSpec(SCS S, SourceLocation Loc, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 464 | const char *&PrevSpec, |
Peter Collingbourne | de32b20 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 465 | unsigned &DiagID, |
| 466 | const LangOptions &Lang) { |
| 467 | // OpenCL prohibits extern, auto, register, and static |
| 468 | // It seems sensible to prohibit private_extern too |
| 469 | if (Lang.OpenCL) { |
| 470 | switch (S) { |
| 471 | case SCS_extern: |
| 472 | case SCS_private_extern: |
| 473 | case SCS_auto: |
| 474 | case SCS_register: |
| 475 | case SCS_static: |
| 476 | DiagID = diag::err_not_opencl_storage_class_specifier; |
| 477 | PrevSpec = getSpecifierName(S); |
| 478 | return true; |
| 479 | default: |
| 480 | break; |
| 481 | } |
| 482 | } |
| 483 | |
Abramo Bagnara | ed5b689 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 484 | if (StorageClassSpec != SCS_unspecified) { |
| 485 | // Changing storage class is allowed only if the previous one |
| 486 | // was the 'extern' that is part of a linkage specification and |
| 487 | // the new storage class is 'typedef'. |
| 488 | if (!(SCS_extern_in_linkage_spec && |
| 489 | StorageClassSpec == SCS_extern && |
| 490 | S == SCS_typedef)) |
| 491 | return BadSpecifier(S, (SCS)StorageClassSpec, PrevSpec, DiagID); |
| 492 | } |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 493 | StorageClassSpec = S; |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 494 | StorageClassSpecLoc = Loc; |
Sebastian Redl | ccdfaba | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 495 | assert((unsigned)S == StorageClassSpec && "SCS constants overflow bitfield"); |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 496 | return false; |
| 497 | } |
| 498 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 499 | bool DeclSpec::SetStorageClassSpecThread(SourceLocation Loc, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 500 | const char *&PrevSpec, |
| 501 | unsigned &DiagID) { |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 502 | if (SCS_thread_specified) { |
| 503 | PrevSpec = "__thread"; |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 504 | DiagID = diag::ext_duplicate_declspec; |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 505 | return true; |
| 506 | } |
| 507 | SCS_thread_specified = true; |
Chris Lattner | 4d8f873 | 2006-11-28 05:05:08 +0000 | [diff] [blame] | 508 | SCS_threadLoc = Loc; |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 509 | return false; |
| 510 | } |
| 511 | |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 512 | /// These methods set the specified attribute of the DeclSpec, but return true |
| 513 | /// and ignore the request if invalid (e.g. "extern" then "auto" is |
| 514 | /// specified). |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 515 | bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 516 | const char *&PrevSpec, |
| 517 | unsigned &DiagID) { |
Chris Lattner | 353f574 | 2006-11-28 04:50:12 +0000 | [diff] [blame] | 518 | if (TypeSpecWidth != TSW_unspecified && |
| 519 | // Allow turning long -> long long. |
| 520 | (W != TSW_longlong || TypeSpecWidth != TSW_long)) |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 521 | return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 522 | TypeSpecWidth = W; |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 523 | TSWLoc = Loc; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 524 | if (TypeAltiVecVector && !TypeAltiVecBool && |
| 525 | ((TypeSpecWidth == TSW_long) || (TypeSpecWidth == TSW_longlong))) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 526 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 527 | DiagID = diag::warn_vector_long_decl_spec_combination; |
| 528 | return true; |
| 529 | } |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 530 | return false; |
| 531 | } |
| 532 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 534 | const char *&PrevSpec, |
| 535 | unsigned &DiagID) { |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 536 | if (TypeSpecComplex != TSC_unspecified) |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 537 | return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID); |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 538 | TypeSpecComplex = C; |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 539 | TSCLoc = Loc; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 540 | return false; |
| 541 | } |
| 542 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 543 | bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 544 | const char *&PrevSpec, |
| 545 | unsigned &DiagID) { |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 546 | if (TypeSpecSign != TSS_unspecified) |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 547 | return BadSpecifier(S, (TSS)TypeSpecSign, PrevSpec, DiagID); |
Chris Lattner | deb42f5 | 2006-08-04 05:26:52 +0000 | [diff] [blame] | 548 | TypeSpecSign = S; |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 549 | TSSLoc = Loc; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 550 | return false; |
| 551 | } |
| 552 | |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 553 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 554 | const char *&PrevSpec, |
| 555 | unsigned &DiagID, |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 556 | ParsedType Rep) { |
| 557 | assert(isTypeRep(T) && "T does not store a type"); |
| 558 | assert(Rep && "no type provided!"); |
| 559 | if (TypeSpecType != TST_unspecified) { |
| 560 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 561 | DiagID = diag::err_invalid_decl_spec_combination; |
| 562 | return true; |
| 563 | } |
| 564 | TypeSpecType = T; |
| 565 | TypeRep = Rep; |
| 566 | TSTLoc = Loc; |
| 567 | TypeSpecOwned = false; |
| 568 | return false; |
| 569 | } |
| 570 | |
| 571 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
| 572 | const char *&PrevSpec, |
| 573 | unsigned &DiagID, |
| 574 | Expr *Rep) { |
| 575 | assert(isExprRep(T) && "T does not store an expr"); |
| 576 | assert(Rep && "no expression provided!"); |
| 577 | if (TypeSpecType != TST_unspecified) { |
| 578 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 579 | DiagID = diag::err_invalid_decl_spec_combination; |
| 580 | return true; |
| 581 | } |
| 582 | TypeSpecType = T; |
| 583 | ExprRep = Rep; |
| 584 | TSTLoc = Loc; |
| 585 | TypeSpecOwned = false; |
| 586 | return false; |
| 587 | } |
| 588 | |
| 589 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
| 590 | const char *&PrevSpec, |
| 591 | unsigned &DiagID, |
| 592 | Decl *Rep, bool Owned) { |
| 593 | assert(isDeclRep(T) && "T does not store a decl"); |
| 594 | // Unlike the other cases, we don't assert that we actually get a decl. |
| 595 | |
| 596 | if (TypeSpecType != TST_unspecified) { |
| 597 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 598 | DiagID = diag::err_invalid_decl_spec_combination; |
| 599 | return true; |
| 600 | } |
| 601 | TypeSpecType = T; |
| 602 | DeclRep = Rep; |
| 603 | TSTLoc = Loc; |
| 604 | TypeSpecOwned = Owned; |
| 605 | return false; |
| 606 | } |
| 607 | |
| 608 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
| 609 | const char *&PrevSpec, |
| 610 | unsigned &DiagID) { |
| 611 | assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) && |
| 612 | "rep required for these type-spec kinds!"); |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 613 | if (TypeSpecType != TST_unspecified) { |
| 614 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 615 | DiagID = diag::err_invalid_decl_spec_combination; |
| 616 | return true; |
| 617 | } |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 618 | if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) { |
| 619 | TypeAltiVecBool = true; |
| 620 | TSTLoc = Loc; |
| 621 | return false; |
| 622 | } |
Chris Lattner | deb42f5 | 2006-08-04 05:26:52 +0000 | [diff] [blame] | 623 | TypeSpecType = T; |
Chris Lattner | b20e894 | 2006-11-28 05:30:29 +0000 | [diff] [blame] | 624 | TSTLoc = Loc; |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 625 | TypeSpecOwned = false; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 626 | if (TypeAltiVecVector && !TypeAltiVecBool && (TypeSpecType == TST_double)) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 627 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 628 | DiagID = diag::err_invalid_vector_decl_spec; |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 629 | return true; |
| 630 | } |
| 631 | return false; |
| 632 | } |
| 633 | |
| 634 | bool DeclSpec::SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, |
| 635 | const char *&PrevSpec, unsigned &DiagID) { |
| 636 | if (TypeSpecType != TST_unspecified) { |
| 637 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 638 | DiagID = diag::err_invalid_vector_decl_spec_combination; |
| 639 | return true; |
| 640 | } |
| 641 | TypeAltiVecVector = isAltiVecVector; |
| 642 | AltiVecLoc = Loc; |
| 643 | return false; |
| 644 | } |
| 645 | |
| 646 | bool DeclSpec::SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, |
| 647 | const char *&PrevSpec, unsigned &DiagID) { |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 648 | if (!TypeAltiVecVector || TypeAltiVecPixel || |
| 649 | (TypeSpecType != TST_unspecified)) { |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 650 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 651 | DiagID = diag::err_invalid_pixel_decl_spec_combination; |
| 652 | return true; |
| 653 | } |
John Thompson | 2233460 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 654 | TypeAltiVecPixel = isAltiVecPixel; |
| 655 | TSTLoc = Loc; |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 656 | return false; |
| 657 | } |
| 658 | |
Douglas Gregor | cd72ba9 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 659 | bool DeclSpec::SetTypeSpecError() { |
| 660 | TypeSpecType = TST_error; |
John McCall | a3707cc | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 661 | TypeSpecOwned = false; |
Douglas Gregor | cd72ba9 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 662 | TSTLoc = SourceLocation(); |
| 663 | return false; |
| 664 | } |
| 665 | |
Chris Lattner | 60809f5 | 2006-11-28 05:18:46 +0000 | [diff] [blame] | 666 | bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 667 | unsigned &DiagID, const LangOptions &Lang) { |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 668 | // Duplicates turn into warnings pre-C99. |
| 669 | if ((TypeQualifiers & T) && !Lang.C99) |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 670 | return BadSpecifier(T, T, PrevSpec, DiagID); |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 671 | TypeQualifiers |= T; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 672 | |
Chris Lattner | 60809f5 | 2006-11-28 05:18:46 +0000 | [diff] [blame] | 673 | switch (T) { |
| 674 | default: assert(0 && "Unknown type qualifier!"); |
| 675 | case TQ_const: TQ_constLoc = Loc; break; |
| 676 | case TQ_restrict: TQ_restrictLoc = Loc; break; |
| 677 | case TQ_volatile: TQ_volatileLoc = Loc; break; |
| 678 | } |
Chris Lattner | da48a8e | 2006-08-04 05:25:55 +0000 | [diff] [blame] | 679 | return false; |
| 680 | } |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 681 | |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 682 | bool DeclSpec::SetFunctionSpecInline(SourceLocation Loc, const char *&PrevSpec, |
| 683 | unsigned &DiagID) { |
Chris Lattner | a925dc6 | 2006-11-28 04:33:46 +0000 | [diff] [blame] | 684 | // 'inline inline' is ok. |
| 685 | FS_inline_specified = true; |
Chris Lattner | 1b22eed | 2006-11-28 05:12:07 +0000 | [diff] [blame] | 686 | FS_inlineLoc = Loc; |
Chris Lattner | a925dc6 | 2006-11-28 04:33:46 +0000 | [diff] [blame] | 687 | return false; |
| 688 | } |
| 689 | |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 690 | bool DeclSpec::SetFunctionSpecVirtual(SourceLocation Loc, const char *&PrevSpec, |
| 691 | unsigned &DiagID) { |
Douglas Gregor | 61956c4 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 692 | // 'virtual virtual' is ok. |
| 693 | FS_virtual_specified = true; |
| 694 | FS_virtualLoc = Loc; |
| 695 | return false; |
| 696 | } |
| 697 | |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 698 | bool DeclSpec::SetFunctionSpecExplicit(SourceLocation Loc, const char *&PrevSpec, |
| 699 | unsigned &DiagID) { |
Douglas Gregor | 61956c4 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 700 | // 'explicit explicit' is ok. |
| 701 | FS_explicit_specified = true; |
| 702 | FS_explicitLoc = Loc; |
| 703 | return false; |
| 704 | } |
| 705 | |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 706 | bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, |
| 707 | unsigned &DiagID) { |
Anders Carlsson | cd8db41 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 708 | if (Friend_specified) { |
| 709 | PrevSpec = "friend"; |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 710 | DiagID = diag::ext_duplicate_declspec; |
Anders Carlsson | cd8db41 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 711 | return true; |
| 712 | } |
John McCall | 49bfce4 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 713 | |
Anders Carlsson | cd8db41 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 714 | Friend_specified = true; |
| 715 | FriendLoc = Loc; |
| 716 | return false; |
| 717 | } |
Chris Lattner | a925dc6 | 2006-11-28 04:33:46 +0000 | [diff] [blame] | 718 | |
Sebastian Redl | 39c2a8b | 2009-11-05 15:47:02 +0000 | [diff] [blame] | 719 | bool DeclSpec::SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec, |
| 720 | unsigned &DiagID) { |
| 721 | // 'constexpr constexpr' is ok. |
| 722 | Constexpr_specified = true; |
| 723 | ConstexprLoc = Loc; |
| 724 | return false; |
| 725 | } |
| 726 | |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 727 | void DeclSpec::setProtocolQualifiers(Decl * const *Protos, |
Argyrios Kyrtzidis | 5ec645b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 728 | unsigned NP, |
| 729 | SourceLocation *ProtoLocs, |
| 730 | SourceLocation LAngleLoc) { |
| 731 | if (NP == 0) return; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 732 | ProtocolQualifiers = new Decl*[NP]; |
Argyrios Kyrtzidis | 5ec645b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 733 | ProtocolLocs = new SourceLocation[NP]; |
John McCall | 4887165 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 734 | memcpy((void*)ProtocolQualifiers, Protos, sizeof(Decl*)*NP); |
Argyrios Kyrtzidis | 5ec645b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 735 | memcpy(ProtocolLocs, ProtoLocs, sizeof(SourceLocation)*NP); |
| 736 | NumProtocolQualifiers = NP; |
| 737 | ProtocolLAngleLoc = LAngleLoc; |
| 738 | } |
| 739 | |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 740 | void DeclSpec::SaveWrittenBuiltinSpecs() { |
| 741 | writtenBS.Sign = getTypeSpecSign(); |
| 742 | writtenBS.Width = getTypeSpecWidth(); |
| 743 | writtenBS.Type = getTypeSpecType(); |
| 744 | // Search the list of attributes for the presence of a mode attribute. |
| 745 | writtenBS.ModeAttr = false; |
John McCall | 53fa714 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 746 | AttributeList* attrs = getAttributes().getList(); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 747 | while (attrs) { |
| 748 | if (attrs->getKind() == AttributeList::AT_mode) { |
| 749 | writtenBS.ModeAttr = true; |
| 750 | break; |
| 751 | } |
| 752 | attrs = attrs->getNext(); |
| 753 | } |
| 754 | } |
| 755 | |
Abramo Bagnara | ed5b689 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 756 | void DeclSpec::SaveStorageSpecifierAsWritten() { |
| 757 | if (SCS_extern_in_linkage_spec && StorageClassSpec == SCS_extern) |
| 758 | // If 'extern' is part of a linkage specification, |
| 759 | // then it is not a storage class "as written". |
| 760 | StorageClassSpecAsWritten = SCS_unspecified; |
| 761 | else |
| 762 | StorageClassSpecAsWritten = StorageClassSpec; |
| 763 | } |
| 764 | |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 765 | /// Finish - This does final analysis of the declspec, rejecting things like |
| 766 | /// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or |
| 767 | /// diag::NUM_DIAGNOSTICS if there is no error. After calling this method, |
| 768 | /// DeclSpec is guaranteed self-consistent, even if an error occurred. |
Douglas Gregor | e3e01a2 | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 769 | void DeclSpec::Finish(Diagnostic &D, Preprocessor &PP) { |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 770 | // Before possibly changing their values, save specs as written. |
| 771 | SaveWrittenBuiltinSpecs(); |
Douglas Gregor | c4df407 | 2010-04-19 22:54:31 +0000 | [diff] [blame] | 772 | SaveStorageSpecifierAsWritten(); |
Douglas Gregor | c9b7a59 | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 773 | |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 774 | // Check the type specifier components first. |
| 775 | |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 776 | // Validate and finalize AltiVec vector declspec. |
| 777 | if (TypeAltiVecVector) { |
| 778 | if (TypeAltiVecBool) { |
| 779 | // Sign specifiers are not allowed with vector bool. (PIM 2.1) |
| 780 | if (TypeSpecSign != TSS_unspecified) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 781 | Diag(D, TSSLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 782 | << getSpecifierName((TSS)TypeSpecSign); |
| 783 | } |
| 784 | |
| 785 | // Only char/int are valid with vector bool. (PIM 2.1) |
Duncan Sands | d3e231e | 2010-06-23 19:34:52 +0000 | [diff] [blame] | 786 | if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) && |
| 787 | (TypeSpecType != TST_int)) || TypeAltiVecPixel) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 788 | Diag(D, TSTLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 789 | << (TypeAltiVecPixel ? "__pixel" : |
| 790 | getSpecifierName((TST)TypeSpecType)); |
| 791 | } |
| 792 | |
| 793 | // Only 'short' is valid with vector bool. (PIM 2.1) |
| 794 | if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short)) |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 795 | Diag(D, TSWLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 796 | << getSpecifierName((TSW)TypeSpecWidth); |
| 797 | |
| 798 | // Elements of vector bool are interpreted as unsigned. (PIM 2.1) |
| 799 | if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) || |
| 800 | (TypeSpecWidth != TSW_unspecified)) |
| 801 | TypeSpecSign = TSS_unsigned; |
| 802 | } |
| 803 | |
| 804 | if (TypeAltiVecPixel) { |
| 805 | //TODO: perform validation |
| 806 | TypeSpecType = TST_int; |
| 807 | TypeSpecSign = TSS_unsigned; |
| 808 | TypeSpecWidth = TSW_short; |
John McCall | a3707cc | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 809 | TypeSpecOwned = false; |
Chris Lattner | 37141f4 | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | |
Argyrios Kyrtzidis | 40e9e48 | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 813 | // signed/unsigned are only valid with int/char/wchar_t. |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 814 | if (TypeSpecSign != TSS_unspecified) { |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 815 | if (TypeSpecType == TST_unspecified) |
| 816 | TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int. |
Argyrios Kyrtzidis | 40e9e48 | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 817 | else if (TypeSpecType != TST_int && |
| 818 | TypeSpecType != TST_char && TypeSpecType != TST_wchar) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 819 | Diag(D, TSSLoc, diag::err_invalid_sign_spec) |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 820 | << getSpecifierName((TST)TypeSpecType); |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 821 | // signed double -> double. |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 822 | TypeSpecSign = TSS_unspecified; |
| 823 | } |
| 824 | } |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 825 | |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 826 | // Validate the width of the type. |
| 827 | switch (TypeSpecWidth) { |
| 828 | case TSW_unspecified: break; |
| 829 | case TSW_short: // short int |
| 830 | case TSW_longlong: // long long int |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 831 | if (TypeSpecType == TST_unspecified) |
| 832 | TypeSpecType = TST_int; // short -> short int, long long -> long long int. |
| 833 | else if (TypeSpecType != TST_int) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 834 | Diag(D, TSWLoc, |
Chris Lattner | 36982e4 | 2007-05-16 17:49:37 +0000 | [diff] [blame] | 835 | TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 836 | : diag::err_invalid_longlong_spec) |
| 837 | << getSpecifierName((TST)TypeSpecType); |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 838 | TypeSpecType = TST_int; |
John McCall | a3707cc | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 839 | TypeSpecOwned = false; |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 840 | } |
| 841 | break; |
| 842 | case TSW_long: // long double, long int |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 843 | if (TypeSpecType == TST_unspecified) |
| 844 | TypeSpecType = TST_int; // long -> long int. |
| 845 | else if (TypeSpecType != TST_int && TypeSpecType != TST_double) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 846 | Diag(D, TSWLoc, diag::err_invalid_long_spec) |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 847 | << getSpecifierName((TST)TypeSpecType); |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 848 | TypeSpecType = TST_int; |
John McCall | a3707cc | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 849 | TypeSpecOwned = false; |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 850 | } |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 851 | break; |
Chris Lattner | 839713c | 2006-08-04 06:15:52 +0000 | [diff] [blame] | 852 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 853 | |
Chris Lattner | 0e89462 | 2006-08-13 19:58:17 +0000 | [diff] [blame] | 854 | // TODO: if the implementation does not implement _Complex or _Imaginary, |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 855 | // disallow their use. Need information about the backend. |
| 856 | if (TypeSpecComplex != TSC_unspecified) { |
| 857 | if (TypeSpecType == TST_unspecified) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 858 | Diag(D, TSCLoc, diag::ext_plain_complex) |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 859 | << FixItHint::CreateInsertion( |
Douglas Gregor | e3e01a2 | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 860 | PP.getLocForEndOfToken(getTypeSpecComplexLoc()), |
| 861 | " double"); |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 862 | TypeSpecType = TST_double; // _Complex -> _Complex double. |
| 863 | } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) { |
Chris Lattner | f63f89a | 2006-08-05 03:28:50 +0000 | [diff] [blame] | 864 | // Note that this intentionally doesn't include _Complex _Bool. |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 865 | Diag(D, TSTLoc, diag::ext_integer_complex); |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 866 | } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) { |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 867 | Diag(D, TSCLoc, diag::err_invalid_complex_spec) |
Chris Lattner | 3b0f3ef | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 868 | << getSpecifierName((TST)TypeSpecType); |
Chris Lattner | fef9d2b | 2006-08-04 06:36:52 +0000 | [diff] [blame] | 869 | TypeSpecComplex = TSC_unspecified; |
| 870 | } |
| 871 | } |
Chris Lattner | 8e90ef6 | 2006-08-05 03:30:45 +0000 | [diff] [blame] | 872 | |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 873 | // C++ [class.friend]p6: |
| 874 | // No storage-class-specifier shall appear in the decl-specifier-seq |
| 875 | // of a friend declaration. |
| 876 | if (isFriendSpecified() && getStorageClassSpec()) { |
| 877 | DeclSpec::SCS SC = getStorageClassSpec(); |
| 878 | const char *SpecName = getSpecifierName(SC); |
| 879 | |
| 880 | SourceLocation SCLoc = getStorageClassSpecLoc(); |
| 881 | SourceLocation SCEndLoc = SCLoc.getFileLocWithOffset(strlen(SpecName)); |
| 882 | |
Argyrios Kyrtzidis | d004064 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 883 | Diag(D, SCLoc, diag::err_friend_storage_spec) |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 884 | << SpecName |
Douglas Gregor | a771f46 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 885 | << FixItHint::CreateRemoval(SourceRange(SCLoc, SCEndLoc)); |
John McCall | 07e91c0 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 886 | |
| 887 | ClearStorageClassSpecs(); |
| 888 | } |
| 889 | |
John McCall | a3707cc | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 890 | assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType)); |
| 891 | |
Chris Lattner | 8e90ef6 | 2006-08-05 03:30:45 +0000 | [diff] [blame] | 892 | // Okay, now we can infer the real type. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 893 | |
Chris Lattner | 0e89462 | 2006-08-13 19:58:17 +0000 | [diff] [blame] | 894 | // TODO: return "auto function" and other bad things based on the real type. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 895 | |
Chris Lattner | 1ae2329 | 2006-08-04 06:42:31 +0000 | [diff] [blame] | 896 | // 'data definition has no type or storage class'? |
Chris Lattner | b9093cd | 2006-08-04 04:39:53 +0000 | [diff] [blame] | 897 | } |
Daniel Dunbar | c74b5cc | 2008-08-11 03:45:03 +0000 | [diff] [blame] | 898 | |
Sebastian Redl | a2b5e31 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 899 | bool DeclSpec::isMissingDeclaratorOk() { |
| 900 | TST tst = getTypeSpecType(); |
John McCall | ba7bf59 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 901 | return isDeclRep(tst) && getRepAsDecl() != 0 && |
| 902 | StorageClassSpec != DeclSpec::SCS_typedef; |
Sebastian Redl | a2b5e31 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 903 | } |
Douglas Gregor | 7861a80 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 904 | |
| 905 | void UnqualifiedId::clear() { |
| 906 | if (Kind == IK_TemplateId) |
| 907 | TemplateId->Destroy(); |
| 908 | |
| 909 | Kind = IK_Identifier; |
| 910 | Identifier = 0; |
| 911 | StartLocation = SourceLocation(); |
| 912 | EndLocation = SourceLocation(); |
| 913 | } |
| 914 | |
| 915 | void UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc, |
| 916 | OverloadedOperatorKind Op, |
| 917 | SourceLocation SymbolLocations[3]) { |
| 918 | Kind = IK_OperatorFunctionId; |
| 919 | StartLocation = OperatorLoc; |
| 920 | EndLocation = OperatorLoc; |
| 921 | OperatorFunctionId.Operator = Op; |
| 922 | for (unsigned I = 0; I != 3; ++I) { |
| 923 | OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I].getRawEncoding(); |
| 924 | |
| 925 | if (SymbolLocations[I].isValid()) |
| 926 | EndLocation = SymbolLocations[I]; |
| 927 | } |
| 928 | } |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 929 | |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 930 | bool VirtSpecifiers::SetSpecifier(Specifier VS, SourceLocation Loc, |
Anders Carlsson | f2ca389 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 931 | const char *&PrevSpec) { |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 932 | if (Specifiers & VS) { |
| 933 | PrevSpec = getSpecifierName(VS); |
| 934 | return true; |
| 935 | } |
| 936 | |
| 937 | Specifiers |= VS; |
| 938 | |
| 939 | switch (VS) { |
| 940 | default: assert(0 && "Unknown specifier!"); |
| 941 | case VS_Override: VS_overrideLoc = Loc; break; |
| 942 | case VS_Final: VS_finalLoc = Loc; break; |
| 943 | case VS_New: VS_newLoc = Loc; break; |
| 944 | } |
Anders Carlsson | f2ca389 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 945 | |
Anders Carlsson | 5610490 | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 946 | return false; |
| 947 | } |
| 948 | |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 949 | const char *VirtSpecifiers::getSpecifierName(Specifier VS) { |
Anders Carlsson | a6d3501 | 2011-01-22 15:11:37 +0000 | [diff] [blame] | 950 | switch (VS) { |
| 951 | default: assert(0 && "Unknown specifier"); |
| 952 | case VS_Override: return "override"; |
| 953 | case VS_Final: return "final"; |
| 954 | case VS_New: return "new"; |
| 955 | } |
| 956 | } |
Anders Carlsson | f2ca389 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 957 | |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 958 | bool ClassVirtSpecifiers::SetSpecifier(Specifier CVS, SourceLocation Loc, |
Anders Carlsson | f2ca389 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 959 | const char *&PrevSpec) { |
| 960 | if (Specifiers & CVS) { |
| 961 | PrevSpec = getSpecifierName(CVS); |
| 962 | return true; |
| 963 | } |
| 964 | |
| 965 | Specifiers |= CVS; |
| 966 | |
| 967 | switch (CVS) { |
| 968 | default: assert(0 && "Unknown specifier!"); |
| 969 | case CVS_Final: CVS_finalLoc = Loc; break; |
| 970 | case CVS_Explicit: CVS_explicitLoc = Loc; break; |
| 971 | } |
| 972 | |
| 973 | return false; |
| 974 | } |
| 975 | |
Anders Carlsson | 4b63d0e | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 976 | const char *ClassVirtSpecifiers::getSpecifierName(Specifier CVS) { |
Anders Carlsson | f2ca389 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 977 | switch (CVS) { |
| 978 | default: assert(0 && "Unknown specifier"); |
| 979 | case CVS_Final: return "final"; |
| 980 | case CVS_Explicit: return "explicit"; |
| 981 | } |
| 982 | } |
| 983 | |