Hello, i don’t know if this is the right way to contribute/discuss some things about cling.
If there is another way, please let me know.
I finally get a cling that starts in windows with MSVC2010. It starts and runs simple commands
like for loops or variable declarations.
The things i made to make cling work on windows are:
-
First, you have to set -fno-use-cxa-atexit as a parameter to the cling command to avoid the __dso_handle thing.
-
Only with this cling enters in an infinite loop trying to parse Templates. This patch resolves this infinite loop:
Index: tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (revision 142137)
+++ tools/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (working copy)
@@ -3282,17 +3282,24 @@
PendingInstantiations.insert(PendingInstantiations.begin(),
Pending.begin(), Pending.end());
}
+
+ //Visit ensure only once each definition
+ //New definitions wont be evaluated here
+ int PendingLocalImplicitInstantiationsSize = PendingLocalImplicitInstantiations.size();
+ int PendingInstantiationsSize = PendingInstantiations.size();
- while (!PendingLocalImplicitInstantiations.empty() ||
- (!LocalOnly && !PendingInstantiations.empty())) {
+ while (PendingLocalImplicitInstantiationsSize > 0 ||
+ PendingInstantiationsSize > 0) {
PendingImplicitInstantiation Inst;
- if (PendingLocalImplicitInstantiations.empty()) {
+ if (PendingLocalImplicitInstantiationsSize == 0) {
Inst = PendingInstantiations.front();
PendingInstantiations.pop_front();
+ PendingInstantiationsSize--;
} else {
Inst = PendingLocalImplicitInstantiations.front();
PendingLocalImplicitInstantiations.pop_front();
+ PendingLocalImplicitInstantiationsSize--;
}
// Instantiate function definitions
@@ -3340,6 +3347,10 @@
InstantiateStaticDataMemberDefinition(/*FIXME:*/Inst.second, Var, true,
DefinitionRequired);
}
+ if ((LangOpts.DelayedTemplateParsing && LateTemplateParser) || (!LangOpts.DelayedTemplateParsing )) {
+ assert(PendingLocalImplicitInstantiations.empty() && PendingInstantiations.empty() && "Pending instantiation not resolved");
+ }
+
}
void Sema::PerformDependentDiagnostics(const DeclContext *Pattern,[/code]
it ensures that the function in charge to resolve templates visit only once each template and also resolve only the template that were present at the moment of the start of the function.
The problem with this is that although the loop is finished, the templates are not resolved.
3) Publish in clang::Parser the LateTemplateFunctionCallback and instantiate it before PerformPendingInstantiations().
This is to resolve the templates in microsoft mode.
[code]Index: tools/cling/lib/Interpreter/IncrementalParser.cpp
===================================================================
--- tools/cling/lib/Interpreter/IncrementalParser.cpp (revision 41538)
+++ tools/cling/lib/Interpreter/IncrementalParser.cpp (working copy)
@@ -295,7 +295,10 @@
m_Consumer->HandleTopLevelDecl(DeclGroupRef(*I));
}
+
+ m_Parser->getActions().SetLateTemplateParser(Parser::LateTemplateParserCallback, m_Parser.get());
getCI()->getSema().PerformPendingInstantiations();
+ m_Parser->getActions().SetLateTemplateParser(NULL, NULL);
DClient.EndSourceFile();
Index: tools/clang/include/clang/Parse/Parser.h
===================================================================
--- tools/clang/include/clang/Parse/Parser.h (revision 142693)
+++ tools/clang/include/clang/Parse/Parser.h (working copy)
@@ -243,6 +243,8 @@
DeclGroupPtrTy FinishPendingObjCActions();
+ static void LateTemplateParserCallback(void *P, const FunctionDecl *FD);
+
private:
//===--------------------------------------------------------------------===//
// Low-Level token peeking and consumption methods.
@@ -1117,7 +1119,6 @@
LateParsedTemplateMapT;
LateParsedTemplateMapT LateParsedTemplateMap;
- static void LateTemplateParserCallback(void *P, const FunctionDecl *FD);
void LateTemplateParser(const FunctionDecl *FD);
Sema::ParsingClassState
- The last thing is that the Preprocessor was left in a state by the template parser that doesn’t allow him to parse more code. Here is a patch to clang ParseTemplate that worked for me:
Index: tools/clang/lib/Parse/ParseTemplate.cpp
===================================================================
--- tools/clang/lib/Parse/ParseTemplate.cpp (revision 142693)
+++ tools/clang/lib/Parse/ParseTemplate.cpp (working copy)
@@ -1254,6 +1254,8 @@
DeclGroupPtrTy grp = Actions.ConvertDeclToDeclGroup(LMT.D);
if (grp)
Actions.getASTConsumer().HandleTopLevelDecl(grp.get());
+
+ PP.RemoveTopOfLexerStack();
}
/// \brief Lex a delayed template function for late parsing.
What do you think about the problems/question/patches ?
Juan