Skip to content

Commit 99b76f9

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

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

simplecpp.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,9 +1486,9 @@ namespace simplecpp {
14861486

14871487
class Macro {
14881488
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) {}
1489+
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) {}
14901490

1491-
Macro(const Token *tok, std::vector<std::string> &f) : nameTokDef(nullptr), files(f), tokenListDefine(f), valueDefinedInCode_(true) {
1491+
Macro(const Token *tok, std::vector<std::string> &f) : nameTokDef(nullptr), files(f), tokenListDefine(new TokenList(f)), valueDefinedInCode_(true) {
14921492
if (sameline(tok->previousSkipComments(), tok))
14931493
throw std::runtime_error("bad macro syntax");
14941494
if (tok->op != '#')
@@ -1504,15 +1504,15 @@ namespace simplecpp {
15041504
throw std::runtime_error("bad macro syntax");
15051505
}
15061506

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

1515-
Macro(const Macro &other) : nameTokDef(nullptr), files(other.files), tokenListDefine(other.files), valueDefinedInCode_(other.valueDefinedInCode_) {
1515+
Macro(const Macro &other) : nameTokDef(nullptr), files(other.files), tokenListDefine(other.tokenListDefine), valueDefinedInCode_(other.valueDefinedInCode_) {
15161516
// TODO: remove the try-catch - see #537
15171517
// avoid bugprone-exception-escape clang-tidy warning
15181518
try {
@@ -1530,11 +1530,11 @@ namespace simplecpp {
15301530
if (this != &other) {
15311531
files = other.files;
15321532
valueDefinedInCode_ = other.valueDefinedInCode_;
1533-
if (other.tokenListDefine.empty())
1533+
if (other.tokenListDefine->empty())
15341534
parseDefine(other.nameTokDef);
15351535
else {
15361536
tokenListDefine = other.tokenListDefine;
1537-
parseDefine(tokenListDefine.cfront());
1537+
parseDefine(tokenListDefine->cfront());
15381538
}
15391539
usageList = other.usageList;
15401540
}
@@ -2390,7 +2390,7 @@ namespace simplecpp {
23902390
std::vector<std::string> &files;
23912391

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

23952395
/** usage of this macro */
23962396
mutable std::list<Location> usageList;

0 commit comments

Comments
 (0)