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
|
|
|
|
//
|
|
|
|
// This file was developed by Chris Lattner and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
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 llvm;
|
|
|
|
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;
|
|
|
|
Prev = prev;
|
|
|
|
}
|
2006-08-14 09:28:29 +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.
|
2006-11-20 09:29:42 +08:00
|
|
|
Action::DeclTy *
|
|
|
|
MinimalAction::isTypeName(const IdentifierInfo &II, Scope *S) const {
|
|
|
|
if (TypeNameInfo *TI = II.getFETokenInfo<TypeNameInfo>())
|
|
|
|
if (TI->isTypeName)
|
|
|
|
return TI;
|
|
|
|
return 0;
|
2006-08-14 08:38:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ParseDeclarator - If this is a typedef declarator, we modify the
|
|
|
|
/// IdentifierInfo::FETokenInfo field to keep track of this fact, until S is
|
|
|
|
/// popped.
|
2006-10-16 08:33:54 +08:00
|
|
|
Action::DeclTy *
|
2006-11-06 02:44:26 +08:00
|
|
|
MinimalAction::ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
|
|
|
|
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>();
|
|
|
|
bool isTypeName = D.getDeclSpec().StorageClassSpec == 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.
|
|
|
|
// It does need to handle the uncommon case of shadowing a typedef name with a
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2006-11-19 10:35:21 +08:00
|
|
|
/// ParsedObjcClassDeclaration -
|
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 *
|
2006-11-19 10:35:21 +08:00
|
|
|
MinimalAction::ParsedObjcClassDeclaration(Scope *S,
|
|
|
|
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.
|
2006-11-03 15:35:12 +08:00
|
|
|
S->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
|
|
|
}
|
|
|
|
|
|
|
|
/// PopScope - When a scope is popped, if any typedefs are now out-of-scope,
|
|
|
|
/// they are removed from the IdentifierInfo::FETokenInfo field.
|
2006-11-06 02:44:26 +08:00
|
|
|
void MinimalAction::PopScope(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
|
|
|
}
|