[cfe-commits] r39188 - in /cfe/cfe/trunk: AST/Sema.h AST/SemaDecl.cpp Parse/DeclSpec.cpp Parse/MinimalAction.cpp Parse/ParseDecl.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/Parse/Action.h include/clang/Parse/DeclSpec.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:40:48 PDT 2007
Author: sabre
Date: Wed Jul 11 11:40:48 2007
New Revision: 39188
URL: http://llvm.org/viewvc/llvm-project?rev=39188&view=rev
Log:
when a typedef name is parsed as part of declspecs, remember the decl for the
typedef.
Modified:
cfe/cfe/trunk/AST/Sema.h
cfe/cfe/trunk/AST/SemaDecl.cpp
cfe/cfe/trunk/Parse/DeclSpec.cpp
cfe/cfe/trunk/Parse/MinimalAction.cpp
cfe/cfe/trunk/Parse/ParseDecl.cpp
cfe/cfe/trunk/Sema/Sema.h
cfe/cfe/trunk/Sema/SemaDecl.cpp
cfe/cfe/trunk/include/clang/Parse/Action.h
cfe/cfe/trunk/include/clang/Parse/DeclSpec.h
Modified: cfe/cfe/trunk/AST/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.h?rev=39188&r1=39187&r2=39188&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Sema.h (original)
+++ cfe/cfe/trunk/AST/Sema.h Wed Jul 11 11:40:48 2007
@@ -53,7 +53,7 @@
//===--------------------------------------------------------------------===//
// Symbol table / Decl tracking callbacks: SemaDecl.cpp.
//
- virtual bool isTypeName(const IdentifierInfo &II, Scope *S) const;
+ virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const;
virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
DeclTy *LastInGroup);
virtual DeclTy *ParseFunctionDefinition(Scope *S, Declarator &D,
Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39188&r1=39187&r2=39188&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:40:48 2007
@@ -21,9 +21,8 @@
using namespace clang;
-bool Sema::isTypeName(const IdentifierInfo &II, Scope *S) const {
- Decl *D = II.getFETokenInfo<Decl>();
- return D != 0 && isa<TypeDecl>(D);
+Sema::DeclTy *Sema::isTypeName(const IdentifierInfo &II, Scope *S) const {
+ return dyn_cast_or_null<TypeDecl>(II.getFETokenInfo<Decl>());
}
void Sema::PopScope(SourceLocation Loc, Scope *S) {
Modified: cfe/cfe/trunk/Parse/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/DeclSpec.cpp?rev=39188&r1=39187&r2=39188&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/DeclSpec.cpp (original)
+++ cfe/cfe/trunk/Parse/DeclSpec.cpp Wed Jul 11 11:40:48 2007
@@ -152,10 +152,11 @@
return false;
}
-bool DeclSpec::SetTypeSpecType(TST T, const char *&PrevSpec) {
+bool DeclSpec::SetTypeSpecType(TST T, const char *&PrevSpec, void *TypeRep) {
if (TypeSpecType != TST_unspecified)
return BadSpecifier(TypeSpecType, PrevSpec);
TypeSpecType = T;
+ TypenameRep = TypeRep;
return false;
}
Modified: cfe/cfe/trunk/Parse/MinimalAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/MinimalAction.cpp?rev=39188&r1=39187&r2=39188&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/MinimalAction.cpp (original)
+++ cfe/cfe/trunk/Parse/MinimalAction.cpp Wed Jul 11 11:40:48 2007
@@ -32,9 +32,12 @@
/// isTypeName - This looks at the IdentifierInfo::FETokenInfo field to
/// determine whether the name is a type name (objc class name or typedef) or
/// not in this scope.
-bool MinimalAction::isTypeName(const IdentifierInfo &II, Scope *S) const {
- TypeNameInfo *TI = II.getFETokenInfo<TypeNameInfo>();
- return TI != 0 && TI->isTypeName;
+Action::DeclTy *
+MinimalAction::isTypeName(const IdentifierInfo &II, Scope *S) const {
+ if (TypeNameInfo *TI = II.getFETokenInfo<TypeNameInfo>())
+ if (TI->isTypeName)
+ return TI;
+ return 0;
}
/// ParseDeclarator - If this is a typedef declarator, we modify the
Modified: cfe/cfe/trunk/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseDecl.cpp?rev=39188&r1=39187&r2=39188&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseDecl.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseDecl.cpp Wed Jul 11 11:40:48 2007
@@ -256,10 +256,13 @@
if (DS.TypeSpecType == DeclSpec::TST_unspecified &&
DS.TypeSpecWidth == DeclSpec::TSW_unspecified &&
DS.TypeSpecComplex == DeclSpec::TSC_unspecified &&
- DS.TypeSpecSign == DeclSpec::TSS_unspecified &&
- // It has to be available as a typedef too!
- Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) {
- isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typedef, PrevSpec);
+ DS.TypeSpecSign == DeclSpec::TSS_unspecified) {
+ // It has to be available as a typedef too!
+ if (void *TypeRep = Actions.isTypeName(*Tok.getIdentifierInfo(),
+ CurScope)) {
+ isInvalid = DS.SetTypeSpecType(DeclSpec::TST_typedef, PrevSpec,
+ TypeRep);
+ }
break;
}
// FALL THROUGH.
@@ -641,7 +644,7 @@
// typedef-name
case tok::identifier:
- return Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope);
+ return Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope) != 0;
// TODO: Attributes.
}
@@ -694,7 +697,7 @@
// typedef-name
case tok::identifier:
- return Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope);
+ return Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope) != 0;
// TODO: Attributes.
}
}
Modified: cfe/cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.h?rev=39188&r1=39187&r2=39188&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/Sema.h (original)
+++ cfe/cfe/trunk/Sema/Sema.h Wed Jul 11 11:40:48 2007
@@ -53,7 +53,7 @@
//===--------------------------------------------------------------------===//
// Symbol table / Decl tracking callbacks: SemaDecl.cpp.
//
- virtual bool isTypeName(const IdentifierInfo &II, Scope *S) const;
+ virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const;
virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
DeclTy *LastInGroup);
virtual DeclTy *ParseFunctionDefinition(Scope *S, Declarator &D,
Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39188&r1=39187&r2=39188&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:40:48 2007
@@ -21,9 +21,8 @@
using namespace clang;
-bool Sema::isTypeName(const IdentifierInfo &II, Scope *S) const {
- Decl *D = II.getFETokenInfo<Decl>();
- return D != 0 && isa<TypeDecl>(D);
+Sema::DeclTy *Sema::isTypeName(const IdentifierInfo &II, Scope *S) const {
+ return dyn_cast_or_null<TypeDecl>(II.getFETokenInfo<Decl>());
}
void Sema::PopScope(SourceLocation Loc, Scope *S) {
Modified: cfe/cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Action.h?rev=39188&r1=39187&r2=39188&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Action.h Wed Jul 11 11:40:48 2007
@@ -81,9 +81,9 @@
// Declaration Tracking Callbacks.
//===--------------------------------------------------------------------===//
- /// isTypeName - Return true if the specified identifier is a typedef name
+ /// isTypeName - Return non-null if the specified identifier is a typedef name
/// in the current scope.
- virtual bool isTypeName(const IdentifierInfo &II, Scope *S) const = 0;
+ virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const = 0;
/// ParseDeclarator - This callback is invoked when a declarator is parsed and
/// 'Init' specifies the initializer if any. This is for things like:
@@ -297,7 +297,7 @@
public:
/// isTypeName - This looks at the IdentifierInfo::FETokenInfo field to
/// determine whether the name is a typedef or not in this scope.
- virtual bool isTypeName(const IdentifierInfo &II, Scope *S) const;
+ virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const;
/// ParseDeclarator - If this is a typedef declarator, we modify the
/// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is
Modified: cfe/cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=39188&r1=39187&r2=39188&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/DeclSpec.h Wed Jul 11 11:40:48 2007
@@ -90,6 +90,11 @@
// function-specifier
bool FS_inline_specified : 1;
+
+ // TypenameRep - If TypeSpecType == TST_typedef, this contains the
+ // representation for the typedef.
+ void *TypenameRep;
+
// attributes.
// FIXME: implement declspec attributes.
@@ -110,7 +115,8 @@
TypeSpecSign(TSS_unspecified),
TypeSpecType(TST_unspecified),
TypeQualifiers(TSS_unspecified),
- FS_inline_specified(false) {
+ FS_inline_specified(false),
+ TypenameRep(0) {
}
/// getParsedSpecifiers - Return a bitmask of which flavors of specifiers this
@@ -125,7 +131,7 @@
bool SetTypeSpecWidth(TSW W, const char *&PrevSpec);
bool SetTypeSpecComplex(TSC C, const char *&PrevSpec);
bool SetTypeSpecSign(TSS S, const char *&PrevSpec);
- bool SetTypeSpecType(TST T, const char *&PrevSpec);
+ bool SetTypeSpecType(TST T, const char *&PrevSpec, void *TypenameRep = 0);
bool SetTypeQual(TQ T, const char *&PrevSpec, const LangOptions &Lang);
More information about the cfe-commits
mailing list