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