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