Skip to content

Commit 5f337ae

Browse files
committed
changed simplecpp::Macro::tokenListDefine to a shared pointer
1 parent af3f67d commit 5f337ae

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

simplecpp.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <limits>
4141
#include <list>
4242
#include <map>
43+
#include <memory>
4344
#include <set>
4445
#include <sstream>
4546
#include <stack>
@@ -1487,9 +1488,9 @@ namespace simplecpp {
14871488

14881489
class Macro {
14891490
public:
1490-
explicit Macro(std::vector<std::string> &f) : nameTokDef(nullptr), valueToken(nullptr), endToken(nullptr), files(f), tokenListDefine(f), variadic(false), variadicOpt(false), valueDefinedInCode_(false) {}
1491+
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) {}
14911492

1492-
Macro(const Token *tok, std::vector<std::string> &f) : nameTokDef(nullptr), files(f), tokenListDefine(f), valueDefinedInCode_(true) {
1493+
Macro(const Token *tok, std::vector<std::string> &f) : nameTokDef(nullptr), files(f), tokenListDefine(new TokenList(f)), valueDefinedInCode_(true) {
14931494
if (sameline(tok->previousSkipComments(), tok))
14941495
throw std::runtime_error("bad macro syntax");
14951496
if (tok->op != '#')
@@ -1505,15 +1506,15 @@ namespace simplecpp {
15051506
throw std::runtime_error("bad macro syntax");
15061507
}
15071508

1508-
Macro(const std::string &name, const std::string &value, std::vector<std::string> &f) : nameTokDef(nullptr), files(f), tokenListDefine(f), valueDefinedInCode_(false) {
1509+
Macro(const std::string &name, const std::string &value, std::vector<std::string> &f) : nameTokDef(nullptr), files(f), tokenListDefine(new TokenList(f)), valueDefinedInCode_(false) {
15091510
const std::string def(name + ' ' + value);
15101511
StdCharBufStream stream(reinterpret_cast<const unsigned char*>(def.data()), def.size());
1511-
tokenListDefine.readfile(stream);
1512-
if (!parseDefine(tokenListDefine.cfront()))
1512+
tokenListDefine->readfile(stream);
1513+
if (!parseDefine(tokenListDefine->cfront()))
15131514
throw std::runtime_error("bad macro syntax. macroname=" + name + " value=" + value);
15141515
}
15151516

1516-
Macro(const Macro &other) : nameTokDef(nullptr), files(other.files), tokenListDefine(other.files), valueDefinedInCode_(other.valueDefinedInCode_) {
1517+
Macro(const Macro &other) : nameTokDef(nullptr), files(other.files), tokenListDefine(other.tokenListDefine), valueDefinedInCode_(other.valueDefinedInCode_) {
15171518
// TODO: remove the try-catch - see #537
15181519
// avoid bugprone-exception-escape clang-tidy warning
15191520
try {
@@ -1531,11 +1532,11 @@ namespace simplecpp {
15311532
if (this != &other) {
15321533
files = other.files;
15331534
valueDefinedInCode_ = other.valueDefinedInCode_;
1534-
if (other.tokenListDefine.empty())
1535+
if (other.tokenListDefine->empty())
15351536
parseDefine(other.nameTokDef);
15361537
else {
15371538
tokenListDefine = other.tokenListDefine;
1538-
parseDefine(tokenListDefine.cfront());
1539+
parseDefine(tokenListDefine->cfront());
15391540
}
15401541
usageList = other.usageList;
15411542
}
@@ -2391,7 +2392,7 @@ namespace simplecpp {
23912392
std::vector<std::string> &files;
23922393

23932394
/** this is used for -D where the definition is not seen anywhere in code */
2394-
TokenList tokenListDefine;
2395+
std::shared_ptr<TokenList> tokenListDefine;
23952396

23962397
/** usage of this macro */
23972398
mutable std::list<Location> usageList;

0 commit comments

Comments
 (0)