Generate fwd decls from nested cling instance

This commit is contained in:
manasij7479 2014-07-28 23:57:56 +05:30 committed by sftnight
parent b2f0efd4d7
commit fd1d5d2290
4 changed files with 43 additions and 19 deletions

View File

@ -278,7 +278,13 @@ namespace cling {
void IncludeCRuntime();
public:
Interpreter(int argc, const char* const *argv, const char* llvmdir = 0);
///\brief Constructor for Interpreter.
///
///\param[in] argc - no. of args.
///\param[in] argv - arguments passed when driver is invoked.
///\param[in] llvmdir - ???
///\param[in] noRuntime - flag to control the presence of runtime universe
Interpreter(int argc, const char* const *argv, const char* llvmdir = 0, bool noRuntime = false);
virtual ~Interpreter();
const InvocationOptions& getOptions() const { return m_Opts; }

View File

@ -531,12 +531,14 @@ namespace cling {
void ForwardDeclPrinter::VisitVarDecl(VarDecl *D) {
if(D->getStorageClass() == SC_Static
|| hasNestedNameSpecifier(D->getType()) ) {
|| hasNestedNameSpecifier(D->getType())
|| D->isDefinedOutsideFunctionOrMethod()) {
m_SkipFlag = true;
return;
}
if(D->isDefinedOutsideFunctionOrMethod() && !(D->getStorageClass() == SC_Extern))
Out << "extern ";
// if(D->isDefinedOutsideFunctionOrMethod() && !(D->getStorageClass() == SC_Extern))
// Out << "extern ";
if (!Policy.SuppressSpecifiers) {
StorageClass SC = D->getStorageClass();
@ -725,12 +727,15 @@ namespace cling {
Out << "{\n";
VisitDeclContext(D);
Indent() << "}";
} else
} else {
Out << "{\n"; // print braces anyway, as the decl may end up getting skipped
Visit(*D->decls_begin());
Out << "}\n";
}
}
void ForwardDeclPrinter::PrintTemplateParameters(const TemplateParameterList *Params,
const TemplateArgumentList *Args) {
const TemplateArgumentList *Args, bool printDefaultArgs ) {
assert(Params);
assert(!Args || Params->size() == Args->size());
@ -758,7 +763,8 @@ namespace cling {
if (Args) {
Out << " = ";
Args->get(i).print(Policy, Out);
} else if (TTP->hasDefaultArgument() && TTP->getName().size() != 0) {
} else if (TTP->hasDefaultArgument() && TTP->getName().size() != 0 /*Workaround*/
&& printDefaultArgs) {
Out << " = ";
Out << TTP->getDefaultArgument().getAsString(Policy);
};
@ -776,7 +782,7 @@ namespace cling {
if (Args) {
Out << " = ";
Args->get(i).print(Policy, Out);
} else if (NTTP->hasDefaultArgument()) {
} else if (NTTP->hasDefaultArgument() && printDefaultArgs) {
Out << " = ";
NTTP->getDefaultArgument()->printPretty(Out, 0, Policy, Indentation);
}
@ -791,8 +797,13 @@ namespace cling {
}
void ForwardDeclPrinter::VisitTemplateDecl(const TemplateDecl *D) {
PrintTemplateParameters(D->getTemplateParameters());
bool isNew = TemplatesWithDefaultArgs.find(D->getNameAsString())
== TemplatesWithDefaultArgs.end();
// TemplatesWithDefaultArgs.insert(D->getNameAsString());
PrintTemplateParameters(D->getTemplateParameters(), 0 ,isNew);
if (const TemplateTemplateParmDecl *TTP =
dyn_cast<TemplateTemplateParmDecl>(D)) {
Out << "class ";
@ -833,11 +844,13 @@ namespace cling {
m_SkipFlag = true;
return;
}
if (PrintInstantiation) {
TemplateParameterList *Params = D->getTemplateParameters();
for (ClassTemplateDecl::spec_iterator I = D->spec_begin(),
E = D->spec_end(); I != E; ++I) {
PrintTemplateParameters(Params, &(*I)->getTemplateArgs());
bool isNewDef = ClassDeclNames.find(D->getNameAsString()) == ClassDeclNames.end();
PrintTemplateParameters(Params, &(*I)->getTemplateArgs(), isNewDef);
Visit(*I);
Out << '\n';
}

View File

@ -30,6 +30,7 @@ namespace cling {
void Print(clang::AccessSpecifier AS);
std::set<std::string> ClassDeclNames;
std::set<std::string> TemplatesWithDefaultArgs;
clang::SourceManager& m_SMgr;
bool m_SkipFlag;
//False by default, true if current item is not to be printed
@ -71,7 +72,7 @@ namespace cling {
void VisitClassTemplateSpecializationDecl(clang::ClassTemplateSpecializationDecl* D);
void PrintTemplateParameters(const clang::TemplateParameterList *Params,
const clang::TemplateArgumentList *Args = 0);
const clang::TemplateArgumentList *Args = 0, bool printDefaultArgs = true);
void prettyPrintAttributes(clang::Decl *D);
void printSemiColon(bool flag=true);

View File

@ -160,7 +160,7 @@ namespace cling {
}
Interpreter::Interpreter(int argc, const char* const *argv,
const char* llvmdir /*= 0*/) :
const char* llvmdir /*= 0*/, bool noRuntime) :
m_UniqueCounter(0), m_PrintDebug(false),
m_DynamicLookupEnabled(false), m_RawInputEnabled(false),
m_LastCustomPragmaDiagPopPoint(){
@ -206,11 +206,12 @@ namespace cling {
DiagnosticConsumer& DClient = getCI()->getDiagnosticClient();
DClient.BeginSourceFile(getCI()->getLangOpts(), &PP);
if (getCI()->getLangOpts().CPlusPlus)
IncludeCXXRuntime();
else
IncludeCRuntime();
if (!noRuntime) {
if (getCI()->getLangOpts().CPlusPlus)
IncludeCXXRuntime();
else
IncludeCRuntime();
}
// Commit the transactions, now that gCling is set up. It is needed for
// static initialization in these transactions through local_cxa_atexit().
for (llvm::SmallVectorImpl<Transaction*>::const_iterator
@ -1194,6 +1195,9 @@ namespace cling {
llvm::StringRef outFile,
bool enableMacros) {
const char *const dummy="cling";
cling::Interpreter instance(1,&dummy,nullptr,true);
CompilationOptions CO;
CO.DeclarationExtraction = 0;
CO.ValuePrinting = 0;
@ -1201,7 +1205,7 @@ namespace cling {
CO.DynamicScoping = 0;
CO.Debug = isPrintingDebug();
cling::Transaction* T = m_IncrParser->Parse
cling::Transaction* T = instance.m_IncrParser->Parse
(std::string("#include \"") + std::string(inFile) + "\"", CO);
// If this was already #included we will get a T == 0.
@ -1256,7 +1260,7 @@ namespace cling {
}
T->setState(Transaction::kCommitted);
unload(1);
// unload(1);
return;
}
void Interpreter::EnableAutoloading() {