Skip to content

Commit 75ef0af

Browse files
committed
Fix issue with decl stmt being added multiple times
1 parent ef56721 commit 75ef0af

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

src/policy_classes/DeclTypePolicySingleEvent.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public srcSAXEventDispatch::PolicyListener {
102102
// start of policy
103103
openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) {
104104
if (!declDepth) {
105+
data.clear();
105106
declDepth = ctx.depth;
106107
CollectTypeHandlers();
107108
CollectNameHandlers();

src/policy_classes/FunctionPolicySingleEvent.hpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public srcSAXEventDispatch::PolicyListener {
152152
void InitializeFunctionPolicyHandlers() {
153153
using namespace srcSAXEventDispatch;
154154
// start of policy
155-
std::function<void (srcSAXEventContext& ctx)> functionStart = [this](srcSAXEventContext& ctx) {
155+
std::function<void (srcSAXEventContext& ctx)> startFunction = [this](srcSAXEventContext& ctx) {
156156
if (!functionDepth) {
157157
functionDepth = ctx.depth;
158158
data = FunctionData{};
@@ -187,27 +187,27 @@ public srcSAXEventDispatch::PolicyListener {
187187
};
188188

189189
// end of policy
190-
std::function<void (srcSAXEventContext& ctx)> functionEnd = [this](srcSAXEventContext& ctx) {
190+
std::function<void (srcSAXEventContext& ctx)> endFunction = [this](srcSAXEventContext& ctx) {
191191
if (functionDepth && functionDepth == ctx.depth) {
192192
functionDepth = 0;
193193
NotifyAll(ctx);
194194
InitializeFunctionPolicyHandlers();
195195
}
196196
};
197197

198-
openEventMap[ParserState::function] = functionStart;
199-
openEventMap[ParserState::functiondecl] = functionStart;
200-
openEventMap[ParserState::constructor] = functionStart;
201-
openEventMap[ParserState::constructordecl] = functionStart;
202-
openEventMap[ParserState::destructor] = functionStart;
203-
openEventMap[ParserState::destructordecl] = functionStart;
204-
205-
closeEventMap[ParserState::function] = functionEnd;
206-
closeEventMap[ParserState::functiondecl] = functionEnd;
207-
closeEventMap[ParserState::constructor] = functionEnd;
208-
closeEventMap[ParserState::constructordecl] = functionEnd;
209-
closeEventMap[ParserState::destructor] = functionEnd;
210-
closeEventMap[ParserState::destructordecl] = functionEnd;
198+
openEventMap[ParserState::function] = startFunction;
199+
openEventMap[ParserState::functiondecl] = startFunction;
200+
openEventMap[ParserState::constructor] = startFunction;
201+
openEventMap[ParserState::constructordecl] = startFunction;
202+
openEventMap[ParserState::destructor] = startFunction;
203+
openEventMap[ParserState::destructordecl] = startFunction;
204+
205+
closeEventMap[ParserState::function] = endFunction;
206+
closeEventMap[ParserState::functiondecl] = endFunction;
207+
closeEventMap[ParserState::constructor] = endFunction;
208+
closeEventMap[ParserState::constructordecl] = endFunction;
209+
closeEventMap[ParserState::destructor] = endFunction;
210+
closeEventMap[ParserState::destructordecl] = endFunction;
211211
}
212212

213213
void CollectXMLAttributeHandlers() {}

src/policy_classes/UnitPolicySingleEvent.hpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,30 @@ class UnitPolicySingleEvent :
7272
openEventMap[ParserState::structn] = startClassPolicy;
7373
closeEventMap[ParserState::structn] = endClassPolicy;
7474

75-
// start functionof policy
76-
openEventMap[ParserState::function] = [this](srcSAXEventContext& ctx) {
75+
// start function of policy
76+
std::function<void(srcSAXEventDispatch::srcSAXEventContext&)> startFunction = [this](srcSAXEventContext& ctx) {
7777
if(!functionPolicy) functionPolicy = new FunctionPolicy{this};
7878
ctx.dispatcher->AddListenerDispatch(functionPolicy);
7979
};
8080

8181
// end of policy
82-
closeEventMap[ParserState::function] = [this](srcSAXEventContext& ctx) {
82+
std::function<void(srcSAXEventDispatch::srcSAXEventContext&)> endFunction = [this](srcSAXEventContext& ctx) {
8383
};
84+
85+
openEventMap[ParserState::function] = startFunction;
86+
openEventMap[ParserState::functiondecl] = startFunction;
87+
openEventMap[ParserState::constructor] = startFunction;
88+
openEventMap[ParserState::constructordecl] = startFunction;
89+
openEventMap[ParserState::destructor] = startFunction;
90+
openEventMap[ParserState::destructordecl] = startFunction;
91+
92+
closeEventMap[ParserState::function] = endFunction;
93+
closeEventMap[ParserState::functiondecl] = endFunction;
94+
closeEventMap[ParserState::constructor] = endFunction;
95+
closeEventMap[ParserState::constructordecl] = endFunction;
96+
closeEventMap[ParserState::destructor] = endFunction;
97+
closeEventMap[ParserState::destructordecl] = endFunction;
98+
8499
}
85100
};
86101

0 commit comments

Comments
 (0)