3939#include < limits>
4040#include < list>
4141#include < map>
42+ #include < memory>
4243#include < set>
4344#include < sstream>
4445#include < stack>
@@ -1499,12 +1500,12 @@ namespace simplecpp {
14991500
15001501 class Macro {
15011502 public:
1502- explicit Macro (std::vector<std::string> &f) : nameTokDef(nullptr ), valueToken(nullptr ), endToken(nullptr ), files(f), tokenListDefine(f ), variadic(false ), variadicOpt(false ), valueDefinedInCode_(false ) {}
1503+ 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 ) {}
15031504
15041505 /* *
15051506 * @throws std::runtime_error thrown on bad macro syntax
15061507 */
1507- Macro (const Token *tok, std::vector<std::string> &f) : nameTokDef(nullptr ), files(f), tokenListDefine(f ), valueDefinedInCode_(true ) {
1508+ Macro (const Token *tok, std::vector<std::string> &f) : nameTokDef(nullptr ), files(f), tokenListDefine(new TokenList(f) ), valueDefinedInCode_(true ) {
15081509 if (sameline (tok->previousSkipComments (), tok))
15091510 throw std::runtime_error (" bad macro syntax" );
15101511 if (tok->op != ' #' )
@@ -1523,15 +1524,15 @@ namespace simplecpp {
15231524 /* *
15241525 * @throws std::runtime_error thrown on bad macro syntax
15251526 */
1526- Macro (const std::string &name, const std::string &value, std::vector<std::string> &f) : nameTokDef(nullptr ), files(f), tokenListDefine(f ), valueDefinedInCode_(false ) {
1527+ Macro (const std::string &name, const std::string &value, std::vector<std::string> &f) : nameTokDef(nullptr ), files(f), tokenListDefine(new TokenList(f) ), valueDefinedInCode_(false ) {
15271528 const std::string def (name + ' ' + value);
15281529 StdCharBufStream stream (reinterpret_cast <const unsigned char *>(def.data ()), def.size ());
1529- tokenListDefine. readfile (stream);
1530- if (!parseDefine (tokenListDefine. cfront ()))
1530+ tokenListDefine-> readfile (stream);
1531+ if (!parseDefine (tokenListDefine-> cfront ()))
15311532 throw std::runtime_error (" bad macro syntax. macroname=" + name + " value=" + value);
15321533 }
15331534
1534- Macro (const Macro &other) : nameTokDef(nullptr ), files(other.files), tokenListDefine(other.files ), valueDefinedInCode_(other.valueDefinedInCode_) {
1535+ Macro (const Macro &other) : nameTokDef(nullptr ), files(other.files), tokenListDefine(other.tokenListDefine ), valueDefinedInCode_(other.valueDefinedInCode_) {
15351536 // TODO: remove the try-catch - see #537
15361537 // avoid bugprone-exception-escape clang-tidy warning
15371538 try {
@@ -1549,12 +1550,12 @@ namespace simplecpp {
15491550 if (this != &other) {
15501551 files = other.files ;
15511552 valueDefinedInCode_ = other.valueDefinedInCode_ ;
1552- if (other.tokenListDefine . empty ()) {
1553+ if (other.tokenListDefine -> empty ()) {
15531554 parseDefine (other.nameTokDef );
15541555 }
15551556 else {
15561557 tokenListDefine = other.tokenListDefine ;
1557- parseDefine (tokenListDefine. cfront ());
1558+ parseDefine (tokenListDefine-> cfront ());
15581559 }
15591560 usageList = other.usageList ;
15601561 }
@@ -2424,7 +2425,7 @@ namespace simplecpp {
24242425 std::vector<std::string> &files;
24252426
24262427 /* * this is used for -D where the definition is not seen anywhere in code */
2427- TokenList tokenListDefine;
2428+ std::shared_ptr< TokenList> tokenListDefine;
24282429
24292430 /* * usage of this macro */
24302431 mutable std::list<Location> usageList;
0 commit comments