#include "clang/Parse/Parser.h"
#include "clang/Parse/DeclSpec.h"
#include "clang/Parse/Scope.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/RecyclingAllocator.h"
#include "llvm/Support/raw_ostream.h"
using namespace clang;
ActionBase::~ActionBase() {}
Action::~Action() {}
Action::DeclPtrTy Action::ActOnUsingDirective(Scope *CurScope,
SourceLocation UsingLoc,
SourceLocation NamespcLoc,
const CXXScopeSpec &SS,
SourceLocation IdentLoc,
IdentifierInfo *NamespcName,
AttributeList *AttrList) {
delete AttrList;
return DeclPtrTy();
}
void PrettyStackTraceActionsDecl::print(llvm::raw_ostream &OS) const {
if (Loc.isValid()) {
Loc.print(OS, SM);
OS << ": ";
}
OS << Message;
std::string Name = Actions.getDeclName(TheDecl);
if (!Name.empty())
OS << " '" << Name << '\'';
OS << '\n';
}
namespace {
struct TypeNameInfo {
TypeNameInfo *Prev;
bool isTypeName;
TypeNameInfo(bool istypename, TypeNameInfo *prev) {
isTypeName = istypename;
Prev = prev;
}
};
struct TypeNameInfoTable {
llvm::RecyclingAllocator<llvm::BumpPtrAllocator, TypeNameInfo> Allocator;
void AddEntry(bool isTypename, IdentifierInfo *II) {
TypeNameInfo *TI = Allocator.Allocate<TypeNameInfo>();
new (TI) TypeNameInfo(isTypename, II->getFETokenInfo<TypeNameInfo>());
II->setFETokenInfo(TI);
}
void DeleteEntry(TypeNameInfo *Entry) {
Entry->~TypeNameInfo();
Allocator.Deallocate(Entry);
}
};
}
static TypeNameInfoTable *getTable(void *TP) {
return static_cast<TypeNameInfoTable*>(TP);
}
MinimalAction::MinimalAction(Preprocessor &pp)
: Idents(pp.getIdentifierTable()), PP(pp) {
TypeNameInfoTablePtr = new TypeNameInfoTable();
}
MinimalAction::~MinimalAction() {
delete getTable(TypeNameInfoTablePtr);
}
void MinimalAction::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
TUScope = S;
TypeNameInfoTable &TNIT = *getTable(TypeNameInfoTablePtr);
if (PP.getTargetInfo().getPointerWidth(0) >= 64) {
TNIT.AddEntry(true, &Idents.get("__int128_t"));
TNIT.AddEntry(true, &Idents.get("__uint128_t"));
}
if (PP.getLangOptions().ObjC1) {
TNIT.AddEntry(true, &Idents.get("id"));
TNIT.AddEntry(true, &Idents.get("SEL"));
TNIT.AddEntry(true, &Idents.get("Class"));
TNIT.AddEntry(true, &Idents.get("Protocol"));
}
}
Action::TypeTy *
MinimalAction::getTypeName(IdentifierInfo &II, SourceLocation Loc,
Scope *S, const CXXScopeSpec *SS) {
if (TypeNameInfo *TI = II.getFETokenInfo<TypeNameInfo>())
if (TI->isTypeName)
return TI;
return 0;
}
bool MinimalAction::isCurrentClassName(const IdentifierInfo &, Scope *,
const CXXScopeSpec *) {
return false;
}
TemplateNameKind
MinimalAction::isTemplateName(const IdentifierInfo &II, Scope *S,
TemplateTy &TemplateDecl,
const CXXScopeSpec *SS) {
return TNK_Non_template;
}
Action::DeclPtrTy
MinimalAction::ActOnDeclarator(Scope *S, Declarator &D) {
IdentifierInfo *II = D.getIdentifier();
if (II == 0) return DeclPtrTy();
TypeNameInfo *weCurrentlyHaveTypeInfo = II->getFETokenInfo<TypeNameInfo>();
bool isTypeName =
D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef;
if (weCurrentlyHaveTypeInfo || isTypeName) {
getTable(TypeNameInfoTablePtr)->AddEntry(isTypeName, II);
S->AddDecl(DeclPtrTy::make(II));
}
return DeclPtrTy();
}
Action::DeclPtrTy
MinimalAction::ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName,
SourceLocation ClassLoc,
IdentifierInfo *SuperName,
SourceLocation SuperLoc,
const DeclPtrTy *ProtoRefs,
unsigned NumProtocols,
SourceLocation EndProtoLoc,
AttributeList *AttrList) {
getTable(TypeNameInfoTablePtr)->AddEntry(true, ClassName);
return DeclPtrTy();
}
Action::DeclPtrTy
MinimalAction::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
IdentifierInfo **IdentList, unsigned NumElts) {
for (unsigned i = 0; i != NumElts; ++i) {
getTable(TypeNameInfoTablePtr)->AddEntry(true, IdentList[i]);
TUScope->AddDecl(DeclPtrTy::make(IdentList[i]));
}
return DeclPtrTy();
}
void MinimalAction::ActOnPopScope(SourceLocation Loc, Scope *S) {
TypeNameInfoTable &Table = *getTable(TypeNameInfoTablePtr);
for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end();
I != E; ++I) {
IdentifierInfo &II = *(*I).getAs<IdentifierInfo>();
TypeNameInfo *TI = II.getFETokenInfo<TypeNameInfo>();
assert(TI && "This decl didn't get pushed??");
if (TI) {
TypeNameInfo *Next = TI->Prev;
Table.DeleteEntry(TI);
II.setFETokenInfo(Next);
}
}
}