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