зеркало из https://github.com/microsoft/clang-1.git
pass the astconsumer into Sema's ctor, clean up some stuff in
Sema::ActOnTranslationUnitScope. The various ObjC pieces at the top of Sema.cpp should be moved into SemaObjC or something. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46787 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
e91c134d8f
Коммит
2ae34ed8ca
|
@ -38,7 +38,7 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
|
||||||
ASTContext Context(PP.getSourceManager(), PP.getTargetInfo(),
|
ASTContext Context(PP.getSourceManager(), PP.getTargetInfo(),
|
||||||
PP.getIdentifierTable(), PP.getSelectorTable());
|
PP.getIdentifierTable(), PP.getSelectorTable());
|
||||||
|
|
||||||
Parser P(PP, *new Sema(PP, Context));
|
Parser P(PP, *new Sema(PP, Context, *Consumer));
|
||||||
PP.EnterMainSourceFile();
|
PP.EnterMainSourceFile();
|
||||||
|
|
||||||
// Initialize the parser.
|
// Initialize the parser.
|
||||||
|
|
|
@ -42,43 +42,44 @@ bool Sema::isObjCObjectPointerType(QualType type) const {
|
||||||
|
|
||||||
void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
|
void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
|
||||||
TUScope = S;
|
TUScope = S;
|
||||||
if (PP.getLangOptions().ObjC1) {
|
if (!PP.getLangOptions().ObjC1) return;
|
||||||
TypedefType *t;
|
|
||||||
|
TypedefType *t;
|
||||||
// Add the built-in ObjC types.
|
|
||||||
t = dyn_cast<TypedefType>(Context.getObjCIdType().getTypePtr());
|
// Add the built-in ObjC types.
|
||||||
t->getDecl()->getIdentifier()->setFETokenInfo(t->getDecl());
|
t = cast<TypedefType>(Context.getObjCIdType().getTypePtr());
|
||||||
TUScope->AddDecl(t->getDecl());
|
t->getDecl()->getIdentifier()->setFETokenInfo(t->getDecl());
|
||||||
t = dyn_cast<TypedefType>(Context.getObjCClassType().getTypePtr());
|
TUScope->AddDecl(t->getDecl());
|
||||||
t->getDecl()->getIdentifier()->setFETokenInfo(t->getDecl());
|
t = cast<TypedefType>(Context.getObjCClassType().getTypePtr());
|
||||||
TUScope->AddDecl(t->getDecl());
|
t->getDecl()->getIdentifier()->setFETokenInfo(t->getDecl());
|
||||||
ObjCInterfaceType *it = dyn_cast<ObjCInterfaceType>(Context.getObjCProtoType());
|
TUScope->AddDecl(t->getDecl());
|
||||||
ObjCInterfaceDecl *IDecl = it->getDecl();
|
ObjCInterfaceType *it = cast<ObjCInterfaceType>(Context.getObjCProtoType());
|
||||||
IDecl->getIdentifier()->setFETokenInfo(IDecl);
|
ObjCInterfaceDecl *IDecl = it->getDecl();
|
||||||
TUScope->AddDecl(IDecl);
|
IDecl->getIdentifier()->setFETokenInfo(IDecl);
|
||||||
t = dyn_cast<TypedefType>(Context.getObjCSelType().getTypePtr());
|
TUScope->AddDecl(IDecl);
|
||||||
t->getDecl()->getIdentifier()->setFETokenInfo(t->getDecl());
|
t = cast<TypedefType>(Context.getObjCSelType().getTypePtr());
|
||||||
TUScope->AddDecl(t->getDecl());
|
t->getDecl()->getIdentifier()->setFETokenInfo(t->getDecl());
|
||||||
}
|
TUScope->AddDecl(t->getDecl());
|
||||||
}
|
}
|
||||||
|
|
||||||
Sema::Sema(Preprocessor &pp, ASTContext &ctxt)
|
Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer)
|
||||||
: PP(pp), Context(ctxt), CurFunctionDecl(0), CurMethodDecl(0) {
|
: PP(pp), Context(ctxt), Consumer(consumer),
|
||||||
|
CurFunctionDecl(0), CurMethodDecl(0) {
|
||||||
|
|
||||||
// Get IdentifierInfo objects for known functions for which we
|
// Get IdentifierInfo objects for known functions for which we
|
||||||
// do extra checking.
|
// do extra checking.
|
||||||
IdentifierTable& IT = PP.getIdentifierTable();
|
IdentifierTable &IT = PP.getIdentifierTable();
|
||||||
|
|
||||||
KnownFunctionIDs[ id_printf ] = &IT.get("printf");
|
KnownFunctionIDs[id_printf] = &IT.get("printf");
|
||||||
KnownFunctionIDs[ id_fprintf ] = &IT.get("fprintf");
|
KnownFunctionIDs[id_fprintf] = &IT.get("fprintf");
|
||||||
KnownFunctionIDs[ id_sprintf ] = &IT.get("sprintf");
|
KnownFunctionIDs[id_sprintf] = &IT.get("sprintf");
|
||||||
KnownFunctionIDs[ id_snprintf ] = &IT.get("snprintf");
|
KnownFunctionIDs[id_snprintf] = &IT.get("snprintf");
|
||||||
KnownFunctionIDs[ id_asprintf ] = &IT.get("asprintf");
|
KnownFunctionIDs[id_asprintf] = &IT.get("asprintf");
|
||||||
KnownFunctionIDs[ id_vsnprintf ] = &IT.get("vsnprintf");
|
KnownFunctionIDs[id_vsnprintf] = &IT.get("vsnprintf");
|
||||||
KnownFunctionIDs[ id_vasprintf ] = &IT.get("vasprintf");
|
KnownFunctionIDs[id_vasprintf] = &IT.get("vasprintf");
|
||||||
KnownFunctionIDs[ id_vfprintf ] = &IT.get("vfprintf");
|
KnownFunctionIDs[id_vfprintf] = &IT.get("vfprintf");
|
||||||
KnownFunctionIDs[ id_vsprintf ] = &IT.get("vsprintf");
|
KnownFunctionIDs[id_vsprintf] = &IT.get("vsprintf");
|
||||||
KnownFunctionIDs[ id_vprintf ] = &IT.get("vprintf");
|
KnownFunctionIDs[id_vprintf] = &IT.get("vprintf");
|
||||||
|
|
||||||
if (PP.getLangOptions().ObjC1) {
|
if (PP.getLangOptions().ObjC1) {
|
||||||
// Synthesize "typedef struct objc_class *Class;"
|
// Synthesize "typedef struct objc_class *Class;"
|
||||||
|
|
|
@ -29,6 +29,7 @@ namespace llvm {
|
||||||
|
|
||||||
namespace clang {
|
namespace clang {
|
||||||
class ASTContext;
|
class ASTContext;
|
||||||
|
class ASTConsumer;
|
||||||
class Preprocessor;
|
class Preprocessor;
|
||||||
class Decl;
|
class Decl;
|
||||||
class ScopedDecl;
|
class ScopedDecl;
|
||||||
|
@ -60,8 +61,8 @@ namespace clang {
|
||||||
/// Sema - This implements semantic analysis and AST building for C.
|
/// Sema - This implements semantic analysis and AST building for C.
|
||||||
class Sema : public Action {
|
class Sema : public Action {
|
||||||
Preprocessor &PP;
|
Preprocessor &PP;
|
||||||
|
|
||||||
ASTContext &Context;
|
ASTContext &Context;
|
||||||
|
ASTConsumer &Consumer;
|
||||||
|
|
||||||
/// CurFunctionDecl - If inside of a function body, this contains a pointer to
|
/// CurFunctionDecl - If inside of a function body, this contains a pointer to
|
||||||
/// the function decl for the function being parsed.
|
/// the function decl for the function being parsed.
|
||||||
|
@ -139,7 +140,7 @@ class Sema : public Action {
|
||||||
llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
|
llvm::DenseMap<Selector, ObjCMethodList> InstanceMethodPool;
|
||||||
llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
|
llvm::DenseMap<Selector, ObjCMethodList> FactoryMethodPool;
|
||||||
public:
|
public:
|
||||||
Sema(Preprocessor &pp, ASTContext &ctxt);
|
Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer);
|
||||||
|
|
||||||
const LangOptions &getLangOptions() const;
|
const LangOptions &getLangOptions() const;
|
||||||
|
|
||||||
|
|
|
@ -624,8 +624,8 @@
|
||||||
DEC8D98B0A9433BC00353FCA /* AST */ = {
|
DEC8D98B0A9433BC00353FCA /* AST */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
35BFBD2B0C9EDE1E006CB644 /* ASTConsumer.h */,
|
|
||||||
DEC8D9A30A94346E00353FCA /* AST.h */,
|
DEC8D9A30A94346E00353FCA /* AST.h */,
|
||||||
|
35BFBD2B0C9EDE1E006CB644 /* ASTConsumer.h */,
|
||||||
DE75ED280B044DC90020CF81 /* ASTContext.h */,
|
DE75ED280B044DC90020CF81 /* ASTContext.h */,
|
||||||
DED676D00B6C786700AAD4A3 /* Builtins.def */,
|
DED676D00B6C786700AAD4A3 /* Builtins.def */,
|
||||||
DED676F90B6C797B00AAD4A3 /* Builtins.h */,
|
DED676F90B6C797B00AAD4A3 /* Builtins.h */,
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
namespace clang {
|
namespace clang {
|
||||||
class ASTContext;
|
class ASTContext;
|
||||||
class Decl;
|
class Decl;
|
||||||
|
class TagDecl;
|
||||||
|
class HandleTagDeclDefinition;
|
||||||
|
|
||||||
/// ASTConsumer - This is an abstract interface that should be implemented by
|
/// ASTConsumer - This is an abstract interface that should be implemented by
|
||||||
/// clients that read ASTs. This abstraction layer allows the client to be
|
/// clients that read ASTs. This abstraction layer allows the client to be
|
||||||
|
@ -31,7 +33,7 @@ public:
|
||||||
|
|
||||||
/// HandleTopLevelDecl - Handle the specified top-level declaration. This is
|
/// HandleTopLevelDecl - Handle the specified top-level declaration. This is
|
||||||
/// called by HandleTopLevelDeclaration to process every top-level Decl*.
|
/// called by HandleTopLevelDeclaration to process every top-level Decl*.
|
||||||
virtual void HandleTopLevelDecl(Decl *D) {};
|
virtual void HandleTopLevelDecl(Decl *D) {}
|
||||||
|
|
||||||
|
|
||||||
/// HandleTopLevelDeclaration - Handle the specified top-level declaration.
|
/// HandleTopLevelDeclaration - Handle the specified top-level declaration.
|
||||||
|
@ -40,6 +42,13 @@ public:
|
||||||
/// can override its behavior; by default it calls HandleTopLevelDecl
|
/// can override its behavior; by default it calls HandleTopLevelDecl
|
||||||
/// for every Decl* in a decl chain.
|
/// for every Decl* in a decl chain.
|
||||||
virtual void HandleTopLevelDeclaration(Decl *D);
|
virtual void HandleTopLevelDeclaration(Decl *D);
|
||||||
|
|
||||||
|
|
||||||
|
/// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
|
||||||
|
/// (e.g. struct, union, enum, class) is completed. This allows the client to
|
||||||
|
/// hack on the type, which can occur at any point in the file (because these
|
||||||
|
/// can be defined in declspecs).
|
||||||
|
virtual void HandleTagDeclDefinition(TagDecl *D) {}
|
||||||
|
|
||||||
/// PrintStats - If desired, print any statistics.
|
/// PrintStats - If desired, print any statistics.
|
||||||
virtual void PrintStats() {
|
virtual void PrintStats() {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче