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/Sema/DeclSpec.h" |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Reid Kleckner | d1a32c3 | 2013-10-08 00:58:57 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame] | 17 | #include "clang/AST/Expr.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" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 20 | #include "clang/Basic/LangOptions.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "clang/Lex/Preprocessor.h" |
| 22 | #include "clang/Parse/ParseDiagnostic.h" // FIXME: remove this back-dependency! |
| 23 | #include "clang/Sema/LocInfoType.h" |
| 24 | #include "clang/Sema/ParsedTemplate.h" |
| 25 | #include "clang/Sema/Sema.h" |
| 26 | #include "clang/Sema/SemaDiagnostic.h" |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/STLExtras.h" |
Richard Smith | ec64244 | 2013-04-12 22:46:28 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/SmallString.h" |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 30 | #include <cstring> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 31 | using namespace clang; |
| 32 | |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 33 | |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 34 | static DiagnosticBuilder Diag(DiagnosticsEngine &D, SourceLocation Loc, |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 35 | unsigned DiagID) { |
| 36 | return D.Report(Loc, DiagID); |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Douglas Gregor | 314b97f | 2009-11-10 19:49:08 +0000 | [diff] [blame] | 39 | |
| 40 | void UnqualifiedId::setTemplateId(TemplateIdAnnotation *TemplateId) { |
| 41 | assert(TemplateId && "NULL template-id annotation?"); |
| 42 | Kind = IK_TemplateId; |
| 43 | this->TemplateId = TemplateId; |
| 44 | StartLocation = TemplateId->TemplateNameLoc; |
| 45 | EndLocation = TemplateId->RAngleLoc; |
| 46 | } |
| 47 | |
Douglas Gregor | 0efc2c1 | 2010-01-13 17:31:36 +0000 | [diff] [blame] | 48 | void UnqualifiedId::setConstructorTemplateId(TemplateIdAnnotation *TemplateId) { |
| 49 | assert(TemplateId && "NULL template-id annotation?"); |
| 50 | Kind = IK_ConstructorTemplateId; |
| 51 | this->TemplateId = TemplateId; |
| 52 | StartLocation = TemplateId->TemplateNameLoc; |
| 53 | EndLocation = TemplateId->RAngleLoc; |
| 54 | } |
| 55 | |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 56 | void CXXScopeSpec::Extend(ASTContext &Context, SourceLocation TemplateKWLoc, |
| 57 | TypeLoc TL, SourceLocation ColonColonLoc) { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 58 | Builder.Extend(Context, TemplateKWLoc, TL, ColonColonLoc); |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 59 | if (Range.getBegin().isInvalid()) |
| 60 | Range.setBegin(TL.getBeginLoc()); |
| 61 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 62 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 63 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 64 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void CXXScopeSpec::Extend(ASTContext &Context, IdentifierInfo *Identifier, |
| 68 | SourceLocation IdentifierLoc, |
| 69 | SourceLocation ColonColonLoc) { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 70 | Builder.Extend(Context, Identifier, IdentifierLoc, ColonColonLoc); |
| 71 | |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 72 | if (Range.getBegin().isInvalid()) |
| 73 | Range.setBegin(IdentifierLoc); |
| 74 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 75 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 76 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 77 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void CXXScopeSpec::Extend(ASTContext &Context, NamespaceDecl *Namespace, |
| 81 | SourceLocation NamespaceLoc, |
| 82 | SourceLocation ColonColonLoc) { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 83 | Builder.Extend(Context, Namespace, NamespaceLoc, ColonColonLoc); |
| 84 | |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 85 | if (Range.getBegin().isInvalid()) |
| 86 | Range.setBegin(NamespaceLoc); |
| 87 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 88 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 89 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 90 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 93 | void CXXScopeSpec::Extend(ASTContext &Context, NamespaceAliasDecl *Alias, |
| 94 | SourceLocation AliasLoc, |
| 95 | SourceLocation ColonColonLoc) { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 96 | Builder.Extend(Context, Alias, AliasLoc, ColonColonLoc); |
| 97 | |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 98 | if (Range.getBegin().isInvalid()) |
| 99 | Range.setBegin(AliasLoc); |
| 100 | Range.setEnd(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 101 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 102 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 103 | "NestedNameSpecifierLoc range computation incorrect"); |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 106 | void CXXScopeSpec::MakeGlobal(ASTContext &Context, |
| 107 | SourceLocation ColonColonLoc) { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 108 | Builder.MakeGlobal(Context, ColonColonLoc); |
| 109 | |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 110 | Range = SourceRange(ColonColonLoc); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 111 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 112 | assert(Range == Builder.getSourceRange() && |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 113 | "NestedNameSpecifierLoc range computation incorrect"); |
| 114 | } |
| 115 | |
| 116 | void CXXScopeSpec::MakeTrivial(ASTContext &Context, |
| 117 | NestedNameSpecifier *Qualifier, SourceRange R) { |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 118 | Builder.MakeTrivial(Context, Qualifier, R); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 119 | Range = R; |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | void CXXScopeSpec::Adopt(NestedNameSpecifierLoc Other) { |
| 123 | if (!Other) { |
| 124 | Range = SourceRange(); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 125 | Builder.Clear(); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 126 | return; |
| 127 | } |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 128 | |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 129 | Range = Other.getSourceRange(); |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 130 | Builder.Adopt(Other); |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 131 | } |
| 132 | |
John McCall | 9dc71d2 | 2011-07-06 06:57:57 +0000 | [diff] [blame] | 133 | SourceLocation CXXScopeSpec::getLastQualifierNameLoc() const { |
| 134 | if (!Builder.getRepresentation()) |
| 135 | return SourceLocation(); |
| 136 | return Builder.getTemporary().getLocalBeginLoc(); |
| 137 | } |
| 138 | |
Douglas Gregor | c22b5ff | 2011-02-25 02:25:35 +0000 | [diff] [blame] | 139 | NestedNameSpecifierLoc |
| 140 | CXXScopeSpec::getWithLocInContext(ASTContext &Context) const { |
Douglas Gregor | b46ae39 | 2011-03-03 21:48:55 +0000 | [diff] [blame] | 141 | if (!Builder.getRepresentation()) |
Douglas Gregor | c34348a | 2011-02-24 17:54:50 +0000 | [diff] [blame] | 142 | return NestedNameSpecifierLoc(); |
| 143 | |
Douglas Gregor | 5f791bb | 2011-02-28 23:58:31 +0000 | [diff] [blame] | 144 | return Builder.getWithLocInContext(Context); |
Douglas Gregor | 2e4c34a | 2011-02-24 00:17:56 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 147 | /// DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function. |
| 148 | /// "TheDeclarator" is the declarator that this will be added to. |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 149 | DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 150 | bool isAmbiguous, |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 151 | SourceLocation LParenLoc, |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 152 | ParamInfo *ArgInfo, |
| 153 | unsigned NumArgs, |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 154 | SourceLocation EllipsisLoc, |
| 155 | SourceLocation RParenLoc, |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 156 | unsigned TypeQuals, |
Douglas Gregor | 83f5172 | 2011-01-26 03:43:54 +0000 | [diff] [blame] | 157 | bool RefQualifierIsLvalueRef, |
| 158 | SourceLocation RefQualifierLoc, |
Douglas Gregor | 43f5103 | 2011-10-19 06:04:55 +0000 | [diff] [blame] | 159 | SourceLocation ConstQualifierLoc, |
| 160 | SourceLocation |
| 161 | VolatileQualifierLoc, |
Douglas Gregor | 90ebed0 | 2011-07-13 21:47:47 +0000 | [diff] [blame] | 162 | SourceLocation MutableLoc, |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 163 | ExceptionSpecificationType |
| 164 | ESpecType, |
| 165 | SourceLocation ESpecLoc, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 166 | ParsedType *Exceptions, |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 167 | SourceRange *ExceptionRanges, |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 168 | unsigned NumExceptions, |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 169 | Expr *NoexceptExpr, |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 170 | SourceLocation LocalRangeBegin, |
| 171 | SourceLocation LocalRangeEnd, |
Douglas Gregor | dab60ad | 2010-10-01 18:44:50 +0000 | [diff] [blame] | 172 | Declarator &TheDeclarator, |
Richard Smith | 54655be | 2012-06-12 01:51:59 +0000 | [diff] [blame] | 173 | TypeResult TrailingReturnType) { |
Richard Smith | 4cf4a5e | 2013-03-28 01:55:44 +0000 | [diff] [blame] | 174 | assert(!(TypeQuals & DeclSpec::TQ_atomic) && |
| 175 | "function cannot have _Atomic qualifier"); |
| 176 | |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 177 | DeclaratorChunk I; |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 178 | I.Kind = Function; |
Abramo Bagnara | 796aa44 | 2011-03-12 11:17:06 +0000 | [diff] [blame] | 179 | I.Loc = LocalRangeBegin; |
| 180 | I.EndLoc = LocalRangeEnd; |
John McCall | 0b7e678 | 2011-03-24 11:26:52 +0000 | [diff] [blame] | 181 | I.Fun.AttrList = 0; |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 182 | I.Fun.hasPrototype = hasProto; |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 183 | I.Fun.isVariadic = EllipsisLoc.isValid(); |
Richard Smith | b9c6261 | 2012-07-30 21:30:52 +0000 | [diff] [blame] | 184 | I.Fun.isAmbiguous = isAmbiguous; |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 185 | I.Fun.LParenLoc = LParenLoc.getRawEncoding(); |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 186 | I.Fun.EllipsisLoc = EllipsisLoc.getRawEncoding(); |
Abramo Bagnara | 59c0a81 | 2012-10-04 21:42:10 +0000 | [diff] [blame] | 187 | I.Fun.RParenLoc = RParenLoc.getRawEncoding(); |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 188 | I.Fun.DeleteArgInfo = false; |
| 189 | I.Fun.TypeQuals = TypeQuals; |
| 190 | I.Fun.NumArgs = NumArgs; |
| 191 | I.Fun.ArgInfo = 0; |
Douglas Gregor | 83f5172 | 2011-01-26 03:43:54 +0000 | [diff] [blame] | 192 | I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef; |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 193 | I.Fun.RefQualifierLoc = RefQualifierLoc.getRawEncoding(); |
Douglas Gregor | 43f5103 | 2011-10-19 06:04:55 +0000 | [diff] [blame] | 194 | I.Fun.ConstQualifierLoc = ConstQualifierLoc.getRawEncoding(); |
| 195 | I.Fun.VolatileQualifierLoc = VolatileQualifierLoc.getRawEncoding(); |
Douglas Gregor | 90ebed0 | 2011-07-13 21:47:47 +0000 | [diff] [blame] | 196 | I.Fun.MutableLoc = MutableLoc.getRawEncoding(); |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 197 | I.Fun.ExceptionSpecType = ESpecType; |
| 198 | I.Fun.ExceptionSpecLoc = ESpecLoc.getRawEncoding(); |
| 199 | I.Fun.NumExceptions = 0; |
| 200 | I.Fun.Exceptions = 0; |
| 201 | I.Fun.NoexceptExpr = 0; |
Richard Smith | 54655be | 2012-06-12 01:51:59 +0000 | [diff] [blame] | 202 | I.Fun.HasTrailingReturnType = TrailingReturnType.isUsable() || |
| 203 | TrailingReturnType.isInvalid(); |
| 204 | I.Fun.TrailingReturnType = TrailingReturnType.get(); |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 205 | |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 206 | // new[] an argument array if needed. |
| 207 | if (NumArgs) { |
| 208 | // If the 'InlineParams' in Declarator is unused and big enough, put our |
| 209 | // parameter list there (in an effort to avoid new/delete traffic). If it |
| 210 | // is already used (consider a function returning a function pointer) or too |
| 211 | // small (function taking too many arguments), go to the heap. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 212 | if (!TheDeclarator.InlineParamsUsed && |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 213 | NumArgs <= llvm::array_lengthof(TheDeclarator.InlineParams)) { |
| 214 | I.Fun.ArgInfo = TheDeclarator.InlineParams; |
| 215 | I.Fun.DeleteArgInfo = false; |
| 216 | TheDeclarator.InlineParamsUsed = true; |
| 217 | } else { |
| 218 | I.Fun.ArgInfo = new DeclaratorChunk::ParamInfo[NumArgs]; |
| 219 | I.Fun.DeleteArgInfo = true; |
| 220 | } |
| 221 | memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs); |
| 222 | } |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 223 | |
| 224 | // Check what exception specification information we should actually store. |
| 225 | switch (ESpecType) { |
| 226 | default: break; // By default, save nothing. |
| 227 | case EST_Dynamic: |
| 228 | // new[] an exception array if needed |
| 229 | if (NumExceptions) { |
| 230 | I.Fun.NumExceptions = NumExceptions; |
| 231 | I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions]; |
| 232 | for (unsigned i = 0; i != NumExceptions; ++i) { |
| 233 | I.Fun.Exceptions[i].Ty = Exceptions[i]; |
| 234 | I.Fun.Exceptions[i].Range = ExceptionRanges[i]; |
| 235 | } |
Sebastian Redl | ef65f06 | 2009-05-29 18:02:33 +0000 | [diff] [blame] | 236 | } |
Sebastian Redl | 6e5d319 | 2011-03-05 22:42:13 +0000 | [diff] [blame] | 237 | break; |
| 238 | |
| 239 | case EST_ComputedNoexcept: |
| 240 | I.Fun.NoexceptExpr = NoexceptExpr; |
| 241 | break; |
Sebastian Redl | 7dc8134 | 2009-04-29 17:30:04 +0000 | [diff] [blame] | 242 | } |
Chris Lattner | 5af2f35 | 2009-01-20 19:11:22 +0000 | [diff] [blame] | 243 | return I; |
| 244 | } |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 245 | |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame] | 246 | bool Declarator::isDeclarationOfFunction() const { |
Richard Smith | 1ab0d90 | 2011-06-25 02:28:38 +0000 | [diff] [blame] | 247 | for (unsigned i = 0, i_end = DeclTypeInfo.size(); i < i_end; ++i) { |
| 248 | switch (DeclTypeInfo[i].Kind) { |
| 249 | case DeclaratorChunk::Function: |
| 250 | return true; |
| 251 | case DeclaratorChunk::Paren: |
| 252 | continue; |
| 253 | case DeclaratorChunk::Pointer: |
| 254 | case DeclaratorChunk::Reference: |
| 255 | case DeclaratorChunk::Array: |
| 256 | case DeclaratorChunk::BlockPointer: |
| 257 | case DeclaratorChunk::MemberPointer: |
| 258 | return false; |
| 259 | } |
| 260 | llvm_unreachable("Invalid type chunk"); |
Richard Smith | 1ab0d90 | 2011-06-25 02:28:38 +0000 | [diff] [blame] | 261 | } |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame] | 262 | |
| 263 | switch (DS.getTypeSpecType()) { |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 264 | case TST_atomic: |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame] | 265 | case TST_auto: |
| 266 | case TST_bool: |
| 267 | case TST_char: |
| 268 | case TST_char16: |
| 269 | case TST_char32: |
| 270 | case TST_class: |
| 271 | case TST_decimal128: |
| 272 | case TST_decimal32: |
| 273 | case TST_decimal64: |
| 274 | case TST_double: |
| 275 | case TST_enum: |
| 276 | case TST_error: |
| 277 | case TST_float: |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 278 | case TST_half: |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame] | 279 | case TST_int: |
Richard Smith | 5a5a971 | 2012-04-04 06:24:32 +0000 | [diff] [blame] | 280 | case TST_int128: |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame] | 281 | case TST_struct: |
Joao Matos | 6666ed4 | 2012-08-31 18:45:21 +0000 | [diff] [blame] | 282 | case TST_interface: |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame] | 283 | case TST_union: |
| 284 | case TST_unknown_anytype: |
| 285 | case TST_unspecified: |
| 286 | case TST_void: |
| 287 | case TST_wchar: |
Guy Benyei | b13621d | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 288 | case TST_image1d_t: |
| 289 | case TST_image1d_array_t: |
| 290 | case TST_image1d_buffer_t: |
| 291 | case TST_image2d_t: |
| 292 | case TST_image2d_array_t: |
| 293 | case TST_image3d_t: |
Guy Benyei | 21f18c4 | 2013-02-07 10:55:47 +0000 | [diff] [blame] | 294 | case TST_sampler_t: |
Guy Benyei | e6b9d80 | 2013-01-20 12:31:11 +0000 | [diff] [blame] | 295 | case TST_event_t: |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame] | 296 | return false; |
| 297 | |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 298 | case TST_decltype_auto: |
| 299 | // This must have an initializer, so can't be a function declaration, |
| 300 | // even if the initializer has function type. |
| 301 | return false; |
| 302 | |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame] | 303 | case TST_decltype: |
| 304 | case TST_typeofExpr: |
| 305 | if (Expr *E = DS.getRepAsExpr()) |
| 306 | return E->getType()->isFunctionType(); |
| 307 | return false; |
| 308 | |
| 309 | case TST_underlyingType: |
| 310 | case TST_typename: |
| 311 | case TST_typeofType: { |
| 312 | QualType QT = DS.getRepAsType().get(); |
| 313 | if (QT.isNull()) |
| 314 | return false; |
| 315 | |
| 316 | if (const LocInfoType *LIT = dyn_cast<LocInfoType>(QT)) |
| 317 | QT = LIT->getType(); |
| 318 | |
| 319 | if (QT.isNull()) |
| 320 | return false; |
| 321 | |
| 322 | return QT->isFunctionType(); |
| 323 | } |
| 324 | } |
David Blaikie | 7530c03 | 2012-01-17 06:56:22 +0000 | [diff] [blame] | 325 | |
| 326 | llvm_unreachable("Invalid TypeSpecType!"); |
Douglas Gregor | 555f57e | 2011-06-25 00:56:27 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Reid Kleckner | d1a32c3 | 2013-10-08 00:58:57 +0000 | [diff] [blame] | 329 | bool Declarator::isStaticMember() { |
| 330 | assert(getContext() == MemberContext); |
| 331 | return getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static || |
| 332 | CXXMethodDecl::isStaticOverloadedOperator( |
| 333 | getName().OperatorFunctionId.Operator); |
| 334 | } |
| 335 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 336 | /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this |
Chris Lattner | 2a327d1 | 2009-02-27 18:35:46 +0000 | [diff] [blame] | 337 | /// declaration specifier includes. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 338 | /// |
| 339 | unsigned DeclSpec::getParsedSpecifiers() const { |
| 340 | unsigned Res = 0; |
| 341 | if (StorageClassSpec != SCS_unspecified || |
Richard Smith | ec64244 | 2013-04-12 22:46:28 +0000 | [diff] [blame] | 342 | ThreadStorageClassSpec != TSCS_unspecified) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 343 | Res |= PQ_StorageClassSpecifier; |
Mike Stump | d420433 | 2008-06-19 19:52:46 +0000 | [diff] [blame] | 344 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 345 | if (TypeQualifiers != TQ_unspecified) |
| 346 | Res |= PQ_TypeQualifier; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 347 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 348 | if (hasTypeSpecifier()) |
| 349 | Res |= PQ_TypeSpecifier; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 350 | |
Richard Smith | de03c15 | 2013-01-17 22:16:11 +0000 | [diff] [blame] | 351 | if (FS_inline_specified || FS_virtual_specified || FS_explicit_specified || |
| 352 | FS_noreturn_specified) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 353 | Res |= PQ_FunctionSpecifier; |
| 354 | return Res; |
| 355 | } |
| 356 | |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 357 | template <class T> static bool BadSpecifier(T TNew, T TPrev, |
| 358 | const char *&PrevSpec, |
Aaron Ballman | c828620 | 2012-08-28 20:55:40 +0000 | [diff] [blame] | 359 | unsigned &DiagID, |
| 360 | bool IsExtension = true) { |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 361 | PrevSpec = DeclSpec::getSpecifierName(TPrev); |
Aaron Ballman | c828620 | 2012-08-28 20:55:40 +0000 | [diff] [blame] | 362 | if (TNew != TPrev) |
| 363 | DiagID = diag::err_invalid_decl_spec_combination; |
| 364 | else |
| 365 | DiagID = IsExtension ? diag::ext_duplicate_declspec : |
| 366 | diag::warn_duplicate_declspec; |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 367 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 368 | } |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 369 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 370 | const char *DeclSpec::getSpecifierName(DeclSpec::SCS S) { |
| 371 | switch (S) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 372 | case DeclSpec::SCS_unspecified: return "unspecified"; |
| 373 | case DeclSpec::SCS_typedef: return "typedef"; |
| 374 | case DeclSpec::SCS_extern: return "extern"; |
| 375 | case DeclSpec::SCS_static: return "static"; |
| 376 | case DeclSpec::SCS_auto: return "auto"; |
| 377 | case DeclSpec::SCS_register: return "register"; |
Eli Friedman | 63054b3 | 2009-04-19 20:27:55 +0000 | [diff] [blame] | 378 | case DeclSpec::SCS_private_extern: return "__private_extern__"; |
Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 379 | case DeclSpec::SCS_mutable: return "mutable"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 380 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 381 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 382 | } |
| 383 | |
Richard Smith | ec64244 | 2013-04-12 22:46:28 +0000 | [diff] [blame] | 384 | const char *DeclSpec::getSpecifierName(DeclSpec::TSCS S) { |
| 385 | switch (S) { |
| 386 | case DeclSpec::TSCS_unspecified: return "unspecified"; |
| 387 | case DeclSpec::TSCS___thread: return "__thread"; |
| 388 | case DeclSpec::TSCS_thread_local: return "thread_local"; |
| 389 | case DeclSpec::TSCS__Thread_local: return "_Thread_local"; |
| 390 | } |
| 391 | llvm_unreachable("Unknown typespec!"); |
| 392 | } |
| 393 | |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 394 | const char *DeclSpec::getSpecifierName(TSW W) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 395 | switch (W) { |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 396 | case TSW_unspecified: return "unspecified"; |
| 397 | case TSW_short: return "short"; |
| 398 | case TSW_long: return "long"; |
| 399 | case TSW_longlong: return "long long"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 400 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 401 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 402 | } |
| 403 | |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 404 | const char *DeclSpec::getSpecifierName(TSC C) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 405 | switch (C) { |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 406 | case TSC_unspecified: return "unspecified"; |
| 407 | case TSC_imaginary: return "imaginary"; |
| 408 | case TSC_complex: return "complex"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 409 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 410 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 414 | const char *DeclSpec::getSpecifierName(TSS S) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 415 | switch (S) { |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 416 | case TSS_unspecified: return "unspecified"; |
| 417 | case TSS_signed: return "signed"; |
| 418 | case TSS_unsigned: return "unsigned"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 419 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 420 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | const char *DeclSpec::getSpecifierName(DeclSpec::TST T) { |
| 424 | switch (T) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 425 | case DeclSpec::TST_unspecified: return "unspecified"; |
| 426 | case DeclSpec::TST_void: return "void"; |
| 427 | case DeclSpec::TST_char: return "char"; |
Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 428 | case DeclSpec::TST_wchar: return "wchar_t"; |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 429 | case DeclSpec::TST_char16: return "char16_t"; |
| 430 | case DeclSpec::TST_char32: return "char32_t"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 431 | case DeclSpec::TST_int: return "int"; |
Richard Smith | 5a5a971 | 2012-04-04 06:24:32 +0000 | [diff] [blame] | 432 | case DeclSpec::TST_int128: return "__int128"; |
Anton Korobeynikov | aa4a99b | 2011-10-14 23:23:15 +0000 | [diff] [blame] | 433 | case DeclSpec::TST_half: return "half"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 434 | case DeclSpec::TST_float: return "float"; |
| 435 | case DeclSpec::TST_double: return "double"; |
| 436 | case DeclSpec::TST_bool: return "_Bool"; |
| 437 | case DeclSpec::TST_decimal32: return "_Decimal32"; |
| 438 | case DeclSpec::TST_decimal64: return "_Decimal64"; |
| 439 | case DeclSpec::TST_decimal128: return "_Decimal128"; |
| 440 | case DeclSpec::TST_enum: return "enum"; |
Chris Lattner | 99dc914 | 2008-04-13 18:59:07 +0000 | [diff] [blame] | 441 | case DeclSpec::TST_class: return "class"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 442 | case DeclSpec::TST_union: return "union"; |
| 443 | case DeclSpec::TST_struct: return "struct"; |
Joao Matos | 6666ed4 | 2012-08-31 18:45:21 +0000 | [diff] [blame] | 444 | case DeclSpec::TST_interface: return "__interface"; |
Douglas Gregor | 1a51b4a | 2009-02-09 15:09:02 +0000 | [diff] [blame] | 445 | case DeclSpec::TST_typename: return "type-name"; |
Steve Naroff | d1861fd | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 446 | case DeclSpec::TST_typeofType: |
| 447 | case DeclSpec::TST_typeofExpr: return "typeof"; |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 448 | case DeclSpec::TST_auto: return "auto"; |
| 449 | case DeclSpec::TST_decltype: return "(decltype)"; |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 450 | case DeclSpec::TST_decltype_auto: return "decltype(auto)"; |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 451 | case DeclSpec::TST_underlyingType: return "__underlying_type"; |
John McCall | a5fc472 | 2011-04-09 22:50:59 +0000 | [diff] [blame] | 452 | case DeclSpec::TST_unknown_anytype: return "__unknown_anytype"; |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 453 | case DeclSpec::TST_atomic: return "_Atomic"; |
Guy Benyei | b13621d | 2012-12-18 14:38:23 +0000 | [diff] [blame] | 454 | case DeclSpec::TST_image1d_t: return "image1d_t"; |
| 455 | case DeclSpec::TST_image1d_array_t: return "image1d_array_t"; |
| 456 | case DeclSpec::TST_image1d_buffer_t: return "image1d_buffer_t"; |
| 457 | case DeclSpec::TST_image2d_t: return "image2d_t"; |
| 458 | case DeclSpec::TST_image2d_array_t: return "image2d_array_t"; |
| 459 | case DeclSpec::TST_image3d_t: return "image3d_t"; |
Guy Benyei | 21f18c4 | 2013-02-07 10:55:47 +0000 | [diff] [blame] | 460 | case DeclSpec::TST_sampler_t: return "sampler_t"; |
Guy Benyei | e6b9d80 | 2013-01-20 12:31:11 +0000 | [diff] [blame] | 461 | case DeclSpec::TST_event_t: return "event_t"; |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 462 | case DeclSpec::TST_error: return "(error)"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 463 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 464 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 465 | } |
| 466 | |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 467 | const char *DeclSpec::getSpecifierName(TQ T) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 468 | switch (T) { |
John McCall | 32d335e | 2009-08-03 18:47:27 +0000 | [diff] [blame] | 469 | case DeclSpec::TQ_unspecified: return "unspecified"; |
| 470 | case DeclSpec::TQ_const: return "const"; |
| 471 | case DeclSpec::TQ_restrict: return "restrict"; |
| 472 | case DeclSpec::TQ_volatile: return "volatile"; |
Richard Smith | 4cf4a5e | 2013-03-28 01:55:44 +0000 | [diff] [blame] | 473 | case DeclSpec::TQ_atomic: return "_Atomic"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 474 | } |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 475 | llvm_unreachable("Unknown typespec!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 476 | } |
| 477 | |
Peter Collingbourne | b8b0e75 | 2011-10-06 03:01:00 +0000 | [diff] [blame] | 478 | bool DeclSpec::SetStorageClassSpec(Sema &S, SCS SC, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 479 | const char *&PrevSpec, |
Peter Collingbourne | b8b0e75 | 2011-10-06 03:01:00 +0000 | [diff] [blame] | 480 | unsigned &DiagID) { |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 481 | // OpenCL v1.1 s6.8g: "The extern, static, auto and register storage-class |
| 482 | // specifiers are not supported. |
Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 483 | // It seems sensible to prohibit private_extern too |
Peter Collingbourne | b8b0e75 | 2011-10-06 03:01:00 +0000 | [diff] [blame] | 484 | // The cl_clang_storage_class_specifiers extension enables support for |
| 485 | // these storage-class specifiers. |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 486 | // OpenCL v1.2 s6.8 changes this to "The auto and register storage-class |
| 487 | // specifiers are not supported." |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 488 | if (S.getLangOpts().OpenCL && |
Peter Collingbourne | b8b0e75 | 2011-10-06 03:01:00 +0000 | [diff] [blame] | 489 | !S.getOpenCLOptions().cl_clang_storage_class_specifiers) { |
| 490 | switch (SC) { |
Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 491 | case SCS_extern: |
| 492 | case SCS_private_extern: |
Tanya Lattner | 5e94d6f | 2012-06-19 23:09:52 +0000 | [diff] [blame] | 493 | case SCS_static: |
| 494 | if (S.getLangOpts().OpenCLVersion < 120) { |
| 495 | DiagID = diag::err_not_opencl_storage_class_specifier; |
| 496 | PrevSpec = getSpecifierName(SC); |
| 497 | return true; |
| 498 | } |
| 499 | break; |
Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 500 | case SCS_auto: |
| 501 | case SCS_register: |
Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 502 | DiagID = diag::err_not_opencl_storage_class_specifier; |
Peter Collingbourne | b8b0e75 | 2011-10-06 03:01:00 +0000 | [diff] [blame] | 503 | PrevSpec = getSpecifierName(SC); |
Peter Collingbourne | e2f82f7 | 2011-02-11 19:59:54 +0000 | [diff] [blame] | 504 | return true; |
| 505 | default: |
| 506 | break; |
| 507 | } |
| 508 | } |
| 509 | |
Abramo Bagnara | 35f9a19 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 510 | if (StorageClassSpec != SCS_unspecified) { |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 511 | // Maybe this is an attempt to use C++11 'auto' outside of C++11 mode. |
Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 512 | bool isInvalid = true; |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 513 | if (TypeSpecType == TST_unspecified && S.getLangOpts().CPlusPlus) { |
Peter Collingbourne | b8b0e75 | 2011-10-06 03:01:00 +0000 | [diff] [blame] | 514 | if (SC == SCS_auto) |
Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 515 | return SetTypeSpecType(TST_auto, Loc, PrevSpec, DiagID); |
| 516 | if (StorageClassSpec == SCS_auto) { |
| 517 | isInvalid = SetTypeSpecType(TST_auto, StorageClassSpecLoc, |
| 518 | PrevSpec, DiagID); |
| 519 | assert(!isInvalid && "auto SCS -> TST recovery failed"); |
| 520 | } |
| 521 | } |
| 522 | |
Abramo Bagnara | 35f9a19 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 523 | // Changing storage class is allowed only if the previous one |
| 524 | // was the 'extern' that is part of a linkage specification and |
| 525 | // the new storage class is 'typedef'. |
Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 526 | if (isInvalid && |
| 527 | !(SCS_extern_in_linkage_spec && |
Abramo Bagnara | 35f9a19 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 528 | StorageClassSpec == SCS_extern && |
Peter Collingbourne | b8b0e75 | 2011-10-06 03:01:00 +0000 | [diff] [blame] | 529 | SC == SCS_typedef)) |
| 530 | return BadSpecifier(SC, (SCS)StorageClassSpec, PrevSpec, DiagID); |
Abramo Bagnara | 35f9a19 | 2010-07-30 16:47:02 +0000 | [diff] [blame] | 531 | } |
Peter Collingbourne | b8b0e75 | 2011-10-06 03:01:00 +0000 | [diff] [blame] | 532 | StorageClassSpec = SC; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 533 | StorageClassSpecLoc = Loc; |
Peter Collingbourne | b8b0e75 | 2011-10-06 03:01:00 +0000 | [diff] [blame] | 534 | assert((unsigned)SC == StorageClassSpec && "SCS constants overflow bitfield"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 535 | return false; |
| 536 | } |
| 537 | |
Richard Smith | ec64244 | 2013-04-12 22:46:28 +0000 | [diff] [blame] | 538 | bool DeclSpec::SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 539 | const char *&PrevSpec, |
| 540 | unsigned &DiagID) { |
Richard Smith | ec64244 | 2013-04-12 22:46:28 +0000 | [diff] [blame] | 541 | if (ThreadStorageClassSpec != TSCS_unspecified) |
| 542 | return BadSpecifier(TSC, (TSCS)ThreadStorageClassSpec, PrevSpec, DiagID); |
| 543 | |
| 544 | ThreadStorageClassSpec = TSC; |
| 545 | ThreadStorageClassSpecLoc = Loc; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 546 | return false; |
| 547 | } |
| 548 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 549 | /// These methods set the specified attribute of the DeclSpec, but return true |
| 550 | /// and ignore the request if invalid (e.g. "extern" then "auto" is |
| 551 | /// specified). |
| 552 | bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 553 | const char *&PrevSpec, |
| 554 | unsigned &DiagID) { |
Abramo Bagnara | 2553eaf | 2011-03-06 22:21:56 +0000 | [diff] [blame] | 555 | // Overwrite TSWLoc only if TypeSpecWidth was unspecified, so that |
| 556 | // for 'long long' we will keep the source location of the first 'long'. |
| 557 | if (TypeSpecWidth == TSW_unspecified) |
| 558 | TSWLoc = Loc; |
| 559 | // Allow turning long -> long long. |
| 560 | else if (W != TSW_longlong || TypeSpecWidth != TSW_long) |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 561 | return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 562 | TypeSpecWidth = W; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 563 | if (TypeAltiVecVector && !TypeAltiVecBool && |
| 564 | ((TypeSpecWidth == TSW_long) || (TypeSpecWidth == TSW_longlong))) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 565 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 566 | DiagID = diag::warn_vector_long_decl_spec_combination; |
| 567 | return true; |
| 568 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 569 | return false; |
| 570 | } |
| 571 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 572 | bool DeclSpec::SetTypeSpecComplex(TSC C, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 573 | const char *&PrevSpec, |
| 574 | unsigned &DiagID) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 575 | if (TypeSpecComplex != TSC_unspecified) |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 576 | return BadSpecifier(C, (TSC)TypeSpecComplex, PrevSpec, DiagID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 577 | TypeSpecComplex = C; |
| 578 | TSCLoc = Loc; |
| 579 | return false; |
| 580 | } |
| 581 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 582 | bool DeclSpec::SetTypeSpecSign(TSS S, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 583 | const char *&PrevSpec, |
| 584 | unsigned &DiagID) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 585 | if (TypeSpecSign != TSS_unspecified) |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 586 | return BadSpecifier(S, (TSS)TypeSpecSign, PrevSpec, DiagID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 587 | TypeSpecSign = S; |
| 588 | TSSLoc = Loc; |
| 589 | return false; |
| 590 | } |
| 591 | |
| 592 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 593 | const char *&PrevSpec, |
| 594 | unsigned &DiagID, |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 595 | ParsedType Rep) { |
Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 596 | return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep); |
| 597 | } |
| 598 | |
| 599 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc, |
| 600 | SourceLocation TagNameLoc, |
| 601 | const char *&PrevSpec, |
| 602 | unsigned &DiagID, |
| 603 | ParsedType Rep) { |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 604 | assert(isTypeRep(T) && "T does not store a type"); |
| 605 | assert(Rep && "no type provided!"); |
| 606 | if (TypeSpecType != TST_unspecified) { |
| 607 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 608 | DiagID = diag::err_invalid_decl_spec_combination; |
| 609 | return true; |
| 610 | } |
| 611 | TypeSpecType = T; |
| 612 | TypeRep = Rep; |
Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 613 | TSTLoc = TagKwLoc; |
| 614 | TSTNameLoc = TagNameLoc; |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 615 | TypeSpecOwned = false; |
| 616 | return false; |
| 617 | } |
| 618 | |
| 619 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
| 620 | const char *&PrevSpec, |
| 621 | unsigned &DiagID, |
| 622 | Expr *Rep) { |
| 623 | assert(isExprRep(T) && "T does not store an expr"); |
| 624 | assert(Rep && "no expression provided!"); |
| 625 | if (TypeSpecType != TST_unspecified) { |
| 626 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 627 | DiagID = diag::err_invalid_decl_spec_combination; |
| 628 | return true; |
| 629 | } |
| 630 | TypeSpecType = T; |
| 631 | ExprRep = Rep; |
| 632 | TSTLoc = Loc; |
Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 633 | TSTNameLoc = Loc; |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 634 | TypeSpecOwned = false; |
| 635 | return false; |
| 636 | } |
| 637 | |
| 638 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
| 639 | const char *&PrevSpec, |
| 640 | unsigned &DiagID, |
| 641 | Decl *Rep, bool Owned) { |
Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 642 | return SetTypeSpecType(T, Loc, Loc, PrevSpec, DiagID, Rep, Owned); |
| 643 | } |
| 644 | |
| 645 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation TagKwLoc, |
| 646 | SourceLocation TagNameLoc, |
| 647 | const char *&PrevSpec, |
| 648 | unsigned &DiagID, |
| 649 | Decl *Rep, bool Owned) { |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 650 | assert(isDeclRep(T) && "T does not store a decl"); |
| 651 | // Unlike the other cases, we don't assert that we actually get a decl. |
| 652 | |
| 653 | if (TypeSpecType != TST_unspecified) { |
| 654 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 655 | DiagID = diag::err_invalid_decl_spec_combination; |
| 656 | return true; |
| 657 | } |
| 658 | TypeSpecType = T; |
| 659 | DeclRep = Rep; |
Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 660 | TSTLoc = TagKwLoc; |
| 661 | TSTNameLoc = TagNameLoc; |
Douglas Gregor | 86a8730 | 2013-05-14 23:22:32 +0000 | [diff] [blame] | 662 | TypeSpecOwned = Owned && Rep != 0; |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 663 | return false; |
| 664 | } |
| 665 | |
| 666 | bool DeclSpec::SetTypeSpecType(TST T, SourceLocation Loc, |
| 667 | const char *&PrevSpec, |
| 668 | unsigned &DiagID) { |
| 669 | assert(!isDeclRep(T) && !isTypeRep(T) && !isExprRep(T) && |
| 670 | "rep required for these type-spec kinds!"); |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 671 | if (TypeSpecType != TST_unspecified) { |
| 672 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 673 | DiagID = diag::err_invalid_decl_spec_combination; |
| 674 | return true; |
| 675 | } |
Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 676 | TSTLoc = Loc; |
| 677 | TSTNameLoc = Loc; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 678 | if (TypeAltiVecVector && (T == TST_bool) && !TypeAltiVecBool) { |
| 679 | TypeAltiVecBool = true; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 680 | return false; |
| 681 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 682 | TypeSpecType = T; |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 683 | TypeSpecOwned = false; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 684 | if (TypeAltiVecVector && !TypeAltiVecBool && (TypeSpecType == TST_double)) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 685 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 686 | DiagID = diag::err_invalid_vector_decl_spec; |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 687 | return true; |
| 688 | } |
| 689 | return false; |
| 690 | } |
| 691 | |
| 692 | bool DeclSpec::SetTypeAltiVecVector(bool isAltiVecVector, SourceLocation Loc, |
| 693 | const char *&PrevSpec, unsigned &DiagID) { |
| 694 | if (TypeSpecType != TST_unspecified) { |
| 695 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 696 | DiagID = diag::err_invalid_vector_decl_spec_combination; |
| 697 | return true; |
| 698 | } |
| 699 | TypeAltiVecVector = isAltiVecVector; |
| 700 | AltiVecLoc = Loc; |
| 701 | return false; |
| 702 | } |
| 703 | |
| 704 | bool DeclSpec::SetTypeAltiVecPixel(bool isAltiVecPixel, SourceLocation Loc, |
| 705 | const char *&PrevSpec, unsigned &DiagID) { |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 706 | if (!TypeAltiVecVector || TypeAltiVecPixel || |
| 707 | (TypeSpecType != TST_unspecified)) { |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 708 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 709 | DiagID = diag::err_invalid_pixel_decl_spec_combination; |
| 710 | return true; |
| 711 | } |
John Thompson | 82287d1 | 2010-02-05 00:12:22 +0000 | [diff] [blame] | 712 | TypeAltiVecPixel = isAltiVecPixel; |
| 713 | TSTLoc = Loc; |
Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 714 | TSTNameLoc = Loc; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 715 | return false; |
| 716 | } |
| 717 | |
Bill Schmidt | 3e3d20b | 2013-07-03 20:54:09 +0000 | [diff] [blame] | 718 | bool DeclSpec::SetTypeAltiVecBool(bool isAltiVecBool, SourceLocation Loc, |
| 719 | const char *&PrevSpec, unsigned &DiagID) { |
| 720 | if (!TypeAltiVecVector || TypeAltiVecBool || |
| 721 | (TypeSpecType != TST_unspecified)) { |
| 722 | PrevSpec = DeclSpec::getSpecifierName((TST) TypeSpecType); |
| 723 | DiagID = diag::err_invalid_vector_bool_decl_spec; |
| 724 | return true; |
| 725 | } |
| 726 | TypeAltiVecBool = isAltiVecBool; |
| 727 | TSTLoc = Loc; |
| 728 | TSTNameLoc = Loc; |
| 729 | return false; |
| 730 | } |
| 731 | |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 732 | bool DeclSpec::SetTypeSpecError() { |
| 733 | TypeSpecType = TST_error; |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 734 | TypeSpecOwned = false; |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 735 | TSTLoc = SourceLocation(); |
Abramo Bagnara | 0daaf32 | 2011-03-16 20:16:18 +0000 | [diff] [blame] | 736 | TSTNameLoc = SourceLocation(); |
Douglas Gregor | ddc29e1 | 2009-02-06 22:42:48 +0000 | [diff] [blame] | 737 | return false; |
| 738 | } |
| 739 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 740 | bool DeclSpec::SetTypeQual(TQ T, SourceLocation Loc, const char *&PrevSpec, |
Richard Smith | d654f2d | 2012-10-17 23:31:46 +0000 | [diff] [blame] | 741 | unsigned &DiagID, const LangOptions &Lang) { |
| 742 | // Duplicates are permitted in C99, but are not permitted in C++. However, |
| 743 | // since this is likely not what the user intended, we will always warn. We |
| 744 | // do not need to set the qualifier's location since we already have it. |
Aaron Ballman | c828620 | 2012-08-28 20:55:40 +0000 | [diff] [blame] | 745 | if (TypeQualifiers & T) { |
Aaron Ballman | a14f400 | 2012-08-29 12:35:14 +0000 | [diff] [blame] | 746 | bool IsExtension = true; |
Richard Smith | d654f2d | 2012-10-17 23:31:46 +0000 | [diff] [blame] | 747 | if (Lang.C99) |
Aaron Ballman | a14f400 | 2012-08-29 12:35:14 +0000 | [diff] [blame] | 748 | IsExtension = false; |
Aaron Ballman | c828620 | 2012-08-28 20:55:40 +0000 | [diff] [blame] | 749 | return BadSpecifier(T, T, PrevSpec, DiagID, IsExtension); |
| 750 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 751 | TypeQualifiers |= T; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 752 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 753 | switch (T) { |
Richard Smith | 4cf4a5e | 2013-03-28 01:55:44 +0000 | [diff] [blame] | 754 | case TQ_unspecified: break; |
| 755 | case TQ_const: TQ_constLoc = Loc; return false; |
| 756 | case TQ_restrict: TQ_restrictLoc = Loc; return false; |
| 757 | case TQ_volatile: TQ_volatileLoc = Loc; return false; |
| 758 | case TQ_atomic: TQ_atomicLoc = Loc; return false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 759 | } |
Richard Smith | 4cf4a5e | 2013-03-28 01:55:44 +0000 | [diff] [blame] | 760 | |
| 761 | llvm_unreachable("Unknown type qualifier!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Chad Rosier | 22aa690 | 2012-12-21 22:24:43 +0000 | [diff] [blame] | 764 | bool DeclSpec::setFunctionSpecInline(SourceLocation Loc) { |
Chad Rosier | 67a0f6e | 2012-12-21 22:38:37 +0000 | [diff] [blame] | 765 | // 'inline inline' is ok. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 766 | FS_inline_specified = true; |
| 767 | FS_inlineLoc = Loc; |
| 768 | return false; |
| 769 | } |
| 770 | |
Chad Rosier | 22aa690 | 2012-12-21 22:24:43 +0000 | [diff] [blame] | 771 | bool DeclSpec::setFunctionSpecVirtual(SourceLocation Loc) { |
Chad Rosier | 67a0f6e | 2012-12-21 22:38:37 +0000 | [diff] [blame] | 772 | // 'virtual virtual' is ok. |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 773 | FS_virtual_specified = true; |
| 774 | FS_virtualLoc = Loc; |
| 775 | return false; |
| 776 | } |
| 777 | |
Chad Rosier | 22aa690 | 2012-12-21 22:24:43 +0000 | [diff] [blame] | 778 | bool DeclSpec::setFunctionSpecExplicit(SourceLocation Loc) { |
Douglas Gregor | b48fe38 | 2008-10-31 09:07:45 +0000 | [diff] [blame] | 779 | // 'explicit explicit' is ok. |
| 780 | FS_explicit_specified = true; |
| 781 | FS_explicitLoc = Loc; |
| 782 | return false; |
| 783 | } |
| 784 | |
Richard Smith | de03c15 | 2013-01-17 22:16:11 +0000 | [diff] [blame] | 785 | bool DeclSpec::setFunctionSpecNoreturn(SourceLocation Loc) { |
| 786 | // '_Noreturn _Noreturn' is ok. |
| 787 | FS_noreturn_specified = true; |
| 788 | FS_noreturnLoc = Loc; |
| 789 | return false; |
| 790 | } |
| 791 | |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 792 | bool DeclSpec::SetFriendSpec(SourceLocation Loc, const char *&PrevSpec, |
| 793 | unsigned &DiagID) { |
Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 794 | if (Friend_specified) { |
| 795 | PrevSpec = "friend"; |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 796 | DiagID = diag::ext_duplicate_declspec; |
Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 797 | return true; |
| 798 | } |
John McCall | fec5401 | 2009-08-03 20:12:06 +0000 | [diff] [blame] | 799 | |
Anders Carlsson | f47f7a1 | 2009-05-06 04:46:28 +0000 | [diff] [blame] | 800 | Friend_specified = true; |
| 801 | FriendLoc = Loc; |
| 802 | return false; |
| 803 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 804 | |
Douglas Gregor | 8d267c5 | 2011-09-09 02:06:17 +0000 | [diff] [blame] | 805 | bool DeclSpec::setModulePrivateSpec(SourceLocation Loc, const char *&PrevSpec, |
| 806 | unsigned &DiagID) { |
| 807 | if (isModulePrivateSpecified()) { |
| 808 | PrevSpec = "__module_private__"; |
| 809 | DiagID = diag::ext_duplicate_declspec; |
| 810 | return true; |
| 811 | } |
| 812 | |
| 813 | ModulePrivateLoc = Loc; |
| 814 | return false; |
| 815 | } |
| 816 | |
Sebastian Redl | 2ac6723 | 2009-11-05 15:47:02 +0000 | [diff] [blame] | 817 | bool DeclSpec::SetConstexprSpec(SourceLocation Loc, const char *&PrevSpec, |
| 818 | unsigned &DiagID) { |
| 819 | // 'constexpr constexpr' is ok. |
| 820 | Constexpr_specified = true; |
| 821 | ConstexprLoc = Loc; |
| 822 | return false; |
| 823 | } |
| 824 | |
John McCall | d226f65 | 2010-08-21 09:40:31 +0000 | [diff] [blame] | 825 | void DeclSpec::setProtocolQualifiers(Decl * const *Protos, |
Argyrios Kyrtzidis | e3a535b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 826 | unsigned NP, |
| 827 | SourceLocation *ProtoLocs, |
| 828 | SourceLocation LAngleLoc) { |
| 829 | if (NP == 0) return; |
David Greene | c23e69d | 2013-01-15 22:09:39 +0000 | [diff] [blame] | 830 | Decl **ProtoQuals = new Decl*[NP]; |
| 831 | memcpy(ProtoQuals, Protos, sizeof(Decl*)*NP); |
| 832 | ProtocolQualifiers = ProtoQuals; |
Argyrios Kyrtzidis | e3a535b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 833 | ProtocolLocs = new SourceLocation[NP]; |
Argyrios Kyrtzidis | e3a535b | 2009-09-29 19:42:11 +0000 | [diff] [blame] | 834 | memcpy(ProtocolLocs, ProtoLocs, sizeof(SourceLocation)*NP); |
| 835 | NumProtocolQualifiers = NP; |
| 836 | ProtocolLAngleLoc = LAngleLoc; |
| 837 | } |
| 838 | |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 839 | void DeclSpec::SaveWrittenBuiltinSpecs() { |
| 840 | writtenBS.Sign = getTypeSpecSign(); |
| 841 | writtenBS.Width = getTypeSpecWidth(); |
| 842 | writtenBS.Type = getTypeSpecType(); |
| 843 | // Search the list of attributes for the presence of a mode attribute. |
| 844 | writtenBS.ModeAttr = false; |
John McCall | 7f040a9 | 2010-12-24 02:08:15 +0000 | [diff] [blame] | 845 | AttributeList* attrs = getAttributes().getList(); |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 846 | while (attrs) { |
Sean Hunt | 8e083e7 | 2012-06-19 23:57:03 +0000 | [diff] [blame] | 847 | if (attrs->getKind() == AttributeList::AT_Mode) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 848 | writtenBS.ModeAttr = true; |
| 849 | break; |
| 850 | } |
| 851 | attrs = attrs->getNext(); |
| 852 | } |
| 853 | } |
| 854 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 855 | /// Finish - This does final analysis of the declspec, rejecting things like |
| 856 | /// "_Imaginary" (lacking an FP type). This returns a diagnostic to issue or |
| 857 | /// diag::NUM_DIAGNOSTICS if there is no error. After calling this method, |
| 858 | /// DeclSpec is guaranteed self-consistent, even if an error occurred. |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 859 | void DeclSpec::Finish(DiagnosticsEngine &D, Preprocessor &PP) { |
Douglas Gregor | ddf889a | 2010-01-18 18:04:31 +0000 | [diff] [blame] | 860 | // Before possibly changing their values, save specs as written. |
| 861 | SaveWrittenBuiltinSpecs(); |
| 862 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 863 | // Check the type specifier components first. |
| 864 | |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 865 | // If decltype(auto) is used, no other type specifiers are permitted. |
| 866 | if (TypeSpecType == TST_decltype_auto && |
| 867 | (TypeSpecWidth != TSW_unspecified || |
| 868 | TypeSpecComplex != TSC_unspecified || |
| 869 | TypeSpecSign != TSS_unspecified || |
| 870 | TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool || |
| 871 | TypeQualifiers)) { |
Benjamin Kramer | c6a3177 | 2013-04-27 15:07:53 +0000 | [diff] [blame] | 872 | const unsigned NumLocs = 8; |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 873 | SourceLocation ExtraLocs[NumLocs] = { |
| 874 | TSWLoc, TSCLoc, TSSLoc, AltiVecLoc, |
| 875 | TQ_constLoc, TQ_restrictLoc, TQ_volatileLoc, TQ_atomicLoc |
| 876 | }; |
| 877 | FixItHint Hints[NumLocs]; |
| 878 | SourceLocation FirstLoc; |
| 879 | for (unsigned I = 0; I != NumLocs; ++I) { |
| 880 | if (!ExtraLocs[I].isInvalid()) { |
| 881 | if (FirstLoc.isInvalid() || |
| 882 | PP.getSourceManager().isBeforeInTranslationUnit(ExtraLocs[I], |
| 883 | FirstLoc)) |
| 884 | FirstLoc = ExtraLocs[I]; |
| 885 | Hints[I] = FixItHint::CreateRemoval(ExtraLocs[I]); |
| 886 | } |
| 887 | } |
| 888 | TypeSpecWidth = TSW_unspecified; |
| 889 | TypeSpecComplex = TSC_unspecified; |
| 890 | TypeSpecSign = TSS_unspecified; |
| 891 | TypeAltiVecVector = TypeAltiVecPixel = TypeAltiVecBool = false; |
| 892 | TypeQualifiers = 0; |
| 893 | Diag(D, TSTLoc, diag::err_decltype_auto_cannot_be_combined) |
| 894 | << Hints[0] << Hints[1] << Hints[2] << Hints[3] |
| 895 | << Hints[4] << Hints[5] << Hints[6] << Hints[7]; |
| 896 | } |
| 897 | |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 898 | // Validate and finalize AltiVec vector declspec. |
| 899 | if (TypeAltiVecVector) { |
| 900 | if (TypeAltiVecBool) { |
| 901 | // Sign specifiers are not allowed with vector bool. (PIM 2.1) |
| 902 | if (TypeSpecSign != TSS_unspecified) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 903 | Diag(D, TSSLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 904 | << getSpecifierName((TSS)TypeSpecSign); |
| 905 | } |
| 906 | |
| 907 | // Only char/int are valid with vector bool. (PIM 2.1) |
Duncan Sands | 2e964a92 | 2010-06-23 19:34:52 +0000 | [diff] [blame] | 908 | if (((TypeSpecType != TST_unspecified) && (TypeSpecType != TST_char) && |
| 909 | (TypeSpecType != TST_int)) || TypeAltiVecPixel) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 910 | Diag(D, TSTLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 911 | << (TypeAltiVecPixel ? "__pixel" : |
| 912 | getSpecifierName((TST)TypeSpecType)); |
| 913 | } |
| 914 | |
| 915 | // Only 'short' is valid with vector bool. (PIM 2.1) |
| 916 | if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short)) |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 917 | Diag(D, TSWLoc, diag::err_invalid_vector_bool_decl_spec) |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 918 | << getSpecifierName((TSW)TypeSpecWidth); |
| 919 | |
| 920 | // Elements of vector bool are interpreted as unsigned. (PIM 2.1) |
| 921 | if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) || |
| 922 | (TypeSpecWidth != TSW_unspecified)) |
| 923 | TypeSpecSign = TSS_unsigned; |
| 924 | } |
| 925 | |
| 926 | if (TypeAltiVecPixel) { |
| 927 | //TODO: perform validation |
| 928 | TypeSpecType = TST_int; |
| 929 | TypeSpecSign = TSS_unsigned; |
| 930 | TypeSpecWidth = TSW_short; |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 931 | TypeSpecOwned = false; |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | |
Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 935 | // signed/unsigned are only valid with int/char/wchar_t. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 936 | if (TypeSpecSign != TSS_unspecified) { |
| 937 | if (TypeSpecType == TST_unspecified) |
| 938 | TypeSpecType = TST_int; // unsigned -> unsigned int, signed -> signed int. |
Richard Smith | 5a5a971 | 2012-04-04 06:24:32 +0000 | [diff] [blame] | 939 | else if (TypeSpecType != TST_int && TypeSpecType != TST_int128 && |
Argyrios Kyrtzidis | 64c438a | 2008-08-09 16:51:54 +0000 | [diff] [blame] | 940 | TypeSpecType != TST_char && TypeSpecType != TST_wchar) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 941 | Diag(D, TSSLoc, diag::err_invalid_sign_spec) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 942 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 943 | // signed double -> double. |
| 944 | TypeSpecSign = TSS_unspecified; |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | // Validate the width of the type. |
| 949 | switch (TypeSpecWidth) { |
| 950 | case TSW_unspecified: break; |
| 951 | case TSW_short: // short int |
| 952 | case TSW_longlong: // long long int |
| 953 | if (TypeSpecType == TST_unspecified) |
| 954 | TypeSpecType = TST_int; // short -> short int, long long -> long long int. |
| 955 | else if (TypeSpecType != TST_int) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 956 | Diag(D, TSWLoc, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 957 | TypeSpecWidth == TSW_short ? diag::err_invalid_short_spec |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 958 | : diag::err_invalid_longlong_spec) |
| 959 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 960 | TypeSpecType = TST_int; |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 961 | TypeSpecOwned = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 962 | } |
| 963 | break; |
| 964 | case TSW_long: // long double, long int |
| 965 | if (TypeSpecType == TST_unspecified) |
| 966 | TypeSpecType = TST_int; // long -> long int. |
| 967 | else if (TypeSpecType != TST_int && TypeSpecType != TST_double) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 968 | Diag(D, TSWLoc, diag::err_invalid_long_spec) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 969 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 970 | TypeSpecType = TST_int; |
John McCall | 9e46b8c | 2010-08-26 17:22:34 +0000 | [diff] [blame] | 971 | TypeSpecOwned = false; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 972 | } |
| 973 | break; |
| 974 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 975 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 976 | // TODO: if the implementation does not implement _Complex or _Imaginary, |
| 977 | // disallow their use. Need information about the backend. |
| 978 | if (TypeSpecComplex != TSC_unspecified) { |
| 979 | if (TypeSpecType == TST_unspecified) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 980 | Diag(D, TSCLoc, diag::ext_plain_complex) |
Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 981 | << FixItHint::CreateInsertion( |
Douglas Gregor | 9b3064b | 2009-04-01 22:41:11 +0000 | [diff] [blame] | 982 | PP.getLocForEndOfToken(getTypeSpecComplexLoc()), |
| 983 | " double"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 984 | TypeSpecType = TST_double; // _Complex -> _Complex double. |
| 985 | } else if (TypeSpecType == TST_int || TypeSpecType == TST_char) { |
| 986 | // Note that this intentionally doesn't include _Complex _Bool. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 987 | if (!PP.getLangOpts().CPlusPlus) |
Eli Friedman | 7ead5c7 | 2012-01-10 04:58:17 +0000 | [diff] [blame] | 988 | Diag(D, TSTLoc, diag::ext_integer_complex); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 989 | } else if (TypeSpecType != TST_float && TypeSpecType != TST_double) { |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 990 | Diag(D, TSCLoc, diag::err_invalid_complex_spec) |
Chris Lattner | 254be6a | 2008-11-22 08:32:36 +0000 | [diff] [blame] | 991 | << getSpecifierName((TST)TypeSpecType); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 992 | TypeSpecComplex = TSC_unspecified; |
| 993 | } |
| 994 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 995 | |
Richard Smith | ec64244 | 2013-04-12 22:46:28 +0000 | [diff] [blame] | 996 | // C11 6.7.1/3, C++11 [dcl.stc]p1, GNU TLS: __thread, thread_local and |
| 997 | // _Thread_local can only appear with the 'static' and 'extern' storage class |
| 998 | // specifiers. We also allow __private_extern__ as an extension. |
| 999 | if (ThreadStorageClassSpec != TSCS_unspecified) { |
| 1000 | switch (StorageClassSpec) { |
| 1001 | case SCS_unspecified: |
| 1002 | case SCS_extern: |
| 1003 | case SCS_private_extern: |
| 1004 | case SCS_static: |
| 1005 | break; |
| 1006 | default: |
| 1007 | if (PP.getSourceManager().isBeforeInTranslationUnit( |
| 1008 | getThreadStorageClassSpecLoc(), getStorageClassSpecLoc())) |
| 1009 | Diag(D, getStorageClassSpecLoc(), |
| 1010 | diag::err_invalid_decl_spec_combination) |
| 1011 | << DeclSpec::getSpecifierName(getThreadStorageClassSpec()) |
| 1012 | << SourceRange(getThreadStorageClassSpecLoc()); |
| 1013 | else |
| 1014 | Diag(D, getThreadStorageClassSpecLoc(), |
| 1015 | diag::err_invalid_decl_spec_combination) |
| 1016 | << DeclSpec::getSpecifierName(getStorageClassSpec()) |
| 1017 | << SourceRange(getStorageClassSpecLoc()); |
| 1018 | // Discard the thread storage class specifier to recover. |
| 1019 | ThreadStorageClassSpec = TSCS_unspecified; |
| 1020 | ThreadStorageClassSpecLoc = SourceLocation(); |
| 1021 | } |
| 1022 | } |
| 1023 | |
Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 1024 | // If no type specifier was provided and we're parsing a language where |
| 1025 | // the type specifier is not optional, but we got 'auto' as a storage |
| 1026 | // class specifier, then assume this is an attempt to use C++0x's 'auto' |
| 1027 | // type specifier. |
Richard Smith | 58eb370 | 2013-04-30 22:43:51 +0000 | [diff] [blame] | 1028 | if (PP.getLangOpts().CPlusPlus && |
Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 1029 | TypeSpecType == TST_unspecified && StorageClassSpec == SCS_auto) { |
| 1030 | TypeSpecType = TST_auto; |
Rafael Espindola | d2615cc | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1031 | StorageClassSpec = SCS_unspecified; |
Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 1032 | TSTLoc = TSTNameLoc = StorageClassSpecLoc; |
| 1033 | StorageClassSpecLoc = SourceLocation(); |
| 1034 | } |
| 1035 | // Diagnose if we've recovered from an ill-formed 'auto' storage class |
Richard Smith | a2c3646 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 1036 | // specifier in a pre-C++11 dialect of C++. |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 1037 | if (!PP.getLangOpts().CPlusPlus11 && TypeSpecType == TST_auto) |
Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 1038 | Diag(D, TSTLoc, diag::ext_auto_type_specifier); |
Richard Smith | 80ad52f | 2013-01-02 11:42:31 +0000 | [diff] [blame] | 1039 | if (PP.getLangOpts().CPlusPlus && !PP.getLangOpts().CPlusPlus11 && |
Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 1040 | StorageClassSpec == SCS_auto) |
| 1041 | Diag(D, StorageClassSpecLoc, diag::warn_auto_storage_class) |
| 1042 | << FixItHint::CreateRemoval(StorageClassSpecLoc); |
Richard Smith | 841804b | 2011-10-17 23:06:20 +0000 | [diff] [blame] | 1043 | if (TypeSpecType == TST_char16 || TypeSpecType == TST_char32) |
| 1044 | Diag(D, TSTLoc, diag::warn_cxx98_compat_unicode_type) |
| 1045 | << (TypeSpecType == TST_char16 ? "char16_t" : "char32_t"); |
Richard Smith | 841804b | 2011-10-17 23:06:20 +0000 | [diff] [blame] | 1046 | if (Constexpr_specified) |
| 1047 | Diag(D, ConstexprLoc, diag::warn_cxx98_compat_constexpr); |
Richard Smith | 8f4fb19 | 2011-09-04 19:54:14 +0000 | [diff] [blame] | 1048 | |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1049 | // C++ [class.friend]p6: |
| 1050 | // No storage-class-specifier shall appear in the decl-specifier-seq |
| 1051 | // of a friend declaration. |
Richard Smith | ec64244 | 2013-04-12 22:46:28 +0000 | [diff] [blame] | 1052 | if (isFriendSpecified() && |
| 1053 | (getStorageClassSpec() || getThreadStorageClassSpec())) { |
| 1054 | SmallString<32> SpecName; |
| 1055 | SourceLocation SCLoc; |
| 1056 | FixItHint StorageHint, ThreadHint; |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1057 | |
Richard Smith | ec64244 | 2013-04-12 22:46:28 +0000 | [diff] [blame] | 1058 | if (DeclSpec::SCS SC = getStorageClassSpec()) { |
| 1059 | SpecName = getSpecifierName(SC); |
| 1060 | SCLoc = getStorageClassSpecLoc(); |
| 1061 | StorageHint = FixItHint::CreateRemoval(SCLoc); |
| 1062 | } |
| 1063 | |
| 1064 | if (DeclSpec::TSCS TSC = getThreadStorageClassSpec()) { |
| 1065 | if (!SpecName.empty()) SpecName += " "; |
| 1066 | SpecName += getSpecifierName(TSC); |
| 1067 | SCLoc = getThreadStorageClassSpecLoc(); |
| 1068 | ThreadHint = FixItHint::CreateRemoval(SCLoc); |
| 1069 | } |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1070 | |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 1071 | Diag(D, SCLoc, diag::err_friend_storage_spec) |
Richard Smith | ec64244 | 2013-04-12 22:46:28 +0000 | [diff] [blame] | 1072 | << SpecName << StorageHint << ThreadHint; |
John McCall | 67d1a67 | 2009-08-06 02:15:43 +0000 | [diff] [blame] | 1073 | |
| 1074 | ClearStorageClassSpecs(); |
| 1075 | } |
| 1076 | |
Douglas Gregor | 6274d30 | 2011-09-09 21:14:29 +0000 | [diff] [blame] | 1077 | assert(!TypeSpecOwned || isDeclRep((TST) TypeSpecType)); |
| 1078 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1079 | // Okay, now we can infer the real type. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1080 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1081 | // 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] | 1082 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1083 | // 'data definition has no type or storage class'? |
| 1084 | } |
Daniel Dunbar | e4858a6 | 2008-08-11 03:45:03 +0000 | [diff] [blame] | 1085 | |
Sebastian Redl | a4ed0d8 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 1086 | bool DeclSpec::isMissingDeclaratorOk() { |
| 1087 | TST tst = getTypeSpecType(); |
John McCall | b3d8748 | 2010-08-24 05:47:05 +0000 | [diff] [blame] | 1088 | return isDeclRep(tst) && getRepAsDecl() != 0 && |
| 1089 | StorageClassSpec != DeclSpec::SCS_typedef; |
Sebastian Redl | a4ed0d8 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 1090 | } |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1091 | |
Douglas Gregor | 3f9a056 | 2009-11-03 01:35:08 +0000 | [diff] [blame] | 1092 | void UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc, |
| 1093 | OverloadedOperatorKind Op, |
| 1094 | SourceLocation SymbolLocations[3]) { |
| 1095 | Kind = IK_OperatorFunctionId; |
| 1096 | StartLocation = OperatorLoc; |
| 1097 | EndLocation = OperatorLoc; |
| 1098 | OperatorFunctionId.Operator = Op; |
| 1099 | for (unsigned I = 0; I != 3; ++I) { |
| 1100 | OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I].getRawEncoding(); |
| 1101 | |
| 1102 | if (SymbolLocations[I].isValid()) |
| 1103 | EndLocation = SymbolLocations[I]; |
| 1104 | } |
| 1105 | } |
Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1106 | |
Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1107 | bool VirtSpecifiers::SetSpecifier(Specifier VS, SourceLocation Loc, |
Anders Carlsson | 46127a9 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 1108 | const char *&PrevSpec) { |
Douglas Gregor | f525160 | 2011-03-08 17:10:18 +0000 | [diff] [blame] | 1109 | LastLocation = Loc; |
| 1110 | |
Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1111 | if (Specifiers & VS) { |
| 1112 | PrevSpec = getSpecifierName(VS); |
| 1113 | return true; |
| 1114 | } |
| 1115 | |
| 1116 | Specifiers |= VS; |
| 1117 | |
| 1118 | switch (VS) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1119 | default: llvm_unreachable("Unknown specifier!"); |
Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1120 | case VS_Override: VS_overrideLoc = Loc; break; |
David Majnemer | 7121bdb | 2013-10-18 00:33:31 +0000 | [diff] [blame^] | 1121 | case VS_Sealed: |
Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1122 | case VS_Final: VS_finalLoc = Loc; break; |
Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1123 | } |
Anders Carlsson | 46127a9 | 2011-01-22 15:58:16 +0000 | [diff] [blame] | 1124 | |
Anders Carlsson | b971dbd | 2011-01-17 03:05:47 +0000 | [diff] [blame] | 1125 | return false; |
| 1126 | } |
| 1127 | |
Anders Carlsson | cc54d59 | 2011-01-22 16:56:46 +0000 | [diff] [blame] | 1128 | const char *VirtSpecifiers::getSpecifierName(Specifier VS) { |
Anders Carlsson | c46bb7d | 2011-01-22 15:11:37 +0000 | [diff] [blame] | 1129 | switch (VS) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1130 | default: llvm_unreachable("Unknown specifier"); |
Anders Carlsson | c46bb7d | 2011-01-22 15:11:37 +0000 | [diff] [blame] | 1131 | case VS_Override: return "override"; |
| 1132 | case VS_Final: return "final"; |
David Majnemer | 7121bdb | 2013-10-18 00:33:31 +0000 | [diff] [blame^] | 1133 | case VS_Sealed: return "sealed"; |
Anders Carlsson | c46bb7d | 2011-01-22 15:11:37 +0000 | [diff] [blame] | 1134 | } |
| 1135 | } |