Select Git revision
MacroManager.cpp
-
Christophe Geuzaine authored
new string macros, allowing define macros explicitly - and use them without a file context (e.g. in Parse commands)
Christophe Geuzaine authorednew string macros, allowing define macros explicitly - and use them without a file context (e.g. in Parse commands)
MacroManager.cpp 2.63 KiB
// GetDP - Copyright (C) 1997-2015 P. Dular, C. Geuzaine
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <getdp@onelab.info>.
#include <stdio.h>
#include <map>
#include <stack>
#include <string>
#include "MacroManager.h"
extern std::string getdp_yystring;
class File_Position
{
public:
long int lineno;
fpos_t position;
FILE *file;
std::string filename;
};
class mystack
{
public:
std::stack<File_Position> s;
};
class mymap
{
public:
std::map<std::string, File_Position> inFile;
std::map<std::string, std::string> inString;
};
MacroManager *MacroManager::_instance = 0;
MacroManager::MacroManager()
{
_macros = new mymap;
_calls = new mystack;
}
MacroManager *MacroManager::Instance()
{
if(!_instance) {
_instance = new MacroManager;
}
return _instance;
}
void MacroManager::clear()
{
_macros->inFile.clear();
_macros->inString.clear();
}
int MacroManager::enterMacro(const std::string &name, FILE **f,
std::string &filename, long int &lno) const
{
if(_macros->inFile.find(name) == _macros->inFile.end())
return 0;
File_Position fpold;
fpold.lineno = lno;
fpold.filename = filename;
fpold.file = *f;
fgetpos(fpold.file, &fpold.position);
_calls->s.push(fpold);
File_Position fp = (_macros->inFile)[name];
fsetpos(fp.file, &fp.position);