Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save restore procedures now available #1681

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
57126ed
save study state.
GillesDuvert Nov 20, 2023
4daa443
current state
GillesDuvert Nov 23, 2023
e7eb58d
GillesDuvert Nov 23, 2023
1ef322c
finally working
GillesDuvert Dec 2, 2023
3a3cae7
OK 1
GillesDuvert Dec 5, 2023
ceec174
compatible with IDL save file
GillesDuvert Dec 5, 2023
c0357ed
manage options related to /routine for save
GillesDuvert Dec 5, 2023
f969c8d
add a crude version number management: if we change the parser, the t…
GillesDuvert Dec 5, 2023
a61dc86
adde SKIP_IF_PRESENT support for restore.
GillesDuvert Dec 5, 2023
2475969
remove annoying compilation warning about uninitialzed variable.
GillesDuvert Dec 6, 2023
4b67d32
Store semiCompiled code outside pro object (as it is sometimes destro…
GillesDuvert Dec 6, 2023
81b1069
remove annoying compilation warning about uninitialzed variable.
GillesDuvert Dec 6, 2023
e57f433
old semicompiled code is now removed when the procedure is updated.
GillesDuvert Dec 6, 2023
b7f514d
HELP behaviour for /FUN, /PRO, /ROUT with or without /BRIEF is OK and…
GillesDuvert Dec 7, 2023
a649832
exact output (sorted keywords, no extra blanks)
GillesDuvert Dec 7, 2023
45924db
differentiate PRO and FUN in save/restore (message format but also in…
GillesDuvert Dec 7, 2023
f44d7b4
put a better message
GillesDuvert Dec 7, 2023
58a318d
try fixing OSX compiler errors.
GillesDuvert Dec 7, 2023
3ac217e
Modified SearchCompilePro to avoid recompiling OBJECTS's methods if t…
GillesDuvert Dec 8, 2023
d861c86
added special case to savetest command (debug)
GillesDuvert Dec 8, 2023
e11bd61
make help,/obj closer to what IDL shows.
GillesDuvert Dec 8, 2023
f59a769
add some save/restore commands for /routines just to increase coverag…
GillesDuvert Dec 8, 2023
be5edbe
save procdures in compressed format to save a lot of space.
GillesDuvert Dec 8, 2023
bf04c4c
version produced from modified ANTLR sources, so: complete
GillesDuvert Dec 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/GDLInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class CUSTOM_API GDLInterpreter : public antlr::TreeParser, public GDLInterprete
static bool CompileFile(const std::string& f,
const std::string& untilPro="",
bool searchForPro=true);

static bool CompileSaveFile(RefDNode theAST);
typedef RefHeap<BaseGDL> RefBaseGDL;
typedef RefHeap<DStructGDL> RefDStructGDL;

Expand Down
2 changes: 1 addition & 1 deletion src/GDLLexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ class CUSTOM_API GDLLexer : public antlr::CharScanner, public GDLTokenTypes
// make copy as we delete 'this'
antlr::TokenStreamSelector* sel=selector;


// make sure errors are reported in right file
parserPtr->setFilename(
static_cast<GDLLexer*>(selector->getCurrentStream())->getFilename());

//GD: see issue #1632 -- deletion must be here and not before previous line!
// here 'this' is deleted (pops selector)
delete sel->getCurrentStream();

Expand Down
4 changes: 3 additions & 1 deletion src/GDLParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class CUSTOM_API GDLParser : public antlr::LLkParser, public GDLTokenTypes
IDL2=DEFINT32 | STRICTARR,
STRICTARRSUBS=32,
STATIC=64,
NOSAVE=128
NOSAVE=128,
GDL_HIDDEN=256 //flag to avoid writing "Compiled module" at compilation.
//Not the same as HIDDEN, that can be set in the procdure code and hides also the procedure from the HELP.
};

void SetCompileOpt( unsigned int cOpt)
Expand Down
8 changes: 4 additions & 4 deletions src/GDLTreeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void GDLTreeParser::procedure_def(RefDNode _t) {
match(antlr::RefAST(_t),IDENTIFIER);
_t = _t->getNextSibling();

comp.StartPro(name->getText(),p_AST->GetCompileOpt(),obj->getText());
comp.StartPro(name->getText(),p_AST->GetCompileOpt(),obj->getText(), RefDNode(procedure_def_AST_in));

break;
}
Expand Down Expand Up @@ -294,7 +294,7 @@ void GDLTreeParser::procedure_def(RefDNode _t) {
case XOR_OP_EQ:
{

comp.StartPro(name->getText(),p_AST->GetCompileOpt());
comp.StartPro(name->getText(),p_AST->GetCompileOpt(),"", RefDNode(procedure_def_AST_in));

break;
}
Expand Down Expand Up @@ -487,7 +487,7 @@ void GDLTreeParser::function_def(RefDNode _t) {
match(antlr::RefAST(_t),IDENTIFIER);
_t = _t->getNextSibling();

comp.StartFun(name->getText(),f_AST->GetCompileOpt(),obj->getText());
comp.StartFun(name->getText(),f_AST->GetCompileOpt(),obj->getText(),RefDNode(function_def_AST_in));

break;
}
Expand Down Expand Up @@ -537,7 +537,7 @@ void GDLTreeParser::function_def(RefDNode _t) {
case XOR_OP_EQ:
{

comp.StartFun(name->getText(),f_AST->GetCompileOpt());
comp.StartFun(name->getText(),f_AST->GetCompileOpt(),"", RefDNode(function_def_AST_in));

break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/basic_fun_jmg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


//#define GDL_DEBUG
#undef GDL_DEBUG
//#undef GDL_DEBUG

namespace lib {

Expand Down
2 changes: 1 addition & 1 deletion src/basic_pro_jmg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "basic_pro_jmg.hpp"

//#define GDL_DEBUG
#undef GDL_DEBUG
//#undef GDL_DEBUG

#if defined(_WIN32) && !defined(__CYGWIN__)
# include "gtdhelper.hpp" // just a workaround, using QueryPerformanceCounter is better
Expand Down
14 changes: 10 additions & 4 deletions src/dcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,16 @@ void DCompiler::EndInteractiveStatement() // add common blocks
ownCommonList.clear(); // not responsible anymore
}

void DCompiler::StartPro(const string& n, const int compileOpt, const string& o)
void DCompiler::StartPro(const string& n, const int compileOpt, const string& o, const RefDNode semiCompiledTree)
{
ClearOwnCommon();
if( n != "$MAIN$" || o != "")
{
pro = new DPro(n,o,actualFile);
pro->SetCompileOpt(compileOpt);
//"restored" procedures have no file name associated. They will be marked as "CompileHidden", to avoid the message "Compiled module" issued when (re)compiling the Lexer code.
if (actualFile.length()==0) pro->AddHiddenToCompileOpt();
pro->SetAstTree(semiCompiledTree); //entry number
}
else
{
Expand All @@ -167,11 +170,14 @@ void DCompiler::ContinueMainPro()
pro = static_cast<DSubUD*>( env->GetPro());
}

void DCompiler::StartFun(const string& n, const int compileOpt = 0, const string& o)
void DCompiler::StartFun(const string& n, const int compileOpt = 0, const string& o, const RefDNode semiCompiledTree)
{
ClearOwnCommon();
pro = new DFun(n,o,actualFile);
pro->SetCompileOpt(compileOpt);
//"restored" procedures have no file name associated. They will be marked as "CompileHidden", to avoid the message "Compiled module" issued when (re)compiling the Lexer code.
if (actualFile.length() == 0) pro->AddHiddenToCompileOpt();
pro->SetAstTree(semiCompiledTree); //entry number
}

bool DCompiler::IsActivePro( DSub* p)
Expand Down Expand Up @@ -245,7 +251,7 @@ void DCompiler::EndPro() // inserts in proList
}
}

if(!pro->isHidden()) { if ( subRoutine == "" || subRoutine == pro->ObjectFileName())
if(!(pro->isHidden() || pro->isGdlHidden())) { if ( subRoutine == "" || subRoutine == pro->ObjectFileName())
Message( "Compiled module: "+pro->ObjectName()+"."); }

// reset pro // will be deleted otherwise
Expand Down Expand Up @@ -312,7 +318,7 @@ void DCompiler::EndFun() // inserts in funList
WarnAboutObsoleteRoutine(pro->ObjectName());
}

if(!pro->isHidden()) { if (subRoutine == "" || subRoutine == pro->ObjectFileName())
if(!(pro->isHidden() || pro->isGdlHidden())) { if (subRoutine == "" || subRoutine == pro->ObjectFileName())
Message( "Compiled module: "+pro->ObjectName()+"."); }
// reset pro // will be deleted otherwise
if( env != NULL) pro=dynamic_cast<DSubUD*>(env->GetPro()); else pro=NULL;
Expand Down
6 changes: 3 additions & 3 deletions src/dcompiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ class DCompiler: public GDLTokenTypes
void ForwardFunction(const std::string&); // add to function list
void AddPar(const std::string&); // add parameter
void AddKey(const std::string&,const std::string&); // add keyword,varName
void StartPro(const std::string&, const int compileOpt = 0, const std::string& o = "");
void StartPro(const std::string&, const int compileOpt = 0, const std::string& o = "", const RefDNode semiCompiledTree=NULL);
void ContinueMainPro();
void EndFunPro();
void EndInteractiveStatement();
void EndPro();
void StartFun(const std::string&, const int compileOpt, const std::string& o = "");
void StartFun(const std::string&, const int compileOpt, const std::string& o = "", const RefDNode semiCompiledTree=NULL);
void EndFun();
void SetClass(const std::string&); // set procedure to member (also add 'self')
DCommonBase* CommonDef(const std::string&); // Common block (re)definition
Expand All @@ -83,7 +83,7 @@ class DCompiler: public GDLTokenTypes
bool IsVar(const std::string&); // variable already defined in actual context?
void Var(RefDNode); // sets var in node
void SysVar(RefDNode); // sets var in node
void SetTree(RefDNode);
void SetTree(RefDNode);
void Label(RefDNode);
void Goto(RefDNode);
bool IsFun() const;
Expand Down
48 changes: 46 additions & 2 deletions src/dinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,19 @@
// }

// searches and compiles procedure (searchForPro == true) or function (searchForPro == false) 'pro'
// if pro/fun is already present because it has been restored, (thus there may be no files, and no filename), return immediately
bool GDLInterpreter::SearchCompilePro(const string& pro, bool searchForPro)
{
std::string name_in_list = StrUpCase(pro);
if (searchForPro) {
for (ProListT::iterator i = proList.begin(); i != proList.end(); ++i) {
if ((*i)->ObjectName() == name_in_list) return true;
}
} else {
for (FunListT::iterator i = funList.begin(); i != funList.end(); ++i) {
if ((*i)->ObjectName() == name_in_list) return true;
}
}
static StrArr openFiles;

string proFile=StrLowCase(pro)+".pro";
Expand Down Expand Up @@ -655,14 +666,13 @@
#ifdef GDL_DEBUG
cout << "Parser output:" << endl;
antlr::print_tree pt;
pt.pr_tree(static_cast<antlr::RefAST>(theAST));
pt.pr_tree(static_cast<antlr::RefAST>(theSemiCompiledAST));
cout << "CompileFile: Parser end." << endl;
#endif

#ifdef GDL_DEBUG
RefDNode trAST;
#endif

GDLTreeParser treeParser( f, untilPro);
try
{
Expand Down Expand Up @@ -702,6 +712,40 @@
return true;
}

bool GDLInterpreter::CompileSaveFile(RefDNode theSemiCompiledAST)
{
#ifdef GDL_DEBUG
RefDNode trAST;
#endif
GDLTreeParser treeParser( "", "");

try
{
treeParser.translation_unit(theSemiCompiledAST);
// if( treeParser.ActiveProCompiled()) RetAll(); //should not happen as CompileSaveFile is not called in this case
}
catch( GDLException& e)

Check warning on line 727 in src/dinterpreter.cpp

View check run for this annotation

Codecov / codecov/patch

src/dinterpreter.cpp#L727

Added line #L727 was not covered by tests
{
ReportCompileError( e, "");

Check warning on line 729 in src/dinterpreter.cpp

View check run for this annotation

Codecov / codecov/patch

src/dinterpreter.cpp#L729

Added line #L729 was not covered by tests
// if( treeParser.ActiveProCompiled()) RetAll();
return false;
}
catch( ANTLRException& e)

Check warning on line 733 in src/dinterpreter.cpp

View check run for this annotation

Codecov / codecov/patch

src/dinterpreter.cpp#L732-L733

Added lines #L732 - L733 were not covered by tests
{
cerr << "Compiler exception: " << e.getMessage() << endl;

Check warning on line 735 in src/dinterpreter.cpp

View check run for this annotation

Codecov / codecov/patch

src/dinterpreter.cpp#L735

Added line #L735 was not covered by tests
// if( treeParser.ActiveProCompiled()) RetAll();
return false;
}

Check warning on line 738 in src/dinterpreter.cpp

View check run for this annotation

Codecov / codecov/patch

src/dinterpreter.cpp#L738

Added line #L738 was not covered by tests
#ifdef GDL_DEBUG
cout << "Tree parser output:" << endl;
antlr::print_tree ptTP;
ptTP.pr_tree(static_cast<antlr::RefAST>(trAST));
cout << "CompileFile: Tree parser end." << endl;
#endif

return true;
}

void AppendExtension( string& argstr)
{
SizeT slPos = argstr.find_last_of( '/');
Expand Down
10 changes: 8 additions & 2 deletions src/dnode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,19 @@ class DNode : public antlr::CommonAST {
var(NULL),
libFun(NULL),
libPro(NULL),
arrIxList(NULL),arrIxListNoAssoc(NULL), labelStart( -1), labelEnd( -1)
arrIxList(NULL),arrIxListNoAssoc(NULL), labelStart( -1), labelEnd( -1), initInt(0)
{
}

DNode( const DNode& cp);

DNode(antlr::RefToken t) : antlr::CommonAST(t) //, down(), right()
DNode(antlr::RefToken t) : antlr::CommonAST(t), //, down(), right()
// , keepRight( false)
cData(NULL),
var(NULL),
libFun(NULL),
libPro(NULL),
arrIxList(NULL),arrIxListNoAssoc(NULL), labelStart( -1), labelEnd( -1), initInt(0)
{
// antlr::CommonAST::setType(t->getType() );
// antlr::CommonAST::setText(t->getText() );
Expand All @@ -100,6 +105,7 @@ class DNode : public antlr::CommonAST {
var=NULL;
arrIxList=NULL;
arrIxListNoAssoc=NULL;
initInt=0;
}

// used by DNodeFactory
Expand Down
19 changes: 18 additions & 1 deletion src/dpro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@

// print out AST tree
//#define GDL_DEBUG
#undef GDL_DEBUG
//#undef GDL_DEBUG

#ifdef GDL_DEBUG
#include "print_tree.hpp"
#endif

CodeListT codeList;

using namespace std;

// vtable
Expand Down Expand Up @@ -260,6 +262,7 @@

labelList.Clear();
delete tree;
codeList.erase(this);
}

DSubUD::DSubUD(const string& n,const string& o,const string& f) :
Expand Down Expand Up @@ -473,3 +476,17 @@
return compileOpt & GDLParser::HIDDEN;
}

bool DSubUD::isGdlHidden()
{
return compileOpt & GDLParser::GDL_HIDDEN;
}

bool DSubUD::isNoSave()

Check warning on line 484 in src/dpro.cpp

View check run for this annotation

Codecov / codecov/patch

src/dpro.cpp#L484

Added line #L484 was not covered by tests
{
return compileOpt & GDLParser::NOSAVE;

Check warning on line 486 in src/dpro.cpp

View check run for this annotation

Codecov / codecov/patch

src/dpro.cpp#L486

Added line #L486 was not covered by tests
}

void DSubUD::AddHiddenToCompileOpt() {
compileOpt |= GDLParser::GDL_HIDDEN;
}

25 changes: 21 additions & 4 deletions src/dpro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
#ifndef DPRO_HPP_
#define DPRO_HPP_

// #include <deque>
#include <string>
#include <algorithm>
#include <vector>
//#include <stack>
#include <map>

#include "basegdl.hpp"
#include "dcommon.hpp"
Expand All @@ -36,6 +35,12 @@
extern bool posixpaths;
}
#endif

class DSubUD;
typedef std::map<DSubUD*, RefDNode> CodeListT;
typedef std::map<DSubUD*, RefDNode>::iterator CodeListIterator;
extern CodeListT codeList;

template<typename T> class Is_eq: public std::function<bool(T)>
{
std::string name;
Expand Down Expand Up @@ -333,7 +338,7 @@ class DSubUD: public DSub

CommonBaseListT common; // common blocks or references
ProgNodeP tree; // the 'code'
unsigned int compileOpt; // e.g. hidden or obsolete
unsigned int compileOpt; // e.g. hidden or obsolete

LabelListT labelList;

Expand All @@ -349,6 +354,9 @@ class DSubUD: public DSub
void Reset();
void DelTree();
void SetTree( ProgNodeP t) { tree = t;}
void SetAstTree( RefDNode n) {
codeList.insert(std::pair<DSubUD*, RefDNode>(this, n));
}

void AddCommon(DCommonBase* c) { common.push_back(c);}
void DeleteLastAddedCommon(bool kill=true)
Expand Down Expand Up @@ -542,12 +550,21 @@ void ReName( SizeT ix, const std::string& s)
{
return tree;
}

RefDNode GetAstTree()
{
//find Semicompiled code saved in codeList
CodeListIterator i = codeList.find(this);
if (i!=codeList.end()) return (*i).second;
return NULL;
}
unsigned int GetCompileOpt() { return compileOpt; }
void SetCompileOpt(const unsigned int n) { compileOpt = n; }
void AddHiddenToCompileOpt();
bool isObsolete();
bool isHidden();
bool isGdlHidden();
bool isStatic();
bool isNoSave();

friend class EnvUDT;
};
Expand Down
2 changes: 1 addition & 1 deletion src/envt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "calendar.hpp"

//#define GDL_DEBUG
#undef GDL_DEBUG
//#undef GDL_DEBUG

class DInterpreter;

Expand Down
2 changes: 1 addition & 1 deletion src/fftw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <gsl/gsl_math.h>
#include "gsl_fun.hpp"

#undef GDL_DEBUG
//#undef GDL_DEBUG

namespace lib {

Expand Down
Loading
Loading