Skip to content

Commit a75d5bc

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

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>
@@ -1486,9 +1487,9 @@ namespace simplecpp {
14861487

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

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

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

1515-
Macro(const Macro &other) : nameTokDef(nullptr), files(other.files), tokenListDefine(other.files), valueDefinedInCode_(other.valueDefinedInCode_) {
1516+
Macro(const Macro &other) : nameTokDef(nullptr), files(other.files), tokenListDefine(other.tokenListDefine), valueDefinedInCode_(other.valueDefinedInCode_) {
15161517
// TODO: remove the try-catch - see #537
15171518
// avoid bugprone-exception-escape clang-tidy warning
15181519
try {
@@ -1530,11 +1531,11 @@ namespace simplecpp {
15301531
if (this != &other) {
15311532
files = other.files;
15321533
valueDefinedInCode_ = other.valueDefinedInCode_;
1533-
if (other.tokenListDefine.empty())
1534+
if (other.tokenListDefine->empty())
15341535
parseDefine(other.nameTokDef);
15351536
else {
15361537
tokenListDefine = other.tokenListDefine;
1537-
parseDefine(tokenListDefine.cfront());
1538+
parseDefine(tokenListDefine->cfront());
15381539
}
15391540
usageList = other.usageList;
15401541
}
@@ -2390,7 +2391,7 @@ namespace simplecpp {
23902391
std::vector<std::string> &files;
23912392

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

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

0 commit comments

Comments
 (0)