2007-07-11 21:01:13 +04:00
|
|
|
//===--- SemaType.cpp - Semantic Analysis for Types -----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 22:59:25 +03:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-07-11 21:01:13 +04:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements type-related semantic analysis.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Sema.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
2007-10-01 23:00:59 +04:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2008-08-11 08:54:23 +04:00
|
|
|
#include "clang/AST/Expr.h"
|
2008-08-11 07:45:03 +04:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
|
|
|
#include "clang/Parse/DeclSpec.h"
|
2007-07-11 21:01:13 +04:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
/// ConvertDeclSpecToType - Convert the specified declspec to the appropriate
|
|
|
|
/// type object. This returns null on error.
|
2008-06-26 10:27:57 +04:00
|
|
|
QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS) {
|
2007-07-11 21:01:13 +04:00
|
|
|
// FIXME: Should move the logic from DeclSpec::Finish to here for validity
|
|
|
|
// checking.
|
2008-02-21 00:40:32 +03:00
|
|
|
QualType Result;
|
2007-07-11 21:01:13 +04:00
|
|
|
|
|
|
|
switch (DS.getTypeSpecType()) {
|
2008-04-05 10:32:51 +04:00
|
|
|
default: assert(0 && "Unknown TypeSpecType!");
|
2008-04-02 10:50:17 +04:00
|
|
|
case DeclSpec::TST_void:
|
|
|
|
Result = Context.VoidTy;
|
|
|
|
break;
|
2007-07-11 21:01:13 +04:00
|
|
|
case DeclSpec::TST_char:
|
|
|
|
if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified)
|
2008-02-21 02:53:49 +03:00
|
|
|
Result = Context.CharTy;
|
2007-07-11 21:01:13 +04:00
|
|
|
else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed)
|
2008-02-21 02:53:49 +03:00
|
|
|
Result = Context.SignedCharTy;
|
2007-07-11 21:01:13 +04:00
|
|
|
else {
|
|
|
|
assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned &&
|
|
|
|
"Unknown TSS value");
|
2008-02-21 02:53:49 +03:00
|
|
|
Result = Context.UnsignedCharTy;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
2008-02-21 00:40:32 +03:00
|
|
|
break;
|
2008-08-09 20:51:54 +04:00
|
|
|
case DeclSpec::TST_wchar:
|
|
|
|
if (DS.getTypeSpecSign() == DeclSpec::TSS_unspecified)
|
|
|
|
Result = Context.WCharTy;
|
|
|
|
else if (DS.getTypeSpecSign() == DeclSpec::TSS_signed) {
|
2008-11-20 09:38:18 +03:00
|
|
|
Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec)
|
|
|
|
<< DS.getSpecifierName(DS.getTypeSpecType());
|
2008-08-09 20:51:54 +04:00
|
|
|
Result = Context.getSignedWCharType();
|
|
|
|
} else {
|
|
|
|
assert(DS.getTypeSpecSign() == DeclSpec::TSS_unsigned &&
|
|
|
|
"Unknown TSS value");
|
2008-11-20 09:38:18 +03:00
|
|
|
Diag(DS.getTypeSpecSignLoc(), diag::ext_invalid_sign_spec)
|
|
|
|
<< DS.getSpecifierName(DS.getTypeSpecType());
|
2008-08-09 20:51:54 +04:00
|
|
|
Result = Context.getUnsignedWCharType();
|
|
|
|
}
|
|
|
|
break;
|
2008-04-05 10:32:51 +04:00
|
|
|
case DeclSpec::TST_unspecified:
|
2008-07-26 04:46:50 +04:00
|
|
|
// "<proto1,proto2>" is an objc qualified ID with a missing id.
|
2008-10-20 06:01:50 +04:00
|
|
|
if (DeclSpec::ProtocolQualifierListTy PQ = DS.getProtocolQualifiers()) {
|
2008-07-26 05:53:50 +04:00
|
|
|
Result = Context.getObjCQualifiedIdType((ObjCProtocolDecl**)PQ,
|
2008-07-26 04:46:50 +04:00
|
|
|
DS.getNumProtocolQualifiers());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-04-05 10:32:51 +04:00
|
|
|
// Unspecified typespec defaults to int in C90. However, the C90 grammar
|
|
|
|
// [C90 6.5] only allows a decl-spec if there was *some* type-specifier,
|
|
|
|
// type-qualifier, or storage-class-specifier. If not, emit an extwarn.
|
|
|
|
// Note that the one exception to this is function definitions, which are
|
|
|
|
// allowed to be completely missing a declspec. This is handled in the
|
|
|
|
// parser already though by it pretending to have seen an 'int' in this
|
|
|
|
// case.
|
|
|
|
if (getLangOptions().ImplicitInt) {
|
|
|
|
if ((DS.getParsedSpecifiers() & (DeclSpec::PQ_StorageClassSpecifier |
|
|
|
|
DeclSpec::PQ_TypeSpecifier |
|
|
|
|
DeclSpec::PQ_TypeQualifier)) == 0)
|
|
|
|
Diag(DS.getSourceRange().getBegin(), diag::ext_missing_declspec);
|
|
|
|
} else {
|
|
|
|
// C99 and C++ require a type specifier. For example, C99 6.7.2p2 says:
|
|
|
|
// "At least one type specifier shall be given in the declaration
|
|
|
|
// specifiers in each declaration, and in the specifier-qualifier list in
|
|
|
|
// each struct declaration and type name."
|
|
|
|
if (!DS.hasTypeSpecifier())
|
|
|
|
Diag(DS.getSourceRange().getBegin(), diag::ext_missing_type_specifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FALL THROUGH.
|
2007-08-21 21:02:28 +04:00
|
|
|
case DeclSpec::TST_int: {
|
2007-07-11 21:01:13 +04:00
|
|
|
if (DS.getTypeSpecSign() != DeclSpec::TSS_unsigned) {
|
|
|
|
switch (DS.getTypeSpecWidth()) {
|
2008-02-21 02:53:49 +03:00
|
|
|
case DeclSpec::TSW_unspecified: Result = Context.IntTy; break;
|
|
|
|
case DeclSpec::TSW_short: Result = Context.ShortTy; break;
|
|
|
|
case DeclSpec::TSW_long: Result = Context.LongTy; break;
|
|
|
|
case DeclSpec::TSW_longlong: Result = Context.LongLongTy; break;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (DS.getTypeSpecWidth()) {
|
2008-02-21 02:53:49 +03:00
|
|
|
case DeclSpec::TSW_unspecified: Result = Context.UnsignedIntTy; break;
|
|
|
|
case DeclSpec::TSW_short: Result = Context.UnsignedShortTy; break;
|
|
|
|
case DeclSpec::TSW_long: Result = Context.UnsignedLongTy; break;
|
|
|
|
case DeclSpec::TSW_longlong: Result =Context.UnsignedLongLongTy; break;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
}
|
2008-02-21 00:40:32 +03:00
|
|
|
break;
|
2007-08-21 21:02:28 +04:00
|
|
|
}
|
2008-02-21 02:53:49 +03:00
|
|
|
case DeclSpec::TST_float: Result = Context.FloatTy; break;
|
2008-02-21 00:40:32 +03:00
|
|
|
case DeclSpec::TST_double:
|
|
|
|
if (DS.getTypeSpecWidth() == DeclSpec::TSW_long)
|
2008-02-21 02:53:49 +03:00
|
|
|
Result = Context.LongDoubleTy;
|
2008-02-21 00:40:32 +03:00
|
|
|
else
|
2008-02-21 02:53:49 +03:00
|
|
|
Result = Context.DoubleTy;
|
2008-02-21 00:40:32 +03:00
|
|
|
break;
|
2008-02-21 02:53:49 +03:00
|
|
|
case DeclSpec::TST_bool: Result = Context.BoolTy; break; // _Bool or bool
|
2007-07-11 21:01:13 +04:00
|
|
|
case DeclSpec::TST_decimal32: // _Decimal32
|
|
|
|
case DeclSpec::TST_decimal64: // _Decimal64
|
|
|
|
case DeclSpec::TST_decimal128: // _Decimal128
|
|
|
|
assert(0 && "FIXME: GNU decimal extensions not supported yet!");
|
2008-04-13 22:59:07 +04:00
|
|
|
case DeclSpec::TST_class:
|
2007-07-11 21:01:13 +04:00
|
|
|
case DeclSpec::TST_enum:
|
|
|
|
case DeclSpec::TST_union:
|
|
|
|
case DeclSpec::TST_struct: {
|
|
|
|
Decl *D = static_cast<Decl *>(DS.getTypeRep());
|
2008-04-13 22:59:07 +04:00
|
|
|
assert(D && "Didn't get a decl for a class/enum/union/struct?");
|
2007-07-11 21:01:13 +04:00
|
|
|
assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 &&
|
|
|
|
DS.getTypeSpecSign() == 0 &&
|
|
|
|
"Can't handle qualifiers on typedef names yet!");
|
|
|
|
// TypeQuals handled by caller.
|
2008-04-14 01:07:44 +04:00
|
|
|
Result = Context.getTypeDeclType(cast<TypeDecl>(D));
|
2008-02-21 00:40:32 +03:00
|
|
|
break;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
case DeclSpec::TST_typedef: {
|
|
|
|
Decl *D = static_cast<Decl *>(DS.getTypeRep());
|
|
|
|
assert(D && "Didn't get a decl for a typedef?");
|
|
|
|
assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 &&
|
|
|
|
DS.getTypeSpecSign() == 0 &&
|
|
|
|
"Can't handle qualifiers on typedef names yet!");
|
2008-07-26 05:53:50 +04:00
|
|
|
DeclSpec::ProtocolQualifierListTy PQ = DS.getProtocolQualifiers();
|
2008-04-14 01:07:44 +04:00
|
|
|
|
2007-09-07 01:24:23 +04:00
|
|
|
// FIXME: Adding a TST_objcInterface clause doesn't seem ideal, so
|
|
|
|
// we have this "hack" for now...
|
2008-01-07 22:49:32 +03:00
|
|
|
if (ObjCInterfaceDecl *ObjCIntDecl = dyn_cast<ObjCInterfaceDecl>(D)) {
|
2008-07-26 05:53:50 +04:00
|
|
|
if (PQ == 0) {
|
2008-02-21 02:53:49 +03:00
|
|
|
Result = Context.getObjCInterfaceType(ObjCIntDecl);
|
2008-02-21 00:40:32 +03:00
|
|
|
break;
|
|
|
|
}
|
2007-10-11 04:55:41 +04:00
|
|
|
|
2008-02-21 02:53:49 +03:00
|
|
|
Result = Context.getObjCQualifiedInterfaceType(ObjCIntDecl,
|
2008-07-26 05:53:50 +04:00
|
|
|
(ObjCProtocolDecl**)PQ,
|
2008-02-21 04:32:26 +03:00
|
|
|
DS.getNumProtocolQualifiers());
|
2008-02-21 00:40:32 +03:00
|
|
|
break;
|
2008-07-26 04:46:50 +04:00
|
|
|
} else if (TypedefDecl *typeDecl = dyn_cast<TypedefDecl>(D)) {
|
2008-07-26 05:53:50 +04:00
|
|
|
if (Context.getObjCIdType() == Context.getTypedefType(typeDecl) && PQ) {
|
|
|
|
// id<protocol-list>
|
|
|
|
Result = Context.getObjCQualifiedIdType((ObjCProtocolDecl**)PQ,
|
|
|
|
DS.getNumProtocolQualifiers());
|
2008-02-21 00:40:32 +03:00
|
|
|
break;
|
2007-12-18 00:03:50 +03:00
|
|
|
}
|
|
|
|
}
|
2007-07-11 21:01:13 +04:00
|
|
|
// TypeQuals handled by caller.
|
2008-04-14 01:07:44 +04:00
|
|
|
Result = Context.getTypeDeclType(dyn_cast<TypeDecl>(D));
|
2008-02-21 00:40:32 +03:00
|
|
|
break;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
2008-02-21 00:40:32 +03:00
|
|
|
case DeclSpec::TST_typeofType:
|
|
|
|
Result = QualType::getFromOpaquePtr(DS.getTypeRep());
|
|
|
|
assert(!Result.isNull() && "Didn't get a type for typeof?");
|
2007-07-31 16:34:36 +04:00
|
|
|
// TypeQuals handled by caller.
|
2008-02-21 02:53:49 +03:00
|
|
|
Result = Context.getTypeOfType(Result);
|
2008-02-21 00:40:32 +03:00
|
|
|
break;
|
2007-07-31 16:34:36 +04:00
|
|
|
case DeclSpec::TST_typeofExpr: {
|
|
|
|
Expr *E = static_cast<Expr *>(DS.getTypeRep());
|
|
|
|
assert(E && "Didn't get an expression for typeof?");
|
|
|
|
// TypeQuals handled by caller.
|
2008-02-21 02:53:49 +03:00
|
|
|
Result = Context.getTypeOfExpr(E);
|
2008-02-21 00:40:32 +03:00
|
|
|
break;
|
2007-07-31 16:34:36 +04:00
|
|
|
}
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
2008-02-21 00:40:32 +03:00
|
|
|
|
|
|
|
// Handle complex types.
|
|
|
|
if (DS.getTypeSpecComplex() == DeclSpec::TSC_complex)
|
2008-02-21 02:53:49 +03:00
|
|
|
Result = Context.getComplexType(Result);
|
2008-02-21 00:40:32 +03:00
|
|
|
|
|
|
|
assert(DS.getTypeSpecComplex() != DeclSpec::TSC_imaginary &&
|
|
|
|
"FIXME: imaginary types not supported yet!");
|
|
|
|
|
2008-02-21 01:04:11 +03:00
|
|
|
// See if there are any attributes on the declspec that apply to the type (as
|
|
|
|
// opposed to the decl).
|
2008-06-26 10:27:57 +04:00
|
|
|
if (const AttributeList *AL = DS.getAttributes())
|
2008-06-29 04:50:08 +04:00
|
|
|
ProcessTypeAttributeList(Result, AL);
|
2008-02-21 04:07:18 +03:00
|
|
|
|
2008-04-02 10:50:17 +04:00
|
|
|
// Apply const/volatile/restrict qualifiers to T.
|
|
|
|
if (unsigned TypeQuals = DS.getTypeQualifiers()) {
|
|
|
|
|
|
|
|
// Enforce C99 6.7.3p2: "Types other than pointer types derived from object
|
|
|
|
// or incomplete types shall not be restrict-qualified." C++ also allows
|
|
|
|
// restrict-qualified references.
|
|
|
|
if (TypeQuals & QualType::Restrict) {
|
2008-04-02 21:35:06 +04:00
|
|
|
if (const PointerLikeType *PT = Result->getAsPointerLikeType()) {
|
|
|
|
QualType EltTy = PT->getPointeeType();
|
|
|
|
|
|
|
|
// If we have a pointer or reference, the pointee must have an object or
|
|
|
|
// incomplete type.
|
|
|
|
if (!EltTy->isIncompleteOrObjectType()) {
|
|
|
|
Diag(DS.getRestrictSpecLoc(),
|
2008-11-20 09:06:08 +03:00
|
|
|
diag::err_typecheck_invalid_restrict_invalid_pointee)
|
2008-11-24 09:25:27 +03:00
|
|
|
<< EltTy << DS.getSourceRange();
|
2008-04-02 21:35:06 +04:00
|
|
|
TypeQuals &= ~QualType::Restrict; // Remove the restrict qualifier.
|
|
|
|
}
|
|
|
|
} else {
|
2008-04-02 10:50:17 +04:00
|
|
|
Diag(DS.getRestrictSpecLoc(),
|
2008-11-20 09:06:08 +03:00
|
|
|
diag::err_typecheck_invalid_restrict_not_pointer)
|
2008-11-24 09:25:27 +03:00
|
|
|
<< Result << DS.getSourceRange();
|
2008-04-02 21:35:06 +04:00
|
|
|
TypeQuals &= ~QualType::Restrict; // Remove the restrict qualifier.
|
2008-04-02 10:50:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Warn about CV qualifiers on functions: C99 6.7.3p8: "If the specification
|
|
|
|
// of a function type includes any type qualifiers, the behavior is
|
|
|
|
// undefined."
|
|
|
|
if (Result->isFunctionType() && TypeQuals) {
|
|
|
|
// Get some location to point at, either the C or V location.
|
|
|
|
SourceLocation Loc;
|
|
|
|
if (TypeQuals & QualType::Const)
|
|
|
|
Loc = DS.getConstSpecLoc();
|
|
|
|
else {
|
|
|
|
assert((TypeQuals & QualType::Volatile) &&
|
|
|
|
"Has CV quals but not C or V?");
|
|
|
|
Loc = DS.getVolatileSpecLoc();
|
|
|
|
}
|
2008-11-20 09:06:08 +03:00
|
|
|
Diag(Loc, diag::warn_typecheck_function_qualifiers)
|
2008-11-24 09:25:27 +03:00
|
|
|
<< Result << DS.getSourceRange();
|
2008-04-02 10:50:17 +04:00
|
|
|
}
|
|
|
|
|
2008-11-03 18:51:28 +03:00
|
|
|
// C++ [dcl.ref]p1:
|
|
|
|
// Cv-qualified references are ill-formed except when the
|
|
|
|
// cv-qualifiers are introduced through the use of a typedef
|
|
|
|
// (7.1.3) or of a template type argument (14.3), in which
|
|
|
|
// case the cv-qualifiers are ignored.
|
|
|
|
if (DS.getTypeSpecType() == DeclSpec::TST_typedef &&
|
|
|
|
TypeQuals && Result->isReferenceType()) {
|
|
|
|
TypeQuals &= ~QualType::Const;
|
|
|
|
TypeQuals &= ~QualType::Volatile;
|
|
|
|
}
|
|
|
|
|
2008-04-02 10:50:17 +04:00
|
|
|
Result = Result.getQualifiedType(TypeQuals);
|
|
|
|
}
|
2008-02-21 04:07:18 +03:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
/// GetTypeForDeclarator - Convert the type for the specified declarator to Type
|
2008-12-02 17:43:59 +03:00
|
|
|
/// instances. Skip the outermost Skip type objects.
|
|
|
|
QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S, unsigned Skip) {
|
2007-08-28 20:40:32 +04:00
|
|
|
// long long is a C99 feature.
|
2007-08-28 20:41:29 +04:00
|
|
|
if (!getLangOptions().C99 && !getLangOptions().CPlusPlus0x &&
|
2007-08-28 20:40:32 +04:00
|
|
|
D.getDeclSpec().getTypeSpecWidth() == DeclSpec::TSW_longlong)
|
|
|
|
Diag(D.getDeclSpec().getTypeSpecWidthLoc(), diag::ext_longlong);
|
|
|
|
|
2008-02-21 02:53:49 +03:00
|
|
|
QualType T = ConvertDeclSpecToType(D.getDeclSpec());
|
2008-11-21 22:14:01 +03:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
// Walk the DeclTypeInfo, building the recursive type as we go. DeclTypeInfos
|
|
|
|
// are ordered from the identifier out, which is opposite of what we want :).
|
2008-12-02 17:43:59 +03:00
|
|
|
for (unsigned i = Skip, e = D.getNumTypeObjects(); i != e; ++i) {
|
|
|
|
DeclaratorChunk &DeclType = D.getTypeObject(e-i-1+Skip);
|
2007-07-11 21:01:13 +04:00
|
|
|
switch (DeclType.Kind) {
|
|
|
|
default: assert(0 && "Unknown decltype!");
|
2008-08-27 20:04:49 +04:00
|
|
|
case DeclaratorChunk::BlockPointer:
|
|
|
|
if (DeclType.Cls.TypeQuals)
|
|
|
|
Diag(D.getIdentifierLoc(), diag::err_qualified_block_pointer_type);
|
|
|
|
if (!T.getTypePtr()->isFunctionType())
|
|
|
|
Diag(D.getIdentifierLoc(), diag::err_nonfunction_block_type);
|
|
|
|
else
|
|
|
|
T = Context.getBlockPointerType(T);
|
|
|
|
break;
|
2007-07-11 21:01:13 +04:00
|
|
|
case DeclaratorChunk::Pointer:
|
2007-08-01 01:33:24 +04:00
|
|
|
if (T->isReferenceType()) {
|
2007-07-11 21:01:13 +04:00
|
|
|
// C++ 8.3.2p4: There shall be no ... pointers to references ...
|
2008-11-20 09:06:08 +03:00
|
|
|
Diag(DeclType.Loc, diag::err_illegal_decl_pointer_to_reference)
|
|
|
|
<< (D.getIdentifier() ? D.getIdentifier()->getName() : "type name");
|
2007-08-28 07:03:08 +04:00
|
|
|
D.setInvalidType(true);
|
2007-07-19 04:42:40 +04:00
|
|
|
T = Context.IntTy;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
|
2008-04-02 10:50:17 +04:00
|
|
|
// Enforce C99 6.7.3p2: "Types other than pointer types derived from
|
|
|
|
// object or incomplete types shall not be restrict-qualified."
|
|
|
|
if ((DeclType.Ptr.TypeQuals & QualType::Restrict) &&
|
2008-04-02 10:59:01 +04:00
|
|
|
!T->isIncompleteOrObjectType()) {
|
2008-11-20 09:06:08 +03:00
|
|
|
Diag(DeclType.Loc, diag::err_typecheck_invalid_restrict_invalid_pointee)
|
2008-11-24 09:25:27 +03:00
|
|
|
<< T;
|
2008-04-02 10:50:17 +04:00
|
|
|
DeclType.Ptr.TypeQuals &= QualType::Restrict;
|
|
|
|
}
|
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
// Apply the pointer typequals to the pointer object.
|
|
|
|
T = Context.getPointerType(T).getQualifiedType(DeclType.Ptr.TypeQuals);
|
|
|
|
break;
|
2008-11-03 18:51:28 +03:00
|
|
|
case DeclaratorChunk::Reference: {
|
|
|
|
// Whether we should suppress the creation of the reference.
|
|
|
|
bool SuppressReference = false;
|
|
|
|
if (T->isReferenceType()) {
|
|
|
|
// C++ [dcl.ref]p4: There shall be no references to references.
|
|
|
|
//
|
|
|
|
// According to C++ DR 106, references to references are only
|
|
|
|
// diagnosed when they are written directly (e.g., "int & &"),
|
|
|
|
// but not when they happen via a typedef:
|
|
|
|
//
|
|
|
|
// typedef int& intref;
|
|
|
|
// typedef intref& intref2;
|
|
|
|
//
|
|
|
|
// Parser::ParserDeclaratorInternal diagnoses the case where
|
|
|
|
// references are written directly; here, we handle the
|
|
|
|
// collapsing of references-to-references as described in C++
|
|
|
|
// DR 106 and amended by C++ DR 540.
|
|
|
|
SuppressReference = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// C++ [dcl.ref]p1:
|
|
|
|
// A declarator that specifies the type “reference to cv void”
|
|
|
|
// is ill-formed.
|
|
|
|
if (T->isVoidType()) {
|
|
|
|
Diag(DeclType.Loc, diag::err_reference_to_void);
|
2007-08-28 07:03:08 +04:00
|
|
|
D.setInvalidType(true);
|
2008-11-03 18:51:28 +03:00
|
|
|
T = Context.IntTy;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
|
2008-04-02 10:50:17 +04:00
|
|
|
// Enforce C99 6.7.3p2: "Types other than pointer types derived from
|
|
|
|
// object or incomplete types shall not be restrict-qualified."
|
|
|
|
if (DeclType.Ref.HasRestrict &&
|
2008-04-02 10:59:01 +04:00
|
|
|
!T->isIncompleteOrObjectType()) {
|
2008-11-20 09:06:08 +03:00
|
|
|
Diag(DeclType.Loc, diag::err_typecheck_invalid_restrict_invalid_pointee)
|
2008-11-24 09:25:27 +03:00
|
|
|
<< T;
|
2008-04-02 10:50:17 +04:00
|
|
|
DeclType.Ref.HasRestrict = false;
|
|
|
|
}
|
|
|
|
|
2008-11-03 18:51:28 +03:00
|
|
|
if (!SuppressReference)
|
|
|
|
T = Context.getReferenceType(T);
|
2008-04-02 10:50:17 +04:00
|
|
|
|
|
|
|
// Handle restrict on references.
|
|
|
|
if (DeclType.Ref.HasRestrict)
|
|
|
|
T.addRestrict();
|
2007-07-11 21:01:13 +04:00
|
|
|
break;
|
2008-11-03 18:51:28 +03:00
|
|
|
}
|
2007-07-11 21:01:13 +04:00
|
|
|
case DeclaratorChunk::Array: {
|
2008-04-02 05:05:10 +04:00
|
|
|
DeclaratorChunk::ArrayTypeInfo &ATI = DeclType.Arr;
|
2007-08-28 20:54:00 +04:00
|
|
|
Expr *ArraySize = static_cast<Expr*>(ATI.NumElts);
|
2007-07-11 21:01:13 +04:00
|
|
|
ArrayType::ArraySizeModifier ASM;
|
|
|
|
if (ATI.isStar)
|
|
|
|
ASM = ArrayType::Star;
|
|
|
|
else if (ATI.hasStatic)
|
|
|
|
ASM = ArrayType::Static;
|
|
|
|
else
|
|
|
|
ASM = ArrayType::Normal;
|
2007-07-19 04:42:40 +04:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
// C99 6.7.5.2p1: If the element type is an incomplete or function type,
|
|
|
|
// reject it (e.g. void ary[7], struct foo ary[7], void ary[7]())
|
|
|
|
if (T->isIncompleteType()) {
|
2008-11-20 09:06:08 +03:00
|
|
|
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_incomplete_type)
|
2008-11-24 09:25:27 +03:00
|
|
|
<< T;
|
2007-08-28 07:03:08 +04:00
|
|
|
T = Context.IntTy;
|
|
|
|
D.setInvalidType(true);
|
2007-07-19 04:42:40 +04:00
|
|
|
} else if (T->isFunctionType()) {
|
2008-11-20 09:06:08 +03:00
|
|
|
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_functions)
|
|
|
|
<< (D.getIdentifier() ? D.getIdentifier()->getName() : "type name");
|
2007-08-28 07:03:08 +04:00
|
|
|
T = Context.getPointerType(T);
|
|
|
|
D.setInvalidType(true);
|
2007-07-31 20:56:34 +04:00
|
|
|
} else if (const ReferenceType *RT = T->getAsReferenceType()) {
|
2007-07-11 21:01:13 +04:00
|
|
|
// C++ 8.3.2p4: There shall be no ... arrays of references ...
|
2008-11-20 09:06:08 +03:00
|
|
|
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_references)
|
|
|
|
<< (D.getIdentifier() ? D.getIdentifier()->getName() : "type name");
|
2008-04-02 21:35:06 +04:00
|
|
|
T = RT->getPointeeType();
|
2007-08-28 07:03:08 +04:00
|
|
|
D.setInvalidType(true);
|
2007-08-01 01:33:24 +04:00
|
|
|
} else if (const RecordType *EltTy = T->getAsRecordType()) {
|
2007-07-11 21:01:13 +04:00
|
|
|
// If the element type is a struct or union that contains a variadic
|
|
|
|
// array, reject it: C99 6.7.2.1p2.
|
|
|
|
if (EltTy->getDecl()->hasFlexibleArrayMember()) {
|
2008-11-24 09:25:27 +03:00
|
|
|
Diag(DeclType.Loc, diag::err_flexible_array_in_array) << T;
|
2007-08-28 07:03:08 +04:00
|
|
|
T = Context.IntTy;
|
|
|
|
D.setInvalidType(true);
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
2008-08-19 02:49:54 +04:00
|
|
|
} else if (T->isObjCInterfaceType()) {
|
2008-11-24 09:25:27 +03:00
|
|
|
Diag(DeclType.Loc, diag::warn_objc_array_of_interfaces) << T;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
2008-08-19 02:49:54 +04:00
|
|
|
|
2007-08-31 02:35:45 +04:00
|
|
|
// C99 6.7.5.2p1: The size expression shall have integer type.
|
|
|
|
if (ArraySize && !ArraySize->getType()->isIntegerType()) {
|
2008-11-20 09:06:08 +03:00
|
|
|
Diag(ArraySize->getLocStart(), diag::err_array_size_non_int)
|
2008-11-24 09:25:27 +03:00
|
|
|
<< ArraySize->getType() << ArraySize->getSourceRange();
|
2007-08-31 02:35:45 +04:00
|
|
|
D.setInvalidType(true);
|
2008-04-02 05:05:10 +04:00
|
|
|
delete ArraySize;
|
|
|
|
ATI.NumElts = ArraySize = 0;
|
2007-08-31 02:35:45 +04:00
|
|
|
}
|
2007-08-30 22:10:14 +04:00
|
|
|
llvm::APSInt ConstVal(32);
|
2008-02-15 21:16:39 +03:00
|
|
|
if (!ArraySize) {
|
|
|
|
T = Context.getIncompleteArrayType(T, ASM, ATI.TypeQuals);
|
2008-12-06 02:32:09 +03:00
|
|
|
} else if (ArraySize->isValueDependent()) {
|
|
|
|
T = Context.getDependentSizedArrayType(T, ArraySize, ASM, ATI.TypeQuals);
|
2008-05-14 04:40:18 +04:00
|
|
|
} else if (!ArraySize->isIntegerConstantExpr(ConstVal, Context) ||
|
2008-12-02 17:43:59 +03:00
|
|
|
!T->isConstantSizeType()) {
|
2008-05-14 04:40:18 +04:00
|
|
|
// Per C99, a variable array is an array with either a non-constant
|
|
|
|
// size or an element type that has a non-constant-size
|
2007-08-30 22:10:14 +04:00
|
|
|
T = Context.getVariableArrayType(T, ArraySize, ASM, ATI.TypeQuals);
|
2008-02-15 21:16:39 +03:00
|
|
|
} else {
|
2007-08-31 02:35:45 +04:00
|
|
|
// C99 6.7.5.2p1: If the expression is a constant expression, it shall
|
|
|
|
// have a value greater than zero.
|
|
|
|
if (ConstVal.isSigned()) {
|
|
|
|
if (ConstVal.isNegative()) {
|
2008-11-19 08:27:50 +03:00
|
|
|
Diag(ArraySize->getLocStart(),
|
|
|
|
diag::err_typecheck_negative_array_size)
|
|
|
|
<< ArraySize->getSourceRange();
|
2007-08-31 02:35:45 +04:00
|
|
|
D.setInvalidType(true);
|
|
|
|
} else if (ConstVal == 0) {
|
|
|
|
// GCC accepts zero sized static arrays.
|
2008-11-19 08:27:50 +03:00
|
|
|
Diag(ArraySize->getLocStart(), diag::ext_typecheck_zero_array_size)
|
|
|
|
<< ArraySize->getSourceRange();
|
2007-08-31 02:35:45 +04:00
|
|
|
}
|
|
|
|
}
|
2007-08-30 22:10:14 +04:00
|
|
|
T = Context.getConstantArrayType(T, ConstVal, ASM, ATI.TypeQuals);
|
2007-08-31 02:35:45 +04:00
|
|
|
}
|
2007-08-28 20:54:00 +04:00
|
|
|
// If this is not C99, extwarn about VLA's and C99 array size modifiers.
|
2008-12-02 17:43:59 +03:00
|
|
|
if (!getLangOptions().C99 &&
|
2007-08-28 20:54:00 +04:00
|
|
|
(ASM != ArrayType::Normal ||
|
2008-12-06 02:32:09 +03:00
|
|
|
(ArraySize && !ArraySize->isValueDependent() &&
|
|
|
|
!ArraySize->isIntegerConstantExpr(Context))))
|
2007-08-28 20:54:00 +04:00
|
|
|
Diag(D.getIdentifierLoc(), diag::ext_vla);
|
2007-07-11 21:01:13 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DeclaratorChunk::Function:
|
|
|
|
// If the function declarator has a prototype (i.e. it is not () and
|
|
|
|
// does not have a K&R-style identifier list), then the arguments are part
|
|
|
|
// of the type, otherwise the argument list is ().
|
|
|
|
const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun;
|
2007-12-19 21:01:43 +03:00
|
|
|
|
2007-12-19 08:31:29 +03:00
|
|
|
// C99 6.7.5.3p1: The return type may not be a function or array type.
|
2007-12-19 21:01:43 +03:00
|
|
|
if (T->isArrayType() || T->isFunctionType()) {
|
2008-11-24 09:25:27 +03:00
|
|
|
Diag(DeclType.Loc, diag::err_func_returning_array_function) << T;
|
2007-12-19 08:31:29 +03:00
|
|
|
T = Context.IntTy;
|
|
|
|
D.setInvalidType(true);
|
|
|
|
}
|
|
|
|
|
2008-08-26 01:31:01 +04:00
|
|
|
if (FTI.NumArgs == 0) {
|
2008-10-16 21:31:08 +04:00
|
|
|
if (getLangOptions().CPlusPlus) {
|
|
|
|
// C++ 8.3.5p2: If the parameter-declaration-clause is empty, the
|
|
|
|
// function takes no arguments.
|
2008-10-25 01:46:40 +04:00
|
|
|
T = Context.getFunctionType(T, NULL, 0, FTI.isVariadic,FTI.TypeQuals);
|
2008-10-16 21:31:08 +04:00
|
|
|
} else {
|
|
|
|
// Simple void foo(), where the incoming T is the result type.
|
|
|
|
T = Context.getFunctionTypeNoProto(T);
|
|
|
|
}
|
2008-08-26 01:31:01 +04:00
|
|
|
} else if (FTI.ArgInfo[0].Param == 0) {
|
2007-07-11 21:01:13 +04:00
|
|
|
// C99 6.7.5.3p3: Reject int(x,y,z) when it's not a function definition.
|
2008-08-26 01:31:01 +04:00
|
|
|
Diag(FTI.ArgInfo[0].IdentLoc, diag::err_ident_list_in_fn_declaration);
|
2007-07-11 21:01:13 +04:00
|
|
|
} else {
|
|
|
|
// Otherwise, we have a function with an argument list that is
|
|
|
|
// potentially variadic.
|
|
|
|
llvm::SmallVector<QualType, 16> ArgTys;
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {
|
2008-04-10 06:22:51 +04:00
|
|
|
ParmVarDecl *Param = (ParmVarDecl *)FTI.ArgInfo[i].Param;
|
|
|
|
QualType ArgTy = Param->getType();
|
2007-07-21 09:30:18 +04:00
|
|
|
assert(!ArgTy.isNull() && "Couldn't parse type?");
|
2007-09-11 02:17:00 +04:00
|
|
|
//
|
|
|
|
// Perform the default function/array conversion (C99 6.7.5.3p[7,8]).
|
|
|
|
// This matches the conversion that is done in
|
2007-11-14 00:49:48 +03:00
|
|
|
// Sema::ActOnParamDeclarator(). Without this conversion, the
|
2007-09-11 02:17:00 +04:00
|
|
|
// argument type in the function prototype *will not* match the
|
|
|
|
// type in ParmVarDecl (which makes the code generator unhappy).
|
|
|
|
//
|
|
|
|
// FIXME: We still apparently need the conversion in
|
2008-04-02 09:18:44 +04:00
|
|
|
// Sema::ActOnParamDeclarator(). This doesn't make any sense, since
|
2007-09-11 02:17:00 +04:00
|
|
|
// it should be driving off the type being created here.
|
|
|
|
//
|
|
|
|
// FIXME: If a source translation tool needs to see the original type,
|
|
|
|
// then we need to consider storing both types somewhere...
|
|
|
|
//
|
2008-04-02 09:18:44 +04:00
|
|
|
if (ArgTy->isArrayType()) {
|
|
|
|
ArgTy = Context.getArrayDecayedType(ArgTy);
|
2008-01-03 01:50:48 +03:00
|
|
|
} else if (ArgTy->isFunctionType())
|
2007-09-11 02:17:00 +04:00
|
|
|
ArgTy = Context.getPointerType(ArgTy);
|
2008-04-02 09:18:44 +04:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
// Look for 'void'. void is allowed only as a single argument to a
|
|
|
|
// function with no other parameters (C99 6.7.5.3p10). We record
|
|
|
|
// int(void) as a FunctionTypeProto with an empty argument list.
|
2007-09-11 02:17:00 +04:00
|
|
|
else if (ArgTy->isVoidType()) {
|
2007-07-11 21:01:13 +04:00
|
|
|
// If this is something like 'float(int, void)', reject it. 'void'
|
|
|
|
// is an incomplete type (C99 6.2.5p19) and function decls cannot
|
|
|
|
// have arguments of incomplete type.
|
|
|
|
if (FTI.NumArgs != 1 || FTI.isVariadic) {
|
|
|
|
Diag(DeclType.Loc, diag::err_void_only_param);
|
2007-07-21 09:18:12 +04:00
|
|
|
ArgTy = Context.IntTy;
|
2008-04-10 06:22:51 +04:00
|
|
|
Param->setType(ArgTy);
|
2007-07-21 09:18:12 +04:00
|
|
|
} else if (FTI.ArgInfo[i].Ident) {
|
|
|
|
// Reject, but continue to parse 'int(void abc)'.
|
2007-07-11 21:01:13 +04:00
|
|
|
Diag(FTI.ArgInfo[i].IdentLoc,
|
2007-07-21 09:26:43 +04:00
|
|
|
diag::err_param_with_void_type);
|
2007-07-21 09:18:12 +04:00
|
|
|
ArgTy = Context.IntTy;
|
2008-04-10 06:22:51 +04:00
|
|
|
Param->setType(ArgTy);
|
2007-07-21 09:18:12 +04:00
|
|
|
} else {
|
|
|
|
// Reject, but continue to parse 'float(const void)'.
|
2008-02-20 23:55:12 +03:00
|
|
|
if (ArgTy.getCVRQualifiers())
|
2007-07-21 09:18:12 +04:00
|
|
|
Diag(DeclType.Loc, diag::err_void_param_qualified);
|
|
|
|
|
|
|
|
// Do not add 'void' to the ArgTys list.
|
|
|
|
break;
|
|
|
|
}
|
2008-08-26 01:31:01 +04:00
|
|
|
} else if (!FTI.hasPrototype) {
|
|
|
|
if (ArgTy->isPromotableIntegerType()) {
|
|
|
|
ArgTy = Context.IntTy;
|
|
|
|
} else if (const BuiltinType* BTy = ArgTy->getAsBuiltinType()) {
|
|
|
|
if (BTy->getKind() == BuiltinType::Float)
|
|
|
|
ArgTy = Context.DoubleTy;
|
|
|
|
}
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ArgTys.push_back(ArgTy);
|
|
|
|
}
|
|
|
|
T = Context.getFunctionType(T, &ArgTys[0], ArgTys.size(),
|
2008-10-25 01:46:40 +04:00
|
|
|
FTI.isVariadic, FTI.TypeQuals);
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-06-29 04:50:08 +04:00
|
|
|
|
|
|
|
// See if there are any attributes on this declarator chunk.
|
|
|
|
if (const AttributeList *AL = DeclType.getAttrs())
|
|
|
|
ProcessTypeAttributeList(T, AL);
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
2008-10-25 01:46:40 +04:00
|
|
|
|
|
|
|
if (getLangOptions().CPlusPlus && T->isFunctionType()) {
|
|
|
|
const FunctionTypeProto *FnTy = T->getAsFunctionTypeProto();
|
|
|
|
assert(FnTy && "Why oh why is there not a FunctionTypeProto here ?");
|
|
|
|
|
|
|
|
// C++ 8.3.5p4: A cv-qualifier-seq shall only be part of the function type
|
|
|
|
// for a nonstatic member function, the function type to which a pointer
|
|
|
|
// to member refers, or the top-level function type of a function typedef
|
|
|
|
// declaration.
|
|
|
|
if (FnTy->getTypeQuals() != 0 &&
|
|
|
|
D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef &&
|
2008-12-16 02:53:10 +03:00
|
|
|
((D.getContext() != Declarator::MemberContext &&
|
|
|
|
(!D.getCXXScopeSpec().isSet() ||
|
|
|
|
!static_cast<DeclContext*>(D.getCXXScopeSpec().getScopeRep())
|
|
|
|
->isCXXRecord())) ||
|
2008-10-25 01:46:40 +04:00
|
|
|
D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_static)) {
|
|
|
|
if (D.isFunctionDeclarator())
|
|
|
|
Diag(D.getIdentifierLoc(), diag::err_invalid_qualified_function_type);
|
|
|
|
else
|
|
|
|
Diag(D.getIdentifierLoc(),
|
|
|
|
diag::err_invalid_qualified_typedef_function_type_use);
|
|
|
|
|
|
|
|
// Strip the cv-quals from the type.
|
|
|
|
T = Context.getFunctionType(FnTy->getResultType(), FnTy->arg_type_begin(),
|
2008-10-26 19:43:14 +03:00
|
|
|
FnTy->getNumArgs(), FnTy->isVariadic(), 0);
|
2008-10-25 01:46:40 +04:00
|
|
|
}
|
|
|
|
}
|
2007-07-11 21:01:13 +04:00
|
|
|
|
2008-06-29 04:19:33 +04:00
|
|
|
// If there were any type attributes applied to the decl itself (not the
|
|
|
|
// type, apply the type attribute to the type!)
|
|
|
|
if (const AttributeList *Attrs = D.getAttributes())
|
2008-06-29 04:50:08 +04:00
|
|
|
ProcessTypeAttributeList(T, Attrs);
|
2008-06-29 04:19:33 +04:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
return T;
|
|
|
|
}
|
|
|
|
|
2008-01-07 22:49:32 +03:00
|
|
|
/// ObjCGetTypeForMethodDefinition - Builds the type for a method definition
|
2007-11-10 01:27:59 +03:00
|
|
|
/// declarator
|
2008-01-07 22:49:32 +03:00
|
|
|
QualType Sema::ObjCGetTypeForMethodDefinition(DeclTy *D) {
|
|
|
|
ObjCMethodDecl *MDecl = dyn_cast<ObjCMethodDecl>(static_cast<Decl *>(D));
|
2007-11-09 02:49:49 +03:00
|
|
|
QualType T = MDecl->getResultType();
|
|
|
|
llvm::SmallVector<QualType, 16> ArgTys;
|
|
|
|
|
2007-11-09 20:18:29 +03:00
|
|
|
// Add the first two invisible argument types for self and _cmd.
|
2007-11-09 22:52:12 +03:00
|
|
|
if (MDecl->isInstance()) {
|
2008-01-07 22:49:32 +03:00
|
|
|
QualType selfTy = Context.getObjCInterfaceType(MDecl->getClassInterface());
|
2007-11-09 22:52:12 +03:00
|
|
|
selfTy = Context.getPointerType(selfTy);
|
|
|
|
ArgTys.push_back(selfTy);
|
|
|
|
}
|
2007-11-09 20:18:29 +03:00
|
|
|
else
|
2008-01-07 22:49:32 +03:00
|
|
|
ArgTys.push_back(Context.getObjCIdType());
|
|
|
|
ArgTys.push_back(Context.getObjCSelType());
|
2007-11-09 20:18:29 +03:00
|
|
|
|
2008-03-16 04:07:14 +03:00
|
|
|
for (int i = 0, e = MDecl->getNumParams(); i != e; ++i) {
|
2007-11-09 02:49:49 +03:00
|
|
|
ParmVarDecl *PDecl = MDecl->getParamDecl(i);
|
|
|
|
QualType ArgTy = PDecl->getType();
|
|
|
|
assert(!ArgTy.isNull() && "Couldn't parse type?");
|
|
|
|
// Perform the default function/array conversion (C99 6.7.5.3p[7,8]).
|
|
|
|
// This matches the conversion that is done in
|
2008-04-02 09:18:44 +04:00
|
|
|
// Sema::ActOnParamDeclarator().
|
|
|
|
if (ArgTy->isArrayType())
|
|
|
|
ArgTy = Context.getArrayDecayedType(ArgTy);
|
2007-11-09 02:49:49 +03:00
|
|
|
else if (ArgTy->isFunctionType())
|
|
|
|
ArgTy = Context.getPointerType(ArgTy);
|
|
|
|
ArgTys.push_back(ArgTy);
|
|
|
|
}
|
|
|
|
T = Context.getFunctionType(T, &ArgTys[0], ArgTys.size(),
|
2008-10-26 19:43:14 +03:00
|
|
|
MDecl->isVariadic(), 0);
|
2007-11-09 02:49:49 +03:00
|
|
|
return T;
|
|
|
|
}
|
|
|
|
|
2008-10-22 18:17:15 +04:00
|
|
|
/// UnwrapSimilarPointerTypes - If T1 and T2 are pointer types (FIXME:
|
|
|
|
/// or pointer-to-member types) that may be similar (C++ 4.4),
|
|
|
|
/// replaces T1 and T2 with the type that they point to and return
|
|
|
|
/// true. If T1 and T2 aren't pointer types or pointer-to-member
|
|
|
|
/// types, or if they are not similar at this level, returns false and
|
|
|
|
/// leaves T1 and T2 unchanged. Top-level qualifiers on T1 and T2 are
|
2008-10-24 19:36:09 +04:00
|
|
|
/// ignored. This function will typically be called in a loop that
|
2008-10-22 18:17:15 +04:00
|
|
|
/// successively "unwraps" pointer and pointer-to-member types to
|
|
|
|
/// compare them at each level.
|
|
|
|
bool Sema::UnwrapSimilarPointerTypes(QualType& T1, QualType& T2)
|
|
|
|
{
|
|
|
|
const PointerType *T1PtrType = T1->getAsPointerType(),
|
|
|
|
*T2PtrType = T2->getAsPointerType();
|
|
|
|
if (T1PtrType && T2PtrType) {
|
|
|
|
T1 = T1PtrType->getPointeeType();
|
|
|
|
T2 = T2PtrType->getPointeeType();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: pointer-to-member types
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-02 17:43:59 +03:00
|
|
|
Sema::TypeResult Sema::ActOnTypeName(Scope *S, Declarator &D) {
|
2007-07-11 21:01:13 +04:00
|
|
|
// C99 6.7.6: Type names have no identifier. This is already validated by
|
|
|
|
// the parser.
|
|
|
|
assert(D.getIdentifier() == 0 && "Type name should have no identifier!");
|
|
|
|
|
2008-12-02 17:43:59 +03:00
|
|
|
QualType T = GetTypeForDeclarator(D, S);
|
2007-08-29 00:14:24 +04:00
|
|
|
|
|
|
|
assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
|
2007-07-11 21:01:13 +04:00
|
|
|
|
2008-05-07 08:49:29 +04:00
|
|
|
// Check that there are no default arguments (C++ only).
|
|
|
|
if (getLangOptions().CPlusPlus)
|
|
|
|
CheckExtraCXXDefaultArguments(D);
|
|
|
|
|
2007-08-29 00:14:24 +04:00
|
|
|
// In this context, we *do not* check D.getInvalidType(). If the declarator
|
|
|
|
// type was invalid, GetTypeForDeclarator() still returns a "valid" type,
|
|
|
|
// though it will not reflect the user specified type.
|
2007-07-11 21:01:13 +04:00
|
|
|
return T.getAsOpaquePtr();
|
|
|
|
}
|
|
|
|
|
2008-06-29 04:50:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Type Attribute Processing
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-02-21 04:08:11 +03:00
|
|
|
|
|
|
|
/// HandleAddressSpaceTypeAttribute - Process an address_space attribute on the
|
2008-06-29 04:50:08 +04:00
|
|
|
/// specified type. The attribute contains 1 argument, the id of the address
|
|
|
|
/// space for the type.
|
|
|
|
static void HandleAddressSpaceTypeAttribute(QualType &Type,
|
|
|
|
const AttributeList &Attr, Sema &S){
|
2008-02-21 04:08:11 +03:00
|
|
|
// If this type is already address space qualified, reject it.
|
|
|
|
// Clause 6.7.3 - Type qualifiers: "No type shall be qualified by qualifiers
|
|
|
|
// for two or more different address spaces."
|
|
|
|
if (Type.getAddressSpace()) {
|
2008-06-29 04:50:08 +04:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_address_multiple_qualifiers);
|
|
|
|
return;
|
2008-02-21 04:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check the attribute arguments.
|
2008-06-29 03:36:30 +04:00
|
|
|
if (Attr.getNumArgs() != 1) {
|
2008-11-20 09:38:18 +03:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
|
2008-06-29 04:50:08 +04:00
|
|
|
return;
|
2008-02-21 04:08:11 +03:00
|
|
|
}
|
2008-06-29 03:36:30 +04:00
|
|
|
Expr *ASArgExpr = static_cast<Expr *>(Attr.getArg(0));
|
2008-02-21 04:08:11 +03:00
|
|
|
llvm::APSInt addrSpace(32);
|
2008-06-29 04:50:08 +04:00
|
|
|
if (!ASArgExpr->isIntegerConstantExpr(addrSpace, S.Context)) {
|
2008-11-19 08:27:50 +03:00
|
|
|
S.Diag(Attr.getLoc(), diag::err_attribute_address_space_not_int)
|
|
|
|
<< ASArgExpr->getSourceRange();
|
2008-06-29 04:50:08 +04:00
|
|
|
return;
|
2008-02-21 04:08:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ASIdx = static_cast<unsigned>(addrSpace.getZExtValue());
|
2008-06-29 04:50:08 +04:00
|
|
|
Type = S.Context.getASQualType(Type, ASIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::ProcessTypeAttributeList(QualType &Result, const AttributeList *AL) {
|
|
|
|
// Scan through and apply attributes to this type where it makes sense. Some
|
|
|
|
// attributes (such as __address_space__, __vector_size__, etc) apply to the
|
|
|
|
// type, but others can be present in the type specifiers even though they
|
|
|
|
// apply to the decl. Here we apply type attributes and ignore the rest.
|
|
|
|
for (; AL; AL = AL->getNext()) {
|
|
|
|
// If this is an attribute we can handle, do so now, otherwise, add it to
|
|
|
|
// the LeftOverAttrs list for rechaining.
|
|
|
|
switch (AL->getKind()) {
|
|
|
|
default: break;
|
|
|
|
case AttributeList::AT_address_space:
|
|
|
|
HandleAddressSpaceTypeAttribute(Result, *AL, *this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-02-21 04:08:11 +03:00
|
|
|
}
|
|
|
|
|
2008-05-27 07:33:27 +04:00
|
|
|
|