Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | //===--- SemaType.cpp - Semantic Analysis for Types -----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Chris Lattner and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements type-related semantic analysis. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "Sema.h" |
| 15 | #include "clang/AST/ASTContext.h" |
| 16 | #include "clang/AST/Decl.h" |
| 17 | #include "clang/Parse/DeclSpec.h" |
| 18 | #include "clang/Lex/IdentifierTable.h" |
Chris Lattner | 11f20f9 | 2007-08-28 16:40:32 +0000 | [diff] [blame] | 19 | #include "clang/Basic/LangOptions.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
| 22 | /// ConvertDeclSpecToType - Convert the specified declspec to the appropriate |
| 23 | /// type object. This returns null on error. |
| 24 | static QualType ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) { |
| 25 | // FIXME: Should move the logic from DeclSpec::Finish to here for validity |
| 26 | // checking. |
| 27 | |
| 28 | switch (DS.getTypeSpecType()) { |
| 29 | default: return QualType(); // FIXME: Handle unimp cases! |
| 30 | case DeclSpec::TST_void: return Ctx.VoidTy; |
| 31 | case DeclSpec::TST_char: |
| 32 | if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified) |
| 33 | return Ctx.CharTy; |
| 34 | else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed) |
| 35 | return Ctx.SignedCharTy; |
| 36 | else { |
| 37 | assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned && |
| 38 | "Unknown TSS value"); |
| 39 | return Ctx.UnsignedCharTy; |
| 40 | } |
| 41 | case DeclSpec::TST_unspecified: // Unspecific typespec defaults to int. |
Chris Lattner | 5328f31 | 2007-08-21 17:02:28 +0000 | [diff] [blame] | 42 | case DeclSpec::TST_int: { |
| 43 | QualType Result; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 44 | if (DS.getTypeSpecSign() != DeclSpec::TSS_unsigned) { |
| 45 | switch (DS.getTypeSpecWidth()) { |
Chris Lattner | 5328f31 | 2007-08-21 17:02:28 +0000 | [diff] [blame] | 46 | case DeclSpec::TSW_unspecified: Result = Ctx.IntTy; break; |
| 47 | case DeclSpec::TSW_short: Result = Ctx.ShortTy; break; |
| 48 | case DeclSpec::TSW_long: Result = Ctx.LongTy; break; |
| 49 | case DeclSpec::TSW_longlong: Result = Ctx.LongLongTy; break; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 50 | } |
| 51 | } else { |
| 52 | switch (DS.getTypeSpecWidth()) { |
Chris Lattner | 5328f31 | 2007-08-21 17:02:28 +0000 | [diff] [blame] | 53 | case DeclSpec::TSW_unspecified: Result = Ctx.UnsignedIntTy; break; |
| 54 | case DeclSpec::TSW_short: Result = Ctx.UnsignedShortTy; break; |
| 55 | case DeclSpec::TSW_long: Result = Ctx.UnsignedLongTy; break; |
| 56 | case DeclSpec::TSW_longlong: Result = Ctx.UnsignedLongLongTy; break; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 57 | } |
| 58 | } |
Chris Lattner | 5328f31 | 2007-08-21 17:02:28 +0000 | [diff] [blame] | 59 | // Handle complex integer types. |
| 60 | if (DS.getTypeSpecComplex() == DeclSpec::TSC_unspecified) |
| 61 | return Result; |
| 62 | assert(DS.getTypeSpecComplex() == DeclSpec::TSC_complex && |
| 63 | "FIXME: imaginary types not supported yet!"); |
| 64 | return Ctx.getComplexType(Result); |
| 65 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 66 | case DeclSpec::TST_float: |
| 67 | if (DS.getTypeSpecComplex() == DeclSpec::TSC_unspecified) |
| 68 | return Ctx.FloatTy; |
| 69 | assert(DS.getTypeSpecComplex() == DeclSpec::TSC_complex && |
| 70 | "FIXME: imaginary types not supported yet!"); |
Chris Lattner | 5328f31 | 2007-08-21 17:02:28 +0000 | [diff] [blame] | 71 | return Ctx.getComplexType(Ctx.FloatTy); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 72 | |
| 73 | case DeclSpec::TST_double: { |
| 74 | bool isLong = DS.getTypeSpecWidth() == DeclSpec::TSW_long; |
Chris Lattner | 5328f31 | 2007-08-21 17:02:28 +0000 | [diff] [blame] | 75 | QualType T = isLong ? Ctx.LongDoubleTy : Ctx.DoubleTy; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 76 | if (DS.getTypeSpecComplex() == DeclSpec::TSC_unspecified) |
Chris Lattner | 5328f31 | 2007-08-21 17:02:28 +0000 | [diff] [blame] | 77 | return T; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 78 | assert(DS.getTypeSpecComplex() == DeclSpec::TSC_complex && |
| 79 | "FIXME: imaginary types not supported yet!"); |
Chris Lattner | 5328f31 | 2007-08-21 17:02:28 +0000 | [diff] [blame] | 80 | return Ctx.getComplexType(T); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 81 | } |
| 82 | case DeclSpec::TST_bool: // _Bool or bool |
| 83 | return Ctx.BoolTy; |
| 84 | case DeclSpec::TST_decimal32: // _Decimal32 |
| 85 | case DeclSpec::TST_decimal64: // _Decimal64 |
| 86 | case DeclSpec::TST_decimal128: // _Decimal128 |
| 87 | assert(0 && "FIXME: GNU decimal extensions not supported yet!"); |
| 88 | case DeclSpec::TST_enum: |
| 89 | case DeclSpec::TST_union: |
| 90 | case DeclSpec::TST_struct: { |
| 91 | Decl *D = static_cast<Decl *>(DS.getTypeRep()); |
| 92 | assert(D && "Didn't get a decl for a enum/union/struct?"); |
| 93 | assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && |
| 94 | DS.getTypeSpecSign() == 0 && |
| 95 | "Can't handle qualifiers on typedef names yet!"); |
| 96 | // TypeQuals handled by caller. |
| 97 | return Ctx.getTagDeclType(cast<TagDecl>(D)); |
| 98 | } |
| 99 | case DeclSpec::TST_typedef: { |
| 100 | Decl *D = static_cast<Decl *>(DS.getTypeRep()); |
| 101 | assert(D && "Didn't get a decl for a typedef?"); |
| 102 | assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && |
| 103 | DS.getTypeSpecSign() == 0 && |
| 104 | "Can't handle qualifiers on typedef names yet!"); |
Steve Naroff | 81f1bba | 2007-09-06 21:24:23 +0000 | [diff] [blame] | 105 | // FIXME: Adding a TST_objcInterface clause doesn't seem ideal, so |
| 106 | // we have this "hack" for now... |
| 107 | if (isa<ObjcInterfaceDecl>(D)) |
| 108 | return Ctx.getObjcInterfaceType(cast<ObjcInterfaceDecl>(D)); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 109 | // TypeQuals handled by caller. |
| 110 | return Ctx.getTypedefType(cast<TypedefDecl>(D)); |
| 111 | } |
Steve Naroff | 7cbb146 | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 112 | case DeclSpec::TST_typeofType: { |
| 113 | QualType T = QualType::getFromOpaquePtr(DS.getTypeRep()); |
| 114 | assert(!T.isNull() && "Didn't get a type for typeof?"); |
| 115 | // TypeQuals handled by caller. |
| 116 | return Ctx.getTypeOfType(T); |
| 117 | } |
| 118 | case DeclSpec::TST_typeofExpr: { |
| 119 | Expr *E = static_cast<Expr *>(DS.getTypeRep()); |
| 120 | assert(E && "Didn't get an expression for typeof?"); |
| 121 | // TypeQuals handled by caller. |
Steve Naroff | 11b649c | 2007-08-01 17:20:42 +0000 | [diff] [blame] | 122 | return Ctx.getTypeOfExpr(E); |
Steve Naroff | 7cbb146 | 2007-07-31 12:34:36 +0000 | [diff] [blame] | 123 | } |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | /// GetTypeForDeclarator - Convert the type for the specified declarator to Type |
| 128 | /// instances. |
| 129 | QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) { |
Chris Lattner | 11f20f9 | 2007-08-28 16:40:32 +0000 | [diff] [blame] | 130 | // long long is a C99 feature. |
Chris Lattner | 1a7d991 | 2007-08-28 16:41:29 +0000 | [diff] [blame] | 131 | if (!getLangOptions().C99 && !getLangOptions().CPlusPlus0x && |
Chris Lattner | 11f20f9 | 2007-08-28 16:40:32 +0000 | [diff] [blame] | 132 | D.getDeclSpec().getTypeSpecWidth() == DeclSpec::TSW_longlong) |
| 133 | Diag(D.getDeclSpec().getTypeSpecWidthLoc(), diag::ext_longlong); |
| 134 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 135 | QualType T = ConvertDeclSpecToType(D.getDeclSpec(), Context); |
Steve Naroff | 91b03f7 | 2007-08-28 03:03:08 +0000 | [diff] [blame] | 136 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 137 | // Apply const/volatile/restrict qualifiers to T. |
| 138 | T = T.getQualifiedType(D.getDeclSpec().getTypeQualifiers()); |
| 139 | |
| 140 | // Walk the DeclTypeInfo, building the recursive type as we go. DeclTypeInfos |
| 141 | // are ordered from the identifier out, which is opposite of what we want :). |
| 142 | for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) { |
| 143 | const DeclaratorChunk &DeclType = D.getTypeObject(e-i-1); |
| 144 | switch (DeclType.Kind) { |
| 145 | default: assert(0 && "Unknown decltype!"); |
| 146 | case DeclaratorChunk::Pointer: |
Chris Lattner | 36be3d8 | 2007-07-31 21:33:24 +0000 | [diff] [blame] | 147 | if (T->isReferenceType()) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 148 | // C++ 8.3.2p4: There shall be no ... pointers to references ... |
| 149 | Diag(D.getIdentifierLoc(), diag::err_illegal_decl_pointer_to_reference, |
| 150 | D.getIdentifier()->getName()); |
Steve Naroff | 91b03f7 | 2007-08-28 03:03:08 +0000 | [diff] [blame] | 151 | D.setInvalidType(true); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 152 | T = Context.IntTy; |
| 153 | } |
| 154 | |
| 155 | // Apply the pointer typequals to the pointer object. |
| 156 | T = Context.getPointerType(T).getQualifiedType(DeclType.Ptr.TypeQuals); |
| 157 | break; |
| 158 | case DeclaratorChunk::Reference: |
Chris Lattner | f0c4a0a | 2007-07-31 16:56:34 +0000 | [diff] [blame] | 159 | if (const ReferenceType *RT = T->getAsReferenceType()) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 160 | // C++ 8.3.2p4: There shall be no references to references ... |
| 161 | Diag(D.getIdentifierLoc(), |
| 162 | diag::err_illegal_decl_reference_to_reference, |
| 163 | D.getIdentifier()->getName()); |
Steve Naroff | 91b03f7 | 2007-08-28 03:03:08 +0000 | [diff] [blame] | 164 | D.setInvalidType(true); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 165 | T = RT->getReferenceeType(); |
| 166 | } |
| 167 | |
| 168 | T = Context.getReferenceType(T); |
| 169 | break; |
| 170 | case DeclaratorChunk::Array: { |
| 171 | const DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr; |
Chris Lattner | 47958f6 | 2007-08-28 16:54:00 +0000 | [diff] [blame] | 172 | Expr *ArraySize = static_cast<Expr*>(ATI.NumElts); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 173 | ArrayType::ArraySizeModifier ASM; |
| 174 | if (ATI.isStar) |
| 175 | ASM = ArrayType::Star; |
| 176 | else if (ATI.hasStatic) |
| 177 | ASM = ArrayType::Static; |
| 178 | else |
| 179 | ASM = ArrayType::Normal; |
| 180 | |
| 181 | // C99 6.7.5.2p1: If the element type is an incomplete or function type, |
| 182 | // reject it (e.g. void ary[7], struct foo ary[7], void ary[7]()) |
| 183 | if (T->isIncompleteType()) { |
| 184 | Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_incomplete_type, |
| 185 | T.getAsString()); |
Steve Naroff | 91b03f7 | 2007-08-28 03:03:08 +0000 | [diff] [blame] | 186 | T = Context.IntTy; |
| 187 | D.setInvalidType(true); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 188 | } else if (T->isFunctionType()) { |
| 189 | Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_functions, |
| 190 | D.getIdentifier()->getName()); |
Steve Naroff | 91b03f7 | 2007-08-28 03:03:08 +0000 | [diff] [blame] | 191 | T = Context.getPointerType(T); |
| 192 | D.setInvalidType(true); |
Chris Lattner | f0c4a0a | 2007-07-31 16:56:34 +0000 | [diff] [blame] | 193 | } else if (const ReferenceType *RT = T->getAsReferenceType()) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 194 | // C++ 8.3.2p4: There shall be no ... arrays of references ... |
| 195 | Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_references, |
| 196 | D.getIdentifier()->getName()); |
Steve Naroff | 91b03f7 | 2007-08-28 03:03:08 +0000 | [diff] [blame] | 197 | T = RT->getReferenceeType(); |
| 198 | D.setInvalidType(true); |
Chris Lattner | 36be3d8 | 2007-07-31 21:33:24 +0000 | [diff] [blame] | 199 | } else if (const RecordType *EltTy = T->getAsRecordType()) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 200 | // If the element type is a struct or union that contains a variadic |
| 201 | // array, reject it: C99 6.7.2.1p2. |
| 202 | if (EltTy->getDecl()->hasFlexibleArrayMember()) { |
| 203 | Diag(DeclType.Loc, diag::err_flexible_array_in_array, |
| 204 | T.getAsString()); |
Steve Naroff | 91b03f7 | 2007-08-28 03:03:08 +0000 | [diff] [blame] | 205 | T = Context.IntTy; |
| 206 | D.setInvalidType(true); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 207 | } |
| 208 | } |
Steve Naroff | 63b6a64 | 2007-08-30 22:35:45 +0000 | [diff] [blame] | 209 | // C99 6.7.5.2p1: The size expression shall have integer type. |
| 210 | if (ArraySize && !ArraySize->getType()->isIntegerType()) { |
| 211 | Diag(ArraySize->getLocStart(), diag::err_array_size_non_int, |
| 212 | ArraySize->getType().getAsString(), ArraySize->getSourceRange()); |
| 213 | D.setInvalidType(true); |
| 214 | } |
Steve Naroff | 24c9b98 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 215 | llvm::APSInt ConstVal(32); |
| 216 | // If no expression was provided, we consider it a VLA. |
| 217 | if (!ArraySize || !ArraySize->isIntegerConstantExpr(ConstVal, Context)) |
| 218 | T = Context.getVariableArrayType(T, ArraySize, ASM, ATI.TypeQuals); |
Steve Naroff | 63b6a64 | 2007-08-30 22:35:45 +0000 | [diff] [blame] | 219 | else { |
| 220 | // C99 6.7.5.2p1: If the expression is a constant expression, it shall |
| 221 | // have a value greater than zero. |
| 222 | if (ConstVal.isSigned()) { |
| 223 | if (ConstVal.isNegative()) { |
| 224 | Diag(ArraySize->getLocStart(), |
| 225 | diag::err_typecheck_negative_array_size, |
| 226 | ArraySize->getSourceRange()); |
| 227 | D.setInvalidType(true); |
| 228 | } else if (ConstVal == 0) { |
| 229 | // GCC accepts zero sized static arrays. |
| 230 | Diag(ArraySize->getLocStart(), diag::ext_typecheck_zero_array_size, |
| 231 | ArraySize->getSourceRange()); |
| 232 | } |
| 233 | } |
Steve Naroff | 24c9b98 | 2007-08-30 18:10:14 +0000 | [diff] [blame] | 234 | T = Context.getConstantArrayType(T, ConstVal, ASM, ATI.TypeQuals); |
Steve Naroff | 63b6a64 | 2007-08-30 22:35:45 +0000 | [diff] [blame] | 235 | } |
Chris Lattner | 47958f6 | 2007-08-28 16:54:00 +0000 | [diff] [blame] | 236 | // If this is not C99, extwarn about VLA's and C99 array size modifiers. |
| 237 | if (!getLangOptions().C99 && |
| 238 | (ASM != ArrayType::Normal || |
| 239 | (ArraySize && !ArraySize->isIntegerConstantExpr(Context)))) |
| 240 | Diag(D.getIdentifierLoc(), diag::ext_vla); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 241 | break; |
| 242 | } |
| 243 | case DeclaratorChunk::Function: |
| 244 | // If the function declarator has a prototype (i.e. it is not () and |
| 245 | // does not have a K&R-style identifier list), then the arguments are part |
| 246 | // of the type, otherwise the argument list is (). |
| 247 | const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun; |
| 248 | if (!FTI.hasPrototype) { |
| 249 | // Simple void foo(), where the incoming T is the result type. |
| 250 | T = Context.getFunctionTypeNoProto(T); |
| 251 | |
| 252 | // C99 6.7.5.3p3: Reject int(x,y,z) when it's not a function definition. |
| 253 | if (FTI.NumArgs != 0) |
| 254 | Diag(FTI.ArgInfo[0].IdentLoc, diag::err_ident_list_in_fn_declaration); |
| 255 | |
| 256 | } else { |
| 257 | // Otherwise, we have a function with an argument list that is |
| 258 | // potentially variadic. |
| 259 | llvm::SmallVector<QualType, 16> ArgTys; |
| 260 | |
| 261 | for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) { |
| 262 | QualType ArgTy = QualType::getFromOpaquePtr(FTI.ArgInfo[i].TypeInfo); |
| 263 | assert(!ArgTy.isNull() && "Couldn't parse type?"); |
Steve Naroff | 1830be7 | 2007-09-10 22:17:00 +0000 | [diff] [blame^] | 264 | // |
| 265 | // Perform the default function/array conversion (C99 6.7.5.3p[7,8]). |
| 266 | // This matches the conversion that is done in |
| 267 | // Sema::ParseParamDeclarator(). Without this conversion, the |
| 268 | // argument type in the function prototype *will not* match the |
| 269 | // type in ParmVarDecl (which makes the code generator unhappy). |
| 270 | // |
| 271 | // FIXME: We still apparently need the conversion in |
| 272 | // Sema::ParseParamDeclarator(). This doesn't make any sense, since |
| 273 | // it should be driving off the type being created here. |
| 274 | // |
| 275 | // FIXME: If a source translation tool needs to see the original type, |
| 276 | // then we need to consider storing both types somewhere... |
| 277 | // |
| 278 | if (const ArrayType *AT = ArgTy->getAsArrayType()) |
| 279 | ArgTy = Context.getPointerType(AT->getElementType()); |
| 280 | else if (ArgTy->isFunctionType()) |
| 281 | ArgTy = Context.getPointerType(ArgTy); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 282 | // Look for 'void'. void is allowed only as a single argument to a |
| 283 | // function with no other parameters (C99 6.7.5.3p10). We record |
| 284 | // int(void) as a FunctionTypeProto with an empty argument list. |
Steve Naroff | 1830be7 | 2007-09-10 22:17:00 +0000 | [diff] [blame^] | 285 | else if (ArgTy->isVoidType()) { |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 286 | // If this is something like 'float(int, void)', reject it. 'void' |
| 287 | // is an incomplete type (C99 6.2.5p19) and function decls cannot |
| 288 | // have arguments of incomplete type. |
| 289 | if (FTI.NumArgs != 1 || FTI.isVariadic) { |
| 290 | Diag(DeclType.Loc, diag::err_void_only_param); |
| 291 | ArgTy = Context.IntTy; |
| 292 | FTI.ArgInfo[i].TypeInfo = ArgTy.getAsOpaquePtr(); |
| 293 | } else if (FTI.ArgInfo[i].Ident) { |
| 294 | // Reject, but continue to parse 'int(void abc)'. |
| 295 | Diag(FTI.ArgInfo[i].IdentLoc, |
| 296 | diag::err_param_with_void_type); |
| 297 | ArgTy = Context.IntTy; |
| 298 | FTI.ArgInfo[i].TypeInfo = ArgTy.getAsOpaquePtr(); |
| 299 | } else { |
| 300 | // Reject, but continue to parse 'float(const void)'. |
| 301 | if (ArgTy.getQualifiers()) |
| 302 | Diag(DeclType.Loc, diag::err_void_param_qualified); |
| 303 | |
| 304 | // Do not add 'void' to the ArgTys list. |
| 305 | break; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | ArgTys.push_back(ArgTy); |
| 310 | } |
| 311 | T = Context.getFunctionType(T, &ArgTys[0], ArgTys.size(), |
| 312 | FTI.isVariadic); |
| 313 | } |
| 314 | break; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | return T; |
| 319 | } |
| 320 | |
| 321 | Sema::TypeResult Sema::ParseTypeName(Scope *S, Declarator &D) { |
| 322 | // C99 6.7.6: Type names have no identifier. This is already validated by |
| 323 | // the parser. |
| 324 | assert(D.getIdentifier() == 0 && "Type name should have no identifier!"); |
| 325 | |
| 326 | QualType T = GetTypeForDeclarator(D, S); |
Steve Naroff | d1ad6ae | 2007-08-28 20:14:24 +0000 | [diff] [blame] | 327 | |
| 328 | assert(!T.isNull() && "GetTypeForDeclarator() returned null type"); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 329 | |
Steve Naroff | d1ad6ae | 2007-08-28 20:14:24 +0000 | [diff] [blame] | 330 | // In this context, we *do not* check D.getInvalidType(). If the declarator |
| 331 | // type was invalid, GetTypeForDeclarator() still returns a "valid" type, |
| 332 | // though it will not reflect the user specified type. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 333 | return T.getAsOpaquePtr(); |
| 334 | } |
| 335 | |
Steve Naroff | 91b03f7 | 2007-08-28 03:03:08 +0000 | [diff] [blame] | 336 | // Called from Parser::ParseParenDeclarator(). |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 337 | Sema::TypeResult Sema::ParseParamDeclaratorType(Scope *S, Declarator &D) { |
| 338 | // Note: parameters have identifiers, but we don't care about them here, we |
| 339 | // just want the type converted. |
| 340 | QualType T = GetTypeForDeclarator(D, S); |
| 341 | |
Steve Naroff | d1ad6ae | 2007-08-28 20:14:24 +0000 | [diff] [blame] | 342 | assert(!T.isNull() && "GetTypeForDeclarator() returned null type"); |
| 343 | |
| 344 | // In this context, we *do not* check D.getInvalidType(). If the declarator |
| 345 | // type was invalid, GetTypeForDeclarator() still returns a "valid" type, |
| 346 | // though it will not reflect the user specified type. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 347 | return T.getAsOpaquePtr(); |
| 348 | } |