2006-11-06 02:44:26 +08:00
|
|
|
//===--- MinimalAction.cpp - Implement the MinimalAction class ------------===//
|
2006-08-14 08:38:06 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-08-14 08:38:06 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-11-06 02:44:26 +08:00
|
|
|
// This file implements the MinimalAction interface.
|
2006-08-14 08:38:06 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Parse/Parser.h"
|
2006-11-12 07:03:42 +08:00
|
|
|
#include "clang/Parse/DeclSpec.h"
|
2006-08-14 09:28:29 +08:00
|
|
|
#include "clang/Parse/Scope.h"
|
2006-08-14 08:38:06 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2006-10-28 07:18:49 +08:00
|
|
|
/// TypeNameInfo - A link exists here for each scope that an identifier is
|
2006-08-14 09:28:29 +08:00
|
|
|
/// defined.
|
2006-10-28 07:18:49 +08:00
|
|
|
struct TypeNameInfo {
|
|
|
|
TypeNameInfo *Prev;
|
|
|
|
bool isTypeName;
|
|
|
|
|
|
|
|
TypeNameInfo(bool istypename, TypeNameInfo *prev) {
|
|
|
|
isTypeName = istypename;
|
2006-11-28 12:28:12 +08:00
|
|
|
Prev = prev;
|
2006-10-28 07:18:49 +08:00
|
|
|
}
|
2006-08-14 09:28:29 +08:00
|
|
|
};
|
|
|
|
|
2008-10-31 16:56:51 +08:00
|
|
|
MinimalAction::MinimalAction(Preprocessor &pp)
|
|
|
|
: Idents(pp.getIdentifierTable()), PP(pp) {}
|
|
|
|
|
|
|
|
void MinimalAction::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
|
2007-11-01 02:42:27 +08:00
|
|
|
TUScope = S;
|
2008-10-31 16:56:51 +08:00
|
|
|
if (!PP.getLangOptions().ObjC1) return;
|
|
|
|
|
|
|
|
// recognize the ObjC built-in type identifiers.
|
2007-11-01 04:55:39 +08:00
|
|
|
IdentifierInfo *II;
|
|
|
|
TypeNameInfo *TI;
|
|
|
|
II = &Idents.get("id");
|
|
|
|
TI = new TypeNameInfo(1, II->getFETokenInfo<TypeNameInfo>());
|
|
|
|
II->setFETokenInfo(TI);
|
|
|
|
II = &Idents.get("SEL");
|
|
|
|
TI = new TypeNameInfo(1, II->getFETokenInfo<TypeNameInfo>());
|
|
|
|
II->setFETokenInfo(TI);
|
|
|
|
II = &Idents.get("Class");
|
|
|
|
TI = new TypeNameInfo(1, II->getFETokenInfo<TypeNameInfo>());
|
|
|
|
II->setFETokenInfo(TI);
|
2007-12-07 08:18:54 +08:00
|
|
|
II = &Idents.get("Protocol");
|
|
|
|
TI = new TypeNameInfo(1, II->getFETokenInfo<TypeNameInfo>());
|
|
|
|
II->setFETokenInfo(TI);
|
2007-11-01 02:42:27 +08:00
|
|
|
}
|
|
|
|
|
2006-11-03 15:35:12 +08:00
|
|
|
/// 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.
|
2008-11-09 00:45:02 +08:00
|
|
|
///
|
|
|
|
/// FIXME: Use the passed CXXScopeSpec for accurate C++ type checking.
|
2008-08-01 18:35:27 +08:00
|
|
|
Action::TypeTy *
|
2008-11-18 04:34:05 +08:00
|
|
|
MinimalAction::isTypeName(IdentifierInfo &II, Scope *S,
|
2008-11-09 00:45:02 +08:00
|
|
|
const CXXScopeSpec *SS) {
|
2006-11-20 09:29:42 +08:00
|
|
|
if (TypeNameInfo *TI = II.getFETokenInfo<TypeNameInfo>())
|
|
|
|
if (TI->isTypeName)
|
|
|
|
return TI;
|
|
|
|
return 0;
|
2006-08-14 08:38:06 +08:00
|
|
|
}
|
|
|
|
|
2008-10-31 17:07:45 +08:00
|
|
|
/// isCurrentClassName - Always returns false, because MinimalAction
|
|
|
|
/// does not support C++ classes with constructors.
|
2008-11-09 00:45:02 +08:00
|
|
|
bool MinimalAction::isCurrentClassName(const IdentifierInfo &, Scope *,
|
|
|
|
const CXXScopeSpec *) {
|
2008-10-31 17:07:45 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-09-16 02:49:24 +08:00
|
|
|
/// ActOnDeclarator - If this is a typedef declarator, we modify the
|
2006-08-14 08:38:06 +08:00
|
|
|
/// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is
|
|
|
|
/// popped.
|
2006-10-16 08:33:54 +08:00
|
|
|
Action::DeclTy *
|
2008-08-06 00:28:08 +08:00
|
|
|
MinimalAction::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup) {
|
2006-10-28 07:18:49 +08:00
|
|
|
IdentifierInfo *II = D.getIdentifier();
|
|
|
|
|
2006-08-14 09:28:29 +08:00
|
|
|
// If there is no identifier associated with this declarator, bail out.
|
2006-10-28 07:18:49 +08:00
|
|
|
if (II == 0) return 0;
|
2006-08-14 09:28:29 +08:00
|
|
|
|
2006-10-28 07:18:49 +08:00
|
|
|
TypeNameInfo *weCurrentlyHaveTypeInfo = II->getFETokenInfo<TypeNameInfo>();
|
2006-11-28 12:28:12 +08:00
|
|
|
bool isTypeName =
|
|
|
|
D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef;
|
2006-08-14 09:28:29 +08:00
|
|
|
|
2006-10-28 07:18:49 +08:00
|
|
|
// this check avoids creating TypeNameInfo objects for the common case.
|
2008-08-05 06:51:42 +08:00
|
|
|
// It does need to handle the uncommon case of shadowing a typedef name with a
|
2006-10-28 07:18:49 +08:00
|
|
|
// non-typedef name. e.g. { typedef int a; a xx; { int a; } }
|
|
|
|
if (weCurrentlyHaveTypeInfo || isTypeName) {
|
|
|
|
TypeNameInfo *TI = new TypeNameInfo(isTypeName, weCurrentlyHaveTypeInfo);
|
|
|
|
|
|
|
|
II->setFETokenInfo(TI);
|
2006-08-14 09:28:29 +08:00
|
|
|
|
2006-10-28 07:18:49 +08:00
|
|
|
// Remember that this needs to be removed when the scope is popped.
|
|
|
|
S->AddDecl(II);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-07 05:24:23 +08:00
|
|
|
Action::DeclTy *
|
2008-07-21 15:13:18 +08:00
|
|
|
MinimalAction::ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
|
2008-07-26 12:13:19 +08:00
|
|
|
IdentifierInfo *ClassName,
|
|
|
|
SourceLocation ClassLoc,
|
|
|
|
IdentifierInfo *SuperName,
|
|
|
|
SourceLocation SuperLoc,
|
|
|
|
DeclTy * const *ProtoRefs,
|
|
|
|
unsigned NumProtocols,
|
|
|
|
SourceLocation EndProtoLoc,
|
|
|
|
AttributeList *AttrList) {
|
2007-09-07 05:24:23 +08:00
|
|
|
TypeNameInfo *TI =
|
|
|
|
new TypeNameInfo(1, ClassName->getFETokenInfo<TypeNameInfo>());
|
|
|
|
|
|
|
|
ClassName->setFETokenInfo(TI);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-10-03 06:39:18 +08:00
|
|
|
/// ActOnForwardClassDeclaration -
|
2006-11-03 15:35:12 +08:00
|
|
|
/// Scope will always be top level file scope.
|
2006-10-28 07:18:49 +08:00
|
|
|
Action::DeclTy *
|
2007-10-11 01:32:04 +08:00
|
|
|
MinimalAction::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
|
2007-09-07 05:24:23 +08:00
|
|
|
IdentifierInfo **IdentList, unsigned NumElts) {
|
2006-11-03 15:35:12 +08:00
|
|
|
for (unsigned i = 0; i != NumElts; ++i) {
|
|
|
|
TypeNameInfo *TI =
|
|
|
|
new TypeNameInfo(1, IdentList[i]->getFETokenInfo<TypeNameInfo>());
|
2006-10-28 07:18:49 +08:00
|
|
|
|
2006-11-03 15:35:12 +08:00
|
|
|
IdentList[i]->setFETokenInfo(TI);
|
2006-10-28 07:18:49 +08:00
|
|
|
|
|
|
|
// Remember that this needs to be removed when the scope is popped.
|
2007-10-11 01:32:04 +08:00
|
|
|
TUScope->AddDecl(IdentList[i]);
|
2006-10-28 07:18:49 +08:00
|
|
|
}
|
2006-10-16 08:33:54 +08:00
|
|
|
return 0;
|
2006-08-14 08:38:06 +08:00
|
|
|
}
|
|
|
|
|
2008-08-05 06:51:42 +08:00
|
|
|
/// ActOnPopScope - When a scope is popped, if any typedefs are now
|
|
|
|
/// out-of-scope, they are removed from the IdentifierInfo::FETokenInfo field.
|
2007-10-11 01:45:44 +08:00
|
|
|
void MinimalAction::ActOnPopScope(SourceLocation Loc, Scope *S) {
|
2006-08-14 09:28:29 +08:00
|
|
|
for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
IdentifierInfo &II = *static_cast<IdentifierInfo*>(*I);
|
2006-10-28 07:18:49 +08:00
|
|
|
TypeNameInfo *TI = II.getFETokenInfo<TypeNameInfo>();
|
2006-08-14 09:28:29 +08:00
|
|
|
assert(TI && "This decl didn't get pushed??");
|
|
|
|
|
2006-11-06 02:44:26 +08:00
|
|
|
if (TI) {
|
2006-10-28 07:18:49 +08:00
|
|
|
TypeNameInfo *Next = TI->Prev;
|
|
|
|
delete TI;
|
2006-11-06 02:44:26 +08:00
|
|
|
|
2006-10-28 07:18:49 +08:00
|
|
|
II.setFETokenInfo(Next);
|
2006-11-06 02:44:26 +08:00
|
|
|
}
|
2006-08-14 09:28:29 +08:00
|
|
|
}
|
2006-08-14 08:38:06 +08:00
|
|
|
}
|