3939#include < limits>
4040#include < list>
4141#include < map>
42+ #include < memory>
4243#include < set>
4344#include < sstream>
4445#include < stack>
@@ -1489,12 +1490,12 @@ namespace simplecpp {
14891490
14901491 class Macro {
14911492 public:
1492- explicit Macro (std::vector<std::string> &f) : nameTokDef(nullptr ), valueToken(nullptr ), endToken(nullptr ), files(f), tokenListDefine(f ), variadic(false ), variadicOpt(false ), valueDefinedInCode_(false ) {}
1493+ explicit Macro (std::vector<std::string> &f) : nameTokDef(nullptr ), valueToken(nullptr ), endToken(nullptr ), files(f), tokenListDefine(new TokenList(f) ), variadic(false ), variadicOpt(false ), valueDefinedInCode_(false ) {}
14931494
14941495 /* *
14951496 * @throws std::runtime_error thrown on bad macro syntax
14961497 */
1497- Macro (const Token *tok, std::vector<std::string> &f) : nameTokDef(nullptr ), files(f), tokenListDefine(f ), valueDefinedInCode_(true ) {
1498+ Macro (const Token *tok, std::vector<std::string> &f) : nameTokDef(nullptr ), files(f), tokenListDefine(new TokenList(f) ), valueDefinedInCode_(true ) {
14981499 if (sameline (tok->previousSkipComments (), tok))
14991500 throw std::runtime_error (" bad macro syntax" );
15001501 if (tok->op != ' #' )
@@ -1513,15 +1514,15 @@ namespace simplecpp {
15131514 /* *
15141515 * @throws std::runtime_error thrown on bad macro syntax
15151516 */
1516- Macro (const std::string &name, const std::string &value, std::vector<std::string> &f) : nameTokDef(nullptr ), files(f), tokenListDefine(f ), valueDefinedInCode_(false ) {
1517+ Macro (const std::string &name, const std::string &value, std::vector<std::string> &f) : nameTokDef(nullptr ), files(f), tokenListDefine(new TokenList(f) ), valueDefinedInCode_(false ) {
15171518 const std::string def (name + ' ' + value);
15181519 StdCharBufStream stream (reinterpret_cast <const unsigned char *>(def.data ()), def.size ());
1519- tokenListDefine. readfile (stream);
1520- if (!parseDefine (tokenListDefine. cfront ()))
1520+ tokenListDefine-> readfile (stream);
1521+ if (!parseDefine (tokenListDefine-> cfront ()))
15211522 throw std::runtime_error (" bad macro syntax. macroname=" + name + " value=" + value);
15221523 }
15231524
1524- Macro (const Macro &other) : nameTokDef(nullptr ), files(other.files), tokenListDefine(other.files ), valueDefinedInCode_(other.valueDefinedInCode_) {
1525+ Macro (const Macro &other) : nameTokDef(nullptr ), files(other.files), tokenListDefine(other.tokenListDefine ), valueDefinedInCode_(other.valueDefinedInCode_) {
15251526 // TODO: remove the try-catch - see #537
15261527 // avoid bugprone-exception-escape clang-tidy warning
15271528 try {
@@ -1539,11 +1540,11 @@ namespace simplecpp {
15391540 if (this != &other) {
15401541 files = other.files ;
15411542 valueDefinedInCode_ = other.valueDefinedInCode_ ;
1542- if (other.tokenListDefine . empty ())
1543+ if (other.tokenListDefine -> empty ())
15431544 parseDefine (other.nameTokDef );
15441545 else {
15451546 tokenListDefine = other.tokenListDefine ;
1546- parseDefine (tokenListDefine. cfront ());
1547+ parseDefine (tokenListDefine-> cfront ());
15471548 }
15481549 usageList = other.usageList ;
15491550 }
@@ -2401,7 +2402,7 @@ namespace simplecpp {
24012402 std::vector<std::string> &files;
24022403
24032404 /* * this is used for -D where the definition is not seen anywhere in code */
2404- TokenList tokenListDefine;
2405+ std::shared_ptr< TokenList> tokenListDefine;
24052406
24062407 /* * usage of this macro */
24072408 mutable std::list<Location> usageList;
0 commit comments