MacroManager.cpp (getdp-3.4.0-source.tgz) | : | MacroManager.cpp (getdp-3.5.0-source.tgz) | ||
---|---|---|---|---|
skipping to change at line 14 | skipping to change at line 14 | |||
// issues on https://gitlab.onelab.info/getdp/getdp/issues. | // issues on https://gitlab.onelab.info/getdp/getdp/issues. | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <map> | #include <map> | |||
#include <stack> | #include <stack> | |||
#include <string> | #include <string> | |||
#include "MacroManager.h" | #include "MacroManager.h" | |||
extern std::string getdp_yystring; | extern std::string getdp_yystring; | |||
class File_Position | class File_Position { | |||
{ | public: | |||
public: | ||||
long int lineno; | long int lineno; | |||
fpos_t position; | fpos_t position; | |||
FILE *file; | FILE *file; | |||
std::string filename; | std::string filename; | |||
}; | }; | |||
class MacroManagerStack | class MacroManagerStack { | |||
{ | public: | |||
public: | ||||
std::stack<File_Position> s; | std::stack<File_Position> s; | |||
}; | }; | |||
class MacroManagerMap | class MacroManagerMap { | |||
{ | public: | |||
public: | ||||
std::map<std::string, File_Position> inFile; | std::map<std::string, File_Position> inFile; | |||
std::map<std::string, std::string> inString; | std::map<std::string, std::string> inString; | |||
}; | }; | |||
MacroManager *MacroManager::_instance = 0; | MacroManager *MacroManager::_instance = 0; | |||
MacroManager::MacroManager() | MacroManager::MacroManager() | |||
{ | { | |||
_macros = new MacroManagerMap; | _macros = new MacroManagerMap; | |||
_calls = new MacroManagerStack; | _calls = new MacroManagerStack; | |||
} | } | |||
MacroManager *MacroManager::Instance() | MacroManager *MacroManager::Instance() | |||
{ | { | |||
if(!_instance) { | if(!_instance) { _instance = new MacroManager; } | |||
_instance = new MacroManager; | ||||
} | ||||
return _instance; | return _instance; | |||
} | } | |||
void MacroManager::clear() | void MacroManager::clear() | |||
{ | { | |||
_macros->inFile.clear(); | _macros->inFile.clear(); | |||
_macros->inString.clear(); | _macros->inString.clear(); | |||
} | } | |||
int MacroManager::enterMacro(const std::string &name, FILE **f, | int MacroManager::enterMacro(const std::string &name, FILE **f, | |||
std::string &filename, long int &lno) const | std::string &filename, long int &lno) const | |||
{ | { | |||
if(_macros->inFile.find(name) == _macros->inFile.end()) | if(_macros->inFile.find(name) == _macros->inFile.end()) return 0; | |||
return 0; | ||||
File_Position fpold; | File_Position fpold; | |||
fpold.lineno = lno; | fpold.lineno = lno; | |||
fpold.filename = filename; | fpold.filename = filename; | |||
fpold.file = *f; | fpold.file = *f; | |||
fgetpos(fpold.file, &fpold.position); | fgetpos(fpold.file, &fpold.position); | |||
_calls->s.push(fpold); | _calls->s.push(fpold); | |||
File_Position fp = (_macros->inFile)[name]; | File_Position fp = (_macros->inFile)[name]; | |||
fsetpos(fp.file, &fp.position); | fsetpos(fp.file, &fp.position); | |||
*f = fp.file; | *f = fp.file; | |||
filename = fp.filename; | filename = fp.filename; | |||
lno = fp.lineno; | lno = fp.lineno; | |||
return 1; | return 1; | |||
} | } | |||
int MacroManager::leaveMacro(FILE **f, std::string &filename, long int &lno) | int MacroManager::leaveMacro(FILE **f, std::string &filename, long int &lno) | |||
{ | { | |||
if(!_calls->s.size()) | if(!_calls->s.size()) return 0; | |||
return 0; | ||||
File_Position fp; | File_Position fp; | |||
fp = _calls->s.top(); | fp = _calls->s.top(); | |||
_calls->s.pop(); | _calls->s.pop(); | |||
fsetpos(fp.file, &fp.position); | fsetpos(fp.file, &fp.position); | |||
*f = fp.file; | *f = fp.file; | |||
filename = fp.filename; | filename = fp.filename; | |||
// lno = fp.lineno; | // lno = fp.lineno; | |||
// To fix: bad line number after leaving macro if not -1 | // To fix: bad line number after leaving macro if not -1 | |||
lno = fp.lineno - 1; | lno = fp.lineno - 1; | |||
return 1; | return 1; | |||
} | } | |||
int MacroManager::createMacro(const std::string &name, FILE *f, | int MacroManager::createMacro(const std::string &name, FILE *f, | |||
const std::string &filename, long int lno) | const std::string &filename, long int lno) | |||
{ | { | |||
if(_macros->inFile.find(name) != _macros->inFile.end()) | if(_macros->inFile.find(name) != _macros->inFile.end()) return 0; | |||
return 0; | ||||
File_Position fp; | File_Position fp; | |||
fp.file = f; | fp.file = f; | |||
fp.filename = filename; | fp.filename = filename; | |||
fp.lineno = lno; | fp.lineno = lno; | |||
fgetpos(fp.file, &fp.position); | fgetpos(fp.file, &fp.position); | |||
(_macros->inFile)[name] = fp; | (_macros->inFile)[name] = fp; | |||
return 1; | return 1; | |||
} | } | |||
int MacroManager::createStringMacro(const std::string &name, | int MacroManager::createStringMacro(const std::string &name, | |||
const std::string &value) | const std::string &value) | |||
{ | { | |||
if(_macros->inString.find(name) != _macros->inString.end()) | if(_macros->inString.find(name) != _macros->inString.end()) return 0; | |||
return 0; | ||||
(_macros->inString)[name] = value; | (_macros->inString)[name] = value; | |||
return 1; | return 1; | |||
} | } | |||
int MacroManager::enterStringMacro(const std::string &name) const | int MacroManager::enterStringMacro(const std::string &name) const | |||
{ | { | |||
if(_macros->inString.find(name) == _macros->inString.end()) | if(_macros->inString.find(name) == _macros->inString.end()) return 0; | |||
return 0; | ||||
getdp_yystring = (_macros->inString)[name]; | getdp_yystring = (_macros->inString)[name]; | |||
return 1; | return 1; | |||
} | } | |||
End of changes. 9 change blocks. | ||||
22 lines changed or deleted | 12 lines changed or added |