diff --git a/clang/AST/SemaType.cpp b/clang/AST/SemaType.cpp index bba3ef5cb456..7529ed628861 100644 --- a/clang/AST/SemaType.cpp +++ b/clang/AST/SemaType.cpp @@ -77,10 +77,10 @@ static TypeRef ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) { //case DeclSpec::TST_union: //case DeclSpec::TST_struct: case DeclSpec::TST_typedef: { - Decl *D = (Decl *)DS.TypenameRep; + Decl *D = (Decl *)DS.getTypenameRep(); assert(D && "Didn't get a decl for a typedef?"); - assert(DS.TypeSpecWidth == 0 && DS.TypeSpecComplex == 0 && - DS.TypeSpecSign == 0 && + assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && + DS.getTypeSpecSign() == 0 && "Can't handle qualifiers on typedef names yet!"); // TypeQuals handled by caller. return Ctx.getTypeDeclType(cast(D)); diff --git a/clang/Parse/DeclSpec.cpp b/clang/Parse/DeclSpec.cpp index 0fc8d70fec5a..6d965e56ec3d 100644 --- a/clang/Parse/DeclSpec.cpp +++ b/clang/Parse/DeclSpec.cpp @@ -28,10 +28,7 @@ unsigned DeclSpec::getParsedSpecifiers() const { if (TypeQualifiers != TQ_unspecified) Res |= PQ_TypeQualifier; - if (TypeSpecWidth != TSW_unspecified || - TypeSpecComplex != TSC_unspecified || - TypeSpecSign != TSS_unspecified || - TypeSpecType != TST_unspecified) + if (hasTypeSpecifier()) Res |= PQ_TypeSpecifier; if (FS_inline_specified) diff --git a/clang/Parse/MinimalAction.cpp b/clang/Parse/MinimalAction.cpp index 30eea7b3f6ca..bd0e30e20491 100644 --- a/clang/Parse/MinimalAction.cpp +++ b/clang/Parse/MinimalAction.cpp @@ -25,7 +25,7 @@ struct TypeNameInfo { TypeNameInfo(bool istypename, TypeNameInfo *prev) { isTypeName = istypename; - Prev = prev; + Prev = prev; } }; @@ -52,7 +52,8 @@ MinimalAction::ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init, if (II == 0) return 0; TypeNameInfo *weCurrentlyHaveTypeInfo = II->getFETokenInfo(); - bool isTypeName = D.getDeclSpec().StorageClassSpec == DeclSpec::SCS_typedef; + bool isTypeName = + D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef; // this check avoids creating TypeNameInfo objects for the common case. // It does need to handle the uncommon case of shadowing a typedef name with a diff --git a/clang/Parse/ParseDecl.cpp b/clang/Parse/ParseDecl.cpp index 0ce55ba5bf56..b5acb28745f4 100644 --- a/clang/Parse/ParseDecl.cpp +++ b/clang/Parse/ParseDecl.cpp @@ -253,10 +253,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS) { // This identifier can only be a typedef name if we haven't already seen // a type-specifier. Without this check we misparse: // typedef int X; struct Y { short X; }; as 'short int'. - if (DS.TypeSpecType == DeclSpec::TST_unspecified && - DS.TypeSpecWidth == DeclSpec::TSW_unspecified && - DS.TypeSpecComplex == DeclSpec::TSC_unspecified && - DS.TypeSpecSign == DeclSpec::TSS_unspecified) { + if (!DS.hasTypeSpecifier()) { // It has to be available as a typedef too! if (void *TypeRep = Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) { @@ -990,7 +987,7 @@ void Parser::ParseParenDeclarator(Declarator &D) { ParseAttributes(); // Verify C99 6.7.5.3p2: The only SCS allowed is 'register'. - switch (DS.StorageClassSpec) { + switch (DS.getStorageClassSpec()) { case DeclSpec::SCS_unspecified: case DeclSpec::SCS_register: break; diff --git a/clang/Sema/SemaType.cpp b/clang/Sema/SemaType.cpp index bba3ef5cb456..7529ed628861 100644 --- a/clang/Sema/SemaType.cpp +++ b/clang/Sema/SemaType.cpp @@ -77,10 +77,10 @@ static TypeRef ConvertDeclSpecToType(const DeclSpec &DS, ASTContext &Ctx) { //case DeclSpec::TST_union: //case DeclSpec::TST_struct: case DeclSpec::TST_typedef: { - Decl *D = (Decl *)DS.TypenameRep; + Decl *D = (Decl *)DS.getTypenameRep(); assert(D && "Didn't get a decl for a typedef?"); - assert(DS.TypeSpecWidth == 0 && DS.TypeSpecComplex == 0 && - DS.TypeSpecSign == 0 && + assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 && + DS.getTypeSpecSign() == 0 && "Can't handle qualifiers on typedef names yet!"); // TypeQuals handled by caller. return Ctx.getTypeDeclType(cast(D)); diff --git a/clang/include/clang/Parse/DeclSpec.h b/clang/include/clang/Parse/DeclSpec.h index 5fbcdda6f1f4..63b9052394f0 100644 --- a/clang/include/clang/Parse/DeclSpec.h +++ b/clang/include/clang/Parse/DeclSpec.h @@ -93,8 +93,6 @@ public: PQ_FunctionSpecifier = 8 }; - - // storage-class-specifier SCS StorageClassSpec : 3; bool SCS_thread_specified : 1; @@ -111,6 +109,7 @@ public: // function-specifier bool FS_inline_specified : 1; +private: // TypenameRep - If TypeSpecType == TST_typedef, this contains the // representation for the typedef. @@ -118,6 +117,7 @@ public: // attributes. // FIXME: implement declspec attributes. +public: DeclSpec() : StorageClassSpec(SCS_unspecified), @@ -131,6 +131,34 @@ public: TypenameRep(0) { } + // storage-class-specifier + SCS getStorageClassSpec() const { return StorageClassSpec; } + bool isThreadSpecified() const { return SCS_thread_specified; } + + // type-specifier + TSW getTypeSpecWidth() const { return TypeSpecWidth; } + TSC getTypeSpecComplex() const { return TypeSpecComplex; } + TSS getTypeSpecSign() const { return TypeSpecSign; } + TST getTypeSpecType() const { return TypeSpecType; } + void *getTypenameRep() const { return TypenameRep; } + + // type-qualifiers + + /// getTypeQualifiers - Return a set of TQs. + unsigned getTypeQualifiers() const { return TypeQualifiers; } + + // function-specifier + bool isInlineSpecified() const { return FS_inline_specified; } + + /// hasTypeSpecifier - Return true if any type-specifier has been found. + bool hasTypeSpecifier() const { + return getTypeSpecType() != DeclSpec::TST_unspecified || + getTypeSpecWidth() != DeclSpec::TSW_unspecified || + getTypeSpecComplex() != DeclSpec::TSC_unspecified || + getTypeSpecSign() != DeclSpec::TSS_unspecified; + } + + /// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this /// DeclSpec includes. ///