From c693cd374f0ed8b44b5c3e94932e7dfab5e9fb03 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 9 Oct 2024 11:24:39 +0900 Subject: [PATCH 001/149] Fix default init of name and add blocks to some conditionals --- src/policy_classes/ClassPolicySingleEvent.hpp | 3 +- .../FunctionPolicySingleEvent.hpp | 3 +- src/policy_classes/TypePolicySingleEvent.cpp | 28 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index 1442b09..560a2eb 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -93,8 +93,9 @@ public srcSAXEventDispatch::PolicyListener { ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(DeclTypePolicy) == typeid(*policy)) { std::shared_ptr>> decl_data = policy->Data>>(); - for (std::shared_ptr decl : *decl_data) + for (std::shared_ptr decl : *decl_data) { data.fields[currentRegion].emplace_back(decl); + } decl_data->clear(); ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(FunctionPolicy) == typeid(*policy)) { diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index d14b061..ba9c3a1 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -135,8 +135,9 @@ public srcSAXEventDispatch::PolicyListener { ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(DeclTypePolicy) == typeid(*policy)) { std::shared_ptr>> decl_data = policy->Data>>(); - for(std::shared_ptr decl : *decl_data) + for(std::shared_ptr decl : *decl_data) { data.locals.push_back(decl); + } decl_data->clear(); ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(ReturnPolicy) == typeid(*policy)) { diff --git a/src/policy_classes/TypePolicySingleEvent.cpp b/src/policy_classes/TypePolicySingleEvent.cpp index 82c930e..f902099 100644 --- a/src/policy_classes/TypePolicySingleEvent.cpp +++ b/src/policy_classes/TypePolicySingleEvent.cpp @@ -10,38 +10,36 @@ std::string TypeData::ToString() const { for (std::size_t pos = 0; pos < types.size(); ++pos) { if (pos != 0) type_str += ' '; const std::pair & type = types[pos]; - if (type.second == TypeData::POINTER) + if (type.second == TypeData::POINTER) { type_str += '*'; - else if (type.second == TypeData::REFERENCE) + } else if (type.second == TypeData::REFERENCE) { type_str += '&'; - else if (type.second == TypeData::RVALUE) + } else if (type.second == TypeData::RVALUE) { type_str += "&&"; - else if (type.second == TypeData::SPECIFIER) + } else if (type.second == TypeData::SPECIFIER) { type_str += *std::any_cast>(type.first); - else if (type.second == TypeData::TYPENAME) + } else if (type.second == TypeData::TYPENAME) { type_str += std::any_cast>(type.first)->ToString(); + } } return type_str; } std::ostream & operator<<(std::ostream & out, const TypeData & typeData) { - //std::cerr << "TPSE\n"; - //std::cerr << "TPSE Size: " << typeData.types.empty() << '\n'; - //std::cerr << "TACO\n"; for(std::size_t pos = 0; pos < typeData.types.size(); ++pos) { - //std::cerr << "TPSE2\n"; if (pos != 0) out << ' '; const std::pair & type = typeData.types[pos]; - if (type.second == TypeData::POINTER) + if (type.second == TypeData::POINTER) { out << '*'; - else if (type.second == TypeData::REFERENCE) + } else if (type.second == TypeData::REFERENCE) { out << '&'; - else if (type.second == TypeData::RVALUE) + } else if (type.second == TypeData::RVALUE) { out << "&&"; - else if (type.second == TypeData::SPECIFIER) + } else if (type.second == TypeData::SPECIFIER) { out << *std::any_cast>(type.first); - else if (type.second == TypeData::TYPENAME) + } else if (type.second == TypeData::TYPENAME) { out << *std::any_cast>(type.first); + } } return out; } @@ -99,7 +97,7 @@ void TypePolicy::CollectNamesHandler() { using namespace srcSAXEventDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if (typeDepth && (typeDepth + 1) == ctx.depth) { - data.types.push_back(std::make_pair(nullptr, TypeData::TYPENAME)); + data.types.push_back(std::make_pair(std::shared_ptr(), TypeData::TYPENAME)); if (!namePolicy) namePolicy = new NamePolicy{this}; ctx.dispatcher->AddListenerDispatch(namePolicy); } From a6caf04da796e502139180f621d844c4de90dde1 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 9 Oct 2024 12:57:55 +0900 Subject: [PATCH 002/149] Fix spelling of destructor --- src/policy_classes/FunctionPolicySingleEvent.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index ba9c3a1..640e613 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -23,7 +23,7 @@ #include struct FunctionData { - enum FunctionType { CONSTRUCTOR, DESTURCTOR, OPERATOR, FUNCTION }; + enum FunctionType { CONSTRUCTOR, DESTRUCTOR, OPERATOR, FUNCTION }; unsigned int lineNumber; std::string language; @@ -173,7 +173,7 @@ public srcSAXEventDispatch::PolicyListener { } else if (ctx.currentTag == "constructor" || ctx.currentTag == "constructor_decl") { data.type = FunctionData::CONSTRUCTOR; } else if (ctx.currentTag == "destructor" || ctx.currentTag == "destructor_decl") { - data.type = FunctionData::DESTURCTOR; + data.type = FunctionData::DESTRUCTOR; } CollectXMLAttributeHandlers(); From 47d2453a45268090fc42468212c9e4e2423d50c0 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 9 Oct 2024 13:35:32 +0900 Subject: [PATCH 003/149] Fix expecting an expr in index that might not be there --- src/policy_classes/ExpressionPolicySingleEvent.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/policy_classes/ExpressionPolicySingleEvent.cpp b/src/policy_classes/ExpressionPolicySingleEvent.cpp index 55a40d6..37e2bed 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.cpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.cpp @@ -12,7 +12,6 @@ std::ostream & operator<<(std::ostream & out, const Token & token) { std::ostream & operator<<(std::ostream & out, const ExpressionData & ex) { for (std::shared_ptr item : ex.expr) { - //out << " Type " << item->type << " "; switch (item->type) { case ExpressionElement::NAME: out << *item->name; break; case ExpressionElement::OP: out << *item->token; break; @@ -32,7 +31,6 @@ ExpressionPolicy::~ExpressionPolicy() { void ExpressionPolicy::Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) { if(typeid(NamePolicy) == typeid(*policy)) { data.expr.push_back(std::make_shared(ExpressionElement::NAME, policy->Data())); - //std::cerr << "Return Name found: " << *(data.expr.back())->name << std::endl; ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if(typeid(CallPolicy) == typeid(*policy)) { data.expr.push_back(std::make_shared(ExpressionElement::CALL, policy->Data())); From 52cc184118ea4875713c74595db4f794a1aa59d1 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 9 Oct 2024 13:42:05 +0900 Subject: [PATCH 004/149] Fix return having unassigned shared_ptr intead of empty expr data --- src/policy_classes/ReturnPolicySingleEvent.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/policy_classes/ReturnPolicySingleEvent.hpp b/src/policy_classes/ReturnPolicySingleEvent.hpp index f5c1ba4..715928d 100644 --- a/src/policy_classes/ReturnPolicySingleEvent.hpp +++ b/src/policy_classes/ReturnPolicySingleEvent.hpp @@ -61,7 +61,7 @@ public srcSAXEventDispatch::PolicyListener { openEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { if (!returnDepth) { returnDepth = ctx.depth; - data = std::shared_ptr(); + data = std::make_shared(); CollectExpressionHandlers(); } }; From e26caf62ef4a2d5a07503fff0db22215c62937c5 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 9 Oct 2024 13:50:29 +0900 Subject: [PATCH 005/149] Fix another issue with expecting expr --- src/policy_classes/DeclTypePolicySingleEvent.hpp | 10 ++++++---- src/policy_classes/ExpressionPolicySingleEvent.cpp | 1 - src/policy_classes/NamePolicySingleEvent.cpp | 6 ++++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/policy_classes/DeclTypePolicySingleEvent.hpp b/src/policy_classes/DeclTypePolicySingleEvent.hpp index fa3d332..5aa28e4 100644 --- a/src/policy_classes/DeclTypePolicySingleEvent.hpp +++ b/src/policy_classes/DeclTypePolicySingleEvent.hpp @@ -102,7 +102,6 @@ public srcSAXEventDispatch::PolicyListener { // start of policy openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { if (!declDepth) { - data.clear(); declDepth = ctx.depth; CollectTypeHandlers(); CollectNameHandlers(); @@ -127,7 +126,8 @@ public srcSAXEventDispatch::PolicyListener { closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { if (declDepth && declDepth == ctx.depth) { declDepth = 0; - NotifyAll(ctx); + NotifyAll(ctx); + data.clear(); InitializeDeclTypePolicyHandlers(); } }; @@ -173,8 +173,10 @@ public srcSAXEventDispatch::PolicyListener { void CollectInitHandlers() { using namespace srcSAXEventDispatch; openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { - if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(expressionPolicy); + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(expressionPolicy); + }; }; } diff --git a/src/policy_classes/ExpressionPolicySingleEvent.cpp b/src/policy_classes/ExpressionPolicySingleEvent.cpp index 37e2bed..663a87d 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.cpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.cpp @@ -5,7 +5,6 @@ #include - std::ostream & operator<<(std::ostream & out, const Token & token) { return out << token.token; } diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index ad16889..4829c99 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -123,8 +123,10 @@ void NamePolicy::CollectTemplateArgumentsHandlers() { void NamePolicy::CollectArrayIndicesHandlers() { using namespace srcSAXEventDispatch; openEventMap[ParserState::index] = [this](srcSAXEventContext& ctx) { - if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(expressionPolicy); + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(expressionPolicy); + }; }; } From 59df9da55e8d1925528e470bb069a19f4516b464 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 9 Oct 2024 14:18:19 +0900 Subject: [PATCH 006/149] Check there is a type before printing --- src/policy_classes/DeclTypePolicySingleEvent.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/policy_classes/DeclTypePolicySingleEvent.hpp b/src/policy_classes/DeclTypePolicySingleEvent.hpp index 5aa28e4..65e48de 100644 --- a/src/policy_classes/DeclTypePolicySingleEvent.hpp +++ b/src/policy_classes/DeclTypePolicySingleEvent.hpp @@ -31,11 +31,15 @@ struct DeclTypeData { bool isStatic; friend std::ostream & operator<<(std::ostream & out, const DeclTypeData & declData) { - out << declData.type->ToString(); - if (declData.name) + if(declData.type) { + out << declData.type->ToString(); + } + if (declData.name) { out << ' ' << *declData.name; - if (declData.initializer) + } + if (declData.initializer) { out << " = " << *declData.initializer; + } return out; } }; From 37a4f2c0ef9d4bcc883b7eb5d46b1fc6604507a4 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 9 Oct 2024 22:32:54 +0900 Subject: [PATCH 007/149] Add tracking if function-type is declared --- .../FunctionPolicySingleEvent.hpp | 387 +++++++++--------- 1 file changed, 196 insertions(+), 191 deletions(-) diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index 640e613..0b6d168 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -29,6 +29,7 @@ struct FunctionData { std::string language; std::string filename; FunctionType type; + bool isDecl; std::shared_ptr returnType; std::shared_ptr name; std::vector> parameters; @@ -85,173 +86,177 @@ public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { private: - FunctionData data; - std::size_t functionDepth; + FunctionData data; + std::size_t functionDepth; - TypePolicy *typePolicy; - NamePolicy *namePolicy; - ParamTypePolicy *paramPolicy; - DeclTypePolicy *declstmtPolicy; + TypePolicy *typePolicy; + NamePolicy *namePolicy; + ParamTypePolicy *paramPolicy; + DeclTypePolicy *declstmtPolicy; ReturnPolicy *returnPolicy; ExpressionPolicy *expressionPolicy; public: - FunctionPolicy(std::initializer_list listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), - data{}, - functionDepth(0), - typePolicy(nullptr), - namePolicy(nullptr), - paramPolicy(nullptr), - declstmtPolicy(nullptr), + FunctionPolicy(std::initializer_list listeners) + : srcSAXEventDispatch::PolicyDispatcher(listeners), + data{}, + functionDepth(0), + typePolicy(nullptr), + namePolicy(nullptr), + paramPolicy(nullptr), + declstmtPolicy(nullptr), expressionPolicy(nullptr), returnPolicy(nullptr) { - InitializeFunctionPolicyHandlers(); - } - - ~FunctionPolicy() { - if (typePolicy) delete typePolicy; - if (namePolicy) delete namePolicy; - if (paramPolicy) delete paramPolicy; - if (declstmtPolicy) delete declstmtPolicy; + InitializeFunctionPolicyHandlers(); + } + + ~FunctionPolicy() { + if (typePolicy) delete typePolicy; + if (namePolicy) delete namePolicy; + if (paramPolicy) delete paramPolicy; + if (declstmtPolicy) delete declstmtPolicy; if (returnPolicy) delete returnPolicy; if (expressionPolicy) delete expressionPolicy; - } + } protected: - std::any DataInner() const override { return std::make_shared(data); } - - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - if (typeid(TypePolicy) == typeid(*policy)) { - data.returnType = policy->Data(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - } else if (typeid(NamePolicy) == typeid(*policy)) { - data.name = policy->Data(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - } else if (typeid(ParamTypePolicy) == typeid(*policy)) { - data.parameters.push_back(policy->Data()); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - } else if (typeid(DeclTypePolicy) == typeid(*policy)) { - std::shared_ptr>> decl_data = policy->Data>>(); - for(std::shared_ptr decl : *decl_data) { - data.locals.push_back(decl); - } - decl_data->clear(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - } else if (typeid(ReturnPolicy) == typeid(*policy)) { + std::any DataInner() const override { return std::make_shared(data); } + + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + + virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { + if (typeid(TypePolicy) == typeid(*policy)) { + data.returnType = policy->Data(); + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } else if (typeid(NamePolicy) == typeid(*policy)) { + data.name = policy->Data(); + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } else if (typeid(ParamTypePolicy) == typeid(*policy)) { + data.parameters.push_back(policy->Data()); + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } else if (typeid(DeclTypePolicy) == typeid(*policy)) { + std::shared_ptr>> decl_data = policy->Data>>(); + for(std::shared_ptr decl : *decl_data) { + data.locals.push_back(decl); + } + decl_data->clear(); + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } else if (typeid(ReturnPolicy) == typeid(*policy)) { data.returnExpressions.push_back(policy->Data()); ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(ExpressionPolicy) == typeid(*policy)) { data.expressions.push_back(policy->Data()); ctx.dispatcher->RemoveListenerDispatch(nullptr); } - } + } private: - void InitializeFunctionPolicyHandlers() { - using namespace srcSAXEventDispatch; - // start of policy - std::function startFunction = [this](srcSAXEventContext& ctx) { - if (!functionDepth) { - functionDepth = ctx.depth; - data = FunctionData{}; - data.lineNumber = ctx.currentLineNumber; + void InitializeFunctionPolicyHandlers() { + using namespace srcSAXEventDispatch; + // start of policy + std::function startFunction = [this](srcSAXEventContext& ctx) { + if (!functionDepth) { + functionDepth = ctx.depth; + data = FunctionData{}; + data.lineNumber = ctx.currentLineNumber; data.language = ctx.currentFileLanguage; data.filename = ctx.currentFilePath; - std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); - if (stereotype_attr_itr != ctx.attributes.end()){ - std::istringstream stereostring(stereotype_attr_itr->second); - data.stereotypes = std::set(std::istream_iterator(stereostring), std::istream_iterator()); - } - if (ctx.currentTag == "function" || ctx.currentTag == "function_decl") { - if (ctx.isOperator) - data.type = FunctionData::OPERATOR; - else - data.type = FunctionData::FUNCTION; - } else if (ctx.currentTag == "constructor" || ctx.currentTag == "constructor_decl") { - data.type = FunctionData::CONSTRUCTOR; - } else if (ctx.currentTag == "destructor" || ctx.currentTag == "destructor_decl") { - data.type = FunctionData::DESTRUCTOR; - } - - CollectXMLAttributeHandlers(); - CollectTypeHandlers(); - CollectNameHandlers(); - CollectParameterHandlers(); - CollectOtherHandlers(); - CollectDeclstmtHandlers(); + std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); + if (stereotype_attr_itr != ctx.attributes.end()){ + std::istringstream stereostring(stereotype_attr_itr->second); + data.stereotypes = std::set(std::istream_iterator(stereostring), std::istream_iterator()); + } + if (ctx.currentTag == "function" || ctx.currentTag == "function_decl") { + if (ctx.isOperator) + data.type = FunctionData::OPERATOR; + else + data.type = FunctionData::FUNCTION; + } else if (ctx.currentTag == "constructor" || ctx.currentTag == "constructor_decl") { + data.type = FunctionData::CONSTRUCTOR; + } else if (ctx.currentTag == "destructor" || ctx.currentTag == "destructor_decl") { + data.type = FunctionData::DESTRUCTOR; + } + + data.isDecl = ctx.currentTag == "function_decl" + || ctx.currentTag == "constructor_decl" + || ctx.currentTag == "destructor_decl"; + + CollectXMLAttributeHandlers(); + CollectTypeHandlers(); + CollectNameHandlers(); + CollectParameterHandlers(); + CollectOtherHandlers(); + CollectDeclstmtHandlers(); CollectReturnHandlers(); CollectExpressionHandlers(); - } - }; - - // end of policy - std::function endFunction = [this](srcSAXEventContext& ctx) { - if (functionDepth && functionDepth == ctx.depth) { - functionDepth = 0; - NotifyAll(ctx); - InitializeFunctionPolicyHandlers(); - } - }; - - openEventMap[ParserState::function] = startFunction; - openEventMap[ParserState::functiondecl] = startFunction; - openEventMap[ParserState::constructor] = startFunction; - openEventMap[ParserState::constructordecl] = startFunction; - openEventMap[ParserState::destructor] = startFunction; - openEventMap[ParserState::destructordecl] = startFunction; - - closeEventMap[ParserState::function] = endFunction; - closeEventMap[ParserState::functiondecl] = endFunction; - closeEventMap[ParserState::constructor] = endFunction; - closeEventMap[ParserState::constructordecl] = endFunction; - closeEventMap[ParserState::destructor] = endFunction; - closeEventMap[ParserState::destructordecl] = endFunction; - } - - void CollectXMLAttributeHandlers() {} - - void CollectTypeHandlers() { - using namespace srcSAXEventDispatch; - openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - if (!typePolicy) typePolicy = new TypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(typePolicy); - } - }; - } - - void CollectNameHandlers() { - using namespace srcSAXEventDispatch; - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - if (!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); - } - }; - } - - void CollectParameterHandlers() { - using namespace srcSAXEventDispatch; - openEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 2) == ctx.depth) { - if (!paramPolicy) paramPolicy = new ParamTypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(paramPolicy); - } - }; - } - }; - - closeEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - NopOpenEvents({ParserState::parameter}); - } - }; - } + } + }; + + // end of policy + std::function endFunction = [this](srcSAXEventContext& ctx) { + if (functionDepth && functionDepth == ctx.depth) { + functionDepth = 0; + NotifyAll(ctx); + InitializeFunctionPolicyHandlers(); + } + }; + + openEventMap[ParserState::function] = startFunction; + openEventMap[ParserState::functiondecl] = startFunction; + openEventMap[ParserState::constructor] = startFunction; + openEventMap[ParserState::constructordecl] = startFunction; + openEventMap[ParserState::destructor] = startFunction; + openEventMap[ParserState::destructordecl] = startFunction; + + closeEventMap[ParserState::function] = endFunction; + closeEventMap[ParserState::functiondecl] = endFunction; + closeEventMap[ParserState::constructor] = endFunction; + closeEventMap[ParserState::constructordecl] = endFunction; + closeEventMap[ParserState::destructor] = endFunction; + closeEventMap[ParserState::destructordecl] = endFunction; + } + + void CollectXMLAttributeHandlers() {} + + void CollectTypeHandlers() { + using namespace srcSAXEventDispatch; + openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { + if (functionDepth && (functionDepth + 1) == ctx.depth) { + if (!typePolicy) typePolicy = new TypePolicy{this}; + ctx.dispatcher->AddListenerDispatch(typePolicy); + } + }; + } + + void CollectNameHandlers() { + using namespace srcSAXEventDispatch; + openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { + if (functionDepth && (functionDepth + 1) == ctx.depth) { + if (!namePolicy) namePolicy = new NamePolicy{this}; + ctx.dispatcher->AddListenerDispatch(namePolicy); + } + }; + } + + void CollectParameterHandlers() { + using namespace srcSAXEventDispatch; + openEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { + if (functionDepth && (functionDepth + 1) == ctx.depth) { + openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { + if (functionDepth && (functionDepth + 2) == ctx.depth) { + if (!paramPolicy) paramPolicy = new ParamTypePolicy{this}; + ctx.dispatcher->AddListenerDispatch(paramPolicy); + } + }; + } + }; + + closeEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { + if (functionDepth && (functionDepth + 1) == ctx.depth) { + NopOpenEvents({ParserState::parameter}); + } + }; + } void CollectReturnHandlers() { using namespace srcSAXEventDispatch; @@ -269,53 +274,53 @@ public srcSAXEventDispatch::PolicyListener { }; } - void CollectOtherHandlers() { - using namespace srcSAXEventDispatch; - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - if (ctx.And({ParserState::specifier})) { - if (ctx.currentToken == "virtual") - data.isVirtual = true; - else if (ctx.currentToken == "static") - data.isStatic = true; - else if (ctx.currentToken == "const") - data.isConst = true; - else if (ctx.currentToken == "final") - data.isFinal = true; - else if (ctx.currentToken == "override") - data.isOverride = true; - else if (ctx.currentToken == "delete") - data.isDelete = true; - else if (ctx.currentToken == "inline") - data.isInline = true; - else if (ctx.currentToken == "constexpr") - data.isConstExpr = true; - } else if (ctx.And({ParserState::literal})) { - data.isPureVirtual = true; - } - } - }; - } - - /** @todo Will not work with local classes. */ - /** @todo May need to add optimization that ignores declaration statement initialization. */ - void CollectDeclstmtHandlers(){ - using namespace srcSAXEventDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - if (!declstmtPolicy) declstmtPolicy = new DeclTypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(declstmtPolicy); - }; - } - }; - - closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - NopOpenEvents({ParserState::declstmt}); - } - }; - } + void CollectOtherHandlers() { + using namespace srcSAXEventDispatch; + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { + if (functionDepth && (functionDepth + 1) == ctx.depth) { + if (ctx.And({ParserState::specifier})) { + if (ctx.currentToken == "virtual") + data.isVirtual = true; + else if (ctx.currentToken == "static") + data.isStatic = true; + else if (ctx.currentToken == "const") + data.isConst = true; + else if (ctx.currentToken == "final") + data.isFinal = true; + else if (ctx.currentToken == "override") + data.isOverride = true; + else if (ctx.currentToken == "delete") + data.isDelete = true; + else if (ctx.currentToken == "inline") + data.isInline = true; + else if (ctx.currentToken == "constexpr") + data.isConstExpr = true; + } else if (ctx.And({ParserState::literal})) { + data.isPureVirtual = true; + } + } + }; + } + + /** @todo Will not work with local classes. */ + /** @todo May need to add optimization that ignores declaration statement initialization. */ + void CollectDeclstmtHandlers(){ + using namespace srcSAXEventDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if (functionDepth && (functionDepth + 1) == ctx.depth) { + openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { + if (!declstmtPolicy) declstmtPolicy = new DeclTypePolicy{this}; + ctx.dispatcher->AddListenerDispatch(declstmtPolicy); + }; + } + }; + + closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if (functionDepth && (functionDepth + 1) == ctx.depth) { + NopOpenEvents({ParserState::declstmt}); + } + }; + } }; From 455929e6012b4c32aebf7394b520f9f2882c09ce Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 10 Oct 2024 05:01:00 +0900 Subject: [PATCH 008/149] Remove uneeded clear --- src/policy_classes/FunctionPolicySingleEvent.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index 0b6d168..829041e 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -139,7 +139,6 @@ public srcSAXEventDispatch::PolicyListener { for(std::shared_ptr decl : *decl_data) { data.locals.push_back(decl); } - decl_data->clear(); ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(ReturnPolicy) == typeid(*policy)) { data.returnExpressions.push_back(policy->Data()); From a0822c6baeaf796b710c156b155ecaad5eb3feb4 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 10 Oct 2024 07:14:01 +0900 Subject: [PATCH 009/149] Always push and pop namespaces --- src/dispatcher/srcSAXEventDispatcher.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/dispatcher/srcSAXEventDispatcher.hpp b/src/dispatcher/srcSAXEventDispatcher.hpp index 68708a4..d97aa33 100644 --- a/src/dispatcher/srcSAXEventDispatcher.hpp +++ b/src/dispatcher/srcSAXEventDispatcher.hpp @@ -317,7 +317,6 @@ namespace srcSAXEventDispatch { DispatchEvent(ParserState::structn, ElementState::open); } }, { "namespace", [this](){ - // classflagopen = true; ++ctx.triggerField[ParserState::namespacen]; DispatchEvent(ParserState::namespacen, ElementState::open); } }, @@ -641,7 +640,6 @@ namespace srcSAXEventDispatch { } }, { "namespace", [this](){ DispatchEvent(ParserState::namespacen, ElementState::close); - ctx.currentNamespaces.pop_back(); --ctx.triggerField[ParserState::namespacen]; } }, { "super_list", [this](){ @@ -1012,8 +1010,7 @@ namespace srcSAXEventDispatch { return false; }) ? ctx.currentToken : ""; - if (namespaceName != "") - ctx.currentNamespaces.push_back(namespaceName); + ctx.currentNamespaces.push_back(namespaceName); } if((ctx.And({ParserState::name, ParserState::function}) || ctx.And({ParserState::name, ParserState::constructor})) && ctx.Nor({ParserState::functionblock, ParserState::type, ParserState::parameterlist, ParserState::genericargumentlist, ParserState::constructorblock, ParserState::throws, ParserState::annotation})){ @@ -1064,6 +1061,10 @@ namespace srcSAXEventDispatch { process2->second(); } + if(ctx.currentTag == "namespace") { + ctx.currentNamespaces.pop_back(); + } + --ctx.depth; if (generateArchive) { xmlTextWriterEndElement(ctx.writer); } @@ -1072,4 +1073,4 @@ namespace srcSAXEventDispatch { }; } -#endif \ No newline at end of file +#endif From a962098241f3eb11eba7e70ae7f9777227556955 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 10 Oct 2024 07:19:23 +0900 Subject: [PATCH 010/149] Fix spacing --- src/dispatcher/srcSAXEventDispatcher.hpp | 332 +++++++++++------------ 1 file changed, 166 insertions(+), 166 deletions(-) diff --git a/src/dispatcher/srcSAXEventDispatcher.hpp b/src/dispatcher/srcSAXEventDispatcher.hpp index d97aa33..b870b38 100644 --- a/src/dispatcher/srcSAXEventDispatcher.hpp +++ b/src/dispatcher/srcSAXEventDispatcher.hpp @@ -86,10 +86,10 @@ namespace srcSAXEventDispatch { currentPState = pstate; currentEState = estate; - for(std::list::iterator listener = elementListeners.begin(); listener != elementListeners.end(); ++listener ){ + for(std::list::iterator listener = elementListeners.begin(); listener != elementListeners.end(); ++listener ) { (*listener)->HandleEvent(pstate, estate, ctx); } - for(std::list::iterator listener = elementListeners.begin(); listener != elementListeners.end(); ++listener ){ + for(std::list::iterator listener = elementListeners.begin(); listener != elementListeners.end(); ++listener ) { (*listener)->SetDispatched(false); } @@ -118,7 +118,7 @@ namespace srcSAXEventDispatch { virtual void AddEvents(std::initializer_list events) { - for(const std::string & event : events){ + for(const std::string & event : events) { AddEvent(event); } @@ -131,7 +131,7 @@ namespace srcSAXEventDispatch { virtual void RemoveEvents(std::initializer_list events) { - for(const std::string & event : events){ + for(const std::string & event : events) { RemoveEvent(event); } @@ -175,13 +175,13 @@ namespace srcSAXEventDispatch { elementListeners.push_back(listener); } void AddListenerDispatch(EventListener* listener) override { - if(dispatching){ + if(dispatching) { listener->HandleEvent(currentPState, currentEState, ctx); } AddListener(listener); } void AddListenerNoDispatch(EventListener* listener) override { - if(dispatching){ + if(dispatching) { listener->SetDispatched(true); } AddListener(listener); @@ -190,57 +190,57 @@ namespace srcSAXEventDispatch { elementListeners.erase(std::find(elementListeners.begin(), elementListeners.end(), listener)); } void RemoveListenerDispatch(EventListener* listener) override { - if(dispatching){ + if(dispatching) { listener->HandleEvent(currentPState, currentEState, ctx); } RemoveListener(listener); } void RemoveListenerNoDispatch(EventListener* listener) override { - if(dispatching){ + if(dispatching) { listener->SetDispatched(true); } RemoveListener(listener); } - void InitializeHandlers(){ + void InitializeHandlers() { process_map = { - {"decl_stmt", [this](){ + {"decl_stmt", [this]() { ++ctx.triggerField[ParserState::declstmt]; DispatchEvent(ParserState::declstmt, ElementState::open); } }, - { "expr_stmt", [this](){ + { "expr_stmt", [this]() { ++ctx.triggerField[ParserState::exprstmt]; DispatchEvent(ParserState::exprstmt, ElementState::open); } }, - { "parameter_list", [this](){ + { "parameter_list", [this]() { ++ctx.triggerField[ParserState::parameterlist]; DispatchEvent(ParserState::parameterlist, ElementState::open); } }, - { "condition", [this](){ + { "condition", [this]() { ++ctx.triggerField[ParserState::condition]; DispatchEvent(ParserState::condition, ElementState::open); } }, - { "switch", [this](){ + { "switch", [this]() { ++ctx.triggerField[ParserState::switchstmt]; DispatchEvent(ParserState::switchstmt, ElementState::open); } }, - { "case", [this](){ + { "case", [this]() { ++ctx.triggerField[ParserState::switchcase]; DispatchEvent(ParserState::switchcase, ElementState::open); } }, - { "do", [this](){ + { "do", [this]() { ++ctx.triggerField[ParserState::dostmt]; DispatchEvent(ParserState::dostmt, ElementState::open); } }, - { "incr", [this](){ + { "incr", [this]() { ++ctx.triggerField[ParserState::incr]; DispatchEvent(ParserState::incr, ElementState::open); } }, - { "decr", [this](){ + { "decr", [this]() { ++ctx.triggerField[ParserState::decr]; DispatchEvent(ParserState::decr, ElementState::open); } }, - { "if", [this](){ - if(!ifelseflagopen){ + { "if", [this]() { + if(!ifelseflagopen) { ifflagopen = true; ++ctx.triggerField[ParserState::ifstmt]; DispatchEvent(ParserState::ifstmt, ElementState::open); @@ -249,30 +249,30 @@ namespace srcSAXEventDispatch { DispatchEvent(ParserState::elseif, ElementState::open); } } }, - { "else", [this](){ + { "else", [this]() { ++ctx.triggerField[ParserState::elsestmt]; DispatchEvent(ParserState::elsestmt, ElementState::open); } }, - { "for", [this](){ + { "for", [this]() { ++ctx.triggerField[ParserState::forstmt]; DispatchEvent(ParserState::forstmt, ElementState::open); } }, - { "control", [this](){ + { "control", [this]() { ++ctx.triggerField[ParserState::control]; DispatchEvent(ParserState::control, ElementState::open); } }, - { "while", [this](){ + { "while", [this]() { whileflagopen = true; ++ctx.triggerField[ParserState::whilestmt]; DispatchEvent(ParserState::whilestmt, ElementState::open); } }, - { "template", [this](){ + { "template", [this]() { ++ctx.triggerField[ParserState::templates]; DispatchEvent(ParserState::templates, ElementState::open); } }, - { "argument_list", [this](){ - if(!ctx.genericDepth.empty()){ - if(ctx.genericDepth.back() == ctx.depth){ + { "argument_list", [this]() { + if(!ctx.genericDepth.empty()) { + if(ctx.genericDepth.back() == ctx.depth) { ++ctx.triggerField[ParserState::genericargumentlist]; DispatchEvent(ParserState::genericargumentlist, ElementState::open); } @@ -280,138 +280,138 @@ namespace srcSAXEventDispatch { DispatchEvent(ParserState::argumentlist, ElementState::open); ++ctx.triggerField[ParserState::argumentlist]; } }, - { "call", [this](){ + { "call", [this]() { ++ctx.triggerField[ParserState::call]; DispatchEvent(ParserState::call, ElementState::open); } }, - { "function", [this](){ + { "function", [this]() { functionflagopen = true; ++ctx.triggerField[ParserState::function]; DispatchEvent(ParserState::function, ElementState::open); } }, - { "constructor", [this](){ + { "constructor", [this]() { constructorflagopen = true; ++ctx.triggerField[ParserState::constructor]; DispatchEvent(ParserState::constructor, ElementState::open); } }, - { "function_decl", [this](){ + { "function_decl", [this]() { ++ctx.triggerField[ParserState::functiondecl]; DispatchEvent(ParserState::functiondecl, ElementState::open); } }, - { "destructor_decl", [this](){ + { "destructor_decl", [this]() { ++ctx.triggerField[ParserState::destructordecl]; DispatchEvent(ParserState::destructordecl, ElementState::open); } }, - { "constructor_decl", [this](){ + { "constructor_decl", [this]() { ++ctx.triggerField[ParserState::constructordecl]; DispatchEvent(ParserState::constructordecl, ElementState::open); } }, - { "class", [this](){ + { "class", [this]() { classflagopen = true; ++ctx.triggerField[ParserState::classn]; DispatchEvent(ParserState::classn, ElementState::open); } }, - { "struct", [this](){ + { "struct", [this]() { classflagopen = true; ++ctx.triggerField[ParserState::classn]; DispatchEvent(ParserState::structn, ElementState::open); } }, - { "namespace", [this](){ + { "namespace", [this]() { ++ctx.triggerField[ParserState::namespacen]; DispatchEvent(ParserState::namespacen, ElementState::open); } }, - { "super_list", [this](){ + { "super_list", [this]() { ++ctx.triggerField[ParserState::super_list]; DispatchEvent(ParserState::super_list, ElementState::open); } }, - { "super", [this](){ + { "super", [this]() { ++ctx.triggerField[ParserState::super]; DispatchEvent(ParserState::super, ElementState::open); } }, - { "public", [this](){ + { "public", [this]() { ++ctx.triggerField[ParserState::publicaccess]; DispatchEvent(ParserState::publicaccess, ElementState::open); } }, - { "protected", [this](){ + { "protected", [this]() { ++ctx.triggerField[ParserState::protectedaccess]; DispatchEvent(ParserState::protectedaccess, ElementState::open); } }, - { "private", [this](){ + { "private", [this]() { ++ctx.triggerField[ParserState::privateaccess]; DispatchEvent(ParserState::privateaccess, ElementState::open); } }, - { "destructor", [this](){ + { "destructor", [this]() { //functionflagopen = true; ++ctx.triggerField[ParserState::destructor]; DispatchEvent(ParserState::destructor, ElementState::open); } }, - { "parameter", [this](){ + { "parameter", [this]() { ++ctx.triggerField[ParserState::parameter]; DispatchEvent(ParserState::parameter, ElementState::open); } }, - { "member_list", [this](){ + { "member_list", [this]() { ++ctx.triggerField[ParserState::memberlist]; DispatchEvent(ParserState::memberlist, ElementState::open); } }, - { "index", [this](){ + { "index", [this]() { ++ctx.triggerField[ParserState::index]; DispatchEvent(ParserState::index, ElementState::open); } }, - { "operator", [this](){ + { "operator", [this]() { ++ctx.triggerField[ParserState::op]; DispatchEvent(ParserState::op, ElementState::open); } }, - { "block", [this](){ + { "block", [this]() { ++ctx.triggerField[ParserState::block]; - if(constructorflagopen){ + if(constructorflagopen) { constructorflagopen = false; ++ctx.triggerField[ParserState::constructorblock]; DispatchEvent(ParserState::constructorblock, ElementState::open); } - if(functionflagopen){ + if(functionflagopen) { functionflagopen = false; ++ctx.triggerField[ParserState::functionblock]; DispatchEvent(ParserState::functionblock, ElementState::open); } - if(classflagopen){ + if(classflagopen) { classflagopen = false; //next time it's set to true, we definitely are in a new one. ++ctx.triggerField[ParserState::classblock]; } - if(whileflagopen){ + if(whileflagopen) { whileflagopen = false; ++ctx.triggerField[ParserState::whileblock]; } - if(ifelseflagopen){ + if(ifelseflagopen) { ifflagopen = false; ++ctx.triggerField[ParserState::ifblock]; } - if(forflagopen){ + if(forflagopen) { forflagopen = false; ++ctx.triggerField[ParserState::forblock]; } DispatchEvent(ParserState::block, ElementState::open); } }, - { "init", [this](){ + { "init", [this]() { ++ctx.triggerField[ParserState::init]; DispatchEvent(ParserState::init, ElementState::open); } }, - { "argument", [this](){ + { "argument", [this]() { ++ctx.triggerField[ParserState::argument]; DispatchEvent(ParserState::argument, ElementState::open); } }, - { "literal", [this](){ + { "literal", [this]() { ++ctx.triggerField[ParserState::literal]; DispatchEvent(ParserState::literal, ElementState::open); } }, - { "modifier", [this](){ + { "modifier", [this]() { ++ctx.triggerField[ParserState::modifier]; DispatchEvent(ParserState::modifier, ElementState::open); } }, - { "decl", [this](){ + { "decl", [this]() { ++ctx.triggerField[ParserState::decl]; DispatchEvent(ParserState::decl, ElementState::open); } }, - { "type", [this](){ + { "type", [this]() { if(ctx.isPrev) { ++ctx.triggerField[ParserState::typeprev]; DispatchEvent(ParserState::typeprev, ElementState::open); @@ -419,130 +419,130 @@ namespace srcSAXEventDispatch { ++ctx.triggerField[ParserState::type]; DispatchEvent(ParserState::type, ElementState::open); } }, - { "typedef", [this](){ + { "typedef", [this]() { ++ctx.triggerField[ParserState::typedefexpr]; DispatchEvent(ParserState::typedefexpr, ElementState::open); } }, - { "expr", [this](){ + { "expr", [this]() { ++ctx.triggerField[ParserState::expr]; DispatchEvent(ParserState::expr, ElementState::open); } }, - { "name", [this](){ + { "name", [this]() { ++ctx.triggerField[ParserState::name]; DispatchEvent(ParserState::name, ElementState::open); } }, - { "macro", [this](){ + { "macro", [this]() { ++ctx.triggerField[ParserState::macro]; DispatchEvent(ParserState::macro, ElementState::open); } }, - { "specifier", [this](){ + { "specifier", [this]() { ++ctx.triggerField[ParserState::specifier]; DispatchEvent(ParserState::specifier, ElementState::open); } }, - { "noun", [this](){ + { "noun", [this]() { ++ctx.triggerField[ParserState::snoun]; DispatchEvent(ParserState::snoun, ElementState::open); } }, - { "propernoun", [this](){ + { "propernoun", [this]() { ++ctx.triggerField[ParserState::propersnoun]; DispatchEvent(ParserState::propersnoun, ElementState::open); } }, - { "pronoun", [this](){ + { "pronoun", [this]() { ++ctx.triggerField[ParserState::spronoun]; DispatchEvent(ParserState::spronoun, ElementState::open); } }, - { "adjective", [this](){ + { "adjective", [this]() { ++ctx.triggerField[ParserState::sadjective]; DispatchEvent(ParserState::sadjective, ElementState::open); } }, - { "verb", [this](){ + { "verb", [this]() { ++ctx.triggerField[ParserState::sverb]; DispatchEvent(ParserState::sverb, ElementState::open); } }, - { "stereotype", [this](){ + { "stereotype", [this]() { ++ctx.triggerField[ParserState::stereotype]; DispatchEvent(ParserState::stereotype, ElementState::open); } }, - { "diff:delete", [this](){ + { "diff:delete", [this]() { ++ctx.triggerField[ParserState::diff_delete]; DispatchEvent(ParserState::diff_delete, ElementState::open); } }, - { "diff:insert", [this](){ + { "diff:insert", [this]() { ++ctx.triggerField[ParserState::diff_insert]; DispatchEvent(ParserState::diff_insert, ElementState::open); } }, - { "diff:common", [this](){ + { "diff:common", [this]() { ++ctx.triggerField[ParserState::diff_common]; DispatchEvent(ParserState::diff_common, ElementState::open); } }, - { "diff:ws", [this](){ + { "diff:ws", [this]() { ++ctx.triggerField[ParserState::diff_ws]; DispatchEvent(ParserState::diff_ws, ElementState::open); } }, - { "unit", [this](){ - if(ctx.triggerField[ParserState::unit] == 0){ + { "unit", [this]() { + if(ctx.triggerField[ParserState::unit] == 0) { ctx.triggerField[ParserState::archive] = 1; DispatchEvent(ParserState::archive, ElementState::open); } ++ctx.triggerField[ParserState::unit]; DispatchEvent(ParserState::unit, ElementState::open); } }, - { "throws", [this](){ + { "throws", [this]() { ++ctx.triggerField[ParserState::throws]; DispatchEvent(ParserState::throws, ElementState::open); } }, - { "annotation", [this](){ + { "annotation", [this]() { ++ctx.triggerField[ParserState::annotation]; DispatchEvent(ParserState::annotation, ElementState::open); } }, - { "return", [this](){ + { "return", [this]() { ++ctx.triggerField[ParserState::returnstmt]; DispatchEvent(ParserState::returnstmt, ElementState::open); } }, - { "comment", [this](){ + { "comment", [this]() { ++ctx.triggerField[ParserState::comment]; DispatchEvent(ParserState::comment, ElementState::open); } }, }; process_map2 = { - {"decl_stmt", [this](){ + {"decl_stmt", [this]() { DispatchEvent(ParserState::declstmt, ElementState::close); --ctx.triggerField[ParserState::declstmt]; } }, - { "expr_stmt", [this](){ + { "expr_stmt", [this]() { DispatchEvent(ParserState::exprstmt, ElementState::close); --ctx.triggerField[ParserState::exprstmt]; } }, - { "parameter_list", [this](){ + { "parameter_list", [this]() { DispatchEvent(ParserState::parameterlist, ElementState::close); --ctx.triggerField[ParserState::parameterlist]; } }, - { "condition", [this](){ + { "condition", [this]() { DispatchEvent(ParserState::condition, ElementState::close); --ctx.triggerField[ParserState::condition]; } }, - { "switch", [this](){ + { "switch", [this]() { DispatchEvent(ParserState::switchstmt, ElementState::close); --ctx.triggerField[ParserState::switchstmt]; } }, - { "case", [this](){ + { "case", [this]() { DispatchEvent(ParserState::switchcase, ElementState::close); --ctx.triggerField[ParserState::switchcase]; } }, - { "do", [this](){ + { "do", [this]() { DispatchEvent(ParserState::dostmt, ElementState::close); --ctx.triggerField[ParserState::dostmt]; } }, - { "incr", [this](){ + { "incr", [this]() { DispatchEvent(ParserState::incr, ElementState::close); --ctx.triggerField[ParserState::incr]; } }, - { "decr", [this](){ + { "decr", [this]() { DispatchEvent(ParserState::decr, ElementState::close); --ctx.triggerField[ParserState::decr]; } }, - { "if", [this](){ - if(!ifelseflagopen){ + { "if", [this]() { + if(!ifelseflagopen) { --ctx.triggerField[ParserState::ifblock]; DispatchEvent(ParserState::ifstmt, ElementState::close); --ctx.triggerField[ParserState::ifstmt]; @@ -552,31 +552,31 @@ namespace srcSAXEventDispatch { ifelseflagopen = false; } } }, - { "else", [this](){ + { "else", [this]() { --ctx.triggerField[ParserState::elsestmt]; DispatchEvent(ParserState::elsestmt, ElementState::close); } }, - { "for", [this](){ + { "for", [this]() { --ctx.triggerField[ParserState::forblock]; DispatchEvent(ParserState::forstmt, ElementState::close); --ctx.triggerField[ParserState::forstmt]; } }, - { "control", [this](){ + { "control", [this]() { --ctx.triggerField[ParserState::control]; DispatchEvent(ParserState::control, ElementState::close); } }, - { "while", [this](){ + { "while", [this]() { --ctx.triggerField[ParserState::whileblock]; DispatchEvent(ParserState::whilestmt, ElementState::close); --ctx.triggerField[ParserState::whilestmt]; } }, - { "template", [this](){ + { "template", [this]() { DispatchEvent(ParserState::templates, ElementState::close); --ctx.triggerField[ParserState::templates]; } }, - { "argument_list", [this](){ - if(!ctx.genericDepth.empty()){ - if(ctx.genericDepth.back() == ctx.depth){ + { "argument_list", [this]() { + if(!ctx.genericDepth.empty()) { + if(ctx.genericDepth.back() == ctx.depth) { DispatchEvent(ParserState::genericargumentlist, ElementState::close); --ctx.triggerField[ParserState::genericargumentlist]; ctx.genericDepth.pop_back(); @@ -585,11 +585,11 @@ namespace srcSAXEventDispatch { DispatchEvent(ParserState::argumentlist, ElementState::close); --ctx.triggerField[ParserState::argumentlist]; } }, - { "call", [this](){ + { "call", [this]() { DispatchEvent(ParserState::call, ElementState::close); --ctx.triggerField[ParserState::call]; } }, - { "function", [this](){ + { "function", [this]() { DispatchEvent(ParserState::functionblock, ElementState::close); ctx.currentFunctionName.clear(); --ctx.triggerField[ParserState::functionblock]; @@ -597,7 +597,7 @@ namespace srcSAXEventDispatch { DispatchEvent(ParserState::function, ElementState::close); --ctx.triggerField[ParserState::function]; } }, - { "constructor", [this](){ + { "constructor", [this]() { //This code causes problems for some reason. FIX. DispatchEvent(ParserState::constructorblock, ElementState::close); ctx.currentFunctionName.clear(); @@ -606,7 +606,7 @@ namespace srcSAXEventDispatch { DispatchEvent(ParserState::constructor, ElementState::close); --ctx.triggerField[ParserState::constructor]; } }, - { "destructor", [this](){ + { "destructor", [this]() { //This code causes problems for some reason. FIX. /* DispatchEvent(ParserState::functionblock, ElementState::close); --ctx.triggerField[ParserState::functionblock];*/ @@ -614,95 +614,95 @@ namespace srcSAXEventDispatch { DispatchEvent(ParserState::destructor, ElementState::close); --ctx.triggerField[ParserState::destructor]; } }, - { "function_decl", [this](){ + { "function_decl", [this]() { DispatchEvent(ParserState::functiondecl, ElementState::close); --ctx.triggerField[ParserState::functiondecl]; } }, - { "constructor_decl", [this](){ + { "constructor_decl", [this]() { DispatchEvent(ParserState::constructordecl, ElementState::close); --ctx.triggerField[ParserState::constructordecl]; } }, - { "destructor_decl", [this](){ + { "destructor_decl", [this]() { DispatchEvent(ParserState::destructordecl, ElementState::close); --ctx.triggerField[ParserState::destructordecl]; } }, - { "class", [this](){ + { "class", [this]() { --ctx.triggerField[ParserState::classblock]; DispatchEvent(ParserState::classn, ElementState::close); ctx.currentClassName.clear(); --ctx.triggerField[ParserState::classn]; } }, - { "struct", [this](){ + { "struct", [this]() { --ctx.triggerField[ParserState::classblock]; DispatchEvent(ParserState::structn, ElementState::close); ctx.currentClassName.clear(); --ctx.triggerField[ParserState::classn]; } }, - { "namespace", [this](){ + { "namespace", [this]() { DispatchEvent(ParserState::namespacen, ElementState::close); --ctx.triggerField[ParserState::namespacen]; } }, - { "super_list", [this](){ + { "super_list", [this]() { DispatchEvent(ParserState::super_list, ElementState::close); --ctx.triggerField[ParserState::super_list]; } }, - { "super", [this](){ + { "super", [this]() { DispatchEvent(ParserState::super, ElementState::close); --ctx.triggerField[ParserState::super]; } }, - { "public", [this](){ + { "public", [this]() { DispatchEvent(ParserState::publicaccess, ElementState::close); --ctx.triggerField[ParserState::publicaccess]; } }, - { "protected", [this](){ + { "protected", [this]() { DispatchEvent(ParserState::protectedaccess, ElementState::close); --ctx.triggerField[ParserState::protectedaccess]; } }, - { "private", [this](){ + { "private", [this]() { DispatchEvent(ParserState::privateaccess, ElementState::close); --ctx.triggerField[ParserState::privateaccess]; } }, - { "parameter", [this](){ + { "parameter", [this]() { DispatchEvent(ParserState::parameter, ElementState::close); --ctx.triggerField[ParserState::parameter]; } }, - { "member_list", [this](){ + { "member_list", [this]() { DispatchEvent(ParserState::memberlist, ElementState::close); --ctx.triggerField[ParserState::memberlist]; } }, - { "index", [this](){ + { "index", [this]() { DispatchEvent(ParserState::index, ElementState::close); --ctx.triggerField[ParserState::index]; } }, - { "operator", [this](){ + { "operator", [this]() { DispatchEvent(ParserState::op, ElementState::close); --ctx.triggerField[ParserState::op]; } }, - { "block", [this](){ + { "block", [this]() { DispatchEvent(ParserState::block, ElementState::close); --ctx.triggerField[ParserState::block]; } }, - { "init", [this](){ + { "init", [this]() { DispatchEvent(ParserState::init, ElementState::close); --ctx.triggerField[ParserState::init]; } }, - { "argument", [this](){ + { "argument", [this]() { DispatchEvent(ParserState::argument, ElementState::close); --ctx.triggerField[ParserState::argument]; } }, - { "literal", [this](){ + { "literal", [this]() { DispatchEvent(ParserState::literal, ElementState::close); --ctx.triggerField[ParserState::literal]; } }, - { "modifier", [this](){ + { "modifier", [this]() { DispatchEvent(ParserState::modifier, ElementState::close); --ctx.triggerField[ParserState::modifier]; } }, - { "decl", [this](){ + { "decl", [this]() { DispatchEvent(ParserState::decl, ElementState::close); --ctx.triggerField[ParserState::decl]; } }, - { "type", [this](){ + { "type", [this]() { if(ctx.isPrev) { DispatchEvent(ParserState::typeprev, ElementState::close); --ctx.triggerField[ParserState::typeprev]; @@ -710,96 +710,96 @@ namespace srcSAXEventDispatch { DispatchEvent(ParserState::type, ElementState::close); --ctx.triggerField[ParserState::type]; } }, - { "typedef", [this](){ + { "typedef", [this]() { DispatchEvent(ParserState::typedefexpr, ElementState::close); --ctx.triggerField[ParserState::typedefexpr]; } }, - { "expr", [this](){ + { "expr", [this]() { DispatchEvent(ParserState::expr, ElementState::close); --ctx.triggerField[ParserState::expr]; } }, - { "name", [this](){ + { "name", [this]() { DispatchEvent(ParserState::name, ElementState::close); --ctx.triggerField[ParserState::name]; } }, - { "macro", [this](){ + { "macro", [this]() { DispatchEvent(ParserState::macro, ElementState::close); --ctx.triggerField[ParserState::macro]; } }, - { "specifier", [this](){ + { "specifier", [this]() { DispatchEvent(ParserState::specifier, ElementState::close); --ctx.triggerField[ParserState::specifier]; } }, - { "noun", [this](){ + { "noun", [this]() { --ctx.triggerField[ParserState::snoun]; DispatchEvent(ParserState::snoun, ElementState::close); } }, - { "propernoun", [this](){ + { "propernoun", [this]() { --ctx.triggerField[ParserState::propersnoun]; DispatchEvent(ParserState::propersnoun, ElementState::close); } }, - { "pronoun", [this](){ + { "pronoun", [this]() { --ctx.triggerField[ParserState::spronoun]; DispatchEvent(ParserState::spronoun, ElementState::close); } }, - { "adjective", [this](){ + { "adjective", [this]() { --ctx.triggerField[ParserState::sadjective]; DispatchEvent(ParserState::sadjective, ElementState::close); } }, - { "verb", [this](){ + { "verb", [this]() { --ctx.triggerField[ParserState::sverb]; DispatchEvent(ParserState::sverb, ElementState::close); } }, - { "stereotype", [this](){ + { "stereotype", [this]() { DispatchEvent(ParserState::stereotype, ElementState::close); --ctx.triggerField[ParserState::stereotype]; } }, - { "diff:delete", [this](){ + { "diff:delete", [this]() { DispatchEvent(ParserState::diff_delete, ElementState::close); --ctx.triggerField[ParserState::diff_delete]; } }, - { "diff_insert", [this](){ + { "diff_insert", [this]() { DispatchEvent(ParserState::diff_insert, ElementState::close); --ctx.triggerField[ParserState::diff_insert]; } }, - { "diff_common", [this](){ + { "diff_common", [this]() { DispatchEvent(ParserState::diff_common, ElementState::close); --ctx.triggerField[ParserState::diff_common]; } }, - { "diff_ws", [this](){ + { "diff_ws", [this]() { DispatchEvent(ParserState::diff_ws, ElementState::close); --ctx.triggerField[ParserState::diff_ws]; } }, - { "unit", [this](){ + { "unit", [this]() { --ctx.triggerField[ParserState::unit]; DispatchEvent(ParserState::unit, ElementState::close); - if(ctx.triggerField[ParserState::unit] == 0){ + if(ctx.triggerField[ParserState::unit] == 0) { ctx.triggerField[ParserState::archive] = 0; DispatchEvent(ParserState::archive, ElementState::close); } } }, - { "return", [this](){ + { "return", [this]() { --ctx.triggerField[ParserState::returnstmt]; DispatchEvent(ParserState::returnstmt, ElementState::close); } }, - { "throws", [this](){ + { "throws", [this]() { --ctx.triggerField[ParserState::throws]; DispatchEvent(ParserState::throws, ElementState::close); } }, - { "annotation", [this](){ + { "annotation", [this]() { --ctx.triggerField[ParserState::annotation]; DispatchEvent(ParserState::annotation, ElementState::close); } }, - { "comment", [this](){ + { "comment", [this]() { --ctx.triggerField[ParserState::comment]; DispatchEvent(ParserState::comment, ElementState::close); } }, - { "xmlattribute", [this](){ + { "xmlattribute", [this]() { ctx.triggerField[ParserState::xmlattribute] = 1; DispatchEvent(ParserState::xmlattribute, ElementState::close); ctx.triggerField[ParserState::xmlattribute] = 0; } }, - { "tokenstring", [this](){ + { "tokenstring", [this]() { ctx.triggerField[ParserState::tokenstring] = 1; DispatchEvent(ParserState::tokenstring, ElementState::close); ctx.triggerField[ParserState::tokenstring] = 0; @@ -836,7 +836,7 @@ namespace srcSAXEventDispatch { virtual void startRoot(const char * localname, const char * prefix, const char * URI, int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, const struct srcsax_attribute * attributes) override { - if(is_archive && generateArchive){ + if(is_archive && generateArchive) { ctx.write_start_tag(localname, prefix, URI, num_namespaces, namespaces, num_attributes, attributes); } std::unordered_map>::const_iterator process = process_map.find("unit"); @@ -863,7 +863,7 @@ namespace srcSAXEventDispatch { int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, const struct srcsax_attribute * attributes) override { - if (generateArchive){ + if (generateArchive) { ctx.write_start_tag(localname, prefix, URI, num_namespaces, namespaces, num_attributes, attributes); } std::unordered_map>::const_iterator process = process_map.find("unit"); @@ -871,7 +871,7 @@ namespace srcSAXEventDispatch { process->second(); } - if(num_attributes >= 3){ + if(num_attributes >= 3) { if (num_attributes >= 5) ctx.currentFileChecksum = std::string(attributes[4].value); ctx.currentFilePath = std::string(attributes[2].value); @@ -897,7 +897,7 @@ namespace srcSAXEventDispatch { int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, const struct srcsax_attribute * attributes) override { - if(generateArchive){ + if(generateArchive) { ctx.write_start_tag(localname, prefix, URI, num_namespaces, namespaces, num_attributes, attributes); } @@ -913,24 +913,24 @@ namespace srcSAXEventDispatch { ctx.currentTag = localName; std::string name; - if(num_attributes){ + if(num_attributes) { name = attributes[0].value; } - if(name == "generic" && localName == "argument_list"){ + if(name == "generic" && localName == "argument_list") { ctx.genericDepth.push_back(ctx.depth); } - if(name == "prev" && localName == "type"){ + if(name == "prev" && localName == "type") { ctx.isPrev = true; } if(name == "operator" && (localName == "function" || localName == "function_decl")) { ctx.isOperator = true; } - if(name == "elseif" && localName == "if"){ + if(name == "elseif" && localName == "if") { ifelseflagopen = true; } - if(localName != ""){ + if(localName != "") { // form attribute map for(int pos = 0; pos < num_attributes; ++pos) { std::string attributeName; @@ -939,9 +939,9 @@ namespace srcSAXEventDispatch { attributeName += ':'; } attributeName += attributes[pos].localname; - if(strcmp(attributes[pos].localname, "start") == 0){ + if(strcmp(attributes[pos].localname, "start") == 0) { std::string posString; - for(int i = 0; attributes[pos].value[i] != ':'; ++i){ + for(int i = 0; attributes[pos].value[i] != ':'; ++i) { posString+=attributes[pos].value[i]; } ctx.currentLineNumber = std::stoi(posString); @@ -991,21 +991,21 @@ namespace srcSAXEventDispatch { ctx.currentToken.append(ch, len); std::unordered_map>::const_iterator process = process_map2.find("tokenstring"); - if(ctx.Or({ParserState::classn, ParserState::structn}) && ctx.IsOpen(ParserState::name) && ctx.Nor({ParserState::classblock, ParserState::super_list})){ + if(ctx.Or({ParserState::classn, ParserState::structn}) && ctx.IsOpen(ParserState::name) && ctx.Nor({ParserState::classblock, ParserState::super_list})) { ctx.currentClassName = std::all_of( std::begin(ctx.currentToken), std::end(ctx.currentToken), - [](char c){ + [](char c) { if(std::isalnum(c) || c == '_') return true; return false; }) ? ctx.currentToken : ""; } - if(ctx.IsOpen({ParserState::namespacen}) && ctx.IsOpen(ParserState::name) && ctx.IsClosed({ParserState::block})){ + if(ctx.IsOpen({ParserState::namespacen}) && ctx.IsOpen(ParserState::name) && ctx.IsClosed({ParserState::block})) { std::string namespaceName = std::all_of( std::begin(ctx.currentToken), std::end(ctx.currentToken), - [](char c){ + [](char c) { if(std::isalnum(c) || c == '_') return true; return false; }) ? ctx.currentToken : ""; @@ -1013,11 +1013,11 @@ namespace srcSAXEventDispatch { ctx.currentNamespaces.push_back(namespaceName); } - if((ctx.And({ParserState::name, ParserState::function}) || ctx.And({ParserState::name, ParserState::constructor})) && ctx.Nor({ParserState::functionblock, ParserState::type, ParserState::parameterlist, ParserState::genericargumentlist, ParserState::constructorblock, ParserState::throws, ParserState::annotation})){ + if((ctx.And({ParserState::name, ParserState::function}) || ctx.And({ParserState::name, ParserState::constructor})) && ctx.Nor({ParserState::functionblock, ParserState::type, ParserState::parameterlist, ParserState::genericargumentlist, ParserState::constructorblock, ParserState::throws, ParserState::annotation})) { ctx.currentFunctionName = std::all_of( std::begin(ctx.currentToken), std::end(ctx.currentToken), - [](char c){ + [](char c) { if(std::isalnum(c) || c == '_') return true; return false; }) ? ctx.currentToken : ""; From a035f7666dc82341566840faf2ef487eef5f4635 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 10 Oct 2024 07:22:40 +0900 Subject: [PATCH 011/149] Change how namespace is collected (minimally) --- src/dispatcher/srcSAXEventDispatcher.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dispatcher/srcSAXEventDispatcher.hpp b/src/dispatcher/srcSAXEventDispatcher.hpp index b870b38..827a896 100644 --- a/src/dispatcher/srcSAXEventDispatcher.hpp +++ b/src/dispatcher/srcSAXEventDispatcher.hpp @@ -960,6 +960,10 @@ namespace srcSAXEventDispatch { ctx.attributes.clear(); } + if(ctx.currentTag == "namespace") { + ctx.currentNamespaces.emplace_back(); + } + for(int pos = 0; pos < num_attributes; ++pos) { ctx.currentAttributeName = ""; @@ -1010,7 +1014,7 @@ namespace srcSAXEventDispatch { return false; }) ? ctx.currentToken : ""; - ctx.currentNamespaces.push_back(namespaceName); + ctx.currentNamespaces.back() += namespaceName; } if((ctx.And({ParserState::name, ParserState::function}) || ctx.And({ParserState::name, ParserState::constructor})) && ctx.Nor({ParserState::functionblock, ParserState::type, ParserState::parameterlist, ParserState::genericargumentlist, ParserState::constructorblock, ParserState::throws, ParserState::annotation})) { From 2e73fbd3ddc01feec35a3e7f9c0ff3cc34081787 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 10 Oct 2024 08:55:54 +0900 Subject: [PATCH 012/149] Rename code to srcDispatch --- CMake/CMakeLists.txt | 4 +-- ...ch_build.cmake => srcdispatch_build.cmake} | 0 ...nstall.cmake => srcdispatch_install.cmake} | 0 src/CMakeLists.txt | 6 ++-- ...SAXEventDispatcher.cpp => srcDispatch.cpp} | 6 ++-- ...SAXEventDispatcher.hpp => srcDispatch.hpp} | 18 +++++------ ...patcher.hpp => srcDispatchSingleEvent.hpp} | 16 +++++----- ...Utilities.hpp => srcDispatchUtilities.hpp} | 14 ++++---- src/policy_classes/CallPolicySingleEvent.cpp | 10 +++--- src/policy_classes/CallPolicySingleEvent.hpp | 16 +++++----- src/policy_classes/ClassPolicy.hpp | 14 ++++---- src/policy_classes/ClassPolicySingleEvent.hpp | 30 ++++++++--------- src/policy_classes/CollectNLContext.hpp | 14 ++++---- src/policy_classes/ConditionalPolicy.hpp | 12 +++---- src/policy_classes/DeclTypePolicy.hpp | 16 +++++----- .../DeclTypePolicySingleEvent.hpp | 28 ++++++++-------- src/policy_classes/ExprPolicy.hpp | 12 +++---- .../ExpressionPolicySingleEvent.cpp | 10 +++--- .../ExpressionPolicySingleEvent.hpp | 16 +++++----- src/policy_classes/FunctionCallPolicy.hpp | 12 +++---- .../FunctionPolicySingleEvent.hpp | 32 +++++++++---------- .../FunctionSignaturePolicy.hpp | 12 +++---- src/policy_classes/NamePolicySingleEvent.cpp | 10 +++--- src/policy_classes/NamePolicySingleEvent.hpp | 18 +++++------ src/policy_classes/ParamTypePolicy.hpp | 12 +++---- .../ParamTypePolicySingleEvent.hpp | 22 ++++++------- src/policy_classes/ReturnPolicy.hpp | 12 +++---- .../ReturnPolicySingleEvent.hpp | 20 ++++++------ src/policy_classes/SNLPolicy.hpp | 12 +++---- src/policy_classes/StereotypePolicy.hpp | 12 +++---- .../TemplateArgumentPolicySingleEvent.cpp | 14 ++++---- .../TemplateArgumentPolicySingleEvent.hpp | 14 ++++---- src/policy_classes/TypePolicySingleEvent.cpp | 16 +++++----- src/policy_classes/TypePolicySingleEvent.hpp | 14 ++++---- src/policy_classes/UnitPolicySingleEvent.hpp | 29 +++++++++-------- 35 files changed, 252 insertions(+), 251 deletions(-) rename CMake/{srcsax_event_dispatch_build.cmake => srcdispatch_build.cmake} (100%) rename CMake/{srcsax_event_dispatch_install.cmake => srcdispatch_install.cmake} (100%) rename src/dispatcher/{srcSAXEventDispatcher.cpp => srcDispatch.cpp} (88%) rename src/dispatcher/{srcSAXEventDispatcher.hpp => srcDispatch.hpp} (98%) rename src/dispatcher/{srcSAXSingleEventDispatcher.hpp => srcDispatchSingleEvent.hpp} (80%) rename src/dispatcher/{srcSAXEventDispatchUtilities.hpp => srcDispatchUtilities.hpp} (97%) diff --git a/CMake/CMakeLists.txt b/CMake/CMakeLists.txt index ccb14fc..d3f18b4 100644 --- a/CMake/CMakeLists.txt +++ b/CMake/CMakeLists.txt @@ -22,7 +22,7 @@ # add this directory list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) -include(srcsax_event_dispatch_build) +include(srcdispatch_build) if(CMAKE_PROJECT_NAME STREQUAL "srcSAXEventDispatch") - include(srcsax_event_dispatch_install) + include(srcdispatch_install) endif() diff --git a/CMake/srcsax_event_dispatch_build.cmake b/CMake/srcdispatch_build.cmake similarity index 100% rename from CMake/srcsax_event_dispatch_build.cmake rename to CMake/srcdispatch_build.cmake diff --git a/CMake/srcsax_event_dispatch_install.cmake b/CMake/srcdispatch_install.cmake similarity index 100% rename from CMake/srcsax_event_dispatch_install.cmake rename to CMake/srcdispatch_install.cmake diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aa011d8..88ef82b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,8 +28,8 @@ file(GLOB POLICY_CLASSES_HEADER policy_classes/*.hpp) # find needed libraries find_package(LibXml2 REQUIRED) -add_library(srcsaxeventdispatch ${DISPATCHER_SOURCE} ${DISPATCHER_HEADER} ${POLICY_CLASSES_SOURCE} ${POLICY_CLASSES_HEADER}) -target_link_libraries(srcsaxeventdispatch PRIVATE LibXml2::LibXml2) +add_library(srcdispatch ${DISPATCHER_SOURCE} ${DISPATCHER_HEADER} ${POLICY_CLASSES_SOURCE} ${POLICY_CLASSES_HEADER}) +target_link_libraries(srcdispatch PRIVATE LibXml2::LibXml2) -install(TARGETS srcsaxeventdispatch) +install(TARGETS srcdispatch) install(FILES ${DISPATCHER_HEADER} ${POLICY_CLASSES_HEADER} DESTINATION include/dispatch) diff --git a/src/dispatcher/srcSAXEventDispatcher.cpp b/src/dispatcher/srcDispatch.cpp similarity index 88% rename from src/dispatcher/srcSAXEventDispatcher.cpp rename to src/dispatcher/srcDispatch.cpp index 9ee5fed..6108d9f 100644 --- a/src/dispatcher/srcSAXEventDispatcher.cpp +++ b/src/dispatcher/srcDispatch.cpp @@ -1,5 +1,5 @@ /** - * @file srcSAXEventDispatcher.cpp + * @file srcDispatch.cpp * * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) * @@ -17,7 +17,7 @@ * along with the srcML Toolkit; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -namespace srcSAXEventDispatch{ +#include +namespace srcDispatch{ } diff --git a/src/dispatcher/srcSAXEventDispatcher.hpp b/src/dispatcher/srcDispatch.hpp similarity index 98% rename from src/dispatcher/srcSAXEventDispatcher.hpp rename to src/dispatcher/srcDispatch.hpp index 827a896..6bdc816 100644 --- a/src/dispatcher/srcSAXEventDispatcher.hpp +++ b/src/dispatcher/srcDispatch.hpp @@ -1,5 +1,5 @@ /** - * @file srcSAXEventDispatcher.hpp + * @file srcDispatch.hpp * * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) * @@ -19,8 +19,8 @@ */ -#ifndef INCLUDED_SRCSAXEVENTDISPATCHER_HPP -#define INCLUDED_SRCSAXEVENTDISPATCHER_HPP +#ifndef INCLUDED_SRCDISPATCH_HPP +#define INCLUDED_SRCDISPATCH_HPP #include #include @@ -29,12 +29,12 @@ #include #include #include -#include +#include #include #include #include -namespace srcSAXEventDispatch { +namespace srcDispatch { template static std::list CreateListenersImpl(PolicyListener * policyListener, std::list & listeners); @@ -64,7 +64,7 @@ namespace srcSAXEventDispatch { } template - class srcSAXEventDispatcher : public srcSAXHandler, public EventDispatcher { + class srcDispatch : public srcSAXHandler, public EventDispatcher { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" @@ -138,14 +138,14 @@ namespace srcSAXEventDispatch { } public: - virtual ~srcSAXEventDispatcher() { + virtual ~srcDispatch() { for(std::size_t count = 0; count < numberAllocatedListeners; ++count) { delete elementListeners.front(); elementListeners.pop_front(); } } - srcSAXEventDispatcher(PolicyListener * listener, bool genArchive = false) : EventDispatcher(srcml_element_stack) { + srcDispatch(PolicyListener * listener, bool genArchive = false) : EventDispatcher(srcml_element_stack) { elementListeners = CreateListeners(listener); numberAllocatedListeners = elementListeners.size(); dispatching = false; @@ -159,7 +159,7 @@ namespace srcSAXEventDispatch { InitializeHandlers(); } - srcSAXEventDispatcher(std::initializer_list listeners, bool genArchive = false) : EventDispatcher(srcml_element_stack) { + srcDispatch(std::initializer_list listeners, bool genArchive = false) : EventDispatcher(srcml_element_stack) { elementListeners = listeners; numberAllocatedListeners = elementListeners.size(); dispatching = false; diff --git a/src/dispatcher/srcSAXSingleEventDispatcher.hpp b/src/dispatcher/srcDispatchSingleEvent.hpp similarity index 80% rename from src/dispatcher/srcSAXSingleEventDispatcher.hpp rename to src/dispatcher/srcDispatchSingleEvent.hpp index ee933d1..dc34a41 100644 --- a/src/dispatcher/srcSAXSingleEventDispatcher.hpp +++ b/src/dispatcher/srcDispatchSingleEvent.hpp @@ -1,5 +1,5 @@ /** - * @file srcSAXSingleEventDispatcher.hpp + * @file srcDispatchSingleEvent.hpp * * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) * @@ -17,21 +17,21 @@ * along with the srcML Toolkit; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef INCLUDED_SRCSAX_SINGLE_EVENT_DISPATCHER_HPP -#define INCLUDED_SRCSAX_SINGLE_EVENT_DISPATCHER_HPP +#ifndef INCLUDED_SRC_DISPATCH_SINGLE_EVENT_HPP +#define INCLUDED_SRC_DISPATCH_SINGLE_EVENT_HPP -#include +#include -namespace srcSAXEventDispatch { +namespace srcDispatch { template - class srcSAXSingleEventDispatcher : public srcSAXEventDispatcher { + class srcDispatchSingleEvent : public srcDispatch { private: bool dispatched; public: - srcSAXSingleEventDispatcher(PolicyListener * listener) : srcSAXEventDispatcher(listener), dispatched(false) {} + srcDispatchSingleEvent(PolicyListener * listener) : srcDispatch(listener), dispatched(false) {} virtual void AddListener(EventListener * listener) override { EventDispatcher::elementListeners.back()->SetDispatched(false); EventDispatcher::elementListeners.push_back(listener); @@ -55,7 +55,7 @@ namespace srcSAXEventDispatch { RemoveListener(listener); } protected: - virtual void DispatchEvent(srcSAXEventDispatch::ParserState pstate, srcSAXEventDispatch::ElementState estate) override { + virtual void DispatchEvent(srcDispatch::ParserState pstate, srcDispatch::ElementState estate) override { while(!dispatched) { diff --git a/src/dispatcher/srcSAXEventDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp similarity index 97% rename from src/dispatcher/srcSAXEventDispatchUtilities.hpp rename to src/dispatcher/srcDispatchUtilities.hpp index b3e1c5d..4561fd3 100644 --- a/src/dispatcher/srcSAXEventDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -1,5 +1,5 @@ /** - * @file srcSAXEventDispatchUtilities.hpp + * @file srcDispatchUtilities.hpp * * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) * @@ -35,7 +35,7 @@ #ifndef INCLUDED_SRCSAX_EVENT_DISPATCH_UTILITIES_HPP #define INCLUDED_SRCSAX_EVENT_DISPATCH_UTILITIES_HPP -namespace srcSAXEventDispatch{ +namespace srcDispatch{ class EventDispatcher; enum ElementState {open, close}; enum ParserState {decl, expr, parameter, declstmt, exprstmt, parameterlist, elseif, elsestmt, @@ -209,7 +209,7 @@ namespace srcSAXEventDispatch{ }; class EventListener { - typedef std::unordered_map, std::hash> EventMap; + typedef std::unordered_map, std::hash> EventMap; protected: bool dispatched; EventMap openEventMap, closeEventMap; @@ -228,7 +228,7 @@ namespace srcSAXEventDispatch{ virtual const EventMap & GetCloseEventMap() const { return closeEventMap; } virtual void HandleEvent() { dispatched = true; } - virtual void HandleEvent(srcSAXEventDispatch::ParserState pstate, srcSAXEventDispatch::ElementState estate, srcSAXEventDispatch::srcSAXEventContext& ctx) { + virtual void HandleEvent(srcDispatch::ParserState pstate, srcDispatch::ElementState estate, srcDispatch::srcSAXEventContext& ctx) { if(dispatched) return; @@ -236,7 +236,7 @@ namespace srcSAXEventDispatch{ switch(estate){ - case srcSAXEventDispatch::ElementState::open: { + case srcDispatch::ElementState::open: { auto event = openEventMap.find(pstate); if(event != openEventMap.end()){ event->second(ctx); @@ -244,7 +244,7 @@ namespace srcSAXEventDispatch{ break; } - case srcSAXEventDispatch::ElementState::close: { + case srcDispatch::ElementState::close: { auto event = closeEventMap.find(pstate); if(event != closeEventMap.end()){ event->second(ctx); @@ -282,7 +282,7 @@ namespace srcSAXEventDispatch{ private: void DefaultEventHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; NopOpenEvents({ ParserState::declstmt, diff --git a/src/policy_classes/CallPolicySingleEvent.cpp b/src/policy_classes/CallPolicySingleEvent.cpp index 708f66a..083cf7e 100644 --- a/src/policy_classes/CallPolicySingleEvent.cpp +++ b/src/policy_classes/CallPolicySingleEvent.cpp @@ -23,8 +23,8 @@ CallPolicy::~CallPolicy() { std::any CallPolicy::DataInner() const { return std::make_shared(data); } -void CallPolicy::Notify(const srcSAXEventDispatch::PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) { - using namespace srcSAXEventDispatch; +void CallPolicy::Notify(const srcDispatch::PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { + using namespace srcDispatch; if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); ctx.dispatcher->RemoveListener(nullptr); @@ -36,7 +36,7 @@ void CallPolicy::Notify(const srcSAXEventDispatch::PolicyDispatcher * policy, co } void CallPolicy::InitializeCallPolicyHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; // start of policy openEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { if (!callDepth) { @@ -60,7 +60,7 @@ void CallPolicy::InitializeCallPolicyHandlers() { void CallPolicy::CollectNameHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if(!namePolicy) namePolicy = new NamePolicy{this}; ctx.dispatcher->AddListenerDispatch(namePolicy); @@ -69,7 +69,7 @@ void CallPolicy::CollectNameHandlers() { void CallPolicy::CollectCallArgumentHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; ctx.dispatcher->AddListenerDispatch(expressionPolicy); diff --git a/src/policy_classes/CallPolicySingleEvent.hpp b/src/policy_classes/CallPolicySingleEvent.hpp index de8c1b0..251a2df 100644 --- a/src/policy_classes/CallPolicySingleEvent.hpp +++ b/src/policy_classes/CallPolicySingleEvent.hpp @@ -5,7 +5,7 @@ #ifndef INCLUDED_CALL_POLICY_SINGLE_EVENT_HPP #define INCLUDED_CALL_POLICY_SINGLE_EVENT_HPP -#include +#include #include #include @@ -39,9 +39,9 @@ struct CallData { }; class CallPolicy : -public srcSAXEventDispatch::EventListener, -public srcSAXEventDispatch::PolicyDispatcher, -public srcSAXEventDispatch::PolicyListener { +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { private: CallData data; @@ -50,8 +50,8 @@ public srcSAXEventDispatch::PolicyListener { ExpressionPolicy *expressionPolicy; public: - CallPolicy(std::initializer_list listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), + CallPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{}, callDepth(0), expressionPolicy(nullptr), @@ -63,8 +63,8 @@ public srcSAXEventDispatch::PolicyListener { protected: std::any DataInner() const override; - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override; - void NotifyWrite(const PolicyDispatcher * policy, srcSAXEventDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override; + void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers private: void InitializeCallPolicyHandlers(); diff --git a/src/policy_classes/ClassPolicy.hpp b/src/policy_classes/ClassPolicy.hpp index e907cc6..2a43557 100644 --- a/src/policy_classes/ClassPolicy.hpp +++ b/src/policy_classes/ClassPolicy.hpp @@ -21,7 +21,7 @@ #ifndef INCLUDED_CLASS_POLICY_HPP #define INCLUDED_CLASS_POLICY_HPP -#include +#include #include #include #include @@ -30,7 +30,7 @@ #include #include -class ClassPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { +class ClassPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { public: struct ClassData { @@ -52,22 +52,22 @@ class ClassPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEven delete declTypePolicy; } - ClassPolicy(std::initializer_list listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners) { + ClassPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners) { funcSigPolicy = new FunctionSignaturePolicy({this}); declTypePolicy = new DeclTypePolicy({this}); InitializeEventHandlers(); } - void NotifyWrite(const PolicyDispatcher * policy, srcSAXEventDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { + void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { if (typeid(FunctionSignaturePolicy) == typeid(*policy)) { SignatureData signatureData = *policy->Data(); data_stack.top().methods.push_back(signatureData); } else if (typeid(DeclTypePolicy) == typeid(*policy)) { - if(!(ctx.IsOpen(srcSAXEventDispatch::ParserState::function))) { + if(!(ctx.IsOpen(srcDispatch::ParserState::function))) { DeclData declarationData = *policy->Data(); data_stack.top().members.push_back(declarationData); } @@ -92,7 +92,7 @@ class ClassPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEven bool gotClassName = true; void InitializeEventHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; //Classes openEventMap[ParserState::classn] = [this](srcSAXEventContext &ctx) { diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index 560a2eb..6084771 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -5,7 +5,7 @@ #ifndef INCLUDED_CLASS_POLICY_SINGLE_EVENT_HPP #define INCLUDED_CLASS_POLICY_SINGLE_EVENT_HPP -#include +#include #include #include @@ -51,9 +51,9 @@ struct ParentData { class ClassPolicy : -public srcSAXEventDispatch::EventListener, -public srcSAXEventDispatch::PolicyDispatcher, -public srcSAXEventDispatch::PolicyListener { +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { private: ClassData data; @@ -66,8 +66,8 @@ public srcSAXEventDispatch::PolicyListener { ClassPolicy * classPolicy; public: - ClassPolicy(std::initializer_list listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), + ClassPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{}, classDepth(0), currentRegion(ClassData::PUBLIC), @@ -85,9 +85,9 @@ public srcSAXEventDispatch::PolicyListener { if (classPolicy) delete classPolicy; } - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { + void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); ctx.dispatcher->RemoveListenerDispatch(nullptr); @@ -120,9 +120,9 @@ public srcSAXEventDispatch::PolicyListener { private: void InitializeClassPolicyHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; // start of policy - std::function startPolicy = [this](srcSAXEventContext& ctx) { + std::function startPolicy = [this](srcSAXEventContext& ctx) { if (!classDepth) { classDepth = ctx.depth; data = ClassData{}; @@ -150,7 +150,7 @@ public srcSAXEventDispatch::PolicyListener { }; // end of policy - std::function endPolicy = [this](srcSAXEventContext& ctx) { + std::function endPolicy = [this](srcSAXEventContext& ctx) { if (classDepth && classDepth == ctx.depth) { classDepth = 0; NotifyAll(ctx); @@ -165,7 +165,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectNameHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if ((classDepth + 1) == ctx.depth) { if (!namePolicy) namePolicy = new NamePolicy{this}; @@ -181,7 +181,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectGenericHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; closeEventMap[ParserState::templates] = [this](srcSAXEventContext& ctx) { if ((classDepth + 1) == ctx.depth) { data.isGeneric = true; @@ -190,7 +190,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectSuperHanders() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::super_list] = [this](srcSAXEventContext& ctx) { if ((classDepth + 1) == ctx.depth) { openEventMap[ParserState::super] = [this](srcSAXEventContext& ctx) { @@ -222,7 +222,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectBlockHanders() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { if ((classDepth + 1) == ctx.depth) { NopOpenEvents({ParserState::name, ParserState::super_list, ParserState::super}); diff --git a/src/policy_classes/CollectNLContext.hpp b/src/policy_classes/CollectNLContext.hpp index 0059781..4d7548a 100644 --- a/src/policy_classes/CollectNLContext.hpp +++ b/src/policy_classes/CollectNLContext.hpp @@ -17,7 +17,7 @@ * along with the srcML Toolkit; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include #include #include #include @@ -27,7 +27,7 @@ #ifndef NLCONTEXTPOLICY #define NLCONTEXTPOLICY -class NLContextPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { +class NLContextPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { public: struct NLSet{ NLSet(std::string idname, std::string acategory, std::string acontext, std::string astereo){ @@ -54,15 +54,15 @@ class NLContextPolicy : public srcSAXEventDispatch::EventListener, public srcSAX std::map identifierposmap; NLContextData data; ~NLContextPolicy(){} - NLContextPolicy(std::initializer_list listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners){ + NLContextPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ sourcenlpolicy.AddListener(this); exprpolicy.AddListener(this); stereotypepolicy.AddListener(this); InitializeEventHandlers(); } - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - using namespace srcSAXEventDispatch; + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + using namespace srcDispatch; if(ctx.IsOpen(ParserState::declstmt) && ctx.IsClosed(ParserState::exprstmt)){ sourcenlpdata = *policy->Data(); std::string top; @@ -125,7 +125,7 @@ class NLContextPolicy : public srcSAXEventDispatch::EventListener, public srcSAX std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; std::stack context; void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { ctx.dispatcher->AddListenerDispatch(&sourcenlpolicy); }; diff --git a/src/policy_classes/ConditionalPolicy.hpp b/src/policy_classes/ConditionalPolicy.hpp index 183eadb..6abb113 100644 --- a/src/policy_classes/ConditionalPolicy.hpp +++ b/src/policy_classes/ConditionalPolicy.hpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -18,15 +18,15 @@ struct DvarData{ std::set> dvars; }; -class ConditionalPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { +class ConditionalPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { public: - ConditionalPolicy(std::initializer_list listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners){ + ConditionalPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ InitializeEventHandlers(); } ~ConditionalPolicy(){} - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers std::unordered_map>* GetConditionalUses() { return &conditionalUses; @@ -76,7 +76,7 @@ class ConditionalPolicy : public srcSAXEventDispatch::EventListener, public srcS bool insertDvar = false; void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; + using namespace srcDispatch; closeEventMap[ParserState::function] = [this](srcSAXEventContext &ctx) { NotifyAll(ctx); diff --git a/src/policy_classes/DeclTypePolicy.hpp b/src/policy_classes/DeclTypePolicy.hpp index 96fc3e0..a8c3c9b 100644 --- a/src/policy_classes/DeclTypePolicy.hpp +++ b/src/policy_classes/DeclTypePolicy.hpp @@ -20,22 +20,22 @@ #ifndef INCLUDED_DECL_TYPE_POLICY_HPP #define INCLUDED_DECL_TYPE_POLICY_HPP -#include +#include #include #include #include -class DeclTypePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { +class DeclTypePolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { public: DeclData data; ~DeclTypePolicy(){} - DeclTypePolicy(std::initializer_list listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners){ + DeclTypePolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ InitializeEventHandlers(); } - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void Finalize(srcSAXEventDispatch::srcSAXEventContext& ctx){ - using namespace srcSAXEventDispatch; + void Finalize(srcDispatch::srcSAXEventContext& ctx){ + using namespace srcDispatch; if( ctx.And({ParserState::declstmt}) || ctx.And({ParserState::forstmt, ParserState::control, ParserState::init}) || ctx.And({ParserState::switchstmt, ParserState::condition}) ){ @@ -106,7 +106,7 @@ class DeclTypePolicy : public srcSAXEventDispatch::EventListener, public srcSAXE std::vector paramNames; void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ bool isDeclToken = ( ctx.And({ParserState::type, ParserState::declstmt}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist}) || diff --git a/src/policy_classes/DeclTypePolicySingleEvent.hpp b/src/policy_classes/DeclTypePolicySingleEvent.hpp index 65e48de..353fc03 100644 --- a/src/policy_classes/DeclTypePolicySingleEvent.hpp +++ b/src/policy_classes/DeclTypePolicySingleEvent.hpp @@ -2,14 +2,14 @@ * @file DeclTypePolicySingleEvent.hpp * * - * MODIFIED from srcSAXEventDispatcher + * MODIFIED from srcDispatch * This collects the initializer * */ #ifndef INCLUDED_DECL_TYPE_POLICY_SINGLE_EVENT_HPP #define INCLUDED_DECL_TYPE_POLICY_SINGLE_EVENT_HPP -#include +#include #include #include @@ -47,9 +47,9 @@ struct DeclTypeData { class DeclTypePolicy : -public srcSAXEventDispatch::EventListener, -public srcSAXEventDispatch::PolicyDispatcher, -public srcSAXEventDispatch::PolicyListener { +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { private: std::vector> data; @@ -63,8 +63,8 @@ public srcSAXEventDispatch::PolicyListener { std::shared_ptr initializer; public: - DeclTypePolicy(std::initializer_list listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), + DeclTypePolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{}, declDepth(0), typePolicy(nullptr), @@ -84,9 +84,9 @@ public srcSAXEventDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared>>(data); } - void NotifyWrite(const PolicyDispatcher * policy, srcSAXEventDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { if (typeid(TypePolicy) == typeid(*policy)) { type = std::shared_ptr(policy->Data()); ctx.dispatcher->RemoveListenerDispatch(nullptr); @@ -102,7 +102,7 @@ public srcSAXEventDispatch::PolicyListener { private: void InitializeDeclTypePolicyHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; // start of policy openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { if (!declDepth) { @@ -138,7 +138,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectTypeHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { if (declDepth && (declDepth + 2) == ctx.depth) { if (!typePolicy) typePolicy = new TypePolicy{this}; @@ -148,7 +148,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectNameHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if (declDepth && (declDepth + 2) == ctx.depth) { if (!namePolicy) namePolicy = new NamePolicy{this}; @@ -158,7 +158,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectSpecifiersHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { if (declDepth && (declDepth + 2) == ctx.depth) { closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { @@ -175,7 +175,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectInitHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; diff --git a/src/policy_classes/ExprPolicy.hpp b/src/policy_classes/ExprPolicy.hpp index 6543fea..842f862 100644 --- a/src/policy_classes/ExprPolicy.hpp +++ b/src/policy_classes/ExprPolicy.hpp @@ -17,14 +17,14 @@ * along with the srcML Toolkit; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include #include #include #include #include #ifndef EXPRPOLICY #define EXPRPOLICY -class ExprPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { +class ExprPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { public: struct ExprData{ ExprData() {lhs = false;} @@ -50,11 +50,11 @@ class ExprPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEvent std::map dataSet; }; ~ExprPolicy(){} - ExprPolicy(std::initializer_list listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners){ + ExprPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ InitializeEventHandlers(); } - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers protected: std::any DataInner() const override { return std::make_shared(exprDataSet); @@ -67,7 +67,7 @@ class ExprPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEvent std::vector currentLine; void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; + using namespace srcDispatch; closeEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ // Long or-statement allows various declaration operators to get planted into diff --git a/src/policy_classes/ExpressionPolicySingleEvent.cpp b/src/policy_classes/ExpressionPolicySingleEvent.cpp index 663a87d..1b291ab 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.cpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.cpp @@ -27,7 +27,7 @@ ExpressionPolicy::~ExpressionPolicy() { if(callPolicy) delete callPolicy; } -void ExpressionPolicy::Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) { +void ExpressionPolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { if(typeid(NamePolicy) == typeid(*policy)) { data.expr.push_back(std::make_shared(ExpressionElement::NAME, policy->Data())); ctx.dispatcher->RemoveListenerDispatch(nullptr); @@ -39,7 +39,7 @@ void ExpressionPolicy::Notify(const PolicyDispatcher * policy, const srcSAXEvent } void ExpressionPolicy::InitializeExpressionPolicyHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; // start of policy std::function expressionStart = [this](srcSAXEventContext& ctx) { if(!exprDepth) { @@ -67,7 +67,7 @@ void ExpressionPolicy::InitializeExpressionPolicyHandlers() { void ExpressionPolicy::CollectNameHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if(!namePolicy) namePolicy = new NamePolicy{this}; ctx.dispatcher->AddListenerDispatch(namePolicy); @@ -75,7 +75,7 @@ void ExpressionPolicy::CollectNameHandlers() { } void ExpressionPolicy::CollectCallHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { if(!callPolicy) callPolicy = new CallPolicy{this}; ctx.dispatcher->AddListenerDispatch(callPolicy); @@ -83,7 +83,7 @@ void ExpressionPolicy::CollectCallHandlers() { } void ExpressionPolicy::CollectOtherHandlers() { //Get the operators - using namespace srcSAXEventDispatch; + using namespace srcDispatch; closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { std::shared_ptr token = std::make_shared(ctx.currentLineNumber, ctx.currentToken); if (ctx.currentTag == "operator") { diff --git a/src/policy_classes/ExpressionPolicySingleEvent.hpp b/src/policy_classes/ExpressionPolicySingleEvent.hpp index 6d37d00..13891f9 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.hpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.hpp @@ -5,7 +5,7 @@ #ifndef INCLUDED_EXPRESSION_POLICY_SINGE_EVENT_HPP #define INCLUDED_EXPRESSION_POLICY_SINGE_EVENT_HPP -#include +#include #include #include @@ -56,9 +56,9 @@ struct ExpressionData { }; class ExpressionPolicy : -public srcSAXEventDispatch::EventListener, -public srcSAXEventDispatch::PolicyDispatcher, -public srcSAXEventDispatch::PolicyListener { +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { private: ExpressionData data; @@ -67,8 +67,8 @@ public srcSAXEventDispatch::PolicyListener { std::size_t exprDepth; public: - ExpressionPolicy(std::initializer_list listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), + ExpressionPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{}, exprDepth(0), namePolicy(nullptr), @@ -82,9 +82,9 @@ public srcSAXEventDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared(data); } - void NotifyWrite(const PolicyDispatcher * policy, srcSAXEventDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override; + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override; private: void InitializeExpressionPolicyHandlers(); diff --git a/src/policy_classes/FunctionCallPolicy.hpp b/src/policy_classes/FunctionCallPolicy.hpp index d1f37ee..cea3d45 100644 --- a/src/policy_classes/FunctionCallPolicy.hpp +++ b/src/policy_classes/FunctionCallPolicy.hpp @@ -17,7 +17,7 @@ * along with the srcML Toolkit; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include #include #include #include @@ -28,7 +28,7 @@ */ #ifndef CALLPOLICY #define CALLPOLICY -class FunctionCallPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { +class FunctionCallPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { /* {CalledFunction1{arg1, line#}, {arg2, line#}, ..., {argn, line#}, NestedCalledFunction1{arg1, line#},{arg2, line#}, ..., {argn, line#} @@ -44,11 +44,11 @@ class FunctionCallPolicy : public srcSAXEventDispatch::EventListener, public src std::vector callargumentlist; }; ~FunctionCallPolicy(){} - FunctionCallPolicy(std::initializer_list listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners){ + FunctionCallPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ InitializeEventHandlers(); } - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers protected: std::any DataInner() const override { return std::make_shared(data); @@ -58,7 +58,7 @@ class FunctionCallPolicy : public srcSAXEventDispatch::EventListener, public src std::string currentTypeName, currentCallName, currentModifier, currentSpecifier; std::string fullFuncIdentifier; void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::argumentlist] = [this](srcSAXEventContext& ctx [[maybe_unused]]) { data.callargumentlist.push_back("("); diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index 829041e..69a2094 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -7,7 +7,7 @@ #ifndef INCLUDED_FUNCTION_POLICY_SINGE_EVENT_HPP #define INCLUDED_FUNCTION_POLICY_SINGE_EVENT_HPP -#include +#include #include #include @@ -81,9 +81,9 @@ struct FunctionData { class FunctionPolicy : -public srcSAXEventDispatch::EventListener, -public srcSAXEventDispatch::PolicyDispatcher, -public srcSAXEventDispatch::PolicyListener { +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { private: FunctionData data; @@ -97,8 +97,8 @@ public srcSAXEventDispatch::PolicyListener { ExpressionPolicy *expressionPolicy; public: - FunctionPolicy(std::initializer_list listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), + FunctionPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{}, functionDepth(0), typePolicy(nullptr), @@ -122,9 +122,9 @@ public srcSAXEventDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared(data); } - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { if (typeid(TypePolicy) == typeid(*policy)) { data.returnType = policy->Data(); ctx.dispatcher->RemoveListenerDispatch(nullptr); @@ -151,7 +151,7 @@ public srcSAXEventDispatch::PolicyListener { private: void InitializeFunctionPolicyHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; // start of policy std::function startFunction = [this](srcSAXEventContext& ctx) { if (!functionDepth) { @@ -218,7 +218,7 @@ public srcSAXEventDispatch::PolicyListener { void CollectXMLAttributeHandlers() {} void CollectTypeHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { if (functionDepth && (functionDepth + 1) == ctx.depth) { if (!typePolicy) typePolicy = new TypePolicy{this}; @@ -228,7 +228,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectNameHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if (functionDepth && (functionDepth + 1) == ctx.depth) { if (!namePolicy) namePolicy = new NamePolicy{this}; @@ -238,7 +238,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectParameterHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { if (functionDepth && (functionDepth + 1) == ctx.depth) { openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { @@ -258,7 +258,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectReturnHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { if (!returnPolicy) returnPolicy = new ReturnPolicy{this}; ctx.dispatcher->AddListenerDispatch(returnPolicy); @@ -266,7 +266,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectExpressionHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { if (!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; ctx.dispatcher->AddListenerDispatch(expressionPolicy); @@ -274,7 +274,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectOtherHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { if (functionDepth && (functionDepth + 1) == ctx.depth) { if (ctx.And({ParserState::specifier})) { @@ -304,7 +304,7 @@ public srcSAXEventDispatch::PolicyListener { /** @todo Will not work with local classes. */ /** @todo May need to add optimization that ignores declaration statement initialization. */ void CollectDeclstmtHandlers(){ - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { if (functionDepth && (functionDepth + 1) == ctx.depth) { openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { diff --git a/src/policy_classes/FunctionSignaturePolicy.hpp b/src/policy_classes/FunctionSignaturePolicy.hpp index ba047f4..1005ad8 100644 --- a/src/policy_classes/FunctionSignaturePolicy.hpp +++ b/src/policy_classes/FunctionSignaturePolicy.hpp @@ -17,7 +17,7 @@ * along with the srcML Toolkit; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include #include #include #include @@ -67,19 +67,19 @@ struct SignatureData{ nameOfContainingClass.clear(); } }; -class FunctionSignaturePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ +class FunctionSignaturePolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener{ public: ~FunctionSignaturePolicy(){} - FunctionSignaturePolicy(std::initializer_list listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners){ + FunctionSignaturePolicy(std::initializer_list listeners = {}) : srcDispatch::PolicyDispatcher(listeners){ currentArgPosition = 1; parampolicy.AddListener(this); InitializeEventHandlers(); } - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override { + void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override { paramdata = policy->Data(); data.parameters.push_back(*paramdata); } - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers protected: std::any DataInner() const override { return std::make_shared(data); @@ -93,7 +93,7 @@ class FunctionSignaturePolicy : public srcSAXEventDispatch::EventListener, publi std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { ctx.dispatcher->AddListener(¶mpolicy); data.lineNumber = ctx.currentLineNumber; diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index 4829c99..14406d1 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -1,7 +1,7 @@ /** * @file NamePolicySingleEvent.cpp * - * MODIFIED from srcSAXEventDispatcher + * MODIFIED from srcDispatch * This collects the expression in the index * */ @@ -53,7 +53,7 @@ NamePolicy::~NamePolicy() { } -void NamePolicy::Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) { +void NamePolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { if (typeid(NamePolicy) == typeid(*policy)) { data.names.push_back(policy->Data()); ctx.dispatcher->RemoveListener(nullptr); @@ -69,7 +69,7 @@ void NamePolicy::Notify(const PolicyDispatcher * policy, const srcSAXEventDispat void NamePolicy::InitializeNamePolicyHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; // start of policy openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if (!nameDepth) { @@ -101,7 +101,7 @@ void NamePolicy::InitializeNamePolicyHandlers() { void NamePolicy::CollectTemplateArgumentsHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext& ctx) { if (nameDepth && (nameDepth + 1) == ctx.depth) { openEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { @@ -121,7 +121,7 @@ void NamePolicy::CollectTemplateArgumentsHandlers() { void NamePolicy::CollectArrayIndicesHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::index] = [this](srcSAXEventContext& ctx) { openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; diff --git a/src/policy_classes/NamePolicySingleEvent.hpp b/src/policy_classes/NamePolicySingleEvent.hpp index 039cc1e..e158f5a 100644 --- a/src/policy_classes/NamePolicySingleEvent.hpp +++ b/src/policy_classes/NamePolicySingleEvent.hpp @@ -1,14 +1,14 @@ /** * @file NamePolicySingleEvent.hpp * - * MODIFIED from srcSAXEventDispatcher + * MODIFIED from srcDispatch * This collects the expression in the index * */ #ifndef INCLUDED_NAME_POLICY_SINGLE_EVENT_HPP #define INCLUDED_NAME_POLICY_SINGLE_EVENT_HPP -#include +#include #include #include @@ -39,9 +39,9 @@ struct NameData { class NamePolicy : -public srcSAXEventDispatch::EventListener, -public srcSAXEventDispatch::PolicyDispatcher, -public srcSAXEventDispatch::PolicyListener { +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { private: NameData data; @@ -51,8 +51,8 @@ public srcSAXEventDispatch::PolicyListener { ExpressionPolicy *expressionPolicy; public: - NamePolicy(std::initializer_list listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), + NamePolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{}, nameDepth(0), namePolicy(nullptr), @@ -66,8 +66,8 @@ public srcSAXEventDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared(data); } - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override; - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override; + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers private: void InitializeNamePolicyHandlers(); diff --git a/src/policy_classes/ParamTypePolicy.hpp b/src/policy_classes/ParamTypePolicy.hpp index 5be1090..0d9d717 100644 --- a/src/policy_classes/ParamTypePolicy.hpp +++ b/src/policy_classes/ParamTypePolicy.hpp @@ -20,19 +20,19 @@ #ifndef INCLUDED_PARAM_TYPE_POLICY_HPP #define INCLUDED_PARAM_TYPE_POLICY_HPP -#include +#include #include #include #include -class ParamTypePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ +class ParamTypePolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener{ public: - ParamTypePolicy(std::initializer_list listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners){ + ParamTypePolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ InitializeEventHandlers(); } ~ParamTypePolicy(){} - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers protected: std::any DataInner() const override { return std::make_shared(data); @@ -42,7 +42,7 @@ class ParamTypePolicy : public srcSAXEventDispatch::EventListener, public srcSAX std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ if(ctx.And({ParserState::type, ParserState::parameter}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ data.namespaces.push_back(ctx.currentToken); diff --git a/src/policy_classes/ParamTypePolicySingleEvent.hpp b/src/policy_classes/ParamTypePolicySingleEvent.hpp index d945470..000d723 100644 --- a/src/policy_classes/ParamTypePolicySingleEvent.hpp +++ b/src/policy_classes/ParamTypePolicySingleEvent.hpp @@ -7,7 +7,7 @@ #define INCLUDED_PARAM_TYPE_POLICY_SINGLE_EVENT_HPP -#include +#include #include #include @@ -31,9 +31,9 @@ struct ParamTypeData { class ParamTypePolicy : -public srcSAXEventDispatch::EventListener, -public srcSAXEventDispatch::PolicyDispatcher, -public srcSAXEventDispatch::PolicyListener { +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { private: ParamTypeData data; @@ -42,8 +42,8 @@ public srcSAXEventDispatch::PolicyListener { NamePolicy* namePolicy; public: - ParamTypePolicy(std::initializer_list listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), + ParamTypePolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{}, paramDepth(0), typePolicy(nullptr), @@ -61,7 +61,7 @@ public srcSAXEventDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared(data); } - virtual void Notify(const PolicyDispatcher* policy, const srcSAXEventDispatch::srcSAXEventContext& ctx) override { + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(TypePolicy) == typeid(*policy)) { data.type = policy->Data(); ctx.dispatcher->RemoveListenerDispatch(nullptr); @@ -71,11 +71,11 @@ public srcSAXEventDispatch::PolicyListener { } } - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers private: void InitializeParamTypePolicyHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; // start of policy openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { if (!paramDepth) { @@ -98,7 +98,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectTypeHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { if (paramDepth && (paramDepth + 2) == ctx.depth) { if (!typePolicy) typePolicy = new TypePolicy{this}; @@ -108,7 +108,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectNameHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if (paramDepth && (paramDepth + 2) == ctx.depth) { if (!namePolicy) namePolicy = new NamePolicy{this}; diff --git a/src/policy_classes/ReturnPolicy.hpp b/src/policy_classes/ReturnPolicy.hpp index 5f891d5..b9e21e9 100644 --- a/src/policy_classes/ReturnPolicy.hpp +++ b/src/policy_classes/ReturnPolicy.hpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -6,16 +6,16 @@ #include #ifndef RETURNPOLICY #define RETURNPOLICY -class ReturnPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { +class ReturnPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { public: - ReturnPolicy(std::initializer_list listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners){ + ReturnPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ InitializeEventHandlers(); } ~ReturnPolicy(){} - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} // doesn't use other parsers - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} // doesn't use other parsers + void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} // doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} // doesn't use other parsers void ClearCollection() { returnUses.clear(); } @@ -29,7 +29,7 @@ class ReturnPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEve std::unordered_map> returnUses; // variablename | line number void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; + using namespace srcDispatch; closeEventMap[ParserState::name] = [this](srcSAXEventContext &ctx) { if(ctx.IsOpen({ParserState::returnstmt}) && ctx.IsClosed({ParserState::comment})){ diff --git a/src/policy_classes/ReturnPolicySingleEvent.hpp b/src/policy_classes/ReturnPolicySingleEvent.hpp index 715928d..9ac6d9a 100644 --- a/src/policy_classes/ReturnPolicySingleEvent.hpp +++ b/src/policy_classes/ReturnPolicySingleEvent.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include @@ -20,9 +20,9 @@ // Collect the expression in the return // class ReturnPolicy : -public srcSAXEventDispatch::EventListener, -public srcSAXEventDispatch::PolicyDispatcher, -public srcSAXEventDispatch::PolicyListener { +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { private: std::shared_ptr data; @@ -30,8 +30,8 @@ public srcSAXEventDispatch::PolicyListener { ExpressionPolicy* exprPolicy; public: - ReturnPolicy(std::initializer_list listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), + ReturnPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{}, returnDepth(0), exprPolicy(nullptr) { @@ -45,18 +45,18 @@ public srcSAXEventDispatch::PolicyListener { protected: std::any DataInner() const override { return data; } - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { if (typeid(ExpressionPolicy) == typeid(*policy)) { data = policy->Data(); ctx.dispatcher->RemoveListener(nullptr); } } - void NotifyWrite(const PolicyDispatcher * policy, srcSAXEventDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers private: void InitializeReturnPolicyHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; // start of policy openEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { if (!returnDepth) { @@ -77,7 +77,7 @@ public srcSAXEventDispatch::PolicyListener { } void CollectExpressionHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; ctx.dispatcher->AddListenerDispatch(exprPolicy); diff --git a/src/policy_classes/SNLPolicy.hpp b/src/policy_classes/SNLPolicy.hpp index 5c6a651..9d856a4 100644 --- a/src/policy_classes/SNLPolicy.hpp +++ b/src/policy_classes/SNLPolicy.hpp @@ -17,13 +17,13 @@ * along with the srcML Toolkit; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include #include #include #ifndef SOURCENLPOLICY #define SOURCENLPOLICY -class SourceNLPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { +class SourceNLPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { public: struct SourceNLData{ SourceNLData(){} @@ -36,11 +36,11 @@ class SourceNLPolicy : public srcSAXEventDispatch::EventListener, public srcSAXE }; SourceNLData data; ~SourceNLPolicy(){} - SourceNLPolicy(std::initializer_list listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners){ + SourceNLPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ InitializeEventHandlers(); } - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers protected: void * DataInner() const override { return new SourceNLData(data); @@ -48,7 +48,7 @@ class SourceNLPolicy : public srcSAXEventDispatch::EventListener, public srcSAXE private: std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; + using namespace srcDispatch; closeEventMap[ParserState::snoun] = [this](srcSAXEventContext& ctx){ //std::cerr< +#include #include #include #include @@ -26,7 +26,7 @@ #ifndef STEREOTYPEPOLICY #define STEREOTYPEPOLICY -class StereotypePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { +class StereotypePolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { public: struct StereotypeData{ StereotypeData() {} @@ -34,11 +34,11 @@ class StereotypePolicy : public srcSAXEventDispatch::EventListener, public srcSA std::vector stereotypes; }; ~StereotypePolicy(){} - StereotypePolicy(std::initializer_list listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners){ + StereotypePolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ InitializeEventHandlers(); } - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers protected: void * DataInner() const override { return new StereotypeData(data); @@ -47,7 +47,7 @@ class StereotypePolicy : public srcSAXEventDispatch::EventListener, public srcSA StereotypeData data; std::string currentStereotype; void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; + using namespace srcDispatch; closeEventMap[ParserState::stereotype] = [this](srcSAXEventContext& ctx){ std::string word; for(char ch : currentStereotype){ diff --git a/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp b/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp index b2de4bb..6317214 100644 --- a/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp +++ b/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp @@ -24,8 +24,8 @@ std::ostream & operator<<(std::ostream & out, const TemplateArgumentData & argum return out; } -TemplateArgumentPolicy::TemplateArgumentPolicy(std::initializer_list listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), +TemplateArgumentPolicy::TemplateArgumentPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{}, argumentDepth(0), namePolicy(nullptr) { @@ -36,19 +36,19 @@ TemplateArgumentPolicy::~TemplateArgumentPolicy() { if (namePolicy) delete namePolicy; } -void TemplateArgumentPolicy::Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) { +void TemplateArgumentPolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { data.data.back().first = policy->Data(); ctx.dispatcher->RemoveListenerDispatch(nullptr); } -void TemplateArgumentPolicy::NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]){} +void TemplateArgumentPolicy::NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]){} std::any TemplateArgumentPolicy::DataInner() const { return std::make_shared(data); } void TemplateArgumentPolicy::InitializeTemplateArgumentPolicyHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; // start of policy openEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { if (!argumentDepth) { @@ -71,7 +71,7 @@ void TemplateArgumentPolicy::InitializeTemplateArgumentPolicyHandlers() { } void TemplateArgumentPolicy::CollectNamesHandler() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { // C++ has depth of 2 others 1 std::size_t elementStackSize = ctx.elementStack.size(); @@ -86,7 +86,7 @@ void TemplateArgumentPolicy::CollectNamesHandler() { } void TemplateArgumentPolicy::CollectOthersHandler() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { // C++ has depth of 2 others 1 std::size_t elementStackSize = ctx.elementStack.size(); diff --git a/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp b/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp index cf7b46d..9cb2c5e 100644 --- a/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp +++ b/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp @@ -5,7 +5,7 @@ #ifndef INCLUDED_TEMPLATE1_ARGUMENT_POLICY_SINGLE_EVENT_HPP #define INCLUDED_TEMPLATE1_ARGUMENT_POLICY_SINGLE_EVENT_HPP -#include +#include #include class NamePolicy; @@ -21,15 +21,15 @@ struct TemplateArgumentData { class TemplateArgumentPolicy : -public srcSAXEventDispatch::EventListener, -public srcSAXEventDispatch::PolicyDispatcher, -public srcSAXEventDispatch::PolicyListener { +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { public: - TemplateArgumentPolicy(std::initializer_list listeners); + TemplateArgumentPolicy(std::initializer_list listeners); ~TemplateArgumentPolicy(); - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override; - virtual void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override; + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override; + virtual void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override; protected: virtual std::any DataInner() const override; diff --git a/src/policy_classes/TypePolicySingleEvent.cpp b/src/policy_classes/TypePolicySingleEvent.cpp index f902099..ed867a5 100644 --- a/src/policy_classes/TypePolicySingleEvent.cpp +++ b/src/policy_classes/TypePolicySingleEvent.cpp @@ -44,8 +44,8 @@ std::ostream & operator<<(std::ostream & out, const TypeData & typeData) { return out; } -TypePolicy::TypePolicy(std::initializer_list listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), +TypePolicy::TypePolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{}, typeDepth(0), namePolicy(nullptr) { @@ -57,20 +57,20 @@ TypePolicy::~TypePolicy(){ if (namePolicy) delete namePolicy; } -void TypePolicy::Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) { +void TypePolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { //this causes undefined behavior if types is empty data.types.back().first = policy->Data(); ctx.dispatcher->RemoveListenerDispatch(nullptr); } -void TypePolicy::NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcSAXEventDispatch::srcSAXEventContext & ctx [[maybe_unused]]){} +void TypePolicy::NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]){} std::any TypePolicy::DataInner() const { return std::make_shared(data); } void TypePolicy::InitializeTypePolicyHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; // start of policy openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { if (!typeDepth) { @@ -94,7 +94,7 @@ void TypePolicy::InitializeTypePolicyHandlers() { } void TypePolicy::CollectNamesHandler() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if (typeDepth && (typeDepth + 1) == ctx.depth) { data.types.push_back(std::make_pair(std::shared_ptr(), TypeData::TYPENAME)); @@ -105,7 +105,7 @@ void TypePolicy::CollectNamesHandler() { } void TypePolicy::CollectModifersHandler() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) { if (typeDepth && (typeDepth + 1) == ctx.depth) { data.types.push_back(std::make_pair(nullptr, TypeData::NONE)); @@ -128,7 +128,7 @@ void TypePolicy::CollectModifersHandler() { } void TypePolicy::CollectSpecifiersHandler() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; openEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { if (typeDepth && (typeDepth + 1) == ctx.depth) { data.types.push_back(std::make_pair(std::make_shared(""), TypeData::SPECIFIER)); diff --git a/src/policy_classes/TypePolicySingleEvent.hpp b/src/policy_classes/TypePolicySingleEvent.hpp index 186d97a..fd6df51 100644 --- a/src/policy_classes/TypePolicySingleEvent.hpp +++ b/src/policy_classes/TypePolicySingleEvent.hpp @@ -5,7 +5,7 @@ #ifndef INCLUDED_TYPE1_POLICY_SINGLE_EVENT_HPP #define INCLUDED_TYPE1_POLICY_SINGLE_EVENT_HPP -#include +#include #include @@ -25,9 +25,9 @@ struct TypeData { class TypePolicy : -public srcSAXEventDispatch::EventListener, -public srcSAXEventDispatch::PolicyDispatcher, -public srcSAXEventDispatch::PolicyListener { +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { private: TypeData data; @@ -35,10 +35,10 @@ public srcSAXEventDispatch::PolicyListener { NamePolicy * namePolicy; public: - TypePolicy(std::initializer_list listeners); + TypePolicy(std::initializer_list listeners); ~TypePolicy(); - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override; - virtual void NotifyWrite(const PolicyDispatcher * policy, srcSAXEventDispatch::srcSAXEventContext & ctx) override; + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override; + virtual void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override; protected: virtual std::any DataInner() const override; diff --git a/src/policy_classes/UnitPolicySingleEvent.hpp b/src/policy_classes/UnitPolicySingleEvent.hpp index 7f53578..e0d74c9 100644 --- a/src/policy_classes/UnitPolicySingleEvent.hpp +++ b/src/policy_classes/UnitPolicySingleEvent.hpp @@ -1,5 +1,5 @@ /** - * Policy for srcSAXEventDispatcher + * Policy for srcDispatch * Listens for both classes and functions * Calls the ClassPolicySingleEvent for class * Calls the FunctionPolicySingleEvent for function @@ -8,11 +8,12 @@ #ifndef INCLUDED_UNIT_POLICY_HPP #define INCLUDED_UNIT_POLICY_HPP -#include +#include #include #include +#include #include #include #include @@ -21,17 +22,17 @@ class UnitPolicySingleEvent : - public srcSAXEventDispatch::EventListener, - public srcSAXEventDispatch::PolicyDispatcher, - public srcSAXEventDispatch::PolicyListener { + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { public: FunctionPolicy *functionPolicy; ClassPolicy *classPolicy; public: - UnitPolicySingleEvent(std::initializer_list listeners) : - srcSAXEventDispatch::PolicyDispatcher(listeners), + UnitPolicySingleEvent(std::initializer_list listeners) : + srcDispatch::PolicyDispatcher(listeners), functionPolicy(nullptr), classPolicy(nullptr) { InitializeUnitPolicyHandlers(); @@ -42,9 +43,9 @@ class UnitPolicySingleEvent : if(classPolicy) delete classPolicy; } - void NotifyWrite(const PolicyDispatcher * policy, srcSAXEventDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { + void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { // Assumes at least one lister which should always be one policyListeners.back()->Notify(policy, ctx); ctx.dispatcher->RemoveListenerDispatch(nullptr); @@ -55,16 +56,16 @@ class UnitPolicySingleEvent : private: void InitializeUnitPolicyHandlers() { - using namespace srcSAXEventDispatch; + using namespace srcDispatch; // start of policy - std::function startClassPolicy = [this](srcSAXEventContext& ctx) { + std::function startClassPolicy = [this](srcSAXEventContext& ctx) { if(!classPolicy) classPolicy = new ClassPolicy{this}; ctx.dispatcher->AddListenerDispatch(classPolicy); }; // end of policy - std::function endClassPolicy = [this](srcSAXEventContext& ctx) { + std::function endClassPolicy = [this](srcSAXEventContext& ctx) { }; openEventMap[ParserState::classn] = startClassPolicy; @@ -73,13 +74,13 @@ class UnitPolicySingleEvent : closeEventMap[ParserState::structn] = endClassPolicy; // start function of policy - std::function startFunction = [this](srcSAXEventContext& ctx) { + std::function startFunction = [this](srcSAXEventContext& ctx) { if(!functionPolicy) functionPolicy = new FunctionPolicy{this}; ctx.dispatcher->AddListenerDispatch(functionPolicy); }; // end of policy - std::function endFunction = [this](srcSAXEventContext& ctx) { + std::function endFunction = [this](srcSAXEventContext& ctx) { }; openEventMap[ParserState::function] = startFunction; From 54b6cc8c62f4bcca1e384ab40ed74e48bfa3b0da Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 10 Oct 2024 09:08:34 +0900 Subject: [PATCH 013/149] Rename to dispatcher with namespace dispatch --- .../{srcDispatch.cpp => srcDispatcher.cpp} | 6 ++++-- .../{srcDispatch.hpp => srcDispatcher.hpp} | 14 +++++++------- ...ingleEvent.hpp => srcDispatcherSingleEvent.hpp} | 8 ++++---- src/policy_classes/ReturnPolicySingleEvent.hpp | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) rename src/dispatcher/{srcDispatch.cpp => srcDispatcher.cpp} (93%) rename src/dispatcher/{srcDispatch.hpp => srcDispatcher.hpp} (99%) rename src/dispatcher/{srcDispatchSingleEvent.hpp => srcDispatcherSingleEvent.hpp} (90%) diff --git a/src/dispatcher/srcDispatch.cpp b/src/dispatcher/srcDispatcher.cpp similarity index 93% rename from src/dispatcher/srcDispatch.cpp rename to src/dispatcher/srcDispatcher.cpp index 6108d9f..678ffc6 100644 --- a/src/dispatcher/srcDispatch.cpp +++ b/src/dispatcher/srcDispatcher.cpp @@ -17,7 +17,9 @@ * along with the srcML Toolkit; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -namespace srcDispatch{ + +#include + +namespace srcDispatch { } diff --git a/src/dispatcher/srcDispatch.hpp b/src/dispatcher/srcDispatcher.hpp similarity index 99% rename from src/dispatcher/srcDispatch.hpp rename to src/dispatcher/srcDispatcher.hpp index 6bdc816..254da06 100644 --- a/src/dispatcher/srcDispatch.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -1,5 +1,5 @@ /** - * @file srcDispatch.hpp + * @file srcDispatcher.hpp * * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) * @@ -19,8 +19,8 @@ */ -#ifndef INCLUDED_SRCDISPATCH_HPP -#define INCLUDED_SRCDISPATCH_HPP +#ifndef INCLUDED_SRCDISPATCHER_HPP +#define INCLUDED_SRCDISPATCHER_HPP #include #include @@ -64,7 +64,7 @@ namespace srcDispatch { } template - class srcDispatch : public srcSAXHandler, public EventDispatcher { + class srcDispatcher : public srcSAXHandler, public EventDispatcher { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" @@ -138,14 +138,14 @@ namespace srcDispatch { } public: - virtual ~srcDispatch() { + virtual ~srcDispatcher() { for(std::size_t count = 0; count < numberAllocatedListeners; ++count) { delete elementListeners.front(); elementListeners.pop_front(); } } - srcDispatch(PolicyListener * listener, bool genArchive = false) : EventDispatcher(srcml_element_stack) { + srcDispatcher(PolicyListener * listener, bool genArchive = false) : EventDispatcher(srcml_element_stack) { elementListeners = CreateListeners(listener); numberAllocatedListeners = elementListeners.size(); dispatching = false; @@ -159,7 +159,7 @@ namespace srcDispatch { InitializeHandlers(); } - srcDispatch(std::initializer_list listeners, bool genArchive = false) : EventDispatcher(srcml_element_stack) { + srcDispatcher(std::initializer_list listeners, bool genArchive = false) : EventDispatcher(srcml_element_stack) { elementListeners = listeners; numberAllocatedListeners = elementListeners.size(); dispatching = false; diff --git a/src/dispatcher/srcDispatchSingleEvent.hpp b/src/dispatcher/srcDispatcherSingleEvent.hpp similarity index 90% rename from src/dispatcher/srcDispatchSingleEvent.hpp rename to src/dispatcher/srcDispatcherSingleEvent.hpp index dc34a41..1a2e344 100644 --- a/src/dispatcher/srcDispatchSingleEvent.hpp +++ b/src/dispatcher/srcDispatcherSingleEvent.hpp @@ -1,5 +1,5 @@ /** - * @file srcDispatchSingleEvent.hpp + * @file srcDispatcherSingleEvent.hpp * * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) * @@ -20,18 +20,18 @@ #ifndef INCLUDED_SRC_DISPATCH_SINGLE_EVENT_HPP #define INCLUDED_SRC_DISPATCH_SINGLE_EVENT_HPP -#include +#include namespace srcDispatch { template - class srcDispatchSingleEvent : public srcDispatch { + class srcDispatcherSingleEvent : public srcDispatcher { private: bool dispatched; public: - srcDispatchSingleEvent(PolicyListener * listener) : srcDispatch(listener), dispatched(false) {} + srcDispatcherSingleEvent(PolicyListener * listener) : srcDispatcher(listener), dispatched(false) {} virtual void AddListener(EventListener * listener) override { EventDispatcher::elementListeners.back()->SetDispatched(false); EventDispatcher::elementListeners.push_back(listener); diff --git a/src/policy_classes/ReturnPolicySingleEvent.hpp b/src/policy_classes/ReturnPolicySingleEvent.hpp index 9ac6d9a..899d414 100644 --- a/src/policy_classes/ReturnPolicySingleEvent.hpp +++ b/src/policy_classes/ReturnPolicySingleEvent.hpp @@ -7,7 +7,7 @@ #define INCLUDED_RETURN_POLICY_SINGLE_EVENT_HPP #include -#include +#include #include #include From e39bf9f8e72d8315b6d32a0718d62ce513de2127 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 10 Oct 2024 11:02:04 +0900 Subject: [PATCH 014/149] Change how namespace is collected --- src/dispatcher/srcDispatcher.hpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 254da06..ad22bbc 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -79,6 +79,9 @@ namespace srcDispatch { std::size_t numberAllocatedListeners; + bool findName; + bool collectText; + protected: void DispatchEvent(ParserState pstate, ElementState estate) override { @@ -149,6 +152,8 @@ namespace srcDispatch { elementListeners = CreateListeners(listener); numberAllocatedListeners = elementListeners.size(); dispatching = false; + findName = false; + collectText = false; generateArchive = genArchive; classflagopen = functionflagopen = constructorflagopen = whileflagopen = ifflagopen = elseflagopen = ifelseflagopen = forflagopen = switchflagopen = false; @@ -163,6 +168,8 @@ namespace srcDispatch { elementListeners = listeners; numberAllocatedListeners = elementListeners.size(); dispatching = false; + findName = false; + collectText = false; generateArchive = genArchive; classflagopen = functionflagopen = constructorflagopen = whileflagopen = ifflagopen = elseflagopen = ifelseflagopen = forflagopen = switchflagopen = false; if(genArchive) { @@ -962,6 +969,13 @@ namespace srcDispatch { if(ctx.currentTag == "namespace") { ctx.currentNamespaces.emplace_back(); + findName = true; + } else if(findName && ctx.currentTag == "name") { + findName = false; + collectText = true; + } else if(collectText && ctx.currentTag == "block") { + findName = false; + collectText = false; } for(int pos = 0; pos < num_attributes; ++pos) { @@ -1005,16 +1019,8 @@ namespace srcDispatch { }) ? ctx.currentToken : ""; } - if(ctx.IsOpen({ParserState::namespacen}) && ctx.IsOpen(ParserState::name) && ctx.IsClosed({ParserState::block})) { - std::string namespaceName = std::all_of( - std::begin(ctx.currentToken), - std::end(ctx.currentToken), - [](char c) { - if(std::isalnum(c) || c == '_') return true; - return false; - }) ? ctx.currentToken : ""; - - ctx.currentNamespaces.back() += namespaceName; + if(collectText) { + ctx.currentNamespaces.back().append(ch, len); } if((ctx.And({ParserState::name, ParserState::function}) || ctx.And({ParserState::name, ParserState::constructor})) && ctx.Nor({ParserState::functionblock, ParserState::type, ParserState::parameterlist, ParserState::genericargumentlist, ParserState::constructorblock, ParserState::throws, ParserState::annotation})) { From 4ca8f7d9c9b0eb9d261cb5c346c02a360859c30c Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 10 Oct 2024 11:18:38 +0900 Subject: [PATCH 015/149] Add handling of when not namespace block --- src/dispatcher/srcDispatcher.hpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index ad22bbc..19b93c1 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include @@ -80,7 +82,7 @@ namespace srcDispatch { std::size_t numberAllocatedListeners; bool findName; - bool collectText; + std::optional collectedText; protected: void DispatchEvent(ParserState pstate, ElementState estate) override { @@ -153,7 +155,7 @@ namespace srcDispatch { numberAllocatedListeners = elementListeners.size(); dispatching = false; findName = false; - collectText = false; + collectedText = std::optional(); generateArchive = genArchive; classflagopen = functionflagopen = constructorflagopen = whileflagopen = ifflagopen = elseflagopen = ifelseflagopen = forflagopen = switchflagopen = false; @@ -169,7 +171,7 @@ namespace srcDispatch { numberAllocatedListeners = elementListeners.size(); dispatching = false; findName = false; - collectText = false; + collectedText = std::optional(); generateArchive = genArchive; classflagopen = functionflagopen = constructorflagopen = whileflagopen = ifflagopen = elseflagopen = ifelseflagopen = forflagopen = switchflagopen = false; if(genArchive) { @@ -972,10 +974,11 @@ namespace srcDispatch { findName = true; } else if(findName && ctx.currentTag == "name") { findName = false; - collectText = true; - } else if(collectText && ctx.currentTag == "block") { + collectedText = std::string(); + } else if(collectedText && (ctx.currentTag == "block")) { findName = false; - collectText = false; + ctx.currentNamespaces.back() = *collectedText; + collectedText = std::optional(); } for(int pos = 0; pos < num_attributes; ++pos) { @@ -1019,8 +1022,8 @@ namespace srcDispatch { }) ? ctx.currentToken : ""; } - if(collectText) { - ctx.currentNamespaces.back().append(ch, len); + if(collectedText) { + collectedText->append(ch, len); } if((ctx.And({ParserState::name, ParserState::function}) || ctx.And({ParserState::name, ParserState::constructor})) && ctx.Nor({ParserState::functionblock, ParserState::type, ParserState::parameterlist, ParserState::genericargumentlist, ParserState::constructorblock, ParserState::throws, ParserState::annotation})) { @@ -1072,7 +1075,8 @@ namespace srcDispatch { } if(ctx.currentTag == "namespace") { - ctx.currentNamespaces.pop_back(); + collectedText = std::optional(); + ctx.currentNamespaces.pop_back(); } --ctx.depth; From 27d58bfd04ae49e681882653e815ff894aa3eac6 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 10 Oct 2024 11:30:25 +0900 Subject: [PATCH 016/149] Finish collecting namespace/class/struct --- src/dispatcher/srcDispatcher.hpp | 34 ++++++++++++++------------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 19b93c1..4f295e8 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -81,7 +81,7 @@ namespace srcDispatch { std::size_t numberAllocatedListeners; - bool findName; + std::optional namePos; std::optional collectedText; protected: @@ -154,7 +154,7 @@ namespace srcDispatch { elementListeners = CreateListeners(listener); numberAllocatedListeners = elementListeners.size(); dispatching = false; - findName = false; + namePos = std::optional(); collectedText = std::optional(); generateArchive = genArchive; classflagopen = functionflagopen = constructorflagopen = whileflagopen = ifflagopen = elseflagopen = ifelseflagopen = forflagopen = switchflagopen = false; @@ -170,7 +170,7 @@ namespace srcDispatch { elementListeners = listeners; numberAllocatedListeners = elementListeners.size(); dispatching = false; - findName = false; + namePos = std::optional(); collectedText = std::optional(); generateArchive = genArchive; classflagopen = functionflagopen = constructorflagopen = whileflagopen = ifflagopen = elseflagopen = ifelseflagopen = forflagopen = switchflagopen = false; @@ -971,13 +971,19 @@ namespace srcDispatch { if(ctx.currentTag == "namespace") { ctx.currentNamespaces.emplace_back(); - findName = true; - } else if(findName && ctx.currentTag == "name") { - findName = false; + namePos = ctx.depth; + } if(ctx.currentTag == "class" || ctx.currentTag == "struct") { + namePos = ctx.depth; + } else if(namePos && (*namePos + 1) == ctx.depth && ctx.currentTag == "name") { + namePos = std::optional(); collectedText = std::string(); - } else if(collectedText && (ctx.currentTag == "block")) { - findName = false; - ctx.currentNamespaces.back() = *collectedText; + } else if(collectedText && (ctx.currentTag == "block" || ctx.currentTag == "super_list")) { + namePos = std::optional(); + if(srcml_element_stack.back() == "namespace") { + ctx.currentNamespaces.back() = *collectedText; + } else { + ctx.currentClassName = *collectedText; + } collectedText = std::optional(); } @@ -1011,16 +1017,6 @@ namespace srcDispatch { ctx.currentToken.clear(); ctx.currentToken.append(ch, len); std::unordered_map>::const_iterator process = process_map2.find("tokenstring"); - - if(ctx.Or({ParserState::classn, ParserState::structn}) && ctx.IsOpen(ParserState::name) && ctx.Nor({ParserState::classblock, ParserState::super_list})) { - ctx.currentClassName = std::all_of( - std::begin(ctx.currentToken), - std::end(ctx.currentToken), - [](char c) { - if(std::isalnum(c) || c == '_') return true; - return false; - }) ? ctx.currentToken : ""; - } if(collectedText) { collectedText->append(ch, len); From 2396952219b9cf9ca22af2d468d56a9973bcc7d6 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 10 Oct 2024 23:36:07 +0900 Subject: [PATCH 017/149] Simplify name gathering --- src/dispatcher/srcDispatcher.hpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 4f295e8..a917dbe 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -81,7 +82,7 @@ namespace srcDispatch { std::size_t numberAllocatedListeners; - std::optional namePos; + const std::unordered_set nameCollectElements{ "class", "struct", "namespace" }; std::optional collectedText; protected: @@ -154,7 +155,6 @@ namespace srcDispatch { elementListeners = CreateListeners(listener); numberAllocatedListeners = elementListeners.size(); dispatching = false; - namePos = std::optional(); collectedText = std::optional(); generateArchive = genArchive; classflagopen = functionflagopen = constructorflagopen = whileflagopen = ifflagopen = elseflagopen = ifelseflagopen = forflagopen = switchflagopen = false; @@ -170,7 +170,6 @@ namespace srcDispatch { elementListeners = listeners; numberAllocatedListeners = elementListeners.size(); dispatching = false; - namePos = std::optional(); collectedText = std::optional(); generateArchive = genArchive; classflagopen = functionflagopen = constructorflagopen = whileflagopen = ifflagopen = elseflagopen = ifelseflagopen = forflagopen = switchflagopen = false; @@ -253,7 +252,7 @@ namespace srcDispatch { ifflagopen = true; ++ctx.triggerField[ParserState::ifstmt]; DispatchEvent(ParserState::ifstmt, ElementState::open); - }else{ + } else { ++ctx.triggerField[ParserState::elseif]; DispatchEvent(ParserState::elseif, ElementState::open); } @@ -971,14 +970,11 @@ namespace srcDispatch { if(ctx.currentTag == "namespace") { ctx.currentNamespaces.emplace_back(); - namePos = ctx.depth; - } if(ctx.currentTag == "class" || ctx.currentTag == "struct") { - namePos = ctx.depth; - } else if(namePos && (*namePos + 1) == ctx.depth && ctx.currentTag == "name") { - namePos = std::optional(); + } + + if(ctx.currentTag == "name" && nameCollectElements.contains(srcml_element_stack.back())) { collectedText = std::string(); } else if(collectedText && (ctx.currentTag == "block" || ctx.currentTag == "super_list")) { - namePos = std::optional(); if(srcml_element_stack.back() == "namespace") { ctx.currentNamespaces.back() = *collectedText; } else { From e67485598430812737d678d4fbea2e14df9b6c13 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 11 Oct 2024 10:56:12 +0900 Subject: [PATCH 018/149] Rename unit policy --- src/policy_classes/UnitPolicySingleEvent.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/policy_classes/UnitPolicySingleEvent.hpp b/src/policy_classes/UnitPolicySingleEvent.hpp index e0d74c9..ed8e938 100644 --- a/src/policy_classes/UnitPolicySingleEvent.hpp +++ b/src/policy_classes/UnitPolicySingleEvent.hpp @@ -21,7 +21,7 @@ #include -class UnitPolicySingleEvent : +class UnitPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { @@ -31,14 +31,14 @@ class UnitPolicySingleEvent : ClassPolicy *classPolicy; public: - UnitPolicySingleEvent(std::initializer_list listeners) : + UnitPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), functionPolicy(nullptr), classPolicy(nullptr) { InitializeUnitPolicyHandlers(); } - ~UnitPolicySingleEvent() { + ~UnitPolicy() { if(functionPolicy) delete functionPolicy; if(classPolicy) delete classPolicy; } From 2b415e326f04d6c23e7386bf4fec9556bbb389cd Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 11 Oct 2024 13:12:55 +0900 Subject: [PATCH 019/149] Do not collect decl --- src/policy_classes/UnitPolicySingleEvent.hpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/policy_classes/UnitPolicySingleEvent.hpp b/src/policy_classes/UnitPolicySingleEvent.hpp index ed8e938..c97eec4 100644 --- a/src/policy_classes/UnitPolicySingleEvent.hpp +++ b/src/policy_classes/UnitPolicySingleEvent.hpp @@ -84,18 +84,12 @@ class UnitPolicy : }; openEventMap[ParserState::function] = startFunction; - openEventMap[ParserState::functiondecl] = startFunction; openEventMap[ParserState::constructor] = startFunction; - openEventMap[ParserState::constructordecl] = startFunction; openEventMap[ParserState::destructor] = startFunction; - openEventMap[ParserState::destructordecl] = startFunction; closeEventMap[ParserState::function] = endFunction; - closeEventMap[ParserState::functiondecl] = endFunction; closeEventMap[ParserState::constructor] = endFunction; - closeEventMap[ParserState::constructordecl] = endFunction; closeEventMap[ParserState::destructor] = endFunction; - closeEventMap[ParserState::destructordecl] = endFunction; } }; From 30a06274e93ed7419806f5dd0b858fd721f55b39 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 11 Oct 2024 13:14:53 +0900 Subject: [PATCH 020/149] Reorganize code --- src/policy_classes/UnitPolicySingleEvent.hpp | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/policy_classes/UnitPolicySingleEvent.hpp b/src/policy_classes/UnitPolicySingleEvent.hpp index c97eec4..3def187 100644 --- a/src/policy_classes/UnitPolicySingleEvent.hpp +++ b/src/policy_classes/UnitPolicySingleEvent.hpp @@ -64,13 +64,14 @@ class UnitPolicy : ctx.dispatcher->AddListenerDispatch(classPolicy); }; + openEventMap[ParserState::classn] = startClassPolicy; + openEventMap[ParserState::structn] = startClassPolicy; + // end of policy std::function endClassPolicy = [this](srcSAXEventContext& ctx) { }; - openEventMap[ParserState::classn] = startClassPolicy; - closeEventMap[ParserState::classn] = endClassPolicy; - openEventMap[ParserState::structn] = startClassPolicy; + closeEventMap[ParserState::classn] = endClassPolicy; closeEventMap[ParserState::structn] = endClassPolicy; // start function of policy @@ -79,17 +80,19 @@ class UnitPolicy : ctx.dispatcher->AddListenerDispatch(functionPolicy); }; + + openEventMap[ParserState::function] = startFunction; + openEventMap[ParserState::constructor] = startFunction; + openEventMap[ParserState::destructor] = startFunction; + // end of policy std::function endFunction = [this](srcSAXEventContext& ctx) { }; - openEventMap[ParserState::function] = startFunction; - openEventMap[ParserState::constructor] = startFunction; - openEventMap[ParserState::destructor] = startFunction; - closeEventMap[ParserState::function] = endFunction; - closeEventMap[ParserState::constructor] = endFunction; - closeEventMap[ParserState::destructor] = endFunction; + closeEventMap[ParserState::function] = endFunction; + closeEventMap[ParserState::constructor] = endFunction; + closeEventMap[ParserState::destructor] = endFunction; } }; From 304f395b55a9d8bf3977c4a33cde4fb6a83cf102 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 15 Oct 2024 10:37:03 +0900 Subject: [PATCH 021/149] Add start of a block policy --- src/policy_classes/BlockSingleEvent.hpp | 138 ++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 src/policy_classes/BlockSingleEvent.hpp diff --git a/src/policy_classes/BlockSingleEvent.hpp b/src/policy_classes/BlockSingleEvent.hpp new file mode 100644 index 0000000..5f49810 --- /dev/null +++ b/src/policy_classes/BlockSingleEvent.hpp @@ -0,0 +1,138 @@ +/** + * @file BlockPolicySingleEvent.hpp + * + * MODIFIED FOR STEREOCODE + * + */ +#ifndef INCLUDED_BLOCK_POLICY_SINGE_EVENT_HPP +#define INCLUDED_BLOCK_POLICY_SINGE_EVENT_HPP + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +struct BlockData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::vector> locals; + std::vector> returns; + std::vector> expr_stmts; + + std::vector> blocks; +}; + + +class BlockPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + BlockData data; + std::size_t BlockDepth; + + DeclTypePolicy* declstmtPolicy; + ReturnPolicy* returnPolicy; + ExpressionPolicy* expressionPolicy; + +public: + BlockPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + blockDepth(0), + declstmtPolicy(nullptr), + expressionPolicy(nullptr), + returnPolicy(nullptr), + blockPolicy(nullptr) { + InitializeBlockPolicyHandlers(); + } + + ~BlockPolicy() { + if (declstmtPolicy) delete declstmtPolicy; + if (returnPolicy) delete returnPolicy; + if (expressionPolicy) delete expressionPolicy; + if (blockPolicy) delete blockPolicy; + } + +protected: + std::any DataInner() const override { return std::make_shared(data); } + + void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + if (typeid(DeclTypePolicy) == typeid(*policy)) { + std::shared_ptr>> decl_data = policy->Data>>(); + for(std::shared_ptr decl : *decl_data) { + data.locals.push_back(decl); + } + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } else if (typeid(ReturnPolicy) == typeid(*policy)) { + data.returns.push_back(policy->Data()); + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } else if (typeid(ExpressionPolicy) == typeid(*policy)) { + data.expr_stmts.push_back(policy->Data()); + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } + } + +private: + void InitializeBlockPolicyHandlers() { + using namespace srcDispatch; + + CollectBlockHandlers(); + CollectDeclstmtHandlers(); + CollectReturnHandlers(); + CollectExpressionHandlers(); + + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!blockDepth) { + blockDepth = ctx.depth; + data = BlockData{}; + } else { + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + } + }; + } + + void CollectReturnHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { + if (!returnPolicy) returnPolicy = new ReturnPolicy{this}; + ctx.dispatcher->AddListenerDispatch(returnPolicy); + }; + } + + void CollectExpressionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if (!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(expressionPolicy); + }; + } + + void CollectDeclstmtHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { + if (!declstmtPolicy) declstmtPolicy = new DeclTypePolicy{this}; + ctx.dispatcher->AddListenerDispatch(declstmtPolicy); + }; + } + +}; + +#endif From e91ba603648bd3a4146cacc446844948cfc35b97 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 15 Oct 2024 10:50:21 +0900 Subject: [PATCH 022/149] Fix errors with block/function --- ...leEvent.hpp => BlockPolicySingleEvent.hpp} | 5 +- .../FunctionPolicySingleEvent.hpp | 94 +++++-------------- 2 files changed, 28 insertions(+), 71 deletions(-) rename src/policy_classes/{BlockSingleEvent.hpp => BlockPolicySingleEvent.hpp} (98%) diff --git a/src/policy_classes/BlockSingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp similarity index 98% rename from src/policy_classes/BlockSingleEvent.hpp rename to src/policy_classes/BlockPolicySingleEvent.hpp index 5f49810..a720571 100644 --- a/src/policy_classes/BlockSingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -39,11 +39,12 @@ public srcDispatch::PolicyListener { private: BlockData data; - std::size_t BlockDepth; + std::size_t blockDepth; DeclTypePolicy* declstmtPolicy; ReturnPolicy* returnPolicy; ExpressionPolicy* expressionPolicy; + BlockPolicy* blockPolicy; public: BlockPolicy(std::initializer_list listeners) @@ -65,7 +66,7 @@ public srcDispatch::PolicyListener { } protected: - std::any DataInner() const override { return std::make_shared(data); } + std::any DataInner() const override { return std::make_shared(data); } void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index 69a2094..b0a1e65 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -10,11 +10,9 @@ #include #include -#include #include #include -#include -#include +#include #include #include @@ -29,15 +27,8 @@ struct FunctionData { std::string language; std::string filename; FunctionType type; - bool isDecl; - std::shared_ptr returnType; - std::shared_ptr name; - std::vector> parameters; - std::vector> locals; //Local variables - std::vector> returnExpressions; //Expressions returned - std::vector> expressions; //All other exprs - std::set stereotypes; + bool isDecl; bool isVirtual; bool isPureVirtual; bool isConst; @@ -48,6 +39,14 @@ struct FunctionData { bool isConstExpr; bool isDelete; + std::set stereotypes; + + std::shared_ptr returnType; + std::shared_ptr name; + std::vector> parameters; + std::shared_ptr block; + + std::string ToString() const { std::string signature = name->ToString(); signature += '('; @@ -89,12 +88,10 @@ public srcDispatch::PolicyListener { FunctionData data; std::size_t functionDepth; - TypePolicy *typePolicy; - NamePolicy *namePolicy; - ParamTypePolicy *paramPolicy; - DeclTypePolicy *declstmtPolicy; - ReturnPolicy *returnPolicy; - ExpressionPolicy *expressionPolicy; + TypePolicy* typePolicy; + NamePolicy* namePolicy; + ParamTypePolicy* paramPolicy; + BlockPolicy* blockPolicy; public: FunctionPolicy(std::initializer_list listeners) @@ -104,19 +101,15 @@ public srcDispatch::PolicyListener { typePolicy(nullptr), namePolicy(nullptr), paramPolicy(nullptr), - declstmtPolicy(nullptr), - expressionPolicy(nullptr), - returnPolicy(nullptr) { + blockPolicy(nullptr) { InitializeFunctionPolicyHandlers(); } ~FunctionPolicy() { - if (typePolicy) delete typePolicy; - if (namePolicy) delete namePolicy; - if (paramPolicy) delete paramPolicy; - if (declstmtPolicy) delete declstmtPolicy; - if (returnPolicy) delete returnPolicy; - if (expressionPolicy) delete expressionPolicy; + if (typePolicy) delete typePolicy; + if (namePolicy) delete namePolicy; + if (paramPolicy) delete paramPolicy; + if (blockPolicy) delete blockPolicy; } protected: @@ -134,17 +127,8 @@ public srcDispatch::PolicyListener { } else if (typeid(ParamTypePolicy) == typeid(*policy)) { data.parameters.push_back(policy->Data()); ctx.dispatcher->RemoveListenerDispatch(nullptr); - } else if (typeid(DeclTypePolicy) == typeid(*policy)) { - std::shared_ptr>> decl_data = policy->Data>>(); - for(std::shared_ptr decl : *decl_data) { - data.locals.push_back(decl); - } - ctx.dispatcher->RemoveListenerDispatch(nullptr); - } else if (typeid(ReturnPolicy) == typeid(*policy)) { - data.returnExpressions.push_back(policy->Data()); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - } else if (typeid(ExpressionPolicy) == typeid(*policy)) { - data.expressions.push_back(policy->Data()); + } else if (typeid(BlockPolicy) == typeid(*policy)) { + data.block = policy->Data(); ctx.dispatcher->RemoveListenerDispatch(nullptr); } } @@ -185,9 +169,7 @@ public srcDispatch::PolicyListener { CollectNameHandlers(); CollectParameterHandlers(); CollectOtherHandlers(); - CollectDeclstmtHandlers(); - CollectReturnHandlers(); - CollectExpressionHandlers(); + CollectBlockHandlers(); } }; @@ -257,22 +239,6 @@ public srcDispatch::PolicyListener { }; } - void CollectReturnHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { - if (!returnPolicy) returnPolicy = new ReturnPolicy{this}; - ctx.dispatcher->AddListenerDispatch(returnPolicy); - }; - } - - void CollectExpressionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(expressionPolicy); - }; - } - void CollectOtherHandlers() { using namespace srcDispatch; closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { @@ -301,22 +267,12 @@ public srcDispatch::PolicyListener { }; } - /** @todo Will not work with local classes. */ - /** @todo May need to add optimization that ignores declaration statement initialization. */ - void CollectDeclstmtHandlers(){ + void CollectBlockHandlers() { using namespace srcDispatch; openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { if (functionDepth && (functionDepth + 1) == ctx.depth) { - openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - if (!declstmtPolicy) declstmtPolicy = new DeclTypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(declstmtPolicy); - }; - } - }; - - closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - NopOpenEvents({ParserState::declstmt}); + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); } }; } From 433fe0f7131164ca74cee19425e970c82cde9ced Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 15 Oct 2024 10:58:51 +0900 Subject: [PATCH 023/149] Add notify to block close --- src/policy_classes/BlockPolicySingleEvent.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index a720571..ceefadb 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -108,6 +108,15 @@ public srcDispatch::PolicyListener { ctx.dispatcher->AddListenerDispatch(blockPolicy); } }; + + closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(blockDepth && blockDepth == ctx.depth) { + blockDepth = 0; + NotifyAll(ctx); + InitializeBlockPolicyHandlers(); + } + }; + } void CollectReturnHandlers() { From 3c6de2e839554ed657da5fb9e5786b3507c1d0ef Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 15 Oct 2024 11:03:11 +0900 Subject: [PATCH 024/149] Fix catch of block notify --- src/policy_classes/BlockPolicySingleEvent.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index ceefadb..61039f7 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -83,6 +83,9 @@ public srcDispatch::PolicyListener { } else if (typeid(ExpressionPolicy) == typeid(*policy)) { data.expr_stmts.push_back(policy->Data()); ctx.dispatcher->RemoveListenerDispatch(nullptr); + } else if (typeid(BlockPolicy) == typeid(*policy)) { + data.blocks.push_back(policy->Data()); + ctx.dispatcher->RemoveListenerDispatch(nullptr); } } From 17ddf61f6e765199c50fbbd700b04805cde73def Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 15 Oct 2024 11:59:58 +0900 Subject: [PATCH 025/149] Add expr stmt policy --- src/policy_classes/BlockPolicySingleEvent.hpp | 28 +++--- .../ExprStmtPolicySingleEvent.hpp | 87 +++++++++++++++++++ 2 files changed, 101 insertions(+), 14 deletions(-) create mode 100644 src/policy_classes/ExprStmtPolicySingleEvent.hpp diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index 61039f7..088d0eb 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -41,10 +41,10 @@ public srcDispatch::PolicyListener { BlockData data; std::size_t blockDepth; - DeclTypePolicy* declstmtPolicy; - ReturnPolicy* returnPolicy; - ExpressionPolicy* expressionPolicy; - BlockPolicy* blockPolicy; + DeclTypePolicy* declstmtPolicy; + ReturnPolicy* returnPolicy; + ExprStmtPolicy* exprStmtPolicy; + BlockPolicy* blockPolicy; public: BlockPolicy(std::initializer_list listeners) @@ -52,17 +52,17 @@ public srcDispatch::PolicyListener { data{}, blockDepth(0), declstmtPolicy(nullptr), - expressionPolicy(nullptr), + exprStmtPolicy(nullptr), returnPolicy(nullptr), blockPolicy(nullptr) { InitializeBlockPolicyHandlers(); } ~BlockPolicy() { - if (declstmtPolicy) delete declstmtPolicy; - if (returnPolicy) delete returnPolicy; - if (expressionPolicy) delete expressionPolicy; - if (blockPolicy) delete blockPolicy; + if (declstmtPolicy) delete declstmtPolicy; + if (returnPolicy) delete returnPolicy; + if (exprStmtPolicy) delete exprStmtPolicy; + if (blockPolicy) delete blockPolicy; } protected: @@ -80,7 +80,7 @@ public srcDispatch::PolicyListener { } else if (typeid(ReturnPolicy) == typeid(*policy)) { data.returns.push_back(policy->Data()); ctx.dispatcher->RemoveListenerDispatch(nullptr); - } else if (typeid(ExpressionPolicy) == typeid(*policy)) { + } else if (typeid(ExprStmtPolicy) == typeid(*policy)) { data.expr_stmts.push_back(policy->Data()); ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(BlockPolicy) == typeid(*policy)) { @@ -132,9 +132,9 @@ public srcDispatch::PolicyListener { void CollectExpressionHandlers() { using namespace srcDispatch; - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(expressionPolicy); + openEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { + if (!exprStmtPolicy) exprStmtPolicy = new ExprStmtPolicy{this}; + ctx.dispatcher->AddListenerDispatch(exprStmtPolicy); }; } diff --git a/src/policy_classes/ExprStmtPolicySingleEvent.hpp b/src/policy_classes/ExprStmtPolicySingleEvent.hpp new file mode 100644 index 0000000..afbdcb5 --- /dev/null +++ b/src/policy_classes/ExprStmtPolicySingleEvent.hpp @@ -0,0 +1,87 @@ +/** + * @file ExprStmtPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_EXPR_STMT_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_EXPR_STMT_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include + +#include +#include +#include + + +class ExprStmtPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + std::shared_ptr data; + std::size_t exprStmtDepth; + ExpressionPolicy* exprPolicy; + +public: + ExprStmtPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + exprStmtDepth(0), + exprPolicy(nullptr) { + InitializeExprStmtPolicyHandlers(); + } + + ~ExprStmtPolicy() { + if (exprPolicy) delete exprPolicy; + } + +protected: + std::any DataInner() const override { return data; } + + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + if (typeid(ExpressionPolicy) == typeid(*policy)) { + data = policy->Data(); + ctx.dispatcher->RemoveListener(nullptr); + } + } + + void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + +private: + void InitializeExprStmtPolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { + if (!exprStmtDepth) { + exprStmtDepth = ctx.depth; + data = std::make_shared(); + CollectExpressionHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { + if (exprStmtDepth && exprStmtDepth == ctx.depth) { + exprStmtDepth = 0; + NotifyAll(ctx); + InitializeExprStmtPolicyHandlers(); + } + }; + } + + void CollectExpressionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(exprPolicy); + }; + } + +}; + +#endif From ab586a1ddda3c2e5ae95106b8234b2eabfb3b950 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 15 Oct 2024 14:33:00 +0900 Subject: [PATCH 026/149] Add start of conditional policy --- .../ConditionalPolicySingleEvent.hpp | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/policy_classes/ConditionalPolicySingleEvent.hpp diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp new file mode 100644 index 0000000..13e5202 --- /dev/null +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -0,0 +1,111 @@ +/** + * @file ConditionalPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_CONDITIONAL_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_CONDITIONAL_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include +#include + +#include +#include +#include + +struct ConditionalData { + + enum ConditionalType { IF, WHILE, FOR, FOREACH, SWITCH, DO }; + + ConditionalType type; + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::shared_ptr condition; + std::shared_ptr block; +}; + + +class ConditionalPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + ConditionalData data; + std::size_t conditionalDepth; + ExpressionPolicy* exprPolicy; + BlockPolicy * blockPolicy; + +public: + ConditionalPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + returnDepth(0), + exprPolicy(nullptr) { + InitializeConditionalPolicyHandlers(); + } + + ~ConditionalPolicy() { + if (exprPolicy) delete exprPolicy; + } + +protected: + std::any DataInner() const override { return std::make_shared(data); } + + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + if (typeid(BlockPolicy) == typeid(*policy)) { + data = policy->Data(); + ctx.dispatcher->RemoveListener(nullptr); + } + } + + void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + +private: + void InitializeConditionalPolicyHandlers() { + using namespace srcDispatch; + + // start of policy + openEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx) { + if (!conditionalDepth) { + conditionalDepth = ctx.depth; + data = ConditionalData{}; + data.type = IF; + CollectConditionHandlers(); + CollectBlockHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx) { + if (conditionalDepth && conditionalDepth == ctx.depth) { + conditionalDepth = 0; + NotifyAll(ctx); + InitializeConditionalPolicyHandlers(); + } + }; + } + + void CollectConditionHandlers() { + } + + void CollectBlockHandlers() { + + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if (conditionalDepth && (conditionalDepth + 1) == ctx.depth) { + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + } + }; + + } + +}; + +#endif From 3066bab22a937d0b00107228d183905b10156d38 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 16 Oct 2024 09:25:19 +0900 Subject: [PATCH 027/149] Set line numbers for block --- src/policy_classes/BlockPolicySingleEvent.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index 088d0eb..e21743f 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -106,6 +106,7 @@ public srcDispatch::PolicyListener { if(!blockDepth) { blockDepth = ctx.depth; data = BlockData{}; + data.startLineNumber = ctx.currentLineNumber; } else { if (!blockPolicy) blockPolicy = new BlockPolicy{this}; ctx.dispatcher->AddListenerDispatch(blockPolicy); @@ -115,6 +116,7 @@ public srcDispatch::PolicyListener { closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { if(blockDepth && blockDepth == ctx.depth) { blockDepth = 0; + data.endLineNumber = ctx.currentLineNumber; NotifyAll(ctx); InitializeBlockPolicyHandlers(); } From 3791a54ff96e7362068e43df9bfbbc7a9212e0c2 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 16 Oct 2024 09:54:21 +0900 Subject: [PATCH 028/149] Flush out more of start/end events for conditionals --- .../ConditionalPolicySingleEvent.cpp | 82 +++++++++++++++++++ .../ConditionalPolicySingleEvent.hpp | 73 +++-------------- 2 files changed, 94 insertions(+), 61 deletions(-) create mode 100644 src/policy_classes/ConditionalPolicySingleEvent.cpp diff --git a/src/policy_classes/ConditionalPolicySingleEvent.cpp b/src/policy_classes/ConditionalPolicySingleEvent.cpp new file mode 100644 index 0000000..02b2e6b --- /dev/null +++ b/src/policy_classes/ConditionalPolicySingleEvent.cpp @@ -0,0 +1,82 @@ +/** + * @file ConditionalPolicySingleEvent.cpp + * + * + */ + +#include + +#include + +ConditionalPolicy::ConditionalPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + conditionalDepth(0), + exprPolicy(nullptr) { + InitializeConditionalPolicyHandlers(); +} + +ConditionalPolicy::~ConditionalPolicy() { + if (exprPolicy) delete exprPolicy; +} + +std::any ConditionalPolicy::DataInner() const { return std::make_shared(data); } + +void ConditionalPolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { + if (typeid(BlockPolicy) == typeid(*policy)) { + data.block = policy->Data(); + ctx.dispatcher->RemoveListener(nullptr); + } +} + +void ConditionalPolicy::NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) {} //doesn't use other parsers + +void ConditionalPolicy::InitializeConditionalPolicyHandlers() { + using namespace srcDispatch; + + #define startConditional(TYPE) \ + [this](srcSAXEventContext& ctx) { \ + if (!conditionalDepth) { \ + conditionalDepth = ctx.depth; \ + data = ConditionalData{}; \ + data.type = TYPE; \ + CollectConditionHandlers(); \ + CollectBlockHandlers(); \ + } \ + }; \ + + openEventMap[ParserState::ifstmt] = startConditional(ConditionalData::IF); + openEventMap[ParserState::whilestmt] = startConditional(ConditionalData::WHILE); + openEventMap[ParserState::forstmt] = startConditional(ConditionalData::FOR); + openEventMap[ParserState::switchstmt] = startConditional(ConditionalData::SWITCH); + openEventMap[ParserState::dostmt] = startConditional(ConditionalData::DO); + + std::function endConditional =[this](srcSAXEventContext& ctx) { + if (conditionalDepth && conditionalDepth == ctx.depth) { + conditionalDepth = 0; + NotifyAll(ctx); + InitializeConditionalPolicyHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::ifstmt] = endConditional; + closeEventMap[ParserState::whilestmt] = endConditional; + closeEventMap[ParserState::forstmt] = endConditional; + closeEventMap[ParserState::switchstmt] = endConditional; + closeEventMap[ParserState::dostmt] = endConditional; +} + +void ConditionalPolicy::CollectConditionHandlers() { +} + +void ConditionalPolicy::CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if (conditionalDepth && (conditionalDepth + 1) == ctx.depth) { + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + } + }; + +} diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index 13e5202..58eed2e 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -7,16 +7,18 @@ #define INCLUDED_CONDITIONAL_POLICY_SINGLE_EVENT_HPP #include -#include +#include #include #include -#include #include #include #include +class BlockPolicy; +class BlockData; + struct ConditionalData { enum ConditionalType { IF, WHILE, FOR, FOREACH, SWITCH, DO }; @@ -43,69 +45,18 @@ public srcDispatch::PolicyListener { BlockPolicy * blockPolicy; public: - ConditionalPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - returnDepth(0), - exprPolicy(nullptr) { - InitializeConditionalPolicyHandlers(); - } - - ~ConditionalPolicy() { - if (exprPolicy) delete exprPolicy; - } + ConditionalPolicy(std::initializer_list listeners); + ~ConditionalPolicy(); protected: - std::any DataInner() const override { return std::make_shared(data); } - - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { - if (typeid(BlockPolicy) == typeid(*policy)) { - data = policy->Data(); - ctx.dispatcher->RemoveListener(nullptr); - } - } - - void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + std::any DataInner() const override; + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override; + void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override; private: - void InitializeConditionalPolicyHandlers() { - using namespace srcDispatch; - - // start of policy - openEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx) { - if (!conditionalDepth) { - conditionalDepth = ctx.depth; - data = ConditionalData{}; - data.type = IF; - CollectConditionHandlers(); - CollectBlockHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx) { - if (conditionalDepth && conditionalDepth == ctx.depth) { - conditionalDepth = 0; - NotifyAll(ctx); - InitializeConditionalPolicyHandlers(); - } - }; - } - - void CollectConditionHandlers() { - } - - void CollectBlockHandlers() { - - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if (conditionalDepth && (conditionalDepth + 1) == ctx.depth) { - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); - } - }; - - } - + void InitializeConditionalPolicyHandlers(); + void CollectConditionHandlers(); + void CollectBlockHandlers(); }; #endif From 173a75890133432fba0144f043bf7cbce3f5ea5f Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 16 Oct 2024 09:57:24 +0900 Subject: [PATCH 029/149] Fix files missing rename for dispatcher --- src/policy_classes/ExprStmtPolicySingleEvent.hpp | 2 +- src/policy_classes/ReturnPolicySingleEvent.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/policy_classes/ExprStmtPolicySingleEvent.hpp b/src/policy_classes/ExprStmtPolicySingleEvent.hpp index afbdcb5..0a39991 100644 --- a/src/policy_classes/ExprStmtPolicySingleEvent.hpp +++ b/src/policy_classes/ExprStmtPolicySingleEvent.hpp @@ -7,7 +7,7 @@ #define INCLUDED_EXPR_STMT_POLICY_SINGLE_EVENT_HPP #include -#include +#include #include #include diff --git a/src/policy_classes/ReturnPolicySingleEvent.hpp b/src/policy_classes/ReturnPolicySingleEvent.hpp index 899d414..4758059 100644 --- a/src/policy_classes/ReturnPolicySingleEvent.hpp +++ b/src/policy_classes/ReturnPolicySingleEvent.hpp @@ -7,7 +7,7 @@ #define INCLUDED_RETURN_POLICY_SINGLE_EVENT_HPP #include -#include +#include #include #include From 888401c2aaf235d350f76ac262c6ae9d2cf163d9 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 16 Oct 2024 10:11:48 +0900 Subject: [PATCH 030/149] Add condition gathering --- .../ConditionPolicySingleEvent.hpp | 89 +++++++++++++++++++ .../ConditionalPolicySingleEvent.cpp | 23 +++-- .../ConditionalPolicySingleEvent.hpp | 10 +-- 3 files changed, 112 insertions(+), 10 deletions(-) create mode 100644 src/policy_classes/ConditionPolicySingleEvent.hpp diff --git a/src/policy_classes/ConditionPolicySingleEvent.hpp b/src/policy_classes/ConditionPolicySingleEvent.hpp new file mode 100644 index 0000000..4187182 --- /dev/null +++ b/src/policy_classes/ConditionPolicySingleEvent.hpp @@ -0,0 +1,89 @@ +/** + * @file ConditionPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_CONDITION_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_CONDITION_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include + +#include +#include +#include + + +// Collect the expression in the return +// +class ConditionPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + std::shared_ptr data; + std::size_t conditionDepth; + ExpressionPolicy* exprPolicy; + +public: + ConditionPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + conditionDepth(0), + exprPolicy(nullptr) { + InitializeConditionPolicyHandlers(); + } + + ~ConditionPolicy() { + if (exprPolicy) delete exprPolicy; + } + +protected: + std::any DataInner() const override { return data; } + + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + if (typeid(ExpressionPolicy) == typeid(*policy)) { + data = policy->Data(); + ctx.dispatcher->RemoveListener(nullptr); + } + } + + void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + +private: + void InitializeConditionPolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if (!conditionDepth) { + conditionDepth = ctx.depth; + data = std::make_shared(); + CollectExpressionHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if (conditionDepth && conditionDepth == ctx.depth) { + conditionDepth = 0; + NotifyAll(ctx); + InitializeConditionPolicyHandlers(); + } + }; + } + + void CollectExpressionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(exprPolicy); + }; + } + +}; + +#endif diff --git a/src/policy_classes/ConditionalPolicySingleEvent.cpp b/src/policy_classes/ConditionalPolicySingleEvent.cpp index 02b2e6b..d0cd221 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.cpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.cpp @@ -12,18 +12,23 @@ ConditionalPolicy::ConditionalPolicy(std::initializer_list(data); } void ConditionalPolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { - if (typeid(BlockPolicy) == typeid(*policy)) { + if (typeid(ConditionPolicy) == typeid(*policy)) { + data.condition = policy->Data(); + ctx.dispatcher->RemoveListener(nullptr); + } else if (typeid(BlockPolicy) == typeid(*policy)) { data.block = policy->Data(); ctx.dispatcher->RemoveListener(nullptr); } @@ -68,15 +73,23 @@ void ConditionalPolicy::InitializeConditionalPolicyHandlers() { } void ConditionalPolicy::CollectConditionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if(!conditionalDepth) return; + if(data.type == ConditionalData::FOR && (conditionalDepth + 2) != ctx.depth) return; + if(data.type != ConditionalData::FOR && (conditionalDepth + 1) != ctx.depth) return; + + if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(conditionPolicy); + }; } void ConditionalPolicy::CollectBlockHandlers() { using namespace srcDispatch; openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if (conditionalDepth && (conditionalDepth + 1) == ctx.depth) { + if(conditionalDepth && (conditionalDepth + 1) == ctx.depth) { if (!blockPolicy) blockPolicy = new BlockPolicy{this}; ctx.dispatcher->AddListenerDispatch(blockPolicy); } }; - } diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index 58eed2e..76188b0 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -39,10 +39,10 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - ConditionalData data; - std::size_t conditionalDepth; - ExpressionPolicy* exprPolicy; - BlockPolicy * blockPolicy; + ConditionalData data; + std::size_t conditionalDepth; + ConditionPolicy* conditionPolicy; + BlockPolicy * blockPolicy; public: ConditionalPolicy(std::initializer_list listeners); From d069bcd843b9a8d23e8c35707a8b4cdacecacc8b Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 16 Oct 2024 10:23:53 +0900 Subject: [PATCH 031/149] Add collection of conditionals --- src/policy_classes/BlockPolicySingleEvent.hpp | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index e21743f..c6d55d3 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -29,6 +30,7 @@ struct BlockData { std::vector> expr_stmts; std::vector> blocks; + std::vector> conditionals; }; @@ -41,10 +43,11 @@ public srcDispatch::PolicyListener { BlockData data; std::size_t blockDepth; - DeclTypePolicy* declstmtPolicy; - ReturnPolicy* returnPolicy; - ExprStmtPolicy* exprStmtPolicy; - BlockPolicy* blockPolicy; + DeclTypePolicy* declstmtPolicy; + ReturnPolicy* returnPolicy; + ExprStmtPolicy* exprStmtPolicy; + BlockPolicy* blockPolicy; + ConditionalPolicy* conditionalPolicy; public: BlockPolicy(std::initializer_list listeners) @@ -54,15 +57,17 @@ public srcDispatch::PolicyListener { declstmtPolicy(nullptr), exprStmtPolicy(nullptr), returnPolicy(nullptr), - blockPolicy(nullptr) { + blockPolicy(nullptr), + conditionalPolicy(nullptr) { InitializeBlockPolicyHandlers(); } ~BlockPolicy() { - if (declstmtPolicy) delete declstmtPolicy; - if (returnPolicy) delete returnPolicy; - if (exprStmtPolicy) delete exprStmtPolicy; - if (blockPolicy) delete blockPolicy; + if (declstmtPolicy) delete declstmtPolicy; + if (returnPolicy) delete returnPolicy; + if (exprStmtPolicy) delete exprStmtPolicy; + if (blockPolicy) delete blockPolicy; + if (conditionalPolicy) delete conditionalPolicy; } protected: @@ -86,6 +91,9 @@ public srcDispatch::PolicyListener { } else if (typeid(BlockPolicy) == typeid(*policy)) { data.blocks.push_back(policy->Data()); ctx.dispatcher->RemoveListenerDispatch(nullptr); + } else if (typeid(ConditionalPolicy) == typeid(*policy)) { + data.conditionals.push_back(policy->Data()); + ctx.dispatcher->RemoveListenerDispatch(nullptr); } } @@ -97,6 +105,7 @@ public srcDispatch::PolicyListener { CollectDeclstmtHandlers(); CollectReturnHandlers(); CollectExpressionHandlers(); + CollectConditionalsHandlers(); } @@ -148,6 +157,22 @@ public srcDispatch::PolicyListener { }; } + void CollectConditionalsHandlers() { + using namespace srcDispatch; + std::function startConditional = [this](srcSAXEventContext& ctx) { + if (!conditionalPolicy) conditionalPolicy = new ConditionalPolicy{this}; + ctx.dispatcher->AddListenerDispatch(conditionalPolicy); + }; + + openEventMap[ParserState::ifstmt] = startConditional; + openEventMap[ParserState::whilestmt] = startConditional; + openEventMap[ParserState::forstmt] = startConditional; + openEventMap[ParserState::switchstmt] = startConditional; + openEventMap[ParserState::dostmt] = startConditional; + + + } + }; #endif From f5ba45ae3677dc5003066146e9ba8cca0f050d64 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 16 Oct 2024 10:26:41 +0900 Subject: [PATCH 032/149] Collect line number info --- .../ConditionalPolicySingleEvent.cpp | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/policy_classes/ConditionalPolicySingleEvent.cpp b/src/policy_classes/ConditionalPolicySingleEvent.cpp index d0cd221..0b613d0 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.cpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.cpp @@ -39,16 +39,17 @@ void ConditionalPolicy::NotifyWrite(const PolicyDispatcher * policy, srcDispatch void ConditionalPolicy::InitializeConditionalPolicyHandlers() { using namespace srcDispatch; - #define startConditional(TYPE) \ - [this](srcSAXEventContext& ctx) { \ - if (!conditionalDepth) { \ - conditionalDepth = ctx.depth; \ - data = ConditionalData{}; \ - data.type = TYPE; \ - CollectConditionHandlers(); \ - CollectBlockHandlers(); \ - } \ - }; \ + #define startConditional(TYPE) \ + [this](srcSAXEventContext& ctx) { \ + if (!conditionalDepth) { \ + conditionalDepth = ctx.depth; \ + data = ConditionalData{}; \ + data.type = TYPE; \ + data.startLineNumber = ctx.currentLineNumber; \ + CollectConditionHandlers(); \ + CollectBlockHandlers(); \ + } \ + }; \ openEventMap[ParserState::ifstmt] = startConditional(ConditionalData::IF); openEventMap[ParserState::whilestmt] = startConditional(ConditionalData::WHILE); @@ -59,6 +60,7 @@ void ConditionalPolicy::InitializeConditionalPolicyHandlers() { std::function endConditional =[this](srcSAXEventContext& ctx) { if (conditionalDepth && conditionalDepth == ctx.depth) { conditionalDepth = 0; + data.endLineNumber = ctx.currentLineNumber; NotifyAll(ctx); InitializeConditionalPolicyHandlers(); } From 74b9dac54686e6c0ac1e0d66b4cca89c26151df9 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 16 Oct 2024 10:32:35 +0900 Subject: [PATCH 033/149] Add conditional print --- src/policy_classes/ConditionalPolicySingleEvent.cpp | 7 +++++++ src/policy_classes/ConditionalPolicySingleEvent.hpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/policy_classes/ConditionalPolicySingleEvent.cpp b/src/policy_classes/ConditionalPolicySingleEvent.cpp index 0b613d0..16e095e 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.cpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.cpp @@ -8,6 +8,13 @@ #include +std::ostream & operator<<(std::ostream& out, const ConditionalData& conditionalData) { + if (conditionalData.condition){ + out << *conditionalData.condition; + } + return out; +} + ConditionalPolicy::ConditionalPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index 76188b0..a2a61eb 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -30,6 +30,8 @@ struct ConditionalData { std::shared_ptr condition; std::shared_ptr block; + + friend std::ostream & operator<<(std::ostream& out, const ConditionalData& conditionalData); }; From 7fddfbd9d4011a491491828ced3b77c2771c6c74 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 18 Oct 2024 11:42:46 +0900 Subject: [PATCH 034/149] Add error classes and add throw to notify --- src/dispatcher/srcDispatchUtilities.hpp | 9 +++++++++ src/policy_classes/BlockPolicySingleEvent.hpp | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 4561fd3..0c01a07 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -29,6 +29,8 @@ #include #include #include +#include + #include #include @@ -208,6 +210,9 @@ namespace srcDispatch{ } }; + class EventError : public std::runtime_error { + public: EventError(const std::string& msg) : std::runtime_error(msg) {} + }; class EventListener { typedef std::unordered_map, std::hash> EventMap; protected: @@ -426,6 +431,10 @@ namespace srcDispatch{ virtual ~EventDispatcher() {} virtual void DispatchEvent(ParserState, ElementState) = 0; }; + + class PolicyError : public std::runtime_error { + public: PolicyError(const std::string& msg) : std::runtime_error(msg) {} + }; class PolicyDispatcher; class PolicyListener { diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index c6d55d3..f80d58d 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -94,6 +94,8 @@ public srcDispatch::PolicyListener { } else if (typeid(ConditionalPolicy) == typeid(*policy)) { data.conditionals.push_back(policy->Data()); ctx.dispatcher->RemoveListenerDispatch(nullptr); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } } From 225b20a2780a193e3c8850d8fd967d269d46e270 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 18 Oct 2024 11:43:48 +0900 Subject: [PATCH 035/149] Remove common code from branches --- src/policy_classes/BlockPolicySingleEvent.hpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index f80d58d..d7e728b 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -81,22 +81,19 @@ public srcDispatch::PolicyListener { for(std::shared_ptr decl : *decl_data) { data.locals.push_back(decl); } - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(ReturnPolicy) == typeid(*policy)) { data.returns.push_back(policy->Data()); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(ExprStmtPolicy) == typeid(*policy)) { data.expr_stmts.push_back(policy->Data()); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(BlockPolicy) == typeid(*policy)) { data.blocks.push_back(policy->Data()); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(ConditionalPolicy) == typeid(*policy)) { data.conditionals.push_back(policy->Data()); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } + + ctx.dispatcher->RemoveListenerDispatch(nullptr); } private: From 5cae7bb9a66b54c88443b86721048ede6dbe7a5a Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 18 Oct 2024 11:50:19 +0900 Subject: [PATCH 036/149] Add error detection to notify --- src/policy_classes/CallPolicySingleEvent.cpp | 9 +++++---- src/policy_classes/ClassPolicySingleEvent.hpp | 10 +++++----- src/policy_classes/ConditionPolicySingleEvent.hpp | 2 ++ src/policy_classes/ConditionalPolicySingleEvent.cpp | 6 ++++-- src/policy_classes/DeclTypePolicySingleEvent.hpp | 6 +++--- src/policy_classes/ExprStmtPolicySingleEvent.hpp | 2 ++ src/policy_classes/ExpressionPolicySingleEvent.cpp | 6 ++++-- src/policy_classes/FunctionPolicySingleEvent.hpp | 8 ++++---- src/policy_classes/NamePolicySingleEvent.cpp | 6 +++--- src/policy_classes/ParamTypePolicySingleEvent.hpp | 6 ++++-- src/policy_classes/ReturnPolicySingleEvent.hpp | 2 ++ 11 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/policy_classes/CallPolicySingleEvent.cpp b/src/policy_classes/CallPolicySingleEvent.cpp index 083cf7e..a31a693 100644 --- a/src/policy_classes/CallPolicySingleEvent.cpp +++ b/src/policy_classes/CallPolicySingleEvent.cpp @@ -27,12 +27,13 @@ void CallPolicy::Notify(const srcDispatch::PolicyDispatcher * policy, const srcD using namespace srcDispatch; if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); - ctx.dispatcher->RemoveListener(nullptr); - } - if (typeid(ExpressionPolicy) == typeid(*policy)) { + } else if (typeid(ExpressionPolicy) == typeid(*policy)) { data.arguments.push_back(policy->Data()); - ctx.dispatcher->RemoveListener(nullptr); + } else { + throw PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } + + ctx.dispatcher->RemoveListener(nullptr); } void CallPolicy::InitializeCallPolicyHandlers() { diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index 6084771..35a79c8 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -90,14 +90,12 @@ public srcDispatch::PolicyListener { void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(DeclTypePolicy) == typeid(*policy)) { std::shared_ptr>> decl_data = policy->Data>>(); for (std::shared_ptr decl : *decl_data) { data.fields[currentRegion].emplace_back(decl); } decl_data->clear(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(FunctionPolicy) == typeid(*policy)) { std::shared_ptr f_data = policy->Data(); if (f_data->isPureVirtual) @@ -108,11 +106,13 @@ public srcDispatch::PolicyListener { data.operators[currentRegion].emplace_back(f_data); else data.methods[currentRegion].emplace_back(f_data); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(ClassPolicy) == typeid(*policy)) { data.innerClasses[currentRegion].emplace_back(policy->Data()); - ctx.dispatcher->RemoveListener(nullptr); - } + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListenerDispatch(nullptr); } protected: diff --git a/src/policy_classes/ConditionPolicySingleEvent.hpp b/src/policy_classes/ConditionPolicySingleEvent.hpp index 4187182..1e2a4a4 100644 --- a/src/policy_classes/ConditionPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionPolicySingleEvent.hpp @@ -49,6 +49,8 @@ public srcDispatch::PolicyListener { if (typeid(ExpressionPolicy) == typeid(*policy)) { data = policy->Data(); ctx.dispatcher->RemoveListener(nullptr); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } } diff --git a/src/policy_classes/ConditionalPolicySingleEvent.cpp b/src/policy_classes/ConditionalPolicySingleEvent.cpp index 16e095e..d134a66 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.cpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.cpp @@ -34,11 +34,13 @@ std::any ConditionalPolicy::DataInner() const { return std::make_sharedData(); - ctx.dispatcher->RemoveListener(nullptr); } else if (typeid(BlockPolicy) == typeid(*policy)) { data.block = policy->Data(); - ctx.dispatcher->RemoveListener(nullptr); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } + + ctx.dispatcher->RemoveListener(nullptr); } void ConditionalPolicy::NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) {} //doesn't use other parsers diff --git a/src/policy_classes/DeclTypePolicySingleEvent.hpp b/src/policy_classes/DeclTypePolicySingleEvent.hpp index 353fc03..6f97a65 100644 --- a/src/policy_classes/DeclTypePolicySingleEvent.hpp +++ b/src/policy_classes/DeclTypePolicySingleEvent.hpp @@ -89,15 +89,15 @@ public srcDispatch::PolicyListener { virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { if (typeid(TypePolicy) == typeid(*policy)) { type = std::shared_ptr(policy->Data()); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(NamePolicy) == typeid(*policy)) { data.back()->name = policy->Data(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(ExpressionPolicy) == typeid(*policy)) { initializer = policy->Data(); - ctx.dispatcher->RemoveListener(nullptr); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } + ctx.dispatcher->RemoveListener(nullptr); } private: diff --git a/src/policy_classes/ExprStmtPolicySingleEvent.hpp b/src/policy_classes/ExprStmtPolicySingleEvent.hpp index 0a39991..ae512e5 100644 --- a/src/policy_classes/ExprStmtPolicySingleEvent.hpp +++ b/src/policy_classes/ExprStmtPolicySingleEvent.hpp @@ -47,6 +47,8 @@ public srcDispatch::PolicyListener { if (typeid(ExpressionPolicy) == typeid(*policy)) { data = policy->Data(); ctx.dispatcher->RemoveListener(nullptr); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } } diff --git a/src/policy_classes/ExpressionPolicySingleEvent.cpp b/src/policy_classes/ExpressionPolicySingleEvent.cpp index 1b291ab..f72505d 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.cpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.cpp @@ -30,12 +30,14 @@ ExpressionPolicy::~ExpressionPolicy() { void ExpressionPolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { if(typeid(NamePolicy) == typeid(*policy)) { data.expr.push_back(std::make_shared(ExpressionElement::NAME, policy->Data())); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if(typeid(CallPolicy) == typeid(*policy)) { data.expr.push_back(std::make_shared(ExpressionElement::CALL, policy->Data())); - ctx.dispatcher->RemoveListenerDispatch(nullptr); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } + //Operators are added in CollectOtherHandlers() + ctx.dispatcher->RemoveListenerDispatch(nullptr); } void ExpressionPolicy::InitializeExpressionPolicyHandlers() { diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index b0a1e65..0455d54 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -120,17 +120,17 @@ public srcDispatch::PolicyListener { virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { if (typeid(TypePolicy) == typeid(*policy)) { data.returnType = policy->Data(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(ParamTypePolicy) == typeid(*policy)) { data.parameters.push_back(policy->Data()); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(BlockPolicy) == typeid(*policy)) { data.block = policy->Data(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } + + ctx.dispatcher->RemoveListenerDispatch(nullptr); } private: diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index 14406d1..ccf166b 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -56,15 +56,15 @@ NamePolicy::~NamePolicy() { void NamePolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { if (typeid(NamePolicy) == typeid(*policy)) { data.names.push_back(policy->Data()); - ctx.dispatcher->RemoveListener(nullptr); } else if (typeid(TemplateArgumentPolicy) == typeid(*policy)) { data.templateArguments.push_back(policy->Data()); - ctx.dispatcher->RemoveListener(nullptr); } else if (typeid(ExpressionPolicy) == typeid(*policy)) { data.indices = policy->Data(); - ctx.dispatcher->RemoveListener(nullptr); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } + ctx.dispatcher->RemoveListener(nullptr); } diff --git a/src/policy_classes/ParamTypePolicySingleEvent.hpp b/src/policy_classes/ParamTypePolicySingleEvent.hpp index 000d723..57a2f76 100644 --- a/src/policy_classes/ParamTypePolicySingleEvent.hpp +++ b/src/policy_classes/ParamTypePolicySingleEvent.hpp @@ -64,11 +64,13 @@ public srcDispatch::PolicyListener { virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(TypePolicy) == typeid(*policy)) { data.type = policy->Data(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); } else if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } + + ctx.dispatcher->RemoveListenerDispatch(nullptr); } void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers diff --git a/src/policy_classes/ReturnPolicySingleEvent.hpp b/src/policy_classes/ReturnPolicySingleEvent.hpp index 4758059..6b9cc58 100644 --- a/src/policy_classes/ReturnPolicySingleEvent.hpp +++ b/src/policy_classes/ReturnPolicySingleEvent.hpp @@ -49,6 +49,8 @@ public srcDispatch::PolicyListener { if (typeid(ExpressionPolicy) == typeid(*policy)) { data = policy->Data(); ctx.dispatcher->RemoveListener(nullptr); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } } From 58252cac38df5a8f54b035a097cff82e5e5be77d Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 21 Oct 2024 12:20:17 +0900 Subject: [PATCH 037/149] Add a control policy, untested/unfinished --- .../ControlPolicySingleEvent.hpp | 162 ++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 src/policy_classes/ControlPolicySingleEvent.hpp diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp new file mode 100644 index 0000000..6b9746b --- /dev/null +++ b/src/policy_classes/ControlPolicySingleEvent.hpp @@ -0,0 +1,162 @@ +/** + * @file ControlPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_CONTROL_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_CONTROL_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include +#include + +#include +#include +#include + +struct ControlData { + + unsigned int lineNumber; + + std::shared_ptr init; + std::shared_ptr condition; + std::shared_ptr incr; + + friend std::ostream & operator<<(std::ostream& out, const ControlData& controlData) { + if(init) out << init << "; "; + if(condition) out << condition << "; "; + if(incr) out << incr; + return out; + } +}; + +// Collect the expression in the return +// +class ControlPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + std::shared_ptr data; + std::size_t controlDepth; + DeclTypePolicy * declPolicy; + ExpressionPolicy* exprPolicy; + +public: + ControlPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + controlDepth(0), + exprPolicy(nullptr) { + InitializeControlPolicyHandlers(); + } + + ~ControlPolicy() { + if (declPolicy) delete declPolicy; + if (exprPolicy) delete exprPolicy; + } + +protected: + std::any DataInner() const override { return std::make_shared(data); } + + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + using namespace srcDispatch; + if(typeid(DeclTypePolicy) == typeid(*policy)) { + data.init = policy->Data(); + } else if(typeid(ExpressionPolicy) == typeid(*policy)) { + if(IsOpen(ParserState::incr)) { + data.incr = policy->Data(); + } else { + data.condition = policy->Data(); + } + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers + +private: + void InitializeControlPolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { + if (!controlDepth) { + controlDepth = ctx.depth; + data = std::make_shared(); + CollectInitHandlers(); + CollectConditionHandlers(); + CollectIncrHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { + if (controlDepth && controlDepth == ctx.depth) { + controlDepth = 0; + NotifyAll(ctx); + InitializeControlPolicyHandlers(); + } + }; + } + + void CollectInitHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { + if(ctx.depth == (controlDepth + 1)) { + openEvent[ParserState::decl] = [this](srcSAXEventContext& ctx) { + if (!declPolicy) declPolicy = new DeclTypePolicy{this}; + ctx.dispatcher->AddListenerDispatch(declPolicy); + }; + } + }; + closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { + if(ctx.depth == (controlDepth + 1)) { + NopOpenEvents({ParserState::decl}); + } + } + } + + void CollectConditionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if(ctx.depth == (controlDepth + 1)) { + openEvent[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(exprPolicy); + }; + } + }; + closeEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if(ctx.depth == (controlDepth + 1)) { + NopOpenEvents({ParserState::expr}); + } + } + } + + void CollectIncrHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { + if(ctx.depth == (controlDepth + 1)) { + openEvent[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(exprPolicy); + }; + } + }; + closeEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { + if(ctx.depth == (controlDepth + 1)) { + NopOpenEvents({ParserState::expr}); + } + } + } + +}; + +#endif From 23087a6ddde6a27853027d4ba88b8d0a70f1af9b Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 21 Oct 2024 14:02:20 +0900 Subject: [PATCH 038/149] Have DeclType handle parameter --- .../DeclTypePolicySingleEvent.hpp | 18 ++- .../FunctionPolicySingleEvent.hpp | 27 ++-- .../ParamTypePolicySingleEvent.hpp | 123 ------------------ 3 files changed, 29 insertions(+), 139 deletions(-) delete mode 100644 src/policy_classes/ParamTypePolicySingleEvent.hpp diff --git a/src/policy_classes/DeclTypePolicySingleEvent.hpp b/src/policy_classes/DeclTypePolicySingleEvent.hpp index 6f97a65..6850892 100644 --- a/src/policy_classes/DeclTypePolicySingleEvent.hpp +++ b/src/policy_classes/DeclTypePolicySingleEvent.hpp @@ -104,7 +104,8 @@ public srcDispatch::PolicyListener { void InitializeDeclTypePolicyHandlers() { using namespace srcDispatch; // start of policy - openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { + + std::function startDeclType = [this](srcSAXEventContext& ctx) { if (!declDepth) { declDepth = ctx.depth; CollectTypeHandlers(); @@ -126,15 +127,24 @@ public srcDispatch::PolicyListener { }; }; - // end of policy - closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { + + openEventMap[ParserState::declstmt] = startDeclType; + openEventMap[ParserState::parameter] = startDeclType; + openEventMap[ParserState::init] = startDeclType; + + std::function endDeclType = [this](srcSAXEventContext& ctx) { if (declDepth && declDepth == ctx.depth) { declDepth = 0; - NotifyAll(ctx); + NotifyAll(ctx); data.clear(); InitializeDeclTypePolicyHandlers(); } }; + + // end of policy + closeEventMap[ParserState::declstmt] = endDeclType; + closeEventMap[ParserState::parameter] = endDeclType; + closeEventMap[ParserState::init] = endDeclType; } void CollectTypeHandlers() { diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index 0455d54..63f970e 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include @@ -43,7 +43,7 @@ struct FunctionData { std::shared_ptr returnType; std::shared_ptr name; - std::vector> parameters; + std::vector> parameters; std::shared_ptr block; @@ -88,10 +88,10 @@ public srcDispatch::PolicyListener { FunctionData data; std::size_t functionDepth; - TypePolicy* typePolicy; - NamePolicy* namePolicy; - ParamTypePolicy* paramPolicy; - BlockPolicy* blockPolicy; + TypePolicy * typePolicy; + NamePolicy * namePolicy; + DeclTypePolicy* declPolicy; + BlockPolicy * blockPolicy; public: FunctionPolicy(std::initializer_list listeners) @@ -100,7 +100,7 @@ public srcDispatch::PolicyListener { functionDepth(0), typePolicy(nullptr), namePolicy(nullptr), - paramPolicy(nullptr), + declPolicy(nullptr), blockPolicy(nullptr) { InitializeFunctionPolicyHandlers(); } @@ -108,7 +108,7 @@ public srcDispatch::PolicyListener { ~FunctionPolicy() { if (typePolicy) delete typePolicy; if (namePolicy) delete namePolicy; - if (paramPolicy) delete paramPolicy; + if (declPolicy) delete declPolicy; if (blockPolicy) delete blockPolicy; } @@ -122,8 +122,11 @@ public srcDispatch::PolicyListener { data.returnType = policy->Data(); } else if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); - } else if (typeid(ParamTypePolicy) == typeid(*policy)) { - data.parameters.push_back(policy->Data()); + } else if (typeid(DeclTypePolicy) == typeid(*policy)) { + std::shared_ptr>> decl_data = policy->Data>>(); + for(std::shared_ptr decl : *decl_data) { + data.parameters.push_back(decl); + } } else if (typeid(BlockPolicy) == typeid(*policy)) { data.block = policy->Data(); } else { @@ -225,8 +228,8 @@ public srcDispatch::PolicyListener { if (functionDepth && (functionDepth + 1) == ctx.depth) { openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { if (functionDepth && (functionDepth + 2) == ctx.depth) { - if (!paramPolicy) paramPolicy = new ParamTypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(paramPolicy); + if (!declPolicy) declPolicy = new DeclTypePolicy{this}; + ctx.dispatcher->AddListenerDispatch(declPolicy); } }; } diff --git a/src/policy_classes/ParamTypePolicySingleEvent.hpp b/src/policy_classes/ParamTypePolicySingleEvent.hpp deleted file mode 100644 index 57a2f76..0000000 --- a/src/policy_classes/ParamTypePolicySingleEvent.hpp +++ /dev/null @@ -1,123 +0,0 @@ -/** - * @file ParamTypePolicySingleEvent.hpp - * - */ - -#ifndef INCLUDED_PARAM_TYPE_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_PARAM_TYPE_POLICY_SINGLE_EVENT_HPP - - -#include - -#include -#include - -#include -#include - -struct ParamTypeData { - - unsigned int lineNumber; - std::shared_ptr type; - std::shared_ptr name; - - friend std::ostream & operator<<(std::ostream& out, const ParamTypeData& paramData) { - out << *paramData.type; - if (paramData.name) - out << ' ' << *paramData.name; - return out; - } -}; - - -class ParamTypePolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - ParamTypeData data; - std::size_t paramDepth; - TypePolicy* typePolicy; - NamePolicy* namePolicy; - -public: - ParamTypePolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - paramDepth(0), - typePolicy(nullptr), - namePolicy(nullptr) { - - InitializeParamTypePolicyHandlers(); - } - - ~ParamTypePolicy() { - if (typePolicy) delete typePolicy; - if (namePolicy) delete namePolicy; - - } - -protected: - std::any DataInner() const override { return std::make_shared(data); } - - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(TypePolicy) == typeid(*policy)) { - data.type = policy->Data(); - } else if (typeid(NamePolicy) == typeid(*policy)) { - data.name = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListenerDispatch(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers - -private: - void InitializeParamTypePolicyHandlers() { - using namespace srcDispatch; - // start of policy - openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { - if (!paramDepth) { - paramDepth = ctx.depth; - data = ParamTypeData{}; - data.lineNumber = ctx.currentLineNumber; - CollectTypeHandlers(); - CollectNameHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { - if (paramDepth && paramDepth == ctx.depth) { - paramDepth = 0; - NotifyAll(ctx); - InitializeParamTypePolicyHandlers(); - } - }; - } - - void CollectTypeHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - if (paramDepth && (paramDepth + 2) == ctx.depth) { - if (!typePolicy) typePolicy = new TypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(typePolicy); - } - }; - } - - void CollectNameHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if (paramDepth && (paramDepth + 2) == ctx.depth) { - if (!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); - } - }; - } -}; - -#endif From cbc4770f5d51bc503b3f90406f5778e77109ff4e Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 21 Oct 2024 14:49:16 +0900 Subject: [PATCH 039/149] Add partially complete control collection --- .../ConditionalPolicySingleEvent.cpp | 25 +++++++-- .../ConditionalPolicySingleEvent.hpp | 7 ++- .../ControlPolicySingleEvent.hpp | 51 +++++++++++-------- 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/policy_classes/ConditionalPolicySingleEvent.cpp b/src/policy_classes/ConditionalPolicySingleEvent.cpp index d134a66..0c7b1f9 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.cpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.cpp @@ -9,9 +9,8 @@ #include std::ostream & operator<<(std::ostream& out, const ConditionalData& conditionalData) { - if (conditionalData.condition){ - out << *conditionalData.condition; - } + if(!conditionalData.control) return out; + out << conditionalData.control; return out; } @@ -19,12 +18,14 @@ ConditionalPolicy::ConditionalPolicy(std::initializer_listData(); + std::shared_ptr condition = std::make_shared(); + condition->condition = policy->Data(); + data.control = condition; + } else if (typeid(ControlPolicy) == typeid(*policy)) { + data.control = policy->Data(); } else if (typeid(BlockPolicy) == typeid(*policy)) { data.block = policy->Data(); } else { @@ -55,6 +60,7 @@ void ConditionalPolicy::InitializeConditionalPolicyHandlers() { data = ConditionalData{}; \ data.type = TYPE; \ data.startLineNumber = ctx.currentLineNumber; \ + CollectControlHandlers(); \ CollectConditionHandlers(); \ CollectBlockHandlers(); \ } \ @@ -83,6 +89,17 @@ void ConditionalPolicy::InitializeConditionalPolicyHandlers() { closeEventMap[ParserState::dostmt] = endConditional; } +void ConditionalPolicy::CollectControlHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { + if(!conditionalDepth) return; + if((conditionalDepth + 1) != ctx.depth) return; + + if (!controlPolicy) controlPolicy = new ControlPolicy{this}; + ctx.dispatcher->AddListenerDispatch(controlPolicy); + }; +} + void ConditionalPolicy::CollectConditionHandlers() { using namespace srcDispatch; openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index a2a61eb..9b4a784 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -28,8 +29,8 @@ struct ConditionalData { unsigned int startLineNumber; unsigned int endLineNumber; - std::shared_ptr condition; - std::shared_ptr block; + std::shared_ptr control; + std::shared_ptr block; friend std::ostream & operator<<(std::ostream& out, const ConditionalData& conditionalData); }; @@ -43,6 +44,7 @@ public srcDispatch::PolicyListener { private: ConditionalData data; std::size_t conditionalDepth; + ControlPolicy * controlPolicy; ConditionPolicy* conditionPolicy; BlockPolicy * blockPolicy; @@ -57,6 +59,7 @@ public srcDispatch::PolicyListener { private: void InitializeConditionalPolicyHandlers(); + void CollectControlHandlers(); void CollectConditionHandlers(); void CollectBlockHandlers(); }; diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp index 6b9746b..43f4b71 100644 --- a/src/policy_classes/ControlPolicySingleEvent.hpp +++ b/src/policy_classes/ControlPolicySingleEvent.hpp @@ -26,9 +26,9 @@ struct ControlData { std::shared_ptr incr; friend std::ostream & operator<<(std::ostream& out, const ControlData& controlData) { - if(init) out << init << "; "; - if(condition) out << condition << "; "; - if(incr) out << incr; + if(controlData.init) out << controlData.init << "; "; + if(controlData.condition) out << controlData.condition << "; "; + if(controlData.incr) out << controlData.incr; return out; } }; @@ -41,10 +41,10 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - std::shared_ptr data; - std::size_t controlDepth; - DeclTypePolicy * declPolicy; - ExpressionPolicy* exprPolicy; + ControlData data; + std::size_t controlDepth; + DeclTypePolicy * declPolicy; + ExpressionPolicy* exprPolicy; public: ControlPolicy(std::initializer_list listeners) @@ -68,10 +68,15 @@ public srcDispatch::PolicyListener { if(typeid(DeclTypePolicy) == typeid(*policy)) { data.init = policy->Data(); } else if(typeid(ExpressionPolicy) == typeid(*policy)) { - if(IsOpen(ParserState::incr)) { - data.incr = policy->Data(); - } else { + if(ctx.IsOpen(ParserState::init)) { + std::shared_ptr expr = policy->Data(); + std::shared_ptr decl = std::make_shared(expr->lineNumber); + decl->initializer = expr; + data.init = decl; + } else if(ctx.IsOpen(ParserState::condition)) { data.condition = policy->Data(); + } else { + data.incr = policy->Data(); } } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); @@ -89,7 +94,7 @@ public srcDispatch::PolicyListener { openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { if (!controlDepth) { controlDepth = ctx.depth; - data = std::make_shared(); + data = ControlData{}; CollectInitHandlers(); CollectConditionHandlers(); CollectIncrHandlers(); @@ -110,24 +115,30 @@ public srcDispatch::PolicyListener { using namespace srcDispatch; openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { if(ctx.depth == (controlDepth + 1)) { - openEvent[ParserState::decl] = [this](srcSAXEventContext& ctx) { - if (!declPolicy) declPolicy = new DeclTypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(declPolicy); + openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { + if(ctx.depth != (controlDepth + 2)) return; + //if (!declPolicy) declPolicy = new DeclTypePolicy{this}; + //ctx.dispatcher->AddListenerDispatch(declPolicy); + }; + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(ctx.depth != (controlDepth + 2)) return; + if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(exprPolicy); }; } }; closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { if(ctx.depth == (controlDepth + 1)) { - NopOpenEvents({ParserState::decl}); + NopOpenEvents({ParserState::decl, ParserState::expr}); } - } + }; } void CollectConditionHandlers() { using namespace srcDispatch; openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { if(ctx.depth == (controlDepth + 1)) { - openEvent[ParserState::expr] = [this](srcSAXEventContext& ctx) { + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; ctx.dispatcher->AddListenerDispatch(exprPolicy); }; @@ -137,14 +148,14 @@ public srcDispatch::PolicyListener { if(ctx.depth == (controlDepth + 1)) { NopOpenEvents({ParserState::expr}); } - } + }; } void CollectIncrHandlers() { using namespace srcDispatch; openEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { if(ctx.depth == (controlDepth + 1)) { - openEvent[ParserState::expr] = [this](srcSAXEventContext& ctx) { + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; ctx.dispatcher->AddListenerDispatch(exprPolicy); }; @@ -154,7 +165,7 @@ public srcDispatch::PolicyListener { if(ctx.depth == (controlDepth + 1)) { NopOpenEvents({ParserState::expr}); } - } + }; } }; From 11f724be790ab8a91104c693c5971fb4d4f7cef9 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 21 Oct 2024 15:15:47 +0900 Subject: [PATCH 040/149] Add limits to init on decl --- .../DeclTypePolicySingleEvent.hpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/policy_classes/DeclTypePolicySingleEvent.hpp b/src/policy_classes/DeclTypePolicySingleEvent.hpp index 6850892..72bb1e1 100644 --- a/src/policy_classes/DeclTypePolicySingleEvent.hpp +++ b/src/policy_classes/DeclTypePolicySingleEvent.hpp @@ -130,7 +130,6 @@ public srcDispatch::PolicyListener { openEventMap[ParserState::declstmt] = startDeclType; openEventMap[ParserState::parameter] = startDeclType; - openEventMap[ParserState::init] = startDeclType; std::function endDeclType = [this](srcSAXEventContext& ctx) { if (declDepth && declDepth == ctx.depth) { @@ -144,7 +143,6 @@ public srcDispatch::PolicyListener { // end of policy closeEventMap[ParserState::declstmt] = endDeclType; closeEventMap[ParserState::parameter] = endDeclType; - closeEventMap[ParserState::init] = endDeclType; } void CollectTypeHandlers() { @@ -187,10 +185,17 @@ public srcDispatch::PolicyListener { void CollectInitHandlers() { using namespace srcDispatch; openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(expressionPolicy); - }; + if (declDepth && (declDepth + 2) == ctx.depth) { + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(expressionPolicy); + }; + } + }; + closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { + if (declDepth && (declDepth + 2) == ctx.depth) { + NopOpenEvents({ParserState::expr}); + } }; } From b8ba7cb8ea5d651c80cfae846f8405536fd71dd5 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 22 Oct 2024 16:25:57 +0900 Subject: [PATCH 041/149] Fix spacing --- src/dispatcher/srcDispatchUtilities.hpp | 2 +- src/policy_classes/BlockPolicySingleEvent.hpp | 14 ++++++------- src/policy_classes/CallPolicySingleEvent.cpp | 4 ++-- src/policy_classes/CallPolicySingleEvent.hpp | 10 ++++----- src/policy_classes/ClassPolicySingleEvent.hpp | 12 +++++------ .../ConditionPolicySingleEvent.hpp | 6 +++--- .../ConditionalPolicySingleEvent.cpp | 8 +++---- .../ConditionalPolicySingleEvent.hpp | 6 +++--- .../ControlPolicySingleEvent.hpp | 21 ++++--------------- .../DeclTypePolicySingleEvent.hpp | 14 ++++++------- .../ExprStmtPolicySingleEvent.hpp | 6 +++--- .../ExpressionPolicySingleEvent.cpp | 6 +++--- .../ExpressionPolicySingleEvent.hpp | 14 ++++++------- .../FunctionPolicySingleEvent.hpp | 8 +++---- src/policy_classes/NamePolicySingleEvent.cpp | 4 ++-- src/policy_classes/NamePolicySingleEvent.hpp | 8 +++---- .../TemplateArgumentPolicySingleEvent.cpp | 10 ++++----- .../TemplateArgumentPolicySingleEvent.hpp | 6 +++--- src/policy_classes/TypePolicySingleEvent.cpp | 12 +++++------ src/policy_classes/TypePolicySingleEvent.hpp | 8 +++---- src/policy_classes/UnitPolicySingleEvent.hpp | 8 +++---- 21 files changed, 87 insertions(+), 100 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 0c01a07..ac7d917 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -37,7 +37,7 @@ #ifndef INCLUDED_SRCSAX_EVENT_DISPATCH_UTILITIES_HPP #define INCLUDED_SRCSAX_EVENT_DISPATCH_UTILITIES_HPP -namespace srcDispatch{ +namespace srcDispatch { class EventDispatcher; enum ElementState {open, close}; enum ParserState {decl, expr, parameter, declstmt, exprstmt, parameterlist, elseif, elsestmt, diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index d7e728b..0d6d5f1 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -43,14 +43,14 @@ public srcDispatch::PolicyListener { BlockData data; std::size_t blockDepth; - DeclTypePolicy* declstmtPolicy; - ReturnPolicy* returnPolicy; - ExprStmtPolicy* exprStmtPolicy; - BlockPolicy* blockPolicy; + DeclTypePolicy * declstmtPolicy; + ReturnPolicy * returnPolicy; + ExprStmtPolicy * exprStmtPolicy; + BlockPolicy * blockPolicy; ConditionalPolicy* conditionalPolicy; public: - BlockPolicy(std::initializer_list listeners) + BlockPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, blockDepth(0), @@ -73,9 +73,9 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared(data); } - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(DeclTypePolicy) == typeid(*policy)) { std::shared_ptr>> decl_data = policy->Data>>(); for(std::shared_ptr decl : *decl_data) { diff --git a/src/policy_classes/CallPolicySingleEvent.cpp b/src/policy_classes/CallPolicySingleEvent.cpp index a31a693..c68a44f 100644 --- a/src/policy_classes/CallPolicySingleEvent.cpp +++ b/src/policy_classes/CallPolicySingleEvent.cpp @@ -4,7 +4,7 @@ */ #include -std::ostream & operator<<(std::ostream & out, const CallData &call) { +std::ostream& operator<<(std::ostream& out, const CallData &call) { out << *(call.name) << "("; bool printComma=false; for (std::shared_ptr arg : call.arguments) { @@ -23,7 +23,7 @@ CallPolicy::~CallPolicy() { std::any CallPolicy::DataInner() const { return std::make_shared(data); } -void CallPolicy::Notify(const srcDispatch::PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { +void CallPolicy::Notify(const srcDispatch::PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { using namespace srcDispatch; if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); diff --git a/src/policy_classes/CallPolicySingleEvent.hpp b/src/policy_classes/CallPolicySingleEvent.hpp index 251a2df..6ab2786 100644 --- a/src/policy_classes/CallPolicySingleEvent.hpp +++ b/src/policy_classes/CallPolicySingleEvent.hpp @@ -35,7 +35,7 @@ struct CallData { std::shared_ptr name; std::vector> arguments; //expressions - friend std::ostream & operator<<(std::ostream & out, const CallData &call); + friend std::ostream& operator<<(std::ostream& out, const CallData &call); }; class CallPolicy : @@ -46,8 +46,8 @@ public srcDispatch::PolicyListener { private: CallData data; std::size_t callDepth; - NamePolicy *namePolicy; - ExpressionPolicy *expressionPolicy; + NamePolicy * namePolicy; + ExpressionPolicy* expressionPolicy; public: CallPolicy(std::initializer_list listeners) @@ -63,8 +63,8 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override; - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override; - void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers private: void InitializeCallPolicyHandlers(); diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index 35a79c8..17dde1e 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -60,10 +60,10 @@ public srcDispatch::PolicyListener { std::size_t classDepth; ClassData::AccessSpecifier currentRegion; - NamePolicy * namePolicy; - DeclTypePolicy * declPolicy; - FunctionPolicy * functionPolicy; - ClassPolicy * classPolicy; + NamePolicy * namePolicy; + DeclTypePolicy* declPolicy; + FunctionPolicy* functionPolicy; + ClassPolicy * classPolicy; public: ClassPolicy(std::initializer_list listeners) @@ -85,9 +85,9 @@ public srcDispatch::PolicyListener { if (classPolicy) delete classPolicy; } - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers - void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); } else if (typeid(DeclTypePolicy) == typeid(*policy)) { diff --git a/src/policy_classes/ConditionPolicySingleEvent.hpp b/src/policy_classes/ConditionPolicySingleEvent.hpp index 1e2a4a4..eb83e3f 100644 --- a/src/policy_classes/ConditionPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionPolicySingleEvent.hpp @@ -30,7 +30,7 @@ public srcDispatch::PolicyListener { ExpressionPolicy* exprPolicy; public: - ConditionPolicy(std::initializer_list listeners) + ConditionPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, conditionDepth(0), @@ -45,7 +45,7 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override { return data; } - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(ExpressionPolicy) == typeid(*policy)) { data = policy->Data(); ctx.dispatcher->RemoveListener(nullptr); @@ -54,7 +54,7 @@ public srcDispatch::PolicyListener { } } - void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers private: void InitializeConditionPolicyHandlers() { diff --git a/src/policy_classes/ConditionalPolicySingleEvent.cpp b/src/policy_classes/ConditionalPolicySingleEvent.cpp index 0c7b1f9..2bb48b9 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.cpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.cpp @@ -8,13 +8,13 @@ #include -std::ostream & operator<<(std::ostream& out, const ConditionalData& conditionalData) { +std::ostream& operator<<(std::ostream& out, const ConditionalData& conditionalData) { if(!conditionalData.control) return out; out << conditionalData.control; return out; } -ConditionalPolicy::ConditionalPolicy(std::initializer_list listeners) +ConditionalPolicy::ConditionalPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, conditionalDepth(0), @@ -32,7 +32,7 @@ ConditionalPolicy::~ConditionalPolicy() { std::any ConditionalPolicy::DataInner() const { return std::make_shared(data); } -void ConditionalPolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { +void ConditionalPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { if (typeid(ConditionPolicy) == typeid(*policy)) { std::shared_ptr condition = std::make_shared(); condition->condition = policy->Data(); @@ -48,7 +48,7 @@ void ConditionalPolicy::Notify(const PolicyDispatcher * policy, const srcDispatc ctx.dispatcher->RemoveListener(nullptr); } -void ConditionalPolicy::NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) {} //doesn't use other parsers +void ConditionalPolicy::NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers void ConditionalPolicy::InitializeConditionalPolicyHandlers() { using namespace srcDispatch; diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index 9b4a784..4a4950b 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -32,7 +32,7 @@ struct ConditionalData { std::shared_ptr control; std::shared_ptr block; - friend std::ostream & operator<<(std::ostream& out, const ConditionalData& conditionalData); + friend std::ostream& operator<<(std::ostream& out, const ConditionalData& conditionalData); }; @@ -54,8 +54,8 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override; - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override; - void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override; + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override; private: void InitializeConditionalPolicyHandlers(); diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp index 43f4b71..d5b6576 100644 --- a/src/policy_classes/ControlPolicySingleEvent.hpp +++ b/src/policy_classes/ControlPolicySingleEvent.hpp @@ -25,7 +25,7 @@ struct ControlData { std::shared_ptr condition; std::shared_ptr incr; - friend std::ostream & operator<<(std::ostream& out, const ControlData& controlData) { + friend std::ostream& operator<<(std::ostream& out, const ControlData& controlData) { if(controlData.init) out << controlData.init << "; "; if(controlData.condition) out << controlData.condition << "; "; if(controlData.incr) out << controlData.incr; @@ -47,7 +47,7 @@ public srcDispatch::PolicyListener { ExpressionPolicy* exprPolicy; public: - ControlPolicy(std::initializer_list listeners) + ControlPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, controlDepth(0), @@ -115,21 +115,8 @@ public srcDispatch::PolicyListener { using namespace srcDispatch; openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { if(ctx.depth == (controlDepth + 1)) { - openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { - if(ctx.depth != (controlDepth + 2)) return; - //if (!declPolicy) declPolicy = new DeclTypePolicy{this}; - //ctx.dispatcher->AddListenerDispatch(declPolicy); - }; - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(ctx.depth != (controlDepth + 2)) return; - if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprPolicy); - }; - } - }; - closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { - if(ctx.depth == (controlDepth + 1)) { - NopOpenEvents({ParserState::decl, ParserState::expr}); + // if (!declPolicy) declPolicy = new DeclTypePolicy{this}; + // ctx.dispatcher->AddListenerDispatch(declPolicy); } }; } diff --git a/src/policy_classes/DeclTypePolicySingleEvent.hpp b/src/policy_classes/DeclTypePolicySingleEvent.hpp index 72bb1e1..6246dac 100644 --- a/src/policy_classes/DeclTypePolicySingleEvent.hpp +++ b/src/policy_classes/DeclTypePolicySingleEvent.hpp @@ -30,7 +30,7 @@ struct DeclTypeData { std::shared_ptr initializer; bool isStatic; - friend std::ostream & operator<<(std::ostream & out, const DeclTypeData & declData) { + friend std::ostream& operator<<(std::ostream& out, const DeclTypeData& declData) { if(declData.type) { out << declData.type->ToString(); } @@ -54,16 +54,16 @@ public srcDispatch::PolicyListener { private: std::vector> data; std::size_t declDepth; - TypePolicy *typePolicy; - NamePolicy *namePolicy; - ExpressionPolicy *expressionPolicy; + TypePolicy * typePolicy; + NamePolicy * namePolicy; + ExpressionPolicy* expressionPolicy; bool isStatic; std::shared_ptr type; std::shared_ptr initializer; public: - DeclTypePolicy(std::initializer_list listeners) + DeclTypePolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, declDepth(0), @@ -84,9 +84,9 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared>>(data); } - void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(TypePolicy) == typeid(*policy)) { type = std::shared_ptr(policy->Data()); } else if (typeid(NamePolicy) == typeid(*policy)) { diff --git a/src/policy_classes/ExprStmtPolicySingleEvent.hpp b/src/policy_classes/ExprStmtPolicySingleEvent.hpp index ae512e5..c5766b8 100644 --- a/src/policy_classes/ExprStmtPolicySingleEvent.hpp +++ b/src/policy_classes/ExprStmtPolicySingleEvent.hpp @@ -28,7 +28,7 @@ public srcDispatch::PolicyListener { ExpressionPolicy* exprPolicy; public: - ExprStmtPolicy(std::initializer_list listeners) + ExprStmtPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, exprStmtDepth(0), @@ -43,7 +43,7 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override { return data; } - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(ExpressionPolicy) == typeid(*policy)) { data = policy->Data(); ctx.dispatcher->RemoveListener(nullptr); @@ -52,7 +52,7 @@ public srcDispatch::PolicyListener { } } - void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers private: void InitializeExprStmtPolicyHandlers() { diff --git a/src/policy_classes/ExpressionPolicySingleEvent.cpp b/src/policy_classes/ExpressionPolicySingleEvent.cpp index f72505d..82d8ce2 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.cpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.cpp @@ -5,11 +5,11 @@ #include -std::ostream & operator<<(std::ostream & out, const Token & token) { +std::ostream& operator<<(std::ostream& out, const Token& token) { return out << token.token; } -std::ostream & operator<<(std::ostream & out, const ExpressionData & ex) { +std::ostream& operator<<(std::ostream& out, const ExpressionData& ex) { for (std::shared_ptr item : ex.expr) { switch (item->type) { case ExpressionElement::NAME: out << *item->name; break; @@ -27,7 +27,7 @@ ExpressionPolicy::~ExpressionPolicy() { if(callPolicy) delete callPolicy; } -void ExpressionPolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { +void ExpressionPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { if(typeid(NamePolicy) == typeid(*policy)) { data.expr.push_back(std::make_shared(ExpressionElement::NAME, policy->Data())); } else if(typeid(CallPolicy) == typeid(*policy)) { diff --git a/src/policy_classes/ExpressionPolicySingleEvent.hpp b/src/policy_classes/ExpressionPolicySingleEvent.hpp index 13891f9..30f4f7d 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.hpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.hpp @@ -32,7 +32,7 @@ struct Token { } unsigned int lineNumber; std::string token; - friend std::ostream & operator<<(std::ostream & out, const Token & token); + friend std::ostream& operator<<(std::ostream& out, const Token& token); }; struct ExpressionElement { @@ -52,7 +52,7 @@ struct ExpressionData { unsigned int lineNumber; std::vector> expr; //All items in expression - friend std::ostream & operator<<(std::ostream & out, const ExpressionData & ex); + friend std::ostream& operator<<(std::ostream& out, const ExpressionData& ex); }; class ExpressionPolicy : @@ -62,12 +62,12 @@ public srcDispatch::PolicyListener { private: ExpressionData data; - NamePolicy *namePolicy; - CallPolicy *callPolicy; + NamePolicy* namePolicy; + CallPolicy* callPolicy; std::size_t exprDepth; public: - ExpressionPolicy(std::initializer_list listeners) + ExpressionPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, exprDepth(0), @@ -82,9 +82,9 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared(data); } - void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override; + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; private: void InitializeExpressionPolicyHandlers(); diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index 63f970e..940b6cd 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -63,7 +63,7 @@ struct FunctionData { return signature; } - friend std::ostream & operator<<(std::ostream & out, const FunctionData & functionData) { + friend std::ostream& operator<<(std::ostream& out, const FunctionData& functionData) { if (functionData.returnType){ out << *functionData.returnType << ' ' << *functionData.name; } @@ -94,7 +94,7 @@ public srcDispatch::PolicyListener { BlockPolicy * blockPolicy; public: - FunctionPolicy(std::initializer_list listeners) + FunctionPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, functionDepth(0), @@ -115,9 +115,9 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared(data); } - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(TypePolicy) == typeid(*policy)) { data.returnType = policy->Data(); } else if (typeid(NamePolicy) == typeid(*policy)) { diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index ccf166b..18ef4bd 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -25,7 +25,7 @@ std::string NameData::ToString() const { } -std::ostream & operator<<(std::ostream & out, const NameData & nameData) { +std::ostream& operator<<(std::ostream& out, const NameData& nameData) { if (!nameData.name.empty()) { out << nameData.name; } @@ -53,7 +53,7 @@ NamePolicy::~NamePolicy() { } -void NamePolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { +void NamePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { if (typeid(NamePolicy) == typeid(*policy)) { data.names.push_back(policy->Data()); } else if (typeid(TemplateArgumentPolicy) == typeid(*policy)) { diff --git a/src/policy_classes/NamePolicySingleEvent.hpp b/src/policy_classes/NamePolicySingleEvent.hpp index e158f5a..a37877a 100644 --- a/src/policy_classes/NamePolicySingleEvent.hpp +++ b/src/policy_classes/NamePolicySingleEvent.hpp @@ -34,7 +34,7 @@ struct NameData { std::string SimpleName() const; std::string ToString() const; - friend std::ostream & operator<<(std::ostream & out, const NameData & nameData); + friend std::ostream& operator<<(std::ostream& out, const NameData& nameData); }; @@ -51,7 +51,7 @@ public srcDispatch::PolicyListener { ExpressionPolicy *expressionPolicy; public: - NamePolicy(std::initializer_list listeners) + NamePolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, nameDepth(0), @@ -66,8 +66,8 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared(data); } - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override; - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers private: void InitializeNamePolicyHandlers(); diff --git a/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp b/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp index 6317214..7d09e64 100644 --- a/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp +++ b/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp @@ -4,11 +4,11 @@ */ #include -std::ostream & operator<<(std::ostream & out, const TemplateArgumentData & argumentData) { +std::ostream& operator<<(std::ostream& out, const TemplateArgumentData& argumentData) { for(std::size_t pos = 0; pos < argumentData.data.size(); ++pos) { if (pos != 0) out << ' '; - const std::pair & element = argumentData.data[pos]; + const std::pair& element = argumentData.data[pos]; if (element.second == TemplateArgumentData::NAME) out << *std::any_cast>(element.first); else if (element.second == TemplateArgumentData::POINTER) @@ -24,7 +24,7 @@ std::ostream & operator<<(std::ostream & out, const TemplateArgumentData & argum return out; } -TemplateArgumentPolicy::TemplateArgumentPolicy(std::initializer_list listeners) +TemplateArgumentPolicy::TemplateArgumentPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, argumentDepth(0), @@ -36,12 +36,12 @@ TemplateArgumentPolicy::~TemplateArgumentPolicy() { if (namePolicy) delete namePolicy; } -void TemplateArgumentPolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { +void TemplateArgumentPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { data.data.back().first = policy->Data(); ctx.dispatcher->RemoveListenerDispatch(nullptr); } -void TemplateArgumentPolicy::NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]){} +void TemplateArgumentPolicy::NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]){} std::any TemplateArgumentPolicy::DataInner() const { return std::make_shared(data); diff --git a/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp b/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp index 9cb2c5e..ce229d8 100644 --- a/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp +++ b/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp @@ -16,7 +16,7 @@ struct TemplateArgumentData { unsigned int lineNumber; std::vector> data; - friend std::ostream & operator<<(std::ostream & out, const TemplateArgumentData & argumentData); + friend std::ostream& operator<<(std::ostream& out, const TemplateArgumentData& argumentData); }; @@ -28,8 +28,8 @@ public srcDispatch::PolicyListener { public: TemplateArgumentPolicy(std::initializer_list listeners); ~TemplateArgumentPolicy(); - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override; - virtual void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override; + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + virtual void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override; protected: virtual std::any DataInner() const override; diff --git a/src/policy_classes/TypePolicySingleEvent.cpp b/src/policy_classes/TypePolicySingleEvent.cpp index ed867a5..9348ef3 100644 --- a/src/policy_classes/TypePolicySingleEvent.cpp +++ b/src/policy_classes/TypePolicySingleEvent.cpp @@ -9,7 +9,7 @@ std::string TypeData::ToString() const { std::string type_str; for (std::size_t pos = 0; pos < types.size(); ++pos) { if (pos != 0) type_str += ' '; - const std::pair & type = types[pos]; + const std::pair& type = types[pos]; if (type.second == TypeData::POINTER) { type_str += '*'; } else if (type.second == TypeData::REFERENCE) { @@ -25,10 +25,10 @@ std::string TypeData::ToString() const { return type_str; } -std::ostream & operator<<(std::ostream & out, const TypeData & typeData) { +std::ostream& operator<<(std::ostream& out, const TypeData& typeData) { for(std::size_t pos = 0; pos < typeData.types.size(); ++pos) { if (pos != 0) out << ' '; - const std::pair & type = typeData.types[pos]; + const std::pair& type = typeData.types[pos]; if (type.second == TypeData::POINTER) { out << '*'; } else if (type.second == TypeData::REFERENCE) { @@ -44,7 +44,7 @@ std::ostream & operator<<(std::ostream & out, const TypeData & typeData) { return out; } -TypePolicy::TypePolicy(std::initializer_list listeners) +TypePolicy::TypePolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, typeDepth(0), @@ -57,13 +57,13 @@ TypePolicy::~TypePolicy(){ if (namePolicy) delete namePolicy; } -void TypePolicy::Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) { +void TypePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { //this causes undefined behavior if types is empty data.types.back().first = policy->Data(); ctx.dispatcher->RemoveListenerDispatch(nullptr); } -void TypePolicy::NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]){} +void TypePolicy::NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]){} std::any TypePolicy::DataInner() const { return std::make_shared(data); diff --git a/src/policy_classes/TypePolicySingleEvent.hpp b/src/policy_classes/TypePolicySingleEvent.hpp index fd6df51..9c0d631 100644 --- a/src/policy_classes/TypePolicySingleEvent.hpp +++ b/src/policy_classes/TypePolicySingleEvent.hpp @@ -20,7 +20,7 @@ struct TypeData { unsigned int lineNumber; std::vector> types; std::string ToString() const; - friend std::ostream & operator<<(std::ostream & out, const TypeData & typeData); + friend std::ostream& operator<<(std::ostream& out, const TypeData& typeData); }; @@ -35,10 +35,10 @@ public srcDispatch::PolicyListener { NamePolicy * namePolicy; public: - TypePolicy(std::initializer_list listeners); + TypePolicy(std::initializer_list listeners); ~TypePolicy(); - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override; - virtual void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override; + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + virtual void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override; protected: virtual std::any DataInner() const override; diff --git a/src/policy_classes/UnitPolicySingleEvent.hpp b/src/policy_classes/UnitPolicySingleEvent.hpp index 3def187..43a7290 100644 --- a/src/policy_classes/UnitPolicySingleEvent.hpp +++ b/src/policy_classes/UnitPolicySingleEvent.hpp @@ -27,8 +27,8 @@ class UnitPolicy : public srcDispatch::PolicyListener { public: - FunctionPolicy *functionPolicy; - ClassPolicy *classPolicy; + FunctionPolicy* functionPolicy; + ClassPolicy * classPolicy; public: UnitPolicy(std::initializer_list listeners) : @@ -43,9 +43,9 @@ class UnitPolicy : if(classPolicy) delete classPolicy; } - void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers - void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { // Assumes at least one lister which should always be one policyListeners.back()->Notify(policy, ctx); ctx.dispatcher->RemoveListenerDispatch(nullptr); From 2b5d60938f206b049341a8564e474d6b8b1ed88f Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 23 Oct 2024 11:08:54 +0900 Subject: [PATCH 042/149] Split For off into own class --- src/policy_classes/BlockPolicySingleEvent.hpp | 31 +++++-- .../ConditionalPolicySingleEvent.cpp | 41 +++------ .../ConditionalPolicySingleEvent.hpp | 8 +- .../ControlPolicySingleEvent.hpp | 53 +++++------ src/policy_classes/ForPolicySingleEvent.cpp | 89 +++++++++++++++++++ src/policy_classes/ForPolicySingleEvent.hpp | 60 +++++++++++++ 6 files changed, 208 insertions(+), 74 deletions(-) create mode 100644 src/policy_classes/ForPolicySingleEvent.cpp create mode 100644 src/policy_classes/ForPolicySingleEvent.hpp diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index 0d6d5f1..6313579 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -25,12 +26,13 @@ struct BlockData { unsigned int startLineNumber; unsigned int endLineNumber; - std::vector> locals; - std::vector> returns; - std::vector> expr_stmts; + std::vector> locals; + std::vector> returns; + std::vector> expr_stmts; - std::vector> blocks; + std::vector> blocks; std::vector> conditionals; + std::vector> fors; }; @@ -48,6 +50,7 @@ public srcDispatch::PolicyListener { ExprStmtPolicy * exprStmtPolicy; BlockPolicy * blockPolicy; ConditionalPolicy* conditionalPolicy; + ForPolicy * forPolicy; public: BlockPolicy(std::initializer_list listeners) @@ -58,7 +61,8 @@ public srcDispatch::PolicyListener { exprStmtPolicy(nullptr), returnPolicy(nullptr), blockPolicy(nullptr), - conditionalPolicy(nullptr) { + conditionalPolicy(nullptr), + forPolicy(nullptr) { InitializeBlockPolicyHandlers(); } @@ -89,6 +93,8 @@ public srcDispatch::PolicyListener { data.blocks.push_back(policy->Data()); } else if (typeid(ConditionalPolicy) == typeid(*policy)) { data.conditionals.push_back(policy->Data()); + } else if (typeid(ForPolicy) == typeid(*policy)) { + data.fors.push_back(policy->Data()); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } @@ -104,7 +110,9 @@ public srcDispatch::PolicyListener { CollectDeclstmtHandlers(); CollectReturnHandlers(); CollectExpressionHandlers(); - CollectConditionalsHandlers(); + CollectConditionalHandlers(); + CollectConditionalHandlers(); + CollectForHandlers(); } @@ -156,7 +164,7 @@ public srcDispatch::PolicyListener { }; } - void CollectConditionalsHandlers() { + void CollectConditionalHandlers() { using namespace srcDispatch; std::function startConditional = [this](srcSAXEventContext& ctx) { if (!conditionalPolicy) conditionalPolicy = new ConditionalPolicy{this}; @@ -165,10 +173,17 @@ public srcDispatch::PolicyListener { openEventMap[ParserState::ifstmt] = startConditional; openEventMap[ParserState::whilestmt] = startConditional; - openEventMap[ParserState::forstmt] = startConditional; openEventMap[ParserState::switchstmt] = startConditional; openEventMap[ParserState::dostmt] = startConditional; + } + + void CollectForHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { + if (!forPolicy) forPolicy = new ForPolicy{this}; + ctx.dispatcher->AddListenerDispatch(forPolicy); + }; } diff --git a/src/policy_classes/ConditionalPolicySingleEvent.cpp b/src/policy_classes/ConditionalPolicySingleEvent.cpp index 2bb48b9..21ec231 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.cpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.cpp @@ -9,23 +9,20 @@ #include std::ostream& operator<<(std::ostream& out, const ConditionalData& conditionalData) { - if(!conditionalData.control) return out; - out << conditionalData.control; - return out; + if(!conditionalData.condition) return out; + return out << conditionalData.condition; } ConditionalPolicy::ConditionalPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, conditionalDepth(0), - controlPolicy(nullptr), conditionPolicy(nullptr), blockPolicy(nullptr) { InitializeConditionalPolicyHandlers(); } ConditionalPolicy::~ConditionalPolicy() { - if (controlPolicy) delete controlPolicy; if (conditionPolicy) delete conditionPolicy; if (blockPolicy) delete blockPolicy; } @@ -34,12 +31,8 @@ std::any ConditionalPolicy::DataInner() const { return std::make_shared condition = std::make_shared(); - condition->condition = policy->Data(); - data.control = condition; - } else if (typeid(ControlPolicy) == typeid(*policy)) { - data.control = policy->Data(); - } else if (typeid(BlockPolicy) == typeid(*policy)) { + data.condition = policy->Data(); + }else if (typeid(BlockPolicy) == typeid(*policy)) { data.block = policy->Data(); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); @@ -60,7 +53,6 @@ void ConditionalPolicy::InitializeConditionalPolicyHandlers() { data = ConditionalData{}; \ data.type = TYPE; \ data.startLineNumber = ctx.currentLineNumber; \ - CollectControlHandlers(); \ CollectConditionHandlers(); \ CollectBlockHandlers(); \ } \ @@ -68,7 +60,6 @@ void ConditionalPolicy::InitializeConditionalPolicyHandlers() { openEventMap[ParserState::ifstmt] = startConditional(ConditionalData::IF); openEventMap[ParserState::whilestmt] = startConditional(ConditionalData::WHILE); - openEventMap[ParserState::forstmt] = startConditional(ConditionalData::FOR); openEventMap[ParserState::switchstmt] = startConditional(ConditionalData::SWITCH); openEventMap[ParserState::dostmt] = startConditional(ConditionalData::DO); @@ -84,28 +75,15 @@ void ConditionalPolicy::InitializeConditionalPolicyHandlers() { // end of policy closeEventMap[ParserState::ifstmt] = endConditional; closeEventMap[ParserState::whilestmt] = endConditional; - closeEventMap[ParserState::forstmt] = endConditional; closeEventMap[ParserState::switchstmt] = endConditional; closeEventMap[ParserState::dostmt] = endConditional; } -void ConditionalPolicy::CollectControlHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { - if(!conditionalDepth) return; - if((conditionalDepth + 1) != ctx.depth) return; - - if (!controlPolicy) controlPolicy = new ControlPolicy{this}; - ctx.dispatcher->AddListenerDispatch(controlPolicy); - }; -} - void ConditionalPolicy::CollectConditionHandlers() { using namespace srcDispatch; openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { if(!conditionalDepth) return; - if(data.type == ConditionalData::FOR && (conditionalDepth + 2) != ctx.depth) return; - if(data.type != ConditionalData::FOR && (conditionalDepth + 1) != ctx.depth) return; + if((conditionalDepth + 1) != ctx.depth) return; if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; ctx.dispatcher->AddListenerDispatch(conditionPolicy); @@ -115,9 +93,10 @@ void ConditionalPolicy::CollectConditionHandlers() { void ConditionalPolicy::CollectBlockHandlers() { using namespace srcDispatch; openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(conditionalDepth && (conditionalDepth + 1) == ctx.depth) { - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); - } + if(!conditionalDepth) return; + if((conditionalDepth + 1) != ctx.depth) return; + + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); }; } diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index 4a4950b..5ae204b 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -22,15 +21,15 @@ class BlockData; struct ConditionalData { - enum ConditionalType { IF, WHILE, FOR, FOREACH, SWITCH, DO }; + enum ConditionalType { IF, WHILE, SWITCH, DO }; ConditionalType type; unsigned int startLineNumber; unsigned int endLineNumber; - std::shared_ptr control; - std::shared_ptr block; + std::shared_ptr condition; + std::shared_ptr block; friend std::ostream& operator<<(std::ostream& out, const ConditionalData& conditionalData); }; @@ -44,7 +43,6 @@ public srcDispatch::PolicyListener { private: ConditionalData data; std::size_t conditionalDepth; - ControlPolicy * controlPolicy; ConditionPolicy* conditionPolicy; BlockPolicy * blockPolicy; diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp index d5b6576..a012ded 100644 --- a/src/policy_classes/ControlPolicySingleEvent.hpp +++ b/src/policy_classes/ControlPolicySingleEvent.hpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -44,6 +45,7 @@ public srcDispatch::PolicyListener { ControlData data; std::size_t controlDepth; DeclTypePolicy * declPolicy; + ConditionPolicy * conditionPolicy; ExpressionPolicy* exprPolicy; public: @@ -56,8 +58,9 @@ public srcDispatch::PolicyListener { } ~ControlPolicy() { - if (declPolicy) delete declPolicy; - if (exprPolicy) delete exprPolicy; + if (declPolicy) delete declPolicy; + if (conditionPolicy) delete conditionPolicy; + if (exprPolicy) delete exprPolicy; } protected: @@ -67,14 +70,14 @@ public srcDispatch::PolicyListener { using namespace srcDispatch; if(typeid(DeclTypePolicy) == typeid(*policy)) { data.init = policy->Data(); - } else if(typeid(ExpressionPolicy) == typeid(*policy)) { + } else if(typeid(ConditionPolicy) == typeid(*policy)) { + data.condition = policy->Data(); + } else if(typeid(ExpressionPolicy) == typeid(*policy)) { if(ctx.IsOpen(ParserState::init)) { std::shared_ptr expr = policy->Data(); std::shared_ptr decl = std::make_shared(expr->lineNumber); decl->initializer = expr; - data.init = decl; - } else if(ctx.IsOpen(ParserState::condition)) { - data.condition = policy->Data(); + data.init = decl; } else { data.incr = policy->Data(); } @@ -114,44 +117,34 @@ public srcDispatch::PolicyListener { void CollectInitHandlers() { using namespace srcDispatch; openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { - if(ctx.depth == (controlDepth + 1)) { - // if (!declPolicy) declPolicy = new DeclTypePolicy{this}; - // ctx.dispatcher->AddListenerDispatch(declPolicy); - } + if(ctx.depth != (controlDepth + 1)) return; + // if (!declPolicy) declPolicy = new DeclTypePolicy{this}; + // ctx.dispatcher->AddListenerDispatch(declPolicy); }; } void CollectConditionHandlers() { using namespace srcDispatch; openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if(ctx.depth == (controlDepth + 1)) { - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprPolicy); - }; - } - }; - closeEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if(ctx.depth == (controlDepth + 1)) { - NopOpenEvents({ParserState::expr}); - } + if(ctx.depth != (controlDepth + 1)) return; + + if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(conditionPolicy); }; } void CollectIncrHandlers() { using namespace srcDispatch; openEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { - if(ctx.depth == (controlDepth + 1)) { - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprPolicy); - }; - } + if(ctx.depth != (controlDepth + 1)) return; + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(exprPolicy); + }; }; closeEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { - if(ctx.depth == (controlDepth + 1)) { - NopOpenEvents({ParserState::expr}); - } + if(ctx.depth != (controlDepth + 1)) return; + NopOpenEvents({ParserState::expr}); }; } diff --git a/src/policy_classes/ForPolicySingleEvent.cpp b/src/policy_classes/ForPolicySingleEvent.cpp new file mode 100644 index 0000000..e94585a --- /dev/null +++ b/src/policy_classes/ForPolicySingleEvent.cpp @@ -0,0 +1,89 @@ +/** + * @file ForPolicySingleEvent.cpp + * + * + */ + +#include + +#include + +std::ostream& operator<<(std::ostream& out, const ForData& conditionalData) { + if(!conditionalData.control) return out; + return out << conditionalData.control; +} + +ForPolicy::ForPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + conditionalDepth(0), + controlPolicy(nullptr), + blockPolicy(nullptr) { + InitializeForPolicyHandlers(); +} + +ForPolicy::~ForPolicy() { + if (controlPolicy) delete controlPolicy; + if (blockPolicy) delete blockPolicy; +} + +std::any ForPolicy::DataInner() const { return std::make_shared(data); } + +void ForPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(ControlPolicy) == typeid(*policy)) { + data.control = policy->Data(); + } else if (typeid(BlockPolicy) == typeid(*policy)) { + data.block = policy->Data(); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); +} + +void ForPolicy::NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers + +void ForPolicy::InitializeForPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { \ + if (!conditionalDepth) { + conditionalDepth = ctx.depth; + data = ForData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectControlHandlers(); + CollectBlockHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::forstmt] =[this](srcSAXEventContext& ctx) { + if (conditionalDepth && conditionalDepth == ctx.depth) { + conditionalDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeForPolicyHandlers(); + } + }; +} + +void ForPolicy::CollectControlHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { + if(!conditionalDepth) return; + if((conditionalDepth + 1) != ctx.depth) return; + + if (!controlPolicy) controlPolicy = new ControlPolicy{this}; + ctx.dispatcher->AddListenerDispatch(controlPolicy); + }; +} + +void ForPolicy::CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(conditionalDepth && (conditionalDepth + 1) == ctx.depth) { + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + } + }; +} diff --git a/src/policy_classes/ForPolicySingleEvent.hpp b/src/policy_classes/ForPolicySingleEvent.hpp new file mode 100644 index 0000000..1673491 --- /dev/null +++ b/src/policy_classes/ForPolicySingleEvent.hpp @@ -0,0 +1,60 @@ +/** + * @file ForPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_FOR_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_FOR_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include + +#include +#include +#include + +class BlockPolicy; +class BlockData; + +struct ForData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::shared_ptr control; + std::shared_ptr block; + + friend std::ostream& operator<<(std::ostream& out, const ForData& conditionalData); +}; + + +class ForPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + ForData data; + std::size_t conditionalDepth; + ControlPolicy * controlPolicy; + BlockPolicy * blockPolicy; + +public: + ForPolicy(std::initializer_list listeners); + ~ForPolicy(); + +protected: + std::any DataInner() const override; + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override; + +private: + void InitializeForPolicyHandlers(); + void CollectControlHandlers(); + void CollectBlockHandlers(); +}; + +#endif From a20ada08c309613db4d857608939c23025c59e78 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 23 Oct 2024 11:45:03 +0900 Subject: [PATCH 043/149] Incr may have multiple expr --- src/policy_classes/ControlPolicySingleEvent.hpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp index a012ded..c1ae555 100644 --- a/src/policy_classes/ControlPolicySingleEvent.hpp +++ b/src/policy_classes/ControlPolicySingleEvent.hpp @@ -22,14 +22,19 @@ struct ControlData { unsigned int lineNumber; - std::shared_ptr init; - std::shared_ptr condition; - std::shared_ptr incr; + std::shared_ptr init; + std::shared_ptr condition; + std::vector> incr; friend std::ostream& operator<<(std::ostream& out, const ControlData& controlData) { if(controlData.init) out << controlData.init << "; "; if(controlData.condition) out << controlData.condition << "; "; - if(controlData.incr) out << controlData.incr; + bool outputComma = false; + for(const std::shared_ptr expr : controlData.incr) { + if(outputComma) out << ", "; + out << expr; + outputComma = true; + } return out; } }; @@ -79,7 +84,7 @@ public srcDispatch::PolicyListener { decl->initializer = expr; data.init = decl; } else { - data.incr = policy->Data(); + data.incr.push_back(policy->Data()); } } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); From ae666bb489da4859700fbc797499424faf1e73af Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 23 Oct 2024 12:52:17 +0900 Subject: [PATCH 044/149] Extract decl policy --- src/policy_classes/BlockPolicySingleEvent.hpp | 6 +- src/policy_classes/ClassPolicySingleEvent.hpp | 7 +- .../ControlPolicySingleEvent.hpp | 18 +- src/policy_classes/DeclPolicySingleEvent.hpp | 179 ++++++++++++++++++ .../DeclTypePolicySingleEvent.hpp | 158 +++------------- .../FunctionPolicySingleEvent.hpp | 16 +- 6 files changed, 231 insertions(+), 153 deletions(-) create mode 100644 src/policy_classes/DeclPolicySingleEvent.hpp diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index 6313579..ead8f70 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -26,7 +26,7 @@ struct BlockData { unsigned int startLineNumber; unsigned int endLineNumber; - std::vector> locals; + std::vector> locals; std::vector> returns; std::vector> expr_stmts; @@ -81,8 +81,8 @@ public srcDispatch::PolicyListener { virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(DeclTypePolicy) == typeid(*policy)) { - std::shared_ptr>> decl_data = policy->Data>>(); - for(std::shared_ptr decl : *decl_data) { + std::shared_ptr>> decl_data = policy->Data>>(); + for(std::shared_ptr decl : *decl_data) { data.locals.push_back(decl); } } else if (typeid(ReturnPolicy) == typeid(*policy)) { diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index 17dde1e..a1142b5 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -32,7 +32,7 @@ struct ClassData { std::shared_ptr name; std::vector parents; - std::vector> fields[3]; + std::vector> fields[3]; std::vector> constructors[3]; std::vector> operators[3]; std::vector> methods[3]; @@ -91,11 +91,10 @@ public srcDispatch::PolicyListener { if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); } else if (typeid(DeclTypePolicy) == typeid(*policy)) { - std::shared_ptr>> decl_data = policy->Data>>(); - for (std::shared_ptr decl : *decl_data) { + std::shared_ptr>> decl_data = policy->Data>>(); + for (std::shared_ptr decl : *decl_data) { data.fields[currentRegion].emplace_back(decl); } - decl_data->clear(); } else if (typeid(FunctionPolicy) == typeid(*policy)) { std::shared_ptr f_data = policy->Data(); if (f_data->isPureVirtual) diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp index c1ae555..0d92a9f 100644 --- a/src/policy_classes/ControlPolicySingleEvent.hpp +++ b/src/policy_classes/ControlPolicySingleEvent.hpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -22,7 +22,7 @@ struct ControlData { unsigned int lineNumber; - std::shared_ptr init; + std::shared_ptr init; std::shared_ptr condition; std::vector> incr; @@ -49,7 +49,7 @@ public srcDispatch::PolicyListener { private: ControlData data; std::size_t controlDepth; - DeclTypePolicy * declPolicy; + DeclPolicy * declPolicy; ConditionPolicy * conditionPolicy; ExpressionPolicy* exprPolicy; @@ -73,16 +73,16 @@ public srcDispatch::PolicyListener { virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { using namespace srcDispatch; - if(typeid(DeclTypePolicy) == typeid(*policy)) { - data.init = policy->Data(); + if(typeid(DeclPolicy) == typeid(*policy)) { + data.init = policy->Data(); } else if(typeid(ConditionPolicy) == typeid(*policy)) { data.condition = policy->Data(); } else if(typeid(ExpressionPolicy) == typeid(*policy)) { if(ctx.IsOpen(ParserState::init)) { std::shared_ptr expr = policy->Data(); - std::shared_ptr decl = std::make_shared(expr->lineNumber); - decl->initializer = expr; - data.init = decl; + std::shared_ptr decl = std::make_shared(expr->lineNumber); + decl->init = expr; + data.init = decl; } else { data.incr.push_back(policy->Data()); } @@ -123,7 +123,7 @@ public srcDispatch::PolicyListener { using namespace srcDispatch; openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { if(ctx.depth != (controlDepth + 1)) return; - // if (!declPolicy) declPolicy = new DeclTypePolicy{this}; + // if (!declPolicy) declPolicy = new DeclPolicy{this}; // ctx.dispatcher->AddListenerDispatch(declPolicy); }; } diff --git a/src/policy_classes/DeclPolicySingleEvent.hpp b/src/policy_classes/DeclPolicySingleEvent.hpp new file mode 100644 index 0000000..1636a1e --- /dev/null +++ b/src/policy_classes/DeclPolicySingleEvent.hpp @@ -0,0 +1,179 @@ +/** + * @file DeclPolicySingleEvent.hpp + * + * + * MODIFIED from srcDispatch + * This collects the initializer + * + */ +#ifndef INCLUDED_DECL_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_DECL_POLICY_SINGLE_EVENT_HPP + +#include + +#include +#include +#include + +#include +#include + +struct DeclData { + + unsigned int lineNumber; + std::shared_ptr type; + std::shared_ptr name; + std::shared_ptr init; + bool isStatic; + + friend std::ostream& operator<<(std::ostream& out, const DeclData& declData) { + if(declData.type) { + out << declData.type->ToString(); + } + if (declData.name) { + out << ' ' << *declData.name; + } + if (declData.init) { + out << " = " << *declData.init; + } + return out; + } +}; + + + +class DeclPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + DeclData data; + std::size_t declDepth; + TypePolicy * typePolicy; + NamePolicy * namePolicy; + ExpressionPolicy* exprPolicy; + +public: + DeclPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + declDepth(0), + typePolicy(nullptr), + namePolicy(nullptr), + exprPolicy(nullptr) { + InitializeDeclPolicyHandlers(); + } + + ~DeclPolicy() { + if (typePolicy) delete typePolicy; + if (namePolicy) delete namePolicy; + if (exprPolicy) delete exprPolicy; + } + +protected: + std::any DataInner() const override { return std::make_shared(data); } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers + + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + if (typeid(TypePolicy) == typeid(*policy)) { + data.type = std::shared_ptr(policy->Data()); + } else if (typeid(NamePolicy) == typeid(*policy)) { + data.name = policy->Data(); + } else if (typeid(ExpressionPolicy) == typeid(*policy)) { + data.init = policy->Data(); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + +private: + void InitializeDeclPolicyHandlers() { + using namespace srcDispatch; + + // start of policy + openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { + if(declDepth) return; + + declDepth = ctx.depth; + data = DeclData{}; + data.lineNumber = ctx.currentLineNumber; + + CollectSpecifiersHandlers(); + CollectTypeHandlers(); + CollectNameHandlers(); + CollectInitHandlers(); + }; + + // close policy + closeEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { + if(!declDepth || declDepth != ctx.depth) return; + + declDepth = 0; + NotifyAll(ctx); + data = DeclData{}; + InitializeDeclPolicyHandlers(); + }; + + } + + void CollectSpecifiersHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { + if(!declDepth || (declDepth + 1) != ctx.depth) return; + + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { + if (ctx.currentToken == "static") + data.isStatic = true; + }; + }; + closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { + if(!declDepth || (declDepth + 1) != ctx.depth) return; + + NopCloseEvents({ParserState::tokenstring}); + }; + } + + void CollectTypeHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { + if(!declDepth || (declDepth + 1) != ctx.depth) return; + + if (!typePolicy) typePolicy = new TypePolicy{this}; + ctx.dispatcher->AddListenerDispatch(typePolicy); + }; + } + + void CollectNameHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { + if(!declDepth || (declDepth + 1) != ctx.depth) return; + + if (!namePolicy) namePolicy = new NamePolicy{this}; + ctx.dispatcher->AddListenerDispatch(namePolicy); + }; + } + + void CollectInitHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { + if(!declDepth || (declDepth + 1) != ctx.depth) return; + + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(!exprPolicy) exprPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(exprPolicy); + }; + }; + closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { + if(!declDepth || (declDepth + 1) != ctx.depth) return; + + NopOpenEvents({ParserState::expr}); + }; + } + +}; + +#endif diff --git a/src/policy_classes/DeclTypePolicySingleEvent.hpp b/src/policy_classes/DeclTypePolicySingleEvent.hpp index 6246dac..02810c9 100644 --- a/src/policy_classes/DeclTypePolicySingleEvent.hpp +++ b/src/policy_classes/DeclTypePolicySingleEvent.hpp @@ -11,88 +11,47 @@ #include -#include -#include -#include +#include #include #include -struct DeclTypeData { - - DeclTypeData(unsigned int lineNumber) - : lineNumber(lineNumber), type(), name(), initializer(), isStatic() { - } - - unsigned int lineNumber; - std::shared_ptr type; - std::shared_ptr name; - std::shared_ptr initializer; - bool isStatic; - - friend std::ostream& operator<<(std::ostream& out, const DeclTypeData& declData) { - if(declData.type) { - out << declData.type->ToString(); - } - if (declData.name) { - out << ' ' << *declData.name; - } - if (declData.initializer) { - out << " = " << *declData.initializer; - } - return out; - } -}; - - - class DeclTypePolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - std::vector> data; - std::size_t declDepth; - TypePolicy * typePolicy; - NamePolicy * namePolicy; - ExpressionPolicy* expressionPolicy; - - bool isStatic; - std::shared_ptr type; - std::shared_ptr initializer; + std::vector> decls; + std::size_t declDepth; + DeclPolicy* declPolicy; public: DeclTypePolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), - data{}, + decls{}, declDepth(0), - typePolicy(nullptr), - isStatic(false), - type(), - expressionPolicy(nullptr), - namePolicy(nullptr) { + declPolicy(nullptr) { InitializeDeclTypePolicyHandlers(); } ~DeclTypePolicy() { - if (typePolicy) delete typePolicy; - if (namePolicy) delete namePolicy; - if (expressionPolicy) delete expressionPolicy; + if (declPolicy) delete declPolicy; } protected: - std::any DataInner() const override { return std::make_shared>>(data); } + std::any DataInner() const override { return std::make_shared>>(decls); } void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(TypePolicy) == typeid(*policy)) { - type = std::shared_ptr(policy->Data()); - } else if (typeid(NamePolicy) == typeid(*policy)) { - data.back()->name = policy->Data(); - } else if (typeid(ExpressionPolicy) == typeid(*policy)) { - initializer = policy->Data(); + if (typeid(DeclPolicy) == typeid(*policy)) { + std::shared_ptr decl = policy->Data(); + if(decls.size()) { + decl->type = decls.back()->type; + decl->isStatic = decls.back()->isStatic; + } + decls.push_back(decl); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } @@ -103,99 +62,40 @@ public srcDispatch::PolicyListener { private: void InitializeDeclTypePolicyHandlers() { using namespace srcDispatch; - // start of policy + // start of policy std::function startDeclType = [this](srcSAXEventContext& ctx) { if (!declDepth) { declDepth = ctx.depth; - CollectTypeHandlers(); - CollectNameHandlers(); - CollectSpecifiersHandlers(); - CollectInitHandlers(); + CollectDeclHandlers(); } - openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { - if (declDepth && (declDepth + 1) == ctx.depth) { - data.push_back(std::make_shared(ctx.currentLineNumber)); - } - }; - closeEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { - if (declDepth && (declDepth + 1) == ctx.depth) { - data.back()->isStatic = isStatic; - data.back()->type = type; - data.back()->initializer = initializer; - } - }; }; openEventMap[ParserState::declstmt] = startDeclType; openEventMap[ParserState::parameter] = startDeclType; + // end of policy std::function endDeclType = [this](srcSAXEventContext& ctx) { - if (declDepth && declDepth == ctx.depth) { - declDepth = 0; - NotifyAll(ctx); - data.clear(); - InitializeDeclTypePolicyHandlers(); - } + if (!declDepth || declDepth != ctx.depth) return; + + declDepth = 0; + NotifyAll(ctx); + decls.clear(); + InitializeDeclTypePolicyHandlers(); }; - // end of policy closeEventMap[ParserState::declstmt] = endDeclType; closeEventMap[ParserState::parameter] = endDeclType; } - void CollectTypeHandlers() { + void CollectDeclHandlers() { using namespace srcDispatch; - openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - if (declDepth && (declDepth + 2) == ctx.depth) { - if (!typePolicy) typePolicy = new TypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(typePolicy); - } - }; - } - - void CollectNameHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if (declDepth && (declDepth + 2) == ctx.depth) { - if (!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); - } - }; - } + openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { + if(!declDepth || (declDepth + 1) != ctx.depth) return; - void CollectSpecifiersHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { - if (declDepth && (declDepth + 2) == ctx.depth) { - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - if (ctx.currentToken == "static") - isStatic = true; - }; - } - }; - closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { - if (declDepth && (declDepth + 1) == ctx.depth) { - NopCloseEvents({ParserState::tokenstring}); - } - }; - } - - void CollectInitHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { - if (declDepth && (declDepth + 2) == ctx.depth) { - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(expressionPolicy); - }; - } - }; - closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { - if (declDepth && (declDepth + 2) == ctx.depth) { - NopOpenEvents({ParserState::expr}); - } + if (!declPolicy) declPolicy = new DeclPolicy{this}; + ctx.dispatcher->AddListenerDispatch(declPolicy); }; } diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index 940b6cd..3340686 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -39,12 +39,12 @@ struct FunctionData { bool isConstExpr; bool isDelete; - std::set stereotypes; + std::set stereotypes; - std::shared_ptr returnType; - std::shared_ptr name; - std::vector> parameters; - std::shared_ptr block; + std::shared_ptr returnType; + std::shared_ptr name; + std::vector> parameters; + std::shared_ptr block; std::string ToString() const { @@ -64,7 +64,7 @@ struct FunctionData { } friend std::ostream& operator<<(std::ostream& out, const FunctionData& functionData) { - if (functionData.returnType){ + if (functionData.returnType) { out << *functionData.returnType << ' ' << *functionData.name; } out << '('; @@ -123,8 +123,8 @@ public srcDispatch::PolicyListener { } else if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); } else if (typeid(DeclTypePolicy) == typeid(*policy)) { - std::shared_ptr>> decl_data = policy->Data>>(); - for(std::shared_ptr decl : *decl_data) { + std::shared_ptr>> decl_data = policy->Data>>(); + for(std::shared_ptr decl : *decl_data) { data.parameters.push_back(decl); } } else if (typeid(BlockPolicy) == typeid(*policy)) { From 54ba654c79d76e189b43aa30f3e296f63c8928da Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 23 Oct 2024 13:14:04 +0900 Subject: [PATCH 045/149] Implement collect init for fors --- .../ConditionalPolicySingleEvent.cpp | 2 +- .../ControlPolicySingleEvent.hpp | 51 ++++++++++++++----- src/policy_classes/ForPolicySingleEvent.cpp | 2 +- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/policy_classes/ConditionalPolicySingleEvent.cpp b/src/policy_classes/ConditionalPolicySingleEvent.cpp index 21ec231..44be271 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.cpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.cpp @@ -10,7 +10,7 @@ std::ostream& operator<<(std::ostream& out, const ConditionalData& conditionalData) { if(!conditionalData.condition) return out; - return out << conditionalData.condition; + return out << *conditionalData.condition; } ConditionalPolicy::ConditionalPolicy(std::initializer_list listeners) diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp index 0d92a9f..a654f8c 100644 --- a/src/policy_classes/ControlPolicySingleEvent.hpp +++ b/src/policy_classes/ControlPolicySingleEvent.hpp @@ -22,18 +22,26 @@ struct ControlData { unsigned int lineNumber; - std::shared_ptr init; + std::vector> init; std::shared_ptr condition; std::vector> incr; friend std::ostream& operator<<(std::ostream& out, const ControlData& controlData) { - if(controlData.init) out << controlData.init << "; "; - if(controlData.condition) out << controlData.condition << "; "; - bool outputComma = false; + + bool outputDeclComma = false; + for(const std::shared_ptr decl : controlData.init) { + if(outputDeclComma) out << ", "; + out << *decl; + outputDeclComma = true; + } + + if(controlData.condition) out << *controlData.condition << "; "; + + bool outputExprComma = false; for(const std::shared_ptr expr : controlData.incr) { - if(outputComma) out << ", "; - out << expr; - outputComma = true; + if(outputExprComma) out << ", "; + out << *expr; + outputExprComma = true; } return out; } @@ -49,7 +57,7 @@ public srcDispatch::PolicyListener { private: ControlData data; std::size_t controlDepth; - DeclPolicy * declPolicy; + DeclPolicy * declPolicy; ConditionPolicy * conditionPolicy; ExpressionPolicy* exprPolicy; @@ -74,15 +82,16 @@ public srcDispatch::PolicyListener { virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { using namespace srcDispatch; if(typeid(DeclPolicy) == typeid(*policy)) { - data.init = policy->Data(); + data.init.push_back(policy->Data()); } else if(typeid(ConditionPolicy) == typeid(*policy)) { data.condition = policy->Data(); } else if(typeid(ExpressionPolicy) == typeid(*policy)) { if(ctx.IsOpen(ParserState::init)) { std::shared_ptr expr = policy->Data(); - std::shared_ptr decl = std::make_shared(expr->lineNumber); + std::shared_ptr decl = std::make_shared(); + decl->lineNumber = expr->lineNumber; decl->init = expr; - data.init = decl; + data.init.push_back(decl); } else { data.incr.push_back(policy->Data()); } @@ -123,9 +132,25 @@ public srcDispatch::PolicyListener { using namespace srcDispatch; openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { if(ctx.depth != (controlDepth + 1)) return; - // if (!declPolicy) declPolicy = new DeclPolicy{this}; - // ctx.dispatcher->AddListenerDispatch(declPolicy); + + openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { + if(ctx.depth != (controlDepth + 2)) return; + + if (!declPolicy) declPolicy = new DeclPolicy{this}; + ctx.dispatcher->AddListenerDispatch(declPolicy); + }; + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(ctx.depth != (controlDepth + 2)) return; + + if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(exprPolicy); + }; }; + closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { + if(ctx.depth != (controlDepth + 1)) return; + NopOpenEvents({ParserState::decl, ParserState::expr}); + }; + } void CollectConditionHandlers() { diff --git a/src/policy_classes/ForPolicySingleEvent.cpp b/src/policy_classes/ForPolicySingleEvent.cpp index e94585a..2549208 100644 --- a/src/policy_classes/ForPolicySingleEvent.cpp +++ b/src/policy_classes/ForPolicySingleEvent.cpp @@ -10,7 +10,7 @@ std::ostream& operator<<(std::ostream& out, const ForData& conditionalData) { if(!conditionalData.control) return out; - return out << conditionalData.control; + return out << *conditionalData.control; } ForPolicy::ForPolicy(std::initializer_list listeners) From 4e9d69ecfe5559618c7139a28cdcec9423368870 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 23 Oct 2024 13:15:15 +0900 Subject: [PATCH 046/149] Remove extra minor spacing --- src/policy_classes/ForPolicySingleEvent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/policy_classes/ForPolicySingleEvent.cpp b/src/policy_classes/ForPolicySingleEvent.cpp index 2549208..5673133 100644 --- a/src/policy_classes/ForPolicySingleEvent.cpp +++ b/src/policy_classes/ForPolicySingleEvent.cpp @@ -23,8 +23,8 @@ ForPolicy::ForPolicy(std::initializer_list listene } ForPolicy::~ForPolicy() { - if (controlPolicy) delete controlPolicy; - if (blockPolicy) delete blockPolicy; + if (controlPolicy) delete controlPolicy; + if (blockPolicy) delete blockPolicy; } std::any ForPolicy::DataInner() const { return std::make_shared(data); } From 8822ea5a06484489a3c8eaf1406803111d7aa6c4 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 06:56:53 +0900 Subject: [PATCH 047/149] Store for/conditionals in an any --- src/policy_classes/BlockPolicySingleEvent.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index ead8f70..96f9153 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -31,7 +31,7 @@ struct BlockData { std::vector> expr_stmts; std::vector> blocks; - std::vector> conditionals; + std::vector conditionals; std::vector> fors; }; @@ -94,7 +94,7 @@ public srcDispatch::PolicyListener { } else if (typeid(ConditionalPolicy) == typeid(*policy)) { data.conditionals.push_back(policy->Data()); } else if (typeid(ForPolicy) == typeid(*policy)) { - data.fors.push_back(policy->Data()); + data.conditionals.push_back(policy->Data()); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } From 794df43c0db23fb32b120cf8d54742e2ed62560f Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 07:17:20 +0900 Subject: [PATCH 048/149] Put conditional policy in hpp --- src/policy_classes/BlockPolicySingleEvent.cpp | 143 +++++++++++++++++ src/policy_classes/BlockPolicySingleEvent.hpp | 146 +++--------------- .../ConditionalPolicySingleEvent.cpp | 102 ------------ .../ConditionalPolicySingleEvent.hpp | 103 ++++++++++-- 4 files changed, 251 insertions(+), 243 deletions(-) create mode 100644 src/policy_classes/BlockPolicySingleEvent.cpp delete mode 100644 src/policy_classes/ConditionalPolicySingleEvent.cpp diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp new file mode 100644 index 0000000..7e20684 --- /dev/null +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -0,0 +1,143 @@ +/** + * @file BlockPolicySingleEvent.hpp + * + * MODIFIED FOR STEREOCODE + * + */ + +#include + +#include + +#include +#include + +BlockPolicy::BlockPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + blockDepth(0), + declstmtPolicy(nullptr), + exprStmtPolicy(nullptr), + returnPolicy(nullptr), + blockPolicy(nullptr), + conditionalPolicy(nullptr), + forPolicy(nullptr) { + InitializeBlockPolicyHandlers(); +} + +BlockPolicy::~BlockPolicy() { + if (declstmtPolicy) delete declstmtPolicy; + if (returnPolicy) delete returnPolicy; + if (exprStmtPolicy) delete exprStmtPolicy; + if (blockPolicy) delete blockPolicy; + if (conditionalPolicy) delete conditionalPolicy; +} + +std::any BlockPolicy::DataInner() const { return std::make_shared(data); } + +void BlockPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(DeclTypePolicy) == typeid(*policy)) { + std::shared_ptr>> decl_data = policy->Data>>(); + for(std::shared_ptr decl : *decl_data) { + data.locals.push_back(decl); + } + } else if (typeid(ReturnPolicy) == typeid(*policy)) { + data.returns.push_back(policy->Data()); + } else if (typeid(ExprStmtPolicy) == typeid(*policy)) { + data.expr_stmts.push_back(policy->Data()); + } else if (typeid(BlockPolicy) == typeid(*policy)) { + data.blocks.push_back(policy->Data()); + } else if (typeid(ConditionalPolicy) == typeid(*policy)) { + data.conditionals.push_back(policy->Data()); + } else if (typeid(ForPolicy) == typeid(*policy)) { + data.conditionals.push_back(policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListenerDispatch(nullptr); +} + +void BlockPolicy::InitializeBlockPolicyHandlers() { + using namespace srcDispatch; + + CollectBlockHandlers(); + CollectDeclstmtHandlers(); + CollectReturnHandlers(); + CollectExpressionHandlers(); + CollectConditionalHandlers(); + CollectConditionalHandlers(); + CollectForHandlers(); + +} + +void BlockPolicy::CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!blockDepth) { + blockDepth = ctx.depth; + data = BlockData{}; + data.startLineNumber = ctx.currentLineNumber; + } else { + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + } + }; + + closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(blockDepth && blockDepth == ctx.depth) { + blockDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeBlockPolicyHandlers(); + } + }; + +} + +void BlockPolicy::CollectReturnHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { + if (!returnPolicy) returnPolicy = new ReturnPolicy{this}; + ctx.dispatcher->AddListenerDispatch(returnPolicy); + }; +} + +void BlockPolicy::CollectExpressionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { + if (!exprStmtPolicy) exprStmtPolicy = new ExprStmtPolicy{this}; + ctx.dispatcher->AddListenerDispatch(exprStmtPolicy); + }; +} + +void BlockPolicy::CollectDeclstmtHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { + if (!declstmtPolicy) declstmtPolicy = new DeclTypePolicy{this}; + ctx.dispatcher->AddListenerDispatch(declstmtPolicy); + }; +} + +void BlockPolicy::CollectConditionalHandlers() { + using namespace srcDispatch; + std::function startConditional = [this](srcSAXEventContext& ctx) { + if (!conditionalPolicy) conditionalPolicy = new ConditionalPolicy{this}; + ctx.dispatcher->AddListenerDispatch(conditionalPolicy); + }; + + openEventMap[ParserState::ifstmt] = startConditional; + openEventMap[ParserState::whilestmt] = startConditional; + openEventMap[ParserState::switchstmt] = startConditional; + openEventMap[ParserState::dostmt] = startConditional; + +} + +void BlockPolicy::CollectForHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { + if (!forPolicy) forPolicy = new ForPolicy{this}; + ctx.dispatcher->AddListenerDispatch(forPolicy); + }; + +} diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index 96f9153..915d9cc 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -12,8 +12,11 @@ #include #include #include -#include -#include + +class ConditionalPolicy; +class ClassData; +class ForPolicy; +class ForData; #include #include @@ -53,139 +56,26 @@ public srcDispatch::PolicyListener { ForPolicy * forPolicy; public: - BlockPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - blockDepth(0), - declstmtPolicy(nullptr), - exprStmtPolicy(nullptr), - returnPolicy(nullptr), - blockPolicy(nullptr), - conditionalPolicy(nullptr), - forPolicy(nullptr) { - InitializeBlockPolicyHandlers(); - } - - ~BlockPolicy() { - if (declstmtPolicy) delete declstmtPolicy; - if (returnPolicy) delete returnPolicy; - if (exprStmtPolicy) delete exprStmtPolicy; - if (blockPolicy) delete blockPolicy; - if (conditionalPolicy) delete conditionalPolicy; - } + BlockPolicy(std::initializer_list listeners); + + ~BlockPolicy(); protected: - std::any DataInner() const override { return std::make_shared(data); } + std::any DataInner() const override; void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(DeclTypePolicy) == typeid(*policy)) { - std::shared_ptr>> decl_data = policy->Data>>(); - for(std::shared_ptr decl : *decl_data) { - data.locals.push_back(decl); - } - } else if (typeid(ReturnPolicy) == typeid(*policy)) { - data.returns.push_back(policy->Data()); - } else if (typeid(ExprStmtPolicy) == typeid(*policy)) { - data.expr_stmts.push_back(policy->Data()); - } else if (typeid(BlockPolicy) == typeid(*policy)) { - data.blocks.push_back(policy->Data()); - } else if (typeid(ConditionalPolicy) == typeid(*policy)) { - data.conditionals.push_back(policy->Data()); - } else if (typeid(ForPolicy) == typeid(*policy)) { - data.conditionals.push_back(policy->Data()); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListenerDispatch(nullptr); - } + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; private: - void InitializeBlockPolicyHandlers() { - using namespace srcDispatch; - - CollectBlockHandlers(); - CollectDeclstmtHandlers(); - CollectReturnHandlers(); - CollectExpressionHandlers(); - CollectConditionalHandlers(); - CollectConditionalHandlers(); - CollectForHandlers(); - - } - - void CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(!blockDepth) { - blockDepth = ctx.depth; - data = BlockData{}; - data.startLineNumber = ctx.currentLineNumber; - } else { - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); - } - }; - - closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(blockDepth && blockDepth == ctx.depth) { - blockDepth = 0; - data.endLineNumber = ctx.currentLineNumber; - NotifyAll(ctx); - InitializeBlockPolicyHandlers(); - } - }; - - } - - void CollectReturnHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { - if (!returnPolicy) returnPolicy = new ReturnPolicy{this}; - ctx.dispatcher->AddListenerDispatch(returnPolicy); - }; - } - - void CollectExpressionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { - if (!exprStmtPolicy) exprStmtPolicy = new ExprStmtPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprStmtPolicy); - }; - } - - void CollectDeclstmtHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - if (!declstmtPolicy) declstmtPolicy = new DeclTypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(declstmtPolicy); - }; - } - - void CollectConditionalHandlers() { - using namespace srcDispatch; - std::function startConditional = [this](srcSAXEventContext& ctx) { - if (!conditionalPolicy) conditionalPolicy = new ConditionalPolicy{this}; - ctx.dispatcher->AddListenerDispatch(conditionalPolicy); - }; - - openEventMap[ParserState::ifstmt] = startConditional; - openEventMap[ParserState::whilestmt] = startConditional; - openEventMap[ParserState::switchstmt] = startConditional; - openEventMap[ParserState::dostmt] = startConditional; - - } - - void CollectForHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { - if (!forPolicy) forPolicy = new ForPolicy{this}; - ctx.dispatcher->AddListenerDispatch(forPolicy); - }; - - } + void InitializeBlockPolicyHandlers(); + + void CollectBlockHandlers(); + void CollectReturnHandlers(); + void CollectExpressionHandlers(); + void CollectDeclstmtHandlers(); + void CollectConditionalHandlers(); + void CollectForHandlers(); }; diff --git a/src/policy_classes/ConditionalPolicySingleEvent.cpp b/src/policy_classes/ConditionalPolicySingleEvent.cpp deleted file mode 100644 index 44be271..0000000 --- a/src/policy_classes/ConditionalPolicySingleEvent.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/** - * @file ConditionalPolicySingleEvent.cpp - * - * - */ - -#include - -#include - -std::ostream& operator<<(std::ostream& out, const ConditionalData& conditionalData) { - if(!conditionalData.condition) return out; - return out << *conditionalData.condition; -} - -ConditionalPolicy::ConditionalPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - conditionalDepth(0), - conditionPolicy(nullptr), - blockPolicy(nullptr) { - InitializeConditionalPolicyHandlers(); -} - -ConditionalPolicy::~ConditionalPolicy() { - if (conditionPolicy) delete conditionPolicy; - if (blockPolicy) delete blockPolicy; -} - -std::any ConditionalPolicy::DataInner() const { return std::make_shared(data); } - -void ConditionalPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(ConditionPolicy) == typeid(*policy)) { - data.condition = policy->Data(); - }else if (typeid(BlockPolicy) == typeid(*policy)) { - data.block = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); -} - -void ConditionalPolicy::NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers - -void ConditionalPolicy::InitializeConditionalPolicyHandlers() { - using namespace srcDispatch; - - #define startConditional(TYPE) \ - [this](srcSAXEventContext& ctx) { \ - if (!conditionalDepth) { \ - conditionalDepth = ctx.depth; \ - data = ConditionalData{}; \ - data.type = TYPE; \ - data.startLineNumber = ctx.currentLineNumber; \ - CollectConditionHandlers(); \ - CollectBlockHandlers(); \ - } \ - }; \ - - openEventMap[ParserState::ifstmt] = startConditional(ConditionalData::IF); - openEventMap[ParserState::whilestmt] = startConditional(ConditionalData::WHILE); - openEventMap[ParserState::switchstmt] = startConditional(ConditionalData::SWITCH); - openEventMap[ParserState::dostmt] = startConditional(ConditionalData::DO); - - std::function endConditional =[this](srcSAXEventContext& ctx) { - if (conditionalDepth && conditionalDepth == ctx.depth) { - conditionalDepth = 0; - data.endLineNumber = ctx.currentLineNumber; - NotifyAll(ctx); - InitializeConditionalPolicyHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::ifstmt] = endConditional; - closeEventMap[ParserState::whilestmt] = endConditional; - closeEventMap[ParserState::switchstmt] = endConditional; - closeEventMap[ParserState::dostmt] = endConditional; -} - -void ConditionalPolicy::CollectConditionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if(!conditionalDepth) return; - if((conditionalDepth + 1) != ctx.depth) return; - - if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(conditionPolicy); - }; -} - -void ConditionalPolicy::CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(!conditionalDepth) return; - if((conditionalDepth + 1) != ctx.depth) return; - - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); - }; -} diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index 5ae204b..4bf36b9 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -11,14 +11,12 @@ #include #include +#include #include #include #include -class BlockPolicy; -class BlockData; - struct ConditionalData { enum ConditionalType { IF, WHILE, SWITCH, DO }; @@ -31,7 +29,10 @@ struct ConditionalData { std::shared_ptr condition; std::shared_ptr block; - friend std::ostream& operator<<(std::ostream& out, const ConditionalData& conditionalData); + friend std::ostream& operator<<(std::ostream& out, const ConditionalData& conditionalData) { + if(!conditionalData.condition) return out; + return out << *conditionalData.condition; + } }; @@ -47,19 +48,95 @@ public srcDispatch::PolicyListener { BlockPolicy * blockPolicy; public: - ConditionalPolicy(std::initializer_list listeners); - ~ConditionalPolicy(); + ConditionalPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + conditionalDepth(0), + conditionPolicy(nullptr), + blockPolicy(nullptr) { + InitializeConditionalPolicyHandlers(); + } + + ~ConditionalPolicy() { + if (conditionPolicy) delete conditionPolicy; + if (blockPolicy) delete blockPolicy; + } protected: - std::any DataInner() const override; - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override; + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(ConditionPolicy) == typeid(*policy)) { + data.condition = policy->Data(); + }else if (typeid(BlockPolicy) == typeid(*policy)) { + data.block = policy->Data(); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers private: - void InitializeConditionalPolicyHandlers(); - void CollectControlHandlers(); - void CollectConditionHandlers(); - void CollectBlockHandlers(); + void InitializeConditionalPolicyHandlers() { + using namespace srcDispatch; + + #define startConditional(TYPE) \ + [this](srcSAXEventContext& ctx) { \ + if (!conditionalDepth) { \ + conditionalDepth = ctx.depth; \ + data = ConditionalData{}; \ + data.type = TYPE; \ + data.startLineNumber = ctx.currentLineNumber; \ + CollectConditionHandlers(); \ + CollectBlockHandlers(); \ + } \ + }; \ + + openEventMap[ParserState::ifstmt] = startConditional(ConditionalData::IF); + openEventMap[ParserState::whilestmt] = startConditional(ConditionalData::WHILE); + openEventMap[ParserState::switchstmt] = startConditional(ConditionalData::SWITCH); + openEventMap[ParserState::dostmt] = startConditional(ConditionalData::DO); + + std::function endConditional =[this](srcSAXEventContext& ctx) { + if (conditionalDepth && conditionalDepth == ctx.depth) { + conditionalDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeConditionalPolicyHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::ifstmt] = endConditional; + closeEventMap[ParserState::whilestmt] = endConditional; + closeEventMap[ParserState::switchstmt] = endConditional; + closeEventMap[ParserState::dostmt] = endConditional; + } + + void CollectConditionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if(!conditionalDepth) return; + if((conditionalDepth + 1) != ctx.depth) return; + + if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(conditionPolicy); + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!conditionalDepth) return; + if((conditionalDepth + 1) != ctx.depth) return; + + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + }; + } }; #endif From 9fc2522d8ccd679cfa13208108b0c4a14d686c32 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 07:30:30 +0900 Subject: [PATCH 049/149] Extract while policy --- src/policy_classes/BlockPolicySingleEvent.cpp | 19 ++- src/policy_classes/BlockPolicySingleEvent.hpp | 6 +- src/policy_classes/WhilePolicySingleEvent.hpp | 134 ++++++++++++++++++ 3 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 src/policy_classes/WhilePolicySingleEvent.hpp diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp index 7e20684..c375049 100644 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -10,6 +10,7 @@ #include #include +#include #include BlockPolicy::BlockPolicy(std::initializer_list listeners) @@ -31,6 +32,8 @@ BlockPolicy::~BlockPolicy() { if (exprStmtPolicy) delete exprStmtPolicy; if (blockPolicy) delete blockPolicy; if (conditionalPolicy) delete conditionalPolicy; + if (whilePolicy) delete whilePolicy; + if (forPolicy) delete forPolicy; } std::any BlockPolicy::DataInner() const { return std::make_shared(data); } @@ -49,9 +52,11 @@ void BlockPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcS data.blocks.push_back(policy->Data()); } else if (typeid(ConditionalPolicy) == typeid(*policy)) { data.conditionals.push_back(policy->Data()); + } else if (typeid(WhilePolicy) == typeid(*policy)) { + data.conditionals.push_back(policy->Data()); } else if (typeid(ForPolicy) == typeid(*policy)) { data.conditionals.push_back(policy->Data()); - } else { + } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } @@ -66,7 +71,7 @@ void BlockPolicy::InitializeBlockPolicyHandlers() { CollectReturnHandlers(); CollectExpressionHandlers(); CollectConditionalHandlers(); - CollectConditionalHandlers(); + CollectWhileHandlers(); CollectForHandlers(); } @@ -127,12 +132,20 @@ void BlockPolicy::CollectConditionalHandlers() { }; openEventMap[ParserState::ifstmt] = startConditional; - openEventMap[ParserState::whilestmt] = startConditional; openEventMap[ParserState::switchstmt] = startConditional; openEventMap[ParserState::dostmt] = startConditional; } +void BlockPolicy::CollectWhileHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { + if (!whilePolicy) whilePolicy = new WhilePolicy{this}; + ctx.dispatcher->AddListenerDispatch(whilePolicy); + }; + +} + void BlockPolicy::CollectForHandlers() { using namespace srcDispatch; openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index 915d9cc..0ff6338 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -14,9 +14,8 @@ #include class ConditionalPolicy; -class ClassData; +class WhilePolicy; class ForPolicy; -class ForData; #include #include @@ -35,7 +34,6 @@ struct BlockData { std::vector> blocks; std::vector conditionals; - std::vector> fors; }; @@ -53,6 +51,7 @@ public srcDispatch::PolicyListener { ExprStmtPolicy * exprStmtPolicy; BlockPolicy * blockPolicy; ConditionalPolicy* conditionalPolicy; + WhilePolicy * whilePolicy; ForPolicy * forPolicy; public: @@ -75,6 +74,7 @@ public srcDispatch::PolicyListener { void CollectExpressionHandlers(); void CollectDeclstmtHandlers(); void CollectConditionalHandlers(); + void CollectWhileHandlers(); void CollectForHandlers(); }; diff --git a/src/policy_classes/WhilePolicySingleEvent.hpp b/src/policy_classes/WhilePolicySingleEvent.hpp new file mode 100644 index 0000000..c8af282 --- /dev/null +++ b/src/policy_classes/WhilePolicySingleEvent.hpp @@ -0,0 +1,134 @@ +/** + * @file WhilePolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_WHILE_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_WHILE_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include +#include + +#include +#include +#include + +struct WhileData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::shared_ptr condition; + std::shared_ptr block; + + friend std::ostream& operator<<(std::ostream& out, const WhileData& whileData) { + if(!whileData.condition) return out; + return out << *whileData.condition; + } +}; + +class WhilePolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + WhileData data; + std::size_t whileDepth; + ConditionPolicy* conditionPolicy; + BlockPolicy * blockPolicy; + +public: + WhilePolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + whileDepth(0), + conditionPolicy(nullptr), + blockPolicy(nullptr) { + InitializeWhilePolicyHandlers(); + } + + ~WhilePolicy() { + if (conditionPolicy) delete conditionPolicy; + if (blockPolicy) delete blockPolicy; + } + +protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(ConditionPolicy) == typeid(*policy)) { + data.condition = policy->Data(); + }else if (typeid(BlockPolicy) == typeid(*policy)) { + data.block = policy->Data(); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers + +private: + void InitializeWhilePolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { + if (!whileDepth) { + whileDepth = ctx.depth; + data = WhileData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectConditionHandlers(); + CollectBlockHandlers(); + } + }; + + std::function endConditional =[this](srcSAXEventContext& ctx) { + if (whileDepth && whileDepth == ctx.depth) { + whileDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeWhilePolicyHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::whilestmt] =[this](srcSAXEventContext& ctx) { + if (whileDepth && whileDepth == ctx.depth) { + whileDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeWhilePolicyHandlers(); + } + }; + } + + void CollectConditionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if(!whileDepth) return; + if((whileDepth + 1) != ctx.depth) return; + + if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(conditionPolicy); + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!whileDepth) return; + if((whileDepth + 1) != ctx.depth) return; + + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + }; + } +}; + +#endif From 8c552e3e0ae9b508bea480468d817ed6aa665e4b Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 07:39:15 +0900 Subject: [PATCH 050/149] Extract Do policy --- src/policy_classes/BlockPolicySingleEvent.cpp | 19 ++- src/policy_classes/BlockPolicySingleEvent.hpp | 3 + src/policy_classes/DoPolicySingleEvent.hpp | 134 ++++++++++++++++++ 3 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 src/policy_classes/DoPolicySingleEvent.hpp diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp index c375049..487b32d 100644 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -12,6 +12,7 @@ #include #include #include +#include BlockPolicy::BlockPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), @@ -22,7 +23,9 @@ BlockPolicy::BlockPolicy(std::initializer_list lis returnPolicy(nullptr), blockPolicy(nullptr), conditionalPolicy(nullptr), - forPolicy(nullptr) { + whilePolicy(nullptr), + forPolicy(nullptr), + doPolicy(nullptr) { InitializeBlockPolicyHandlers(); } @@ -34,6 +37,7 @@ BlockPolicy::~BlockPolicy() { if (conditionalPolicy) delete conditionalPolicy; if (whilePolicy) delete whilePolicy; if (forPolicy) delete forPolicy; + if (doPolicy) delete forPolicy; } std::any BlockPolicy::DataInner() const { return std::make_shared(data); } @@ -56,6 +60,8 @@ void BlockPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcS data.conditionals.push_back(policy->Data()); } else if (typeid(ForPolicy) == typeid(*policy)) { data.conditionals.push_back(policy->Data()); + } else if (typeid(DoPolicy) == typeid(*policy)) { + data.conditionals.push_back(policy->Data()); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } @@ -72,7 +78,7 @@ void BlockPolicy::InitializeBlockPolicyHandlers() { CollectExpressionHandlers(); CollectConditionalHandlers(); CollectWhileHandlers(); - CollectForHandlers(); + CollectDoHandlers(); } @@ -154,3 +160,12 @@ void BlockPolicy::CollectForHandlers() { }; } + +void BlockPolicy::CollectDoHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { + if (!forPolicy) forPolicy = new ForPolicy{this}; + ctx.dispatcher->AddListenerDispatch(forPolicy); + }; + +} diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index 0ff6338..53e34e0 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -16,6 +16,7 @@ class ConditionalPolicy; class WhilePolicy; class ForPolicy; +class DoPolicy; #include #include @@ -53,6 +54,7 @@ public srcDispatch::PolicyListener { ConditionalPolicy* conditionalPolicy; WhilePolicy * whilePolicy; ForPolicy * forPolicy; + DoPolicy * doPolicy; public: BlockPolicy(std::initializer_list listeners); @@ -76,6 +78,7 @@ public srcDispatch::PolicyListener { void CollectConditionalHandlers(); void CollectWhileHandlers(); void CollectForHandlers(); + void CollectDoHandlers(); }; diff --git a/src/policy_classes/DoPolicySingleEvent.hpp b/src/policy_classes/DoPolicySingleEvent.hpp new file mode 100644 index 0000000..69981d3 --- /dev/null +++ b/src/policy_classes/DoPolicySingleEvent.hpp @@ -0,0 +1,134 @@ +/** + * @file DoPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_DO_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_DO_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include +#include + +#include +#include +#include + +struct DoData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::shared_ptr condition; + std::shared_ptr block; + + friend std::ostream& operator<<(std::ostream& out, const DoData& doData) { + if(!doData.condition) return out; + return out << *doData.condition; + } +}; + +class DoPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + DoData data; + std::size_t doDepth; + ConditionPolicy* conditionPolicy; + BlockPolicy * blockPolicy; + +public: + DoPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + doDepth(0), + conditionPolicy(nullptr), + blockPolicy(nullptr) { + InitializeDoPolicyHandlers(); + } + + ~DoPolicy() { + if (conditionPolicy) delete conditionPolicy; + if (blockPolicy) delete blockPolicy; + } + +protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(ConditionPolicy) == typeid(*policy)) { + data.condition = policy->Data(); + }else if (typeid(BlockPolicy) == typeid(*policy)) { + data.block = policy->Data(); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers + +private: + void InitializeDoPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::dostmt] = [this](srcSAXEventContext& ctx) { + if (!doDepth) { + doDepth = ctx.depth; + data = DoData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectConditionHandlers(); + CollectBlockHandlers(); + } + }; + + std::function endConditional =[this](srcSAXEventContext& ctx) { + if (doDepth && doDepth == ctx.depth) { + doDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeDoPolicyHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::dostmt] =[this](srcSAXEventContext& ctx) { + if (doDepth && doDepth == ctx.depth) { + doDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeDoPolicyHandlers(); + } + }; + } + + void CollectConditionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if(!doDepth) return; + if((doDepth + 1) != ctx.depth) return; + + if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(conditionPolicy); + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!doDepth) return; + if((doDepth + 1) != ctx.depth) return; + + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + }; + } +}; + +#endif From adccb334e1d4316501c46e472b583032ff0f531d Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 07:43:38 +0900 Subject: [PATCH 051/149] Extract Switch policy --- src/policy_classes/BlockPolicySingleEvent.cpp | 18 ++- src/policy_classes/BlockPolicySingleEvent.hpp | 3 + .../SwitchPolicySingleEvent.hpp | 134 ++++++++++++++++++ 3 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 src/policy_classes/SwitchPolicySingleEvent.hpp diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp index 487b32d..b4ca3f7 100644 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -23,6 +24,7 @@ BlockPolicy::BlockPolicy(std::initializer_list lis returnPolicy(nullptr), blockPolicy(nullptr), conditionalPolicy(nullptr), + switchPolicy(nullptr), whilePolicy(nullptr), forPolicy(nullptr), doPolicy(nullptr) { @@ -35,6 +37,7 @@ BlockPolicy::~BlockPolicy() { if (exprStmtPolicy) delete exprStmtPolicy; if (blockPolicy) delete blockPolicy; if (conditionalPolicy) delete conditionalPolicy; + if (switchPolicy) delete switchPolicy; if (whilePolicy) delete whilePolicy; if (forPolicy) delete forPolicy; if (doPolicy) delete forPolicy; @@ -56,6 +59,8 @@ void BlockPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcS data.blocks.push_back(policy->Data()); } else if (typeid(ConditionalPolicy) == typeid(*policy)) { data.conditionals.push_back(policy->Data()); + } else if (typeid(SwitchPolicy) == typeid(*policy)) { + data.conditionals.push_back(policy->Data()); } else if (typeid(WhilePolicy) == typeid(*policy)) { data.conditionals.push_back(policy->Data()); } else if (typeid(ForPolicy) == typeid(*policy)) { @@ -77,7 +82,9 @@ void BlockPolicy::InitializeBlockPolicyHandlers() { CollectReturnHandlers(); CollectExpressionHandlers(); CollectConditionalHandlers(); + CollectSwitchHandlers(); CollectWhileHandlers(); + CollectForHandlers(); CollectDoHandlers(); } @@ -138,8 +145,15 @@ void BlockPolicy::CollectConditionalHandlers() { }; openEventMap[ParserState::ifstmt] = startConditional; - openEventMap[ParserState::switchstmt] = startConditional; - openEventMap[ParserState::dostmt] = startConditional; + +} + +void BlockPolicy::CollectSwitchHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { + if (!switchPolicy) switchPolicy = new SwitchPolicy{this}; + ctx.dispatcher->AddListenerDispatch(switchPolicy); + }; } diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index 53e34e0..9c16990 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -14,6 +14,7 @@ #include class ConditionalPolicy; +class SwitchPolicy; class WhilePolicy; class ForPolicy; class DoPolicy; @@ -52,6 +53,7 @@ public srcDispatch::PolicyListener { ExprStmtPolicy * exprStmtPolicy; BlockPolicy * blockPolicy; ConditionalPolicy* conditionalPolicy; + SwitchPolicy * switchPolicy; WhilePolicy * whilePolicy; ForPolicy * forPolicy; DoPolicy * doPolicy; @@ -76,6 +78,7 @@ public srcDispatch::PolicyListener { void CollectExpressionHandlers(); void CollectDeclstmtHandlers(); void CollectConditionalHandlers(); + void CollectSwitchHandlers(); void CollectWhileHandlers(); void CollectForHandlers(); void CollectDoHandlers(); diff --git a/src/policy_classes/SwitchPolicySingleEvent.hpp b/src/policy_classes/SwitchPolicySingleEvent.hpp new file mode 100644 index 0000000..90a9c84 --- /dev/null +++ b/src/policy_classes/SwitchPolicySingleEvent.hpp @@ -0,0 +1,134 @@ +/** + * @file SwitchPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_SWITCH_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_SWITCH_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include +#include + +#include +#include +#include + +struct SwitchData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::shared_ptr condition; + std::shared_ptr block; + + friend std::ostream& operator<<(std::ostream& out, const SwitchData& switchData) { + if(!switchData.condition) return out; + return out << *switchData.condition; + } +}; + +class SwitchPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + SwitchData data; + std::size_t switchDepth; + ConditionPolicy* conditionPolicy; + BlockPolicy * blockPolicy; + +public: + SwitchPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + switchDepth(0), + conditionPolicy(nullptr), + blockPolicy(nullptr) { + InitializeSwitchPolicyHandlers(); + } + + ~SwitchPolicy() { + if (conditionPolicy) delete conditionPolicy; + if (blockPolicy) delete blockPolicy; + } + +protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(ConditionPolicy) == typeid(*policy)) { + data.condition = policy->Data(); + }else if (typeid(BlockPolicy) == typeid(*policy)) { + data.block = policy->Data(); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers + +private: + void InitializeSwitchPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::switchstmt] = [this](srcSAXEventContext& ctx) { + if (!switchDepth) { + switchDepth = ctx.depth; + data = SwitchData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectConditionHandlers(); + CollectBlockHandlers(); + } + }; + + std::function endConditional =[this](srcSAXEventContext& ctx) { + if (switchDepth && switchDepth == ctx.depth) { + switchDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeSwitchPolicyHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::switchstmt] =[this](srcSAXEventContext& ctx) { + if (switchDepth && switchDepth == ctx.depth) { + switchDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeSwitchPolicyHandlers(); + } + }; + } + + void CollectConditionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if(!switchDepth) return; + if((switchDepth + 1) != ctx.depth) return; + + if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(conditionPolicy); + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!switchDepth) return; + if((switchDepth + 1) != ctx.depth) return; + + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + }; + } +}; + +#endif From 1c18a9ad10a85d744eacc83a10793158dbdc35d5 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 07:55:57 +0900 Subject: [PATCH 052/149] Fix policy registering --- src/policy_classes/BlockPolicySingleEvent.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp index b4ca3f7..b89a80a 100644 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -150,7 +150,7 @@ void BlockPolicy::CollectConditionalHandlers() { void BlockPolicy::CollectSwitchHandlers() { using namespace srcDispatch; - openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { + openEventMap[ParserState::switchstmt] = [this](srcSAXEventContext& ctx) { if (!switchPolicy) switchPolicy = new SwitchPolicy{this}; ctx.dispatcher->AddListenerDispatch(switchPolicy); }; @@ -177,9 +177,9 @@ void BlockPolicy::CollectForHandlers() { void BlockPolicy::CollectDoHandlers() { using namespace srcDispatch; - openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { - if (!forPolicy) forPolicy = new ForPolicy{this}; - ctx.dispatcher->AddListenerDispatch(forPolicy); + openEventMap[ParserState::dostmt] = [this](srcSAXEventContext& ctx) { + if (!doPolicy) doPolicy = new DoPolicy{this}; + ctx.dispatcher->AddListenerDispatch(doPolicy); }; } From 728702a81764f171f56ab2f714640bc396147581 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 08:05:51 +0900 Subject: [PATCH 053/149] Add support for if_stmt --- src/dispatcher/srcDispatchUtilities.hpp | 2 +- src/dispatcher/srcDispatcher.hpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index ac7d917..4b15553 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -47,7 +47,7 @@ namespace srcDispatch { super_list, super, publicaccess, privateaccess, protectedaccess, preproc, whilestmt, forstmt, ifstmt, nonterminal, macro, classblock, functionblock, constructorblock, ifblock, whileblock, forblock, switchstmt, switchcase, specifier, throws, typedefexpr, userdefined, comment, annotation, condition, - dostmt, incr, decr, control, + dostmt, incr, decr, control, ifgroup, // NLP states snoun, propersnoun, spronoun, sadjective, sverb, diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index a917dbe..35d3172 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -247,6 +247,10 @@ namespace srcDispatch { ++ctx.triggerField[ParserState::decr]; DispatchEvent(ParserState::decr, ElementState::open); } }, + { "if_stmt", [this]() { + ++ctx.triggerField[ParserState::ifgroup]; + DispatchEvent(ParserState::ifgroup, ElementState::open); + } }, { "if", [this]() { if(!ifelseflagopen) { ifflagopen = true; @@ -549,6 +553,10 @@ namespace srcDispatch { DispatchEvent(ParserState::decr, ElementState::close); --ctx.triggerField[ParserState::decr]; } }, + { "if_stmt", [this]() { + DispatchEvent(ParserState::ifgroup, ElementState::close); + --ctx.triggerField[ParserState::ifgroup]; + } }, { "if", [this]() { if(!ifelseflagopen) { --ctx.triggerField[ParserState::ifblock]; From 0ca25fbb5b568e3e4f2aaabf5ebecd3170b7e5b8 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 08:30:21 +0900 Subject: [PATCH 054/149] Extract out a if_stmt policy --- src/policy_classes/BlockPolicySingleEvent.cpp | 24 ++- src/policy_classes/BlockPolicySingleEvent.hpp | 8 +- src/policy_classes/DoPolicySingleEvent.hpp | 9 -- .../ElseIfPolicySingleEvent.hpp | 125 +++++++++++++++ src/policy_classes/ElsePolicySingleEvent.hpp | 113 ++++++++++++++ src/policy_classes/IfPolicySingleEvent.hpp | 125 +++++++++++++++ .../IfStmtPolicySingleEvent.hpp | 143 ++++++++++++++++++ .../SwitchPolicySingleEvent.hpp | 11 +- src/policy_classes/WhilePolicySingleEvent.hpp | 9 -- 9 files changed, 522 insertions(+), 45 deletions(-) create mode 100644 src/policy_classes/ElseIfPolicySingleEvent.hpp create mode 100644 src/policy_classes/ElsePolicySingleEvent.hpp create mode 100644 src/policy_classes/IfPolicySingleEvent.hpp create mode 100644 src/policy_classes/IfStmtPolicySingleEvent.hpp diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp index b89a80a..8df6091 100644 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -9,7 +9,7 @@ #include -#include +#include #include #include #include @@ -23,7 +23,7 @@ BlockPolicy::BlockPolicy(std::initializer_list lis exprStmtPolicy(nullptr), returnPolicy(nullptr), blockPolicy(nullptr), - conditionalPolicy(nullptr), + ifStmtPolicy(nullptr), switchPolicy(nullptr), whilePolicy(nullptr), forPolicy(nullptr), @@ -36,11 +36,11 @@ BlockPolicy::~BlockPolicy() { if (returnPolicy) delete returnPolicy; if (exprStmtPolicy) delete exprStmtPolicy; if (blockPolicy) delete blockPolicy; - if (conditionalPolicy) delete conditionalPolicy; + if (ifStmtPolicy) delete ifStmtPolicy; if (switchPolicy) delete switchPolicy; if (whilePolicy) delete whilePolicy; if (forPolicy) delete forPolicy; - if (doPolicy) delete forPolicy; + if (doPolicy) delete doPolicy; } std::any BlockPolicy::DataInner() const { return std::make_shared(data); } @@ -57,8 +57,8 @@ void BlockPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcS data.expr_stmts.push_back(policy->Data()); } else if (typeid(BlockPolicy) == typeid(*policy)) { data.blocks.push_back(policy->Data()); - } else if (typeid(ConditionalPolicy) == typeid(*policy)) { - data.conditionals.push_back(policy->Data()); + } else if (typeid(IfStmtPolicy) == typeid(*policy)) { + data.conditionals.push_back(policy->Data()); } else if (typeid(SwitchPolicy) == typeid(*policy)) { data.conditionals.push_back(policy->Data()); } else if (typeid(WhilePolicy) == typeid(*policy)) { @@ -81,7 +81,7 @@ void BlockPolicy::InitializeBlockPolicyHandlers() { CollectDeclstmtHandlers(); CollectReturnHandlers(); CollectExpressionHandlers(); - CollectConditionalHandlers(); + CollectIfStmtHandlers(); CollectSwitchHandlers(); CollectWhileHandlers(); CollectForHandlers(); @@ -137,15 +137,13 @@ void BlockPolicy::CollectDeclstmtHandlers() { }; } -void BlockPolicy::CollectConditionalHandlers() { +void BlockPolicy::CollectIfStmtHandlers() { using namespace srcDispatch; - std::function startConditional = [this](srcSAXEventContext& ctx) { - if (!conditionalPolicy) conditionalPolicy = new ConditionalPolicy{this}; - ctx.dispatcher->AddListenerDispatch(conditionalPolicy); + openEventMap[ParserState::ifgroup] = [this](srcSAXEventContext& ctx) { + if (!ifStmtPolicy) ifStmtPolicy = new IfStmtPolicy{this}; + ctx.dispatcher->AddListenerDispatch(ifStmtPolicy); }; - openEventMap[ParserState::ifstmt] = startConditional; - } void BlockPolicy::CollectSwitchHandlers() { diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index 9c16990..c99e9f6 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -13,7 +13,7 @@ #include #include -class ConditionalPolicy; +class IfStmtPolicy; class SwitchPolicy; class WhilePolicy; class ForPolicy; @@ -30,7 +30,7 @@ struct BlockData { unsigned int startLineNumber; unsigned int endLineNumber; - std::vector> locals; + std::vector> locals; std::vector> returns; std::vector> expr_stmts; @@ -52,7 +52,7 @@ public srcDispatch::PolicyListener { ReturnPolicy * returnPolicy; ExprStmtPolicy * exprStmtPolicy; BlockPolicy * blockPolicy; - ConditionalPolicy* conditionalPolicy; + IfStmtPolicy * ifStmtPolicy; SwitchPolicy * switchPolicy; WhilePolicy * whilePolicy; ForPolicy * forPolicy; @@ -77,7 +77,7 @@ public srcDispatch::PolicyListener { void CollectReturnHandlers(); void CollectExpressionHandlers(); void CollectDeclstmtHandlers(); - void CollectConditionalHandlers(); + void CollectIfStmtHandlers(); void CollectSwitchHandlers(); void CollectWhileHandlers(); void CollectForHandlers(); diff --git a/src/policy_classes/DoPolicySingleEvent.hpp b/src/policy_classes/DoPolicySingleEvent.hpp index 69981d3..ce08cea 100644 --- a/src/policy_classes/DoPolicySingleEvent.hpp +++ b/src/policy_classes/DoPolicySingleEvent.hpp @@ -88,15 +88,6 @@ public srcDispatch::PolicyListener { } }; - std::function endConditional =[this](srcSAXEventContext& ctx) { - if (doDepth && doDepth == ctx.depth) { - doDepth = 0; - data.endLineNumber = ctx.currentLineNumber; - NotifyAll(ctx); - InitializeDoPolicyHandlers(); - } - }; - // end of policy closeEventMap[ParserState::dostmt] =[this](srcSAXEventContext& ctx) { if (doDepth && doDepth == ctx.depth) { diff --git a/src/policy_classes/ElseIfPolicySingleEvent.hpp b/src/policy_classes/ElseIfPolicySingleEvent.hpp new file mode 100644 index 0000000..14fdbe6 --- /dev/null +++ b/src/policy_classes/ElseIfPolicySingleEvent.hpp @@ -0,0 +1,125 @@ +/** + * @file ElseIfPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_ELSEIF_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_ELSEIF_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include +#include + +#include +#include +#include + +struct ElseIfData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::shared_ptr condition; + std::shared_ptr block; + + friend std::ostream& operator<<(std::ostream& out, const ElseIfData& elseIfData) { + if(!elseIfData.condition) return out; + return out << *elseIfData.condition; + } +}; + +class ElseIfPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + ElseIfData data; + std::size_t elseIfDepth; + ConditionPolicy* conditionPolicy; + BlockPolicy * blockPolicy; + +public: + ElseIfPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + elseIfDepth(0), + conditionPolicy(nullptr), + blockPolicy(nullptr) { + InitializeElseIfPolicyHandlers(); + } + + ~ElseIfPolicy() { + if (conditionPolicy) delete conditionPolicy; + if (blockPolicy) delete blockPolicy; + } + +protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(ConditionPolicy) == typeid(*policy)) { + data.condition = policy->Data(); + }else if (typeid(BlockPolicy) == typeid(*policy)) { + data.block = policy->Data(); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers + +private: + void InitializeElseIfPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::elseif] = [this](srcSAXEventContext& ctx) { + if (!elseIfDepth) { + elseIfDepth = ctx.depth; + data = ElseIfData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectConditionHandlers(); + CollectBlockHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::elseif] =[this](srcSAXEventContext& ctx) { + if (elseIfDepth && elseIfDepth == ctx.depth) { + elseIfDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeElseIfPolicyHandlers(); + } + }; + } + + void CollectConditionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if(!elseIfDepth) return; + if((elseIfDepth + 1) != ctx.depth) return; + + if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(conditionPolicy); + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!elseIfDepth) return; + if((elseIfDepth + 1) != ctx.depth) return; + + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + }; + } +}; + +#endif diff --git a/src/policy_classes/ElsePolicySingleEvent.hpp b/src/policy_classes/ElsePolicySingleEvent.hpp new file mode 100644 index 0000000..8abd08b --- /dev/null +++ b/src/policy_classes/ElsePolicySingleEvent.hpp @@ -0,0 +1,113 @@ +/** + * @file ElsePolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_ELSE_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_ELSE_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include +#include + +#include +#include +#include + +struct ElseData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::shared_ptr condition; + std::shared_ptr block; + + friend std::ostream& operator<<(std::ostream& out, const ElseData& elseData) { + if(!elseData.condition) return out; + return out << *elseData.condition; + } +}; + +class ElsePolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + ElseData data; + std::size_t elseDepth; + ConditionPolicy* conditionPolicy; + BlockPolicy * blockPolicy; + +public: + ElsePolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + elseDepth(0), + conditionPolicy(nullptr), + blockPolicy(nullptr) { + InitializeElsePolicyHandlers(); + } + + ~ElsePolicy() { + if (conditionPolicy) delete conditionPolicy; + if (blockPolicy) delete blockPolicy; + } + +protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(ConditionPolicy) == typeid(*policy)) { + data.condition = policy->Data(); + }else if (typeid(BlockPolicy) == typeid(*policy)) { + data.block = policy->Data(); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers + +private: + void InitializeElsePolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::elsestmt] = [this](srcSAXEventContext& ctx) { + if (!elseDepth) { + elseDepth = ctx.depth; + data = ElseData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectBlockHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::elsestmt] =[this](srcSAXEventContext& ctx) { + if (elseDepth && elseDepth == ctx.depth) { + elseDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeElsePolicyHandlers(); + } + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!elseDepth) return; + if((elseDepth + 1) != ctx.depth) return; + + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + }; + } +}; + +#endif diff --git a/src/policy_classes/IfPolicySingleEvent.hpp b/src/policy_classes/IfPolicySingleEvent.hpp new file mode 100644 index 0000000..1411fce --- /dev/null +++ b/src/policy_classes/IfPolicySingleEvent.hpp @@ -0,0 +1,125 @@ +/** + * @file IfPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_IF_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_IF_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include +#include + +#include +#include +#include + +struct IfData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::shared_ptr condition; + std::shared_ptr block; + + friend std::ostream& operator<<(std::ostream& out, const IfData& ifData) { + if(!ifData.condition) return out; + return out << *ifData.condition; + } +}; + +class IfPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + IfData data; + std::size_t ifDepth; + ConditionPolicy* conditionPolicy; + BlockPolicy * blockPolicy; + +public: + IfPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + ifDepth(0), + conditionPolicy(nullptr), + blockPolicy(nullptr) { + InitializeIfPolicyHandlers(); + } + + ~IfPolicy() { + if (conditionPolicy) delete conditionPolicy; + if (blockPolicy) delete blockPolicy; + } + +protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(ConditionPolicy) == typeid(*policy)) { + data.condition = policy->Data(); + }else if (typeid(BlockPolicy) == typeid(*policy)) { + data.block = policy->Data(); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers + +private: + void InitializeIfPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx) { + if (!ifDepth) { + ifDepth = ctx.depth; + data = IfData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectConditionHandlers(); + CollectBlockHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::ifstmt] =[this](srcSAXEventContext& ctx) { + if (ifDepth && ifDepth == ctx.depth) { + ifDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeIfPolicyHandlers(); + } + }; + } + + void CollectConditionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if(!ifDepth) return; + if((ifDepth + 1) != ctx.depth) return; + + if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(conditionPolicy); + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!ifDepth) return; + if((ifDepth + 1) != ctx.depth) return; + + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + }; + } +}; + +#endif diff --git a/src/policy_classes/IfStmtPolicySingleEvent.hpp b/src/policy_classes/IfStmtPolicySingleEvent.hpp new file mode 100644 index 0000000..8f0ecf4 --- /dev/null +++ b/src/policy_classes/IfStmtPolicySingleEvent.hpp @@ -0,0 +1,143 @@ +/** + * @file IfStmtPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_IF_STMT_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_IF_STMT_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +struct IfStmtData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::vector clauses; + + friend std::ostream& operator<<(std::ostream& out, const IfStmtData& ifStmtData) { + if(ifStmtData.clauses.empty()) return out; + if(ifStmtData.clauses.front().type() != typeid(std::shared_ptr)) return out; + return out << *std::any_cast>(ifStmtData.clauses.front()); + } +}; + +class IfStmtPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + IfStmtData data; + std::size_t ifStmtDepth; + IfPolicy * ifPolicy; + ElseIfPolicy * elseIfPolicy; + ElsePolicy * elsePolicy; + +public: + IfStmtPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + ifStmtDepth(0), + ifPolicy(nullptr), + elseIfPolicy(nullptr), + elsePolicy(nullptr) { + InitializeIfStmtPolicyHandlers(); + } + + ~IfStmtPolicy() { + if (ifPolicy) delete ifPolicy; + if (elseIfPolicy) delete elseIfPolicy; + if (elsePolicy) delete elsePolicy; + } + +protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(IfPolicy) == typeid(*policy)) { + data.clauses.push_back(policy->Data()); + } else if (typeid(ElseIfPolicy) == typeid(*policy)) { + data.clauses.push_back(policy->Data()); + } else if (typeid(ElsePolicy) == typeid(*policy)) { + data.clauses.push_back(policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers + +private: + void InitializeIfStmtPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::ifgroup] = [this](srcSAXEventContext& ctx) { + if (!ifStmtDepth) { + ifStmtDepth = ctx.depth; + data = IfStmtData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectIfHandlers(); + CollectElseIfHandlers(); + CollectElseHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::ifgroup] =[this](srcSAXEventContext& ctx) { + if (ifStmtDepth && ifStmtDepth == ctx.depth) { + ifStmtDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeIfStmtPolicyHandlers(); + } + }; + } + + void CollectIfHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx) { + if(!ifStmtDepth) return; + if((ifStmtDepth + 1) != ctx.depth) return; + + if (!ifPolicy) ifPolicy = new IfPolicy{this}; + ctx.dispatcher->AddListenerDispatch(ifPolicy); + }; + } + + void CollectElseIfHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::elseif] = [this](srcSAXEventContext& ctx) { + if(!ifStmtDepth) return; + if((ifStmtDepth + 1) != ctx.depth) return; + + if (!elseIfPolicy) elseIfPolicy = new ElseIfPolicy{this}; + ctx.dispatcher->AddListenerDispatch(elseIfPolicy); + }; + } + + void CollectElseHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::elsestmt] = [this](srcSAXEventContext& ctx) { + if(!ifStmtDepth) return; + if((ifStmtDepth + 1) != ctx.depth) return; + + if (!elsePolicy) elsePolicy = new ElsePolicy{this}; + ctx.dispatcher->AddListenerDispatch(elsePolicy); + }; + } +}; + +#endif diff --git a/src/policy_classes/SwitchPolicySingleEvent.hpp b/src/policy_classes/SwitchPolicySingleEvent.hpp index 90a9c84..0263e65 100644 --- a/src/policy_classes/SwitchPolicySingleEvent.hpp +++ b/src/policy_classes/SwitchPolicySingleEvent.hpp @@ -86,16 +86,7 @@ public srcDispatch::PolicyListener { CollectConditionHandlers(); CollectBlockHandlers(); } - }; - - std::function endConditional =[this](srcSAXEventContext& ctx) { - if (switchDepth && switchDepth == ctx.depth) { - switchDepth = 0; - data.endLineNumber = ctx.currentLineNumber; - NotifyAll(ctx); - InitializeSwitchPolicyHandlers(); - } - }; + }; // end of policy closeEventMap[ParserState::switchstmt] =[this](srcSAXEventContext& ctx) { diff --git a/src/policy_classes/WhilePolicySingleEvent.hpp b/src/policy_classes/WhilePolicySingleEvent.hpp index c8af282..8d471f1 100644 --- a/src/policy_classes/WhilePolicySingleEvent.hpp +++ b/src/policy_classes/WhilePolicySingleEvent.hpp @@ -88,15 +88,6 @@ public srcDispatch::PolicyListener { } }; - std::function endConditional =[this](srcSAXEventContext& ctx) { - if (whileDepth && whileDepth == ctx.depth) { - whileDepth = 0; - data.endLineNumber = ctx.currentLineNumber; - NotifyAll(ctx); - InitializeWhilePolicyHandlers(); - } - }; - // end of policy closeEventMap[ParserState::whilestmt] =[this](srcSAXEventContext& ctx) { if (whileDepth && whileDepth == ctx.depth) { From d14af5d60e05632bbc00a5c702918ee6ced2137f Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 10:22:13 +0900 Subject: [PATCH 055/149] Put For in hpp to match rest --- src/policy_classes/ForPolicySingleEvent.cpp | 89 ------------------- src/policy_classes/ForPolicySingleEvent.hpp | 97 ++++++++++++++++++--- 2 files changed, 84 insertions(+), 102 deletions(-) delete mode 100644 src/policy_classes/ForPolicySingleEvent.cpp diff --git a/src/policy_classes/ForPolicySingleEvent.cpp b/src/policy_classes/ForPolicySingleEvent.cpp deleted file mode 100644 index 5673133..0000000 --- a/src/policy_classes/ForPolicySingleEvent.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/** - * @file ForPolicySingleEvent.cpp - * - * - */ - -#include - -#include - -std::ostream& operator<<(std::ostream& out, const ForData& conditionalData) { - if(!conditionalData.control) return out; - return out << *conditionalData.control; -} - -ForPolicy::ForPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - conditionalDepth(0), - controlPolicy(nullptr), - blockPolicy(nullptr) { - InitializeForPolicyHandlers(); -} - -ForPolicy::~ForPolicy() { - if (controlPolicy) delete controlPolicy; - if (blockPolicy) delete blockPolicy; -} - -std::any ForPolicy::DataInner() const { return std::make_shared(data); } - -void ForPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(ControlPolicy) == typeid(*policy)) { - data.control = policy->Data(); - } else if (typeid(BlockPolicy) == typeid(*policy)) { - data.block = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); -} - -void ForPolicy::NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers - -void ForPolicy::InitializeForPolicyHandlers() { - using namespace srcDispatch; - - openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { \ - if (!conditionalDepth) { - conditionalDepth = ctx.depth; - data = ForData{}; - data.startLineNumber = ctx.currentLineNumber; - CollectControlHandlers(); - CollectBlockHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::forstmt] =[this](srcSAXEventContext& ctx) { - if (conditionalDepth && conditionalDepth == ctx.depth) { - conditionalDepth = 0; - data.endLineNumber = ctx.currentLineNumber; - NotifyAll(ctx); - InitializeForPolicyHandlers(); - } - }; -} - -void ForPolicy::CollectControlHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { - if(!conditionalDepth) return; - if((conditionalDepth + 1) != ctx.depth) return; - - if (!controlPolicy) controlPolicy = new ControlPolicy{this}; - ctx.dispatcher->AddListenerDispatch(controlPolicy); - }; -} - -void ForPolicy::CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(conditionalDepth && (conditionalDepth + 1) == ctx.depth) { - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); - } - }; -} diff --git a/src/policy_classes/ForPolicySingleEvent.hpp b/src/policy_classes/ForPolicySingleEvent.hpp index 1673491..58157cf 100644 --- a/src/policy_classes/ForPolicySingleEvent.hpp +++ b/src/policy_classes/ForPolicySingleEvent.hpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -27,7 +28,10 @@ struct ForData { std::shared_ptr control; std::shared_ptr block; - friend std::ostream& operator<<(std::ostream& out, const ForData& conditionalData); + friend std::ostream& operator<<(std::ostream& out, const ForData& conditionalData) { + if(!conditionalData.control) return out; + return out << *conditionalData.control; + } }; @@ -37,24 +41,91 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - ForData data; - std::size_t conditionalDepth; - ControlPolicy * controlPolicy; - BlockPolicy * blockPolicy; + ForData data; + std::size_t conditionalDepth; + ControlPolicy * controlPolicy; + BlockPolicy * blockPolicy; public: - ForPolicy(std::initializer_list listeners); - ~ForPolicy(); + + ForPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + conditionalDepth(0), + controlPolicy(nullptr), + blockPolicy(nullptr) { + InitializeForPolicyHandlers(); + } + + ~ForPolicy() { + if (controlPolicy) delete controlPolicy; + if (blockPolicy) delete blockPolicy; + } protected: - std::any DataInner() const override; - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override; + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(ControlPolicy) == typeid(*policy)) { + data.control = policy->Data(); + } else if (typeid(BlockPolicy) == typeid(*policy)) { + data.block = policy->Data(); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers private: - void InitializeForPolicyHandlers(); - void CollectControlHandlers(); - void CollectBlockHandlers(); + + void InitializeForPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { \ + if (!conditionalDepth) { + conditionalDepth = ctx.depth; + data = ForData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectControlHandlers(); + CollectBlockHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::forstmt] =[this](srcSAXEventContext& ctx) { + if (conditionalDepth && conditionalDepth == ctx.depth) { + conditionalDepth = 0; + data.endLineNumber = ctx.currentLineNumber; + NotifyAll(ctx); + InitializeForPolicyHandlers(); + } + }; + } + + + void CollectControlHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { + if(!conditionalDepth) return; + if((conditionalDepth + 1) != ctx.depth) return; + + if (!controlPolicy) controlPolicy = new ControlPolicy{this}; + ctx.dispatcher->AddListenerDispatch(controlPolicy); + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(conditionalDepth && (conditionalDepth + 1) == ctx.depth) { + if (!blockPolicy) blockPolicy = new BlockPolicy{this}; + ctx.dispatcher->AddListenerDispatch(blockPolicy); + } + }; + } }; #endif From 564fe01f07ce67aadb2424534821e98533907541 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 10:24:04 +0900 Subject: [PATCH 056/149] Rename conditional to for --- src/policy_classes/ForPolicySingleEvent.hpp | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/policy_classes/ForPolicySingleEvent.hpp b/src/policy_classes/ForPolicySingleEvent.hpp index 58157cf..e3b7876 100644 --- a/src/policy_classes/ForPolicySingleEvent.hpp +++ b/src/policy_classes/ForPolicySingleEvent.hpp @@ -28,9 +28,9 @@ struct ForData { std::shared_ptr control; std::shared_ptr block; - friend std::ostream& operator<<(std::ostream& out, const ForData& conditionalData) { - if(!conditionalData.control) return out; - return out << *conditionalData.control; + friend std::ostream& operator<<(std::ostream& out, const ForData& forData) { + if(!forData.control) return out; + return out << *forData.control; } }; @@ -42,7 +42,7 @@ public srcDispatch::PolicyListener { private: ForData data; - std::size_t conditionalDepth; + std::size_t forDepth; ControlPolicy * controlPolicy; BlockPolicy * blockPolicy; @@ -51,7 +51,7 @@ public srcDispatch::PolicyListener { ForPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - conditionalDepth(0), + forDepth(0), controlPolicy(nullptr), blockPolicy(nullptr) { InitializeForPolicyHandlers(); @@ -85,8 +85,8 @@ public srcDispatch::PolicyListener { using namespace srcDispatch; openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { \ - if (!conditionalDepth) { - conditionalDepth = ctx.depth; + if (!forDepth) { + forDepth = ctx.depth; data = ForData{}; data.startLineNumber = ctx.currentLineNumber; CollectControlHandlers(); @@ -96,8 +96,8 @@ public srcDispatch::PolicyListener { // end of policy closeEventMap[ParserState::forstmt] =[this](srcSAXEventContext& ctx) { - if (conditionalDepth && conditionalDepth == ctx.depth) { - conditionalDepth = 0; + if (forDepth && forDepth == ctx.depth) { + forDepth = 0; data.endLineNumber = ctx.currentLineNumber; NotifyAll(ctx); InitializeForPolicyHandlers(); @@ -109,8 +109,8 @@ public srcDispatch::PolicyListener { void CollectControlHandlers() { using namespace srcDispatch; openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { - if(!conditionalDepth) return; - if((conditionalDepth + 1) != ctx.depth) return; + if(!forDepth) return; + if((forDepth + 1) != ctx.depth) return; if (!controlPolicy) controlPolicy = new ControlPolicy{this}; ctx.dispatcher->AddListenerDispatch(controlPolicy); @@ -120,7 +120,7 @@ public srcDispatch::PolicyListener { void CollectBlockHandlers() { using namespace srcDispatch; openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(conditionalDepth && (conditionalDepth + 1) == ctx.depth) { + if(forDepth && (forDepth + 1) == ctx.depth) { if (!blockPolicy) blockPolicy = new BlockPolicy{this}; ctx.dispatcher->AddListenerDispatch(blockPolicy); } From fd43978c6b8b705a42e31004d45e4511f79d750a Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 13:59:41 +0900 Subject: [PATCH 057/149] Make an Incr policy --- .../ControlPolicySingleEvent.hpp | 38 ++++--- src/policy_classes/IncrPolicySingleEvent.hpp | 104 ++++++++++++++++++ 2 files changed, 125 insertions(+), 17 deletions(-) create mode 100644 src/policy_classes/IncrPolicySingleEvent.hpp diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp index a654f8c..6822490 100644 --- a/src/policy_classes/ControlPolicySingleEvent.hpp +++ b/src/policy_classes/ControlPolicySingleEvent.hpp @@ -11,8 +11,9 @@ #include #include -#include #include +#include +#include #include #include @@ -22,16 +23,20 @@ struct ControlData { unsigned int lineNumber; - std::vector> init; + std::vector init; std::shared_ptr condition; std::vector> incr; friend std::ostream& operator<<(std::ostream& out, const ControlData& controlData) { bool outputDeclComma = false; - for(const std::shared_ptr decl : controlData.init) { + for(const std::any item : controlData.init) { if(outputDeclComma) out << ", "; - out << *decl; + if(item.type() == typeid(std::shared_ptr)) + out << *std::any_cast>(item); + else { + out << *std::any_cast>(item); + } outputDeclComma = true; } @@ -58,22 +63,27 @@ public srcDispatch::PolicyListener { ControlData data; std::size_t controlDepth; DeclPolicy * declPolicy; - ConditionPolicy * conditionPolicy; ExpressionPolicy* exprPolicy; + ConditionPolicy * conditionPolicy; + IncrPolicy * incrPolicy; public: ControlPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, controlDepth(0), - exprPolicy(nullptr) { + declPolicy(nullptr), + exprPolicy(nullptr), + conditionPolicy(nullptr), + incrPolicy(nullptr) { InitializeControlPolicyHandlers(); } ~ControlPolicy() { if (declPolicy) delete declPolicy; - if (conditionPolicy) delete conditionPolicy; if (exprPolicy) delete exprPolicy; + if (conditionPolicy) delete conditionPolicy; + if (incrPolicy) delete incrPolicy; } protected: @@ -83,18 +93,12 @@ public srcDispatch::PolicyListener { using namespace srcDispatch; if(typeid(DeclPolicy) == typeid(*policy)) { data.init.push_back(policy->Data()); + } else if(typeid(ExpressionPolicy) == typeid(*policy)) { + data.init.push_back(policy->Data()); } else if(typeid(ConditionPolicy) == typeid(*policy)) { data.condition = policy->Data(); - } else if(typeid(ExpressionPolicy) == typeid(*policy)) { - if(ctx.IsOpen(ParserState::init)) { - std::shared_ptr expr = policy->Data(); - std::shared_ptr decl = std::make_shared(); - decl->lineNumber = expr->lineNumber; - decl->init = expr; - data.init.push_back(decl); - } else { - data.incr.push_back(policy->Data()); - } + } else if(typeid(IncrPolicy) == typeid(*policy)) { + data.incr.push_back(policy->Data()); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } diff --git a/src/policy_classes/IncrPolicySingleEvent.hpp b/src/policy_classes/IncrPolicySingleEvent.hpp new file mode 100644 index 0000000..a56324e --- /dev/null +++ b/src/policy_classes/IncrPolicySingleEvent.hpp @@ -0,0 +1,104 @@ +/** + * @file IncrPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_INCR_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_INCR_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include +#include + +#include +#include +#include + +struct IncrData { + + unsigned int startLineNumber; + std::shared_ptr expr; + + friend std::ostream& operator<<(std::ostream& out, const IncrData& incrData) { + if(!incrData.expr) return out; + return out << *incrData.expr; + } +}; + +class IncrPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + IncrData data; + std::size_t incrDepth; + ExpressionPolicy* exprPolicy; + +public: + IncrPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + incrDepth(0), + exprPolicy(nullptr) { + InitializeIncrPolicyHandlers(); + } + + ~IncrPolicy() { + if (exprPolicy) delete exprPolicy; + } + +protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(ExpressionPolicy) == typeid(*policy)) { + data.expr = policy->Data(); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers + +private: + void InitializeIncrPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { + if (!incrDepth) { + incrDepth = ctx.depth; + data = IncrData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectExpressionHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::incr] =[this](srcSAXEventContext& ctx) { + if (incrDepth && incrDepth == ctx.depth) { + incrDepth = 0; + NotifyAll(ctx); + InitializeIncrPolicyHandlers(); + } + }; + } + + void CollectExpressionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(!incrDepth) return; + if((incrDepth + 1) != ctx.depth) return; + + if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(exprPolicy); + }; + } +}; + +#endif From a7c2106b44ead2e5a58b23dd8fd4204f213dbf4a Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 14:23:07 +0900 Subject: [PATCH 058/149] Implment while via Conditional --- .../ConditionalPolicySingleEvent.hpp | 61 +++--------- src/policy_classes/WhilePolicySingleEvent.hpp | 95 +------------------ 2 files changed, 18 insertions(+), 138 deletions(-) diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index 4bf36b9..6155f00 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -17,31 +17,13 @@ #include #include -struct ConditionalData { - - enum ConditionalType { IF, WHILE, SWITCH, DO }; - - ConditionalType type; - - unsigned int startLineNumber; - unsigned int endLineNumber; - - std::shared_ptr condition; - std::shared_ptr block; - - friend std::ostream& operator<<(std::ostream& out, const ConditionalData& conditionalData) { - if(!conditionalData.condition) return out; - return out << *conditionalData.condition; - } -}; - - +template class ConditionalPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { -private: +protected: ConditionalData data; std::size_t conditionalDepth; ConditionPolicy* conditionPolicy; @@ -68,7 +50,7 @@ public srcDispatch::PolicyListener { void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { if (typeid(ConditionPolicy) == typeid(*policy)) { data.condition = policy->Data(); - }else if (typeid(BlockPolicy) == typeid(*policy)) { + } else if (typeid(BlockPolicy) == typeid(*policy)) { data.block = policy->Data(); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); @@ -79,28 +61,21 @@ public srcDispatch::PolicyListener { void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers -private: void InitializeConditionalPolicyHandlers() { using namespace srcDispatch; - #define startConditional(TYPE) \ - [this](srcSAXEventContext& ctx) { \ - if (!conditionalDepth) { \ - conditionalDepth = ctx.depth; \ - data = ConditionalData{}; \ - data.type = TYPE; \ - data.startLineNumber = ctx.currentLineNumber; \ - CollectConditionHandlers(); \ - CollectBlockHandlers(); \ - } \ - }; \ - - openEventMap[ParserState::ifstmt] = startConditional(ConditionalData::IF); - openEventMap[ParserState::whilestmt] = startConditional(ConditionalData::WHILE); - openEventMap[ParserState::switchstmt] = startConditional(ConditionalData::SWITCH); - openEventMap[ParserState::dostmt] = startConditional(ConditionalData::DO); - - std::function endConditional =[this](srcSAXEventContext& ctx) { + openEventMap[DispatchEvent] = [this](srcSAXEventContext& ctx) { + if (!conditionalDepth) { + conditionalDepth = ctx.depth; + data = ConditionalData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectConditionHandlers(); + CollectBlockHandlers(); + } + }; + + // end of policy + closeEventMap[DispatchEvent] =[this](srcSAXEventContext& ctx) { if (conditionalDepth && conditionalDepth == ctx.depth) { conditionalDepth = 0; data.endLineNumber = ctx.currentLineNumber; @@ -108,12 +83,6 @@ public srcDispatch::PolicyListener { InitializeConditionalPolicyHandlers(); } }; - - // end of policy - closeEventMap[ParserState::ifstmt] = endConditional; - closeEventMap[ParserState::whilestmt] = endConditional; - closeEventMap[ParserState::switchstmt] = endConditional; - closeEventMap[ParserState::dostmt] = endConditional; } void CollectConditionHandlers() { diff --git a/src/policy_classes/WhilePolicySingleEvent.hpp b/src/policy_classes/WhilePolicySingleEvent.hpp index 8d471f1..5cf12d9 100644 --- a/src/policy_classes/WhilePolicySingleEvent.hpp +++ b/src/policy_classes/WhilePolicySingleEvent.hpp @@ -6,12 +6,8 @@ #ifndef INCLUDED_WHILE_POLICY_SINGLE_EVENT_HPP #define INCLUDED_WHILE_POLICY_SINGLE_EVENT_HPP -#include -#include #include - -#include -#include +#include #include #include @@ -31,95 +27,10 @@ struct WhileData { } }; -class WhilePolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - WhileData data; - std::size_t whileDepth; - ConditionPolicy* conditionPolicy; - BlockPolicy * blockPolicy; - +class WhilePolicy : public ConditionalPolicy { public: WhilePolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - whileDepth(0), - conditionPolicy(nullptr), - blockPolicy(nullptr) { - InitializeWhilePolicyHandlers(); - } - - ~WhilePolicy() { - if (conditionPolicy) delete conditionPolicy; - if (blockPolicy) delete blockPolicy; - } - -protected: - std::any DataInner() const { return std::make_shared(data); } - - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(ConditionPolicy) == typeid(*policy)) { - data.condition = policy->Data(); - }else if (typeid(BlockPolicy) == typeid(*policy)) { - data.block = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers - -private: - void InitializeWhilePolicyHandlers() { - using namespace srcDispatch; - - openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { - if (!whileDepth) { - whileDepth = ctx.depth; - data = WhileData{}; - data.startLineNumber = ctx.currentLineNumber; - CollectConditionHandlers(); - CollectBlockHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::whilestmt] =[this](srcSAXEventContext& ctx) { - if (whileDepth && whileDepth == ctx.depth) { - whileDepth = 0; - data.endLineNumber = ctx.currentLineNumber; - NotifyAll(ctx); - InitializeWhilePolicyHandlers(); - } - }; - } - - void CollectConditionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if(!whileDepth) return; - if((whileDepth + 1) != ctx.depth) return; - - if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(conditionPolicy); - }; - } - - void CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(!whileDepth) return; - if((whileDepth + 1) != ctx.depth) return; - - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); - }; - } + : ConditionalPolicy(listeners) {} }; #endif From 118e2e4f5e2e8e10d9622c790fd2841928394911 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 14:32:03 +0900 Subject: [PATCH 059/149] Refactor Do and Switch --- src/policy_classes/DoPolicySingleEvent.hpp | 95 +----------------- .../SwitchPolicySingleEvent.hpp | 96 +------------------ 2 files changed, 6 insertions(+), 185 deletions(-) diff --git a/src/policy_classes/DoPolicySingleEvent.hpp b/src/policy_classes/DoPolicySingleEvent.hpp index ce08cea..32fb2d2 100644 --- a/src/policy_classes/DoPolicySingleEvent.hpp +++ b/src/policy_classes/DoPolicySingleEvent.hpp @@ -6,12 +6,8 @@ #ifndef INCLUDED_DO_POLICY_SINGLE_EVENT_HPP #define INCLUDED_DO_POLICY_SINGLE_EVENT_HPP -#include -#include #include - -#include -#include +#include #include #include @@ -31,95 +27,10 @@ struct DoData { } }; -class DoPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - DoData data; - std::size_t doDepth; - ConditionPolicy* conditionPolicy; - BlockPolicy * blockPolicy; - +class DoPolicy : public ConditionalPolicy { public: DoPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - doDepth(0), - conditionPolicy(nullptr), - blockPolicy(nullptr) { - InitializeDoPolicyHandlers(); - } - - ~DoPolicy() { - if (conditionPolicy) delete conditionPolicy; - if (blockPolicy) delete blockPolicy; - } - -protected: - std::any DataInner() const { return std::make_shared(data); } - - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(ConditionPolicy) == typeid(*policy)) { - data.condition = policy->Data(); - }else if (typeid(BlockPolicy) == typeid(*policy)) { - data.block = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers - -private: - void InitializeDoPolicyHandlers() { - using namespace srcDispatch; - - openEventMap[ParserState::dostmt] = [this](srcSAXEventContext& ctx) { - if (!doDepth) { - doDepth = ctx.depth; - data = DoData{}; - data.startLineNumber = ctx.currentLineNumber; - CollectConditionHandlers(); - CollectBlockHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::dostmt] =[this](srcSAXEventContext& ctx) { - if (doDepth && doDepth == ctx.depth) { - doDepth = 0; - data.endLineNumber = ctx.currentLineNumber; - NotifyAll(ctx); - InitializeDoPolicyHandlers(); - } - }; - } - - void CollectConditionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if(!doDepth) return; - if((doDepth + 1) != ctx.depth) return; - - if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(conditionPolicy); - }; - } - - void CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(!doDepth) return; - if((doDepth + 1) != ctx.depth) return; - - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); - }; - } + : ConditionalPolicy(listeners) {} }; #endif diff --git a/src/policy_classes/SwitchPolicySingleEvent.hpp b/src/policy_classes/SwitchPolicySingleEvent.hpp index 0263e65..6d9664d 100644 --- a/src/policy_classes/SwitchPolicySingleEvent.hpp +++ b/src/policy_classes/SwitchPolicySingleEvent.hpp @@ -6,12 +6,8 @@ #ifndef INCLUDED_SWITCH_POLICY_SINGLE_EVENT_HPP #define INCLUDED_SWITCH_POLICY_SINGLE_EVENT_HPP -#include -#include #include - -#include -#include +#include #include #include @@ -31,95 +27,9 @@ struct SwitchData { } }; -class SwitchPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - SwitchData data; - std::size_t switchDepth; - ConditionPolicy* conditionPolicy; - BlockPolicy * blockPolicy; - +class SwitchPolicy : public ConditionalPolicy { public: SwitchPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - switchDepth(0), - conditionPolicy(nullptr), - blockPolicy(nullptr) { - InitializeSwitchPolicyHandlers(); - } - - ~SwitchPolicy() { - if (conditionPolicy) delete conditionPolicy; - if (blockPolicy) delete blockPolicy; - } - -protected: - std::any DataInner() const { return std::make_shared(data); } - - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(ConditionPolicy) == typeid(*policy)) { - data.condition = policy->Data(); - }else if (typeid(BlockPolicy) == typeid(*policy)) { - data.block = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers - -private: - void InitializeSwitchPolicyHandlers() { - using namespace srcDispatch; - - openEventMap[ParserState::switchstmt] = [this](srcSAXEventContext& ctx) { - if (!switchDepth) { - switchDepth = ctx.depth; - data = SwitchData{}; - data.startLineNumber = ctx.currentLineNumber; - CollectConditionHandlers(); - CollectBlockHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::switchstmt] =[this](srcSAXEventContext& ctx) { - if (switchDepth && switchDepth == ctx.depth) { - switchDepth = 0; - data.endLineNumber = ctx.currentLineNumber; - NotifyAll(ctx); - InitializeSwitchPolicyHandlers(); - } - }; - } - - void CollectConditionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if(!switchDepth) return; - if((switchDepth + 1) != ctx.depth) return; - - if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(conditionPolicy); - }; - } - - void CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(!switchDepth) return; - if((switchDepth + 1) != ctx.depth) return; - - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); - }; - } + : ConditionalPolicy(listeners) {} }; - #endif From aa7f8521b301b8ac495029a45d0eb209a59e223b Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 14:43:14 +0900 Subject: [PATCH 060/149] Refactor if, else, and elseif --- .../ElseIfPolicySingleEvent.hpp | 95 +------------------ src/policy_classes/ElsePolicySingleEvent.hpp | 83 +--------------- src/policy_classes/IfPolicySingleEvent.hpp | 95 +------------------ 3 files changed, 9 insertions(+), 264 deletions(-) diff --git a/src/policy_classes/ElseIfPolicySingleEvent.hpp b/src/policy_classes/ElseIfPolicySingleEvent.hpp index 14fdbe6..596070c 100644 --- a/src/policy_classes/ElseIfPolicySingleEvent.hpp +++ b/src/policy_classes/ElseIfPolicySingleEvent.hpp @@ -6,12 +6,8 @@ #ifndef INCLUDED_ELSEIF_POLICY_SINGLE_EVENT_HPP #define INCLUDED_ELSEIF_POLICY_SINGLE_EVENT_HPP -#include -#include #include - -#include -#include +#include #include #include @@ -31,95 +27,10 @@ struct ElseIfData { } }; -class ElseIfPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - ElseIfData data; - std::size_t elseIfDepth; - ConditionPolicy* conditionPolicy; - BlockPolicy * blockPolicy; - +class ElseIfPolicy : public ConditionalPolicy { public: ElseIfPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - elseIfDepth(0), - conditionPolicy(nullptr), - blockPolicy(nullptr) { - InitializeElseIfPolicyHandlers(); - } - - ~ElseIfPolicy() { - if (conditionPolicy) delete conditionPolicy; - if (blockPolicy) delete blockPolicy; - } - -protected: - std::any DataInner() const { return std::make_shared(data); } - - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(ConditionPolicy) == typeid(*policy)) { - data.condition = policy->Data(); - }else if (typeid(BlockPolicy) == typeid(*policy)) { - data.block = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers - -private: - void InitializeElseIfPolicyHandlers() { - using namespace srcDispatch; - - openEventMap[ParserState::elseif] = [this](srcSAXEventContext& ctx) { - if (!elseIfDepth) { - elseIfDepth = ctx.depth; - data = ElseIfData{}; - data.startLineNumber = ctx.currentLineNumber; - CollectConditionHandlers(); - CollectBlockHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::elseif] =[this](srcSAXEventContext& ctx) { - if (elseIfDepth && elseIfDepth == ctx.depth) { - elseIfDepth = 0; - data.endLineNumber = ctx.currentLineNumber; - NotifyAll(ctx); - InitializeElseIfPolicyHandlers(); - } - }; - } - - void CollectConditionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if(!elseIfDepth) return; - if((elseIfDepth + 1) != ctx.depth) return; - - if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(conditionPolicy); - }; - } - - void CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(!elseIfDepth) return; - if((elseIfDepth + 1) != ctx.depth) return; - - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); - }; - } + : ConditionalPolicy(listeners) {} }; #endif diff --git a/src/policy_classes/ElsePolicySingleEvent.hpp b/src/policy_classes/ElsePolicySingleEvent.hpp index 8abd08b..8d1a412 100644 --- a/src/policy_classes/ElsePolicySingleEvent.hpp +++ b/src/policy_classes/ElsePolicySingleEvent.hpp @@ -6,12 +6,8 @@ #ifndef INCLUDED_ELSE_POLICY_SINGLE_EVENT_HPP #define INCLUDED_ELSE_POLICY_SINGLE_EVENT_HPP -#include -#include #include - -#include -#include +#include #include #include @@ -31,83 +27,10 @@ struct ElseData { } }; -class ElsePolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - ElseData data; - std::size_t elseDepth; - ConditionPolicy* conditionPolicy; - BlockPolicy * blockPolicy; - +class ElsePolicy : public ConditionalPolicy { public: ElsePolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - elseDepth(0), - conditionPolicy(nullptr), - blockPolicy(nullptr) { - InitializeElsePolicyHandlers(); - } - - ~ElsePolicy() { - if (conditionPolicy) delete conditionPolicy; - if (blockPolicy) delete blockPolicy; - } - -protected: - std::any DataInner() const { return std::make_shared(data); } - - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(ConditionPolicy) == typeid(*policy)) { - data.condition = policy->Data(); - }else if (typeid(BlockPolicy) == typeid(*policy)) { - data.block = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers - -private: - void InitializeElsePolicyHandlers() { - using namespace srcDispatch; - - openEventMap[ParserState::elsestmt] = [this](srcSAXEventContext& ctx) { - if (!elseDepth) { - elseDepth = ctx.depth; - data = ElseData{}; - data.startLineNumber = ctx.currentLineNumber; - CollectBlockHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::elsestmt] =[this](srcSAXEventContext& ctx) { - if (elseDepth && elseDepth == ctx.depth) { - elseDepth = 0; - data.endLineNumber = ctx.currentLineNumber; - NotifyAll(ctx); - InitializeElsePolicyHandlers(); - } - }; - } - - void CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(!elseDepth) return; - if((elseDepth + 1) != ctx.depth) return; - - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); - }; - } + : ConditionalPolicy(listeners) {} }; #endif diff --git a/src/policy_classes/IfPolicySingleEvent.hpp b/src/policy_classes/IfPolicySingleEvent.hpp index 1411fce..4a9b693 100644 --- a/src/policy_classes/IfPolicySingleEvent.hpp +++ b/src/policy_classes/IfPolicySingleEvent.hpp @@ -6,12 +6,8 @@ #ifndef INCLUDED_IF_POLICY_SINGLE_EVENT_HPP #define INCLUDED_IF_POLICY_SINGLE_EVENT_HPP -#include -#include #include - -#include -#include +#include #include #include @@ -31,95 +27,10 @@ struct IfData { } }; -class IfPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - IfData data; - std::size_t ifDepth; - ConditionPolicy* conditionPolicy; - BlockPolicy * blockPolicy; - +class IfPolicy : public ConditionalPolicy { public: IfPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - ifDepth(0), - conditionPolicy(nullptr), - blockPolicy(nullptr) { - InitializeIfPolicyHandlers(); - } - - ~IfPolicy() { - if (conditionPolicy) delete conditionPolicy; - if (blockPolicy) delete blockPolicy; - } - -protected: - std::any DataInner() const { return std::make_shared(data); } - - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(ConditionPolicy) == typeid(*policy)) { - data.condition = policy->Data(); - }else if (typeid(BlockPolicy) == typeid(*policy)) { - data.block = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers - -private: - void InitializeIfPolicyHandlers() { - using namespace srcDispatch; - - openEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx) { - if (!ifDepth) { - ifDepth = ctx.depth; - data = IfData{}; - data.startLineNumber = ctx.currentLineNumber; - CollectConditionHandlers(); - CollectBlockHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::ifstmt] =[this](srcSAXEventContext& ctx) { - if (ifDepth && ifDepth == ctx.depth) { - ifDepth = 0; - data.endLineNumber = ctx.currentLineNumber; - NotifyAll(ctx); - InitializeIfPolicyHandlers(); - } - }; - } - - void CollectConditionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if(!ifDepth) return; - if((ifDepth + 1) != ctx.depth) return; - - if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(conditionPolicy); - }; - } - - void CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(!ifDepth) return; - if((ifDepth + 1) != ctx.depth) return; - - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); - }; - } + : ConditionalPolicy(listeners) {} }; #endif From 623b7e9feaf1bd50cf782fd6132bcb820c26226c Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 15:11:01 +0900 Subject: [PATCH 061/149] Add namespaces to class/function --- src/policy_classes/ClassPolicySingleEvent.hpp | 3 +++ src/policy_classes/FunctionPolicySingleEvent.hpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index a1142b5..88984ab 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -24,6 +24,8 @@ struct ClassData { enum ClassType : std::size_t { CLASS, STRUCT }; //UNION, ENUM? enum AccessSpecifier { PUBLIC = 0, PRIVATE = 1, PROTECTED = 2 }; + std::vector namespaces; + unsigned int lineNumber; std::string language; std::string filename; @@ -125,6 +127,7 @@ public srcDispatch::PolicyListener { if (!classDepth) { classDepth = ctx.depth; data = ClassData{}; + data.namespace = ctx.currentNamespaces; data.lineNumber = ctx.currentLineNumber; std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); if (stereotype_attr_itr != ctx.attributes.end()){ diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index 3340686..05af09a 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -23,6 +23,8 @@ struct FunctionData { enum FunctionType { CONSTRUCTOR, DESTRUCTOR, OPERATOR, FUNCTION }; + std::vector namespaces; + unsigned int lineNumber; std::string language; std::string filename; @@ -144,6 +146,7 @@ public srcDispatch::PolicyListener { if (!functionDepth) { functionDepth = ctx.depth; data = FunctionData{}; + data.namespaces = ctx.currentNamespaces; data.lineNumber = ctx.currentLineNumber; data.language = ctx.currentFileLanguage; data.filename = ctx.currentFilePath; From 635ce3390d5a9d908788369a1fdc73e4c9f0456e Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 11 Nov 2024 15:22:43 +0900 Subject: [PATCH 062/149] Fix namepace reference --- src/policy_classes/ClassPolicySingleEvent.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index 88984ab..d7f5d8d 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -127,7 +127,7 @@ public srcDispatch::PolicyListener { if (!classDepth) { classDepth = ctx.depth; data = ClassData{}; - data.namespace = ctx.currentNamespaces; + data.namespaces = ctx.currentNamespaces; data.lineNumber = ctx.currentLineNumber; std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); if (stereotype_attr_itr != ctx.attributes.end()){ From 549f0d67e747884b4967cd134810d8b3bf69dd99 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Sun, 17 Nov 2024 10:16:17 +0900 Subject: [PATCH 063/149] Collect operators in names --- src/policy_classes/NamePolicySingleEvent.cpp | 51 ++++++++--- src/policy_classes/NamePolicySingleEvent.hpp | 17 ++-- .../OperatorPolicySingleEvent.hpp | 84 +++++++++++++++++++ 3 files changed, 132 insertions(+), 20 deletions(-) create mode 100644 src/policy_classes/OperatorPolicySingleEvent.hpp diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index 18ef4bd..c99506e 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -7,31 +7,40 @@ */ #include +#include + std::string NameData::SimpleName() const { - if (!name.empty()) + if (!name.empty()) { return name; - return names.back()->SimpleName(); -} + } + assert(names.back().type() == typeid(std::shared_ptr)); + return std::any_cast>(names.back())->SimpleName(); +} std::string NameData::ToString() const { + std::string str = name; - for(std::size_t pos = 0; pos < names.size(); ++pos) { - if (pos != 0) - str += ' '; - str += names[pos]->ToString(); + for(const std::any& name_element : names) { + if(name_element.type() == typeid(std::shared_ptr)) { + str += std::any_cast>(name_element)->ToString(); + } else { + str += std::any_cast>(name_element)->op; + } } return str; } std::ostream& operator<<(std::ostream& out, const NameData& nameData) { - if (!nameData.name.empty()) { - out << nameData.name; - } - for (size_t pos = 0; pos < nameData.names.size(); ++pos) { - if (pos != 0) out << "::"; - out << (*nameData.names[pos]); + out << nameData.name; + + for(const std::any& name_element : nameData.names) { + if(name_element.type() == typeid(std::shared_ptr)) { + out << *std::any_cast>(name_element); + } else { + out << std::any_cast>(name_element)->op; + } } if (!nameData.templateArguments.empty()) { out << '<'; @@ -48,14 +57,18 @@ std::ostream& operator<<(std::ostream& out, const NameData& nameData) { NamePolicy::~NamePolicy() { if (namePolicy) delete namePolicy; + if (operatorPolicy) delete operatorPolicy; if (expressionPolicy) delete expressionPolicy; if (templateArgumentPolicy) delete templateArgumentPolicy; } void NamePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(NamePolicy) == typeid(*policy)) { data.names.push_back(policy->Data()); + } else if (typeid(OperatorPolicy) == typeid(*policy)) { + data.names.push_back(policy->Data()); } else if (typeid(TemplateArgumentPolicy) == typeid(*policy)) { data.templateArguments.push_back(policy->Data()); } else if (typeid(ExpressionPolicy) == typeid(*policy)) { @@ -76,6 +89,7 @@ void NamePolicy::InitializeNamePolicyHandlers() { nameDepth = ctx.depth; data = NameData{}; data.lineNumber = ctx.currentLineNumber; + CollectOperatorsHandlers(); CollectTemplateArgumentsHandlers(); CollectArrayIndicesHandlers(); } else if ((nameDepth + 1) == ctx.depth) { @@ -99,6 +113,17 @@ void NamePolicy::InitializeNamePolicyHandlers() { }; } +void NamePolicy::CollectOperatorsHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { + if(!nameDepth) return; + if((nameDepth + 1) != ctx.depth) return; + + if(!operatorPolicy) operatorPolicy = new OperatorPolicy{this}; + ctx.dispatcher->AddListenerDispatch(operatorPolicy); + }; +} + void NamePolicy::CollectTemplateArgumentsHandlers() { using namespace srcDispatch; diff --git a/src/policy_classes/NamePolicySingleEvent.hpp b/src/policy_classes/NamePolicySingleEvent.hpp index a37877a..4ff516d 100644 --- a/src/policy_classes/NamePolicySingleEvent.hpp +++ b/src/policy_classes/NamePolicySingleEvent.hpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -23,12 +24,11 @@ class ExpressionPolicy; struct TemplateArgumentData; class TemplateArgumentPolicy; - struct NameData { unsigned int lineNumber; std::string name; - std::vector> names; + std::vector names; std::vector> templateArguments; std::shared_ptr indices; @@ -44,11 +44,12 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - NameData data; - std::size_t nameDepth; - NamePolicy *namePolicy; - TemplateArgumentPolicy *templateArgumentPolicy; - ExpressionPolicy *expressionPolicy; + NameData data; + std::size_t nameDepth; + NamePolicy * namePolicy; + OperatorPolicy * operatorPolicy; + TemplateArgumentPolicy* templateArgumentPolicy; + ExpressionPolicy * expressionPolicy; public: NamePolicy(std::initializer_list listeners) @@ -56,6 +57,7 @@ public srcDispatch::PolicyListener { data{}, nameDepth(0), namePolicy(nullptr), + operatorPolicy(nullptr), expressionPolicy(nullptr), templateArgumentPolicy(nullptr) { InitializeNamePolicyHandlers(); @@ -71,6 +73,7 @@ public srcDispatch::PolicyListener { private: void InitializeNamePolicyHandlers(); + void CollectOperatorsHandlers(); void CollectTemplateArgumentsHandlers(); void CollectArrayIndicesHandlers(); }; diff --git a/src/policy_classes/OperatorPolicySingleEvent.hpp b/src/policy_classes/OperatorPolicySingleEvent.hpp new file mode 100644 index 0000000..e885754 --- /dev/null +++ b/src/policy_classes/OperatorPolicySingleEvent.hpp @@ -0,0 +1,84 @@ +/** + * @file OperatorPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_OPERATOR_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_OPERATOR_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include +#include + +struct OperatorData { + + unsigned int startLineNumber; + std::string op; + + friend std::ostream& operator<<(std::ostream& out, const OperatorData& operatorData) { + return out << operatorData.op; + } +}; + +class OperatorPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + OperatorData data; + std::size_t operatorDepth; + +public: + OperatorPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + operatorDepth(0) { + InitializeOperatorPolicyHandlers(); + } + + ~OperatorPolicy() { + } + +protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) {} + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} + +private: + void InitializeOperatorPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { + if (!operatorDepth) { + operatorDepth = ctx.depth; + data = OperatorData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectTokenHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::op] =[this](srcSAXEventContext& ctx) { + if (operatorDepth && operatorDepth == ctx.depth) { + operatorDepth = 0; + NotifyAll(ctx); + InitializeOperatorPolicyHandlers(); + } + }; + } + + void CollectTokenHandlers() { + using namespace srcDispatch; + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { + data.op += ctx.currentToken; + }; + } +}; + +#endif From 741bfa927737c6a3aa52aaad881f249664376f18 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Sun, 17 Nov 2024 10:24:58 +0900 Subject: [PATCH 064/149] Fix build warnings --- src/policy_classes/CallPolicySingleEvent.hpp | 4 ++-- src/policy_classes/ControlPolicySingleEvent.hpp | 4 ++-- src/policy_classes/ExpressionPolicySingleEvent.hpp | 2 +- src/policy_classes/ForPolicySingleEvent.hpp | 2 +- src/policy_classes/NamePolicySingleEvent.cpp | 2 +- src/policy_classes/NamePolicySingleEvent.hpp | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/policy_classes/CallPolicySingleEvent.hpp b/src/policy_classes/CallPolicySingleEvent.hpp index 6ab2786..d784dd7 100644 --- a/src/policy_classes/CallPolicySingleEvent.hpp +++ b/src/policy_classes/CallPolicySingleEvent.hpp @@ -54,8 +54,8 @@ public srcDispatch::PolicyListener { : srcDispatch::PolicyDispatcher(listeners), data{}, callDepth(0), - expressionPolicy(nullptr), - namePolicy(nullptr) { + namePolicy(nullptr), + expressionPolicy(nullptr) { InitializeCallPolicyHandlers(); } diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp index 6822490..c9cb9cc 100644 --- a/src/policy_classes/ControlPolicySingleEvent.hpp +++ b/src/policy_classes/ControlPolicySingleEvent.hpp @@ -30,7 +30,7 @@ struct ControlData { friend std::ostream& operator<<(std::ostream& out, const ControlData& controlData) { bool outputDeclComma = false; - for(const std::any item : controlData.init) { + for(const std::any& item : controlData.init) { if(outputDeclComma) out << ", "; if(item.type() == typeid(std::shared_ptr)) out << *std::any_cast>(item); @@ -43,7 +43,7 @@ struct ControlData { if(controlData.condition) out << *controlData.condition << "; "; bool outputExprComma = false; - for(const std::shared_ptr expr : controlData.incr) { + for(const std::shared_ptr& expr : controlData.incr) { if(outputExprComma) out << ", "; out << *expr; outputExprComma = true; diff --git a/src/policy_classes/ExpressionPolicySingleEvent.hpp b/src/policy_classes/ExpressionPolicySingleEvent.hpp index 30f4f7d..a21256d 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.hpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.hpp @@ -62,9 +62,9 @@ public srcDispatch::PolicyListener { private: ExpressionData data; + std::size_t exprDepth; NamePolicy* namePolicy; CallPolicy* callPolicy; - std::size_t exprDepth; public: ExpressionPolicy(std::initializer_list listeners) diff --git a/src/policy_classes/ForPolicySingleEvent.hpp b/src/policy_classes/ForPolicySingleEvent.hpp index e3b7876..a03cedd 100644 --- a/src/policy_classes/ForPolicySingleEvent.hpp +++ b/src/policy_classes/ForPolicySingleEvent.hpp @@ -18,7 +18,7 @@ #include class BlockPolicy; -class BlockData; +struct BlockData; struct ForData { diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index c99506e..4215c1d 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -58,8 +58,8 @@ std::ostream& operator<<(std::ostream& out, const NameData& nameData) { NamePolicy::~NamePolicy() { if (namePolicy) delete namePolicy; if (operatorPolicy) delete operatorPolicy; - if (expressionPolicy) delete expressionPolicy; if (templateArgumentPolicy) delete templateArgumentPolicy; + if (expressionPolicy) delete expressionPolicy; } diff --git a/src/policy_classes/NamePolicySingleEvent.hpp b/src/policy_classes/NamePolicySingleEvent.hpp index 4ff516d..dfa29bf 100644 --- a/src/policy_classes/NamePolicySingleEvent.hpp +++ b/src/policy_classes/NamePolicySingleEvent.hpp @@ -58,8 +58,8 @@ public srcDispatch::PolicyListener { nameDepth(0), namePolicy(nullptr), operatorPolicy(nullptr), - expressionPolicy(nullptr), - templateArgumentPolicy(nullptr) { + templateArgumentPolicy(nullptr), + expressionPolicy(nullptr) { InitializeNamePolicyHandlers(); } From 83f62d6c846ad8688ccb52a0fd9225ae31629400 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Sun, 17 Nov 2024 10:29:28 +0900 Subject: [PATCH 065/149] Fix more build warnings --- src/dispatcher/srcDispatchUtilities.hpp | 25 ++++++++------------ src/policy_classes/UnitPolicySingleEvent.hpp | 4 ++-- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 4b15553..1806458 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -66,16 +66,16 @@ namespace srcDispatch { public: srcSAXEventContext() = delete; srcSAXEventContext(EventDispatcher * dispatcher, const std::vector & elementStack) - : dispatcher(dispatcher), + : writer{0}, + archiveBuffer{0}, + dispatcher(dispatcher), elementStack(elementStack), + currentLineNumber{0}, triggerField(std::vector(MAXENUMVALUE, 0)), depth(0), isPrev(false), isOperator(false), - endArchive(false), - currentLineNumber{0}, - archiveBuffer{0}, - writer{0} {} + endArchive(false) {} ~srcSAXEventContext(){ if(writer){ xmlBufferFree(archiveBuffer); @@ -138,20 +138,19 @@ namespace srcDispatch { srcML does not escape " while libxml2 does escape quotations. */ - int ret = 0; char * text = (char *)text_content.c_str(); for(char * pos = text; *pos; ++pos) { if(*pos != '"') continue; *pos = 0; - ret = xmlTextWriterWriteString(writer, (const xmlChar *)text); + xmlTextWriterWriteString(writer, (const xmlChar *)text); *pos = '\"'; xmlTextWriterWriteRaw(writer, (const xmlChar *)"\""); text = pos + 1; } - ret = xmlTextWriterWriteString(writer, (const xmlChar *)text); + xmlTextWriterWriteString(writer, (const xmlChar *)text); } } inline bool And(const std::vector vec) const{ @@ -268,18 +267,14 @@ namespace srcDispatch { void NopOpenEvents(std::initializer_list states) { for(ParserState state : states) { - - openEventMap[state] = [this](const srcSAXEventContext& ctx [[maybe_unused]]) {}; - + openEventMap[state] = [](const srcSAXEventContext& ctx [[maybe_unused]]) {}; } } void NopCloseEvents(std::initializer_list states) { for(ParserState state : states) { - - closeEventMap[state] = [this](const srcSAXEventContext& ctx [[maybe_unused]]) {}; - + closeEventMap[state] = [](const srcSAXEventContext& ctx [[maybe_unused]]) {}; } } @@ -427,7 +422,7 @@ namespace srcDispatch { std::list elementListeners; EventDispatcher(const std::vector & elementStack) - : elementListeners(), ctx(this, elementStack) {} + : ctx(this, elementStack), elementListeners() {} virtual ~EventDispatcher() {} virtual void DispatchEvent(ParserState, ElementState) = 0; }; diff --git a/src/policy_classes/UnitPolicySingleEvent.hpp b/src/policy_classes/UnitPolicySingleEvent.hpp index 43a7290..b567c9c 100644 --- a/src/policy_classes/UnitPolicySingleEvent.hpp +++ b/src/policy_classes/UnitPolicySingleEvent.hpp @@ -68,7 +68,7 @@ class UnitPolicy : openEventMap[ParserState::structn] = startClassPolicy; // end of policy - std::function endClassPolicy = [this](srcSAXEventContext& ctx) { + std::function endClassPolicy = [](srcSAXEventContext& ctx) { }; closeEventMap[ParserState::classn] = endClassPolicy; @@ -86,7 +86,7 @@ class UnitPolicy : openEventMap[ParserState::destructor] = startFunction; // end of policy - std::function endFunction = [this](srcSAXEventContext& ctx) { + std::function endFunction = [](srcSAXEventContext& ctx) { }; From 8f0a2343c7fb67c4188b14119b09afe98c0f2042 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Sun, 17 Nov 2024 10:46:17 +0900 Subject: [PATCH 066/149] Refactor expression to use operator and new literal policies --- .../ExpressionPolicySingleEvent.cpp | 59 +++++++------ .../ExpressionPolicySingleEvent.hpp | 39 +++------ .../LiteralPolicySingleEvent.hpp | 84 +++++++++++++++++++ 3 files changed, 129 insertions(+), 53 deletions(-) create mode 100644 src/policy_classes/LiteralPolicySingleEvent.hpp diff --git a/src/policy_classes/ExpressionPolicySingleEvent.cpp b/src/policy_classes/ExpressionPolicySingleEvent.cpp index 82d8ce2..cf248bb 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.cpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.cpp @@ -5,17 +5,16 @@ #include -std::ostream& operator<<(std::ostream& out, const Token& token) { - return out << token.token; -} - std::ostream& operator<<(std::ostream& out, const ExpressionData& ex) { - for (std::shared_ptr item : ex.expr) { - switch (item->type) { - case ExpressionElement::NAME: out << *item->name; break; - case ExpressionElement::OP: out << *item->token; break; - case ExpressionElement::LITERAL: out << *item->token; break; - case ExpressionElement::CALL: out << *item->call; break; + for (std::any item : ex.expr) { + if(item.type() == typeid(std::shared_ptr)) { + out << *std::any_cast>(item); + } else if(item.type() == typeid(std::shared_ptr)) { + out << *std::any_cast>(item); + } else if(item.type() == typeid(std::shared_ptr)) { + out << *std::any_cast>(item); + } else if(item.type() == typeid(std::shared_ptr)) { + out << *std::any_cast>(item); } out << " "; } @@ -23,15 +22,21 @@ std::ostream& operator<<(std::ostream& out, const ExpressionData& ex) { } ExpressionPolicy::~ExpressionPolicy() { - if(namePolicy) delete namePolicy; - if(callPolicy) delete callPolicy; + if(namePolicy) delete namePolicy; + if(operatorPolicy) delete operatorPolicy; + if(literalPolicy) delete literalPolicy; + if(callPolicy) delete callPolicy; } void ExpressionPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { if(typeid(NamePolicy) == typeid(*policy)) { - data.expr.push_back(std::make_shared(ExpressionElement::NAME, policy->Data())); - } else if(typeid(CallPolicy) == typeid(*policy)) { - data.expr.push_back(std::make_shared(ExpressionElement::CALL, policy->Data())); + data.expr.push_back(policy->Data()); + } else if(typeid(OperatorPolicy) == typeid(*policy)) { + data.expr.push_back(policy->Data()); + } else if(typeid(LiteralPolicy) == typeid(*policy)) { + data.expr.push_back(policy->Data()); + } else if(typeid(CallPolicy) == typeid(*policy)) { + data.expr.push_back(policy->Data()); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } @@ -50,7 +55,8 @@ void ExpressionPolicy::InitializeExpressionPolicyHandlers() { data.lineNumber = ctx.currentLineNumber; CollectNameHandlers(); CollectCallHandlers(); - CollectOtherHandlers(); + CollectOperatorHandlers(); + CollectLiteralHandlers(); } }; @@ -84,17 +90,18 @@ void ExpressionPolicy::CollectCallHandlers() { }; } -void ExpressionPolicy::CollectOtherHandlers() { //Get the operators +void ExpressionPolicy::CollectOperatorHandlers() { using namespace srcDispatch; - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - std::shared_ptr token = std::make_shared(ctx.currentLineNumber, ctx.currentToken); - if (ctx.currentTag == "operator") { - data.expr.push_back(std::make_shared(ExpressionElement::OP, token)); - } - if (ctx.currentTag == "literal") { - data.expr.push_back(std::make_shared(ExpressionElement::LITERAL, token)); - } - + openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { + if(!operatorPolicy) operatorPolicy = new OperatorPolicy{this}; + ctx.dispatcher->AddListenerDispatch(operatorPolicy); }; } +void ExpressionPolicy::CollectLiteralHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { + if(!literalPolicy) literalPolicy = new LiteralPolicy{this}; + ctx.dispatcher->AddListenerDispatch(literalPolicy); + }; +} diff --git a/src/policy_classes/ExpressionPolicySingleEvent.hpp b/src/policy_classes/ExpressionPolicySingleEvent.hpp index a21256d..c38783d 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.hpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.hpp @@ -8,6 +8,8 @@ #include #include +#include +#include #include #include @@ -26,31 +28,10 @@ class NamePolicy; //Names, operators, calls in the correct order. //Need for determining variable use, variable modification, calls -struct Token { - Token(unsigned int lineNumber, const std::string& token) - : lineNumber(lineNumber), token(token) { - } - unsigned int lineNumber; - std::string token; - friend std::ostream& operator<<(std::ostream& out, const Token& token); -}; - -struct ExpressionElement { - enum ExprType { NAME, OP, CALL, LITERAL}; - - ExprType type; - std::shared_ptr name; - std::shared_ptr token; - std::shared_ptr call; - ExpressionElement(ExprType t, std::shared_ptr item) : type(t), name(item) {}; - ExpressionElement(ExprType t, std::shared_ptr item) : type(t), token(item){}; - ExpressionElement(ExprType t, std::shared_ptr item) : type(t), call(item) {}; -}; - struct ExpressionData { unsigned int lineNumber; - std::vector> expr; //All items in expression + std::vector expr; friend std::ostream& operator<<(std::ostream& out, const ExpressionData& ex); }; @@ -63,8 +44,10 @@ public srcDispatch::PolicyListener { private: ExpressionData data; std::size_t exprDepth; - NamePolicy* namePolicy; - CallPolicy* callPolicy; + NamePolicy * namePolicy; + OperatorPolicy* operatorPolicy; + LiteralPolicy * literalPolicy; + CallPolicy * callPolicy; public: ExpressionPolicy(std::initializer_list listeners) @@ -72,8 +55,9 @@ public srcDispatch::PolicyListener { data{}, exprDepth(0), namePolicy(nullptr), - callPolicy(nullptr) - { + operatorPolicy(nullptr), + literalPolicy(nullptr), + callPolicy(nullptr) { InitializeExpressionPolicyHandlers(); } @@ -90,7 +74,8 @@ public srcDispatch::PolicyListener { void InitializeExpressionPolicyHandlers(); void CollectCallHandlers(); void CollectNameHandlers(); - void CollectOtherHandlers(); + void CollectOperatorHandlers(); + void CollectLiteralHandlers(); }; #endif diff --git a/src/policy_classes/LiteralPolicySingleEvent.hpp b/src/policy_classes/LiteralPolicySingleEvent.hpp new file mode 100644 index 0000000..3fe3ed5 --- /dev/null +++ b/src/policy_classes/LiteralPolicySingleEvent.hpp @@ -0,0 +1,84 @@ +/** + * @file LiteralPolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_LITERAL_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_LITERAL_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include +#include + +struct LiteralData { + + unsigned int startLineNumber; + std::string literal; + + friend std::ostream& operator<<(std::ostream& out, const LiteralData& literalData) { + return out << literalData.literal; + } +}; + +class LiteralPolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + LiteralData data; + std::size_t literalDepth; + +public: + LiteralPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + literalDepth(0) { + InitializeLiteralPolicyHandlers(); + } + + ~LiteralPolicy() { + } + +protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) {} + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} + +private: + void InitializeLiteralPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { + if (!literalDepth) { + literalDepth = ctx.depth; + data = LiteralData{}; + data.startLineNumber = ctx.currentLineNumber; + CollectTokenHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::literal] =[this](srcSAXEventContext& ctx) { + if (literalDepth && literalDepth == ctx.depth) { + literalDepth = 0; + NotifyAll(ctx); + InitializeLiteralPolicyHandlers(); + } + }; + } + + void CollectTokenHandlers() { + using namespace srcDispatch; + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { + data.literal += ctx.currentToken; + }; + } +}; + +#endif From 4bbbf2d0e674542b2d0fd81b16da58d43eaa7fe4 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Sun, 17 Nov 2024 13:13:15 +0900 Subject: [PATCH 067/149] Output entire name if has local text (e.g., operator functions) --- src/policy_classes/NamePolicySingleEvent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index 4215c1d..c58761d 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -11,7 +11,7 @@ std::string NameData::SimpleName() const { if (!name.empty()) { - return name; + return ToString(); } assert(names.back().type() == typeid(std::shared_ptr)); From 09de43881bb6cb07025bb58bccb551c3f68d3e59 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 18 Nov 2024 13:20:43 +0900 Subject: [PATCH 068/149] Collect range info in decl --- src/dispatcher/srcDispatchUtilities.hpp | 2 +- src/dispatcher/srcDispatcher.hpp | 10 ++++++- src/policy_classes/DeclPolicySingleEvent.hpp | 30 +++++++++++++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 1806458..13bd867 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -47,7 +47,7 @@ namespace srcDispatch { super_list, super, publicaccess, privateaccess, protectedaccess, preproc, whilestmt, forstmt, ifstmt, nonterminal, macro, classblock, functionblock, constructorblock, ifblock, whileblock, forblock, switchstmt, switchcase, specifier, throws, typedefexpr, userdefined, comment, annotation, condition, - dostmt, incr, decr, control, ifgroup, + dostmt, incr, decr, control, ifgroup, range, // NLP states snoun, propersnoun, spronoun, sadjective, sverb, diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 35d3172..e29088d 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -407,6 +407,10 @@ namespace srcDispatch { ++ctx.triggerField[ParserState::init]; DispatchEvent(ParserState::init, ElementState::open); } }, + { "range", [this]() { + ++ctx.triggerField[ParserState::range]; + DispatchEvent(ParserState::range, ElementState::open); + } }, { "argument", [this]() { ++ctx.triggerField[ParserState::argument]; DispatchEvent(ParserState::argument, ElementState::open); @@ -701,7 +705,11 @@ namespace srcDispatch { { "init", [this]() { DispatchEvent(ParserState::init, ElementState::close); --ctx.triggerField[ParserState::init]; - } }, + } }, + { "range", [this]() { + DispatchEvent(ParserState::range, ElementState::close); + --ctx.triggerField[ParserState::range]; + } }, { "argument", [this]() { DispatchEvent(ParserState::argument, ElementState::close); --ctx.triggerField[ParserState::argument]; diff --git a/src/policy_classes/DeclPolicySingleEvent.hpp b/src/policy_classes/DeclPolicySingleEvent.hpp index 1636a1e..b7172c9 100644 --- a/src/policy_classes/DeclPolicySingleEvent.hpp +++ b/src/policy_classes/DeclPolicySingleEvent.hpp @@ -24,6 +24,7 @@ struct DeclData { std::shared_ptr type; std::shared_ptr name; std::shared_ptr init; + std::shared_ptr range; bool isStatic; friend std::ostream& operator<<(std::ostream& out, const DeclData& declData) { @@ -36,6 +37,9 @@ struct DeclData { if (declData.init) { out << " = " << *declData.init; } + if (declData.range) { + out << " : " << *declData.range; + } return out; } }; @@ -77,12 +81,17 @@ public srcDispatch::PolicyListener { void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + using namespace srcDispatch; if (typeid(TypePolicy) == typeid(*policy)) { data.type = std::shared_ptr(policy->Data()); } else if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); } else if (typeid(ExpressionPolicy) == typeid(*policy)) { - data.init = policy->Data(); + if(ctx.IsOpen(ParserState::range)) { + data.range = policy->Data(); + } else { + data.init = policy->Data(); + } } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } @@ -106,6 +115,7 @@ public srcDispatch::PolicyListener { CollectTypeHandlers(); CollectNameHandlers(); CollectInitHandlers(); + CollectRangeHandlers(); }; // close policy @@ -174,6 +184,24 @@ public srcDispatch::PolicyListener { }; } + void CollectRangeHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::range] = [this](srcSAXEventContext& ctx) { + if(!declDepth || (declDepth + 1) != ctx.depth) return; + + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(!exprPolicy) exprPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(exprPolicy); + }; + }; + closeEventMap[ParserState::range] = [this](srcSAXEventContext& ctx) { + if(!declDepth || (declDepth + 1) != ctx.depth) return; + + NopOpenEvents({ParserState::expr}); + }; + } + + }; #endif From 08c663a249bff4d5ac89f9d4c3f4141b7cae4db8 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 18 Nov 2024 13:46:33 +0900 Subject: [PATCH 069/149] Gather template info as expression --- src/policy_classes/NamePolicySingleEvent.cpp | 13 +- src/policy_classes/NamePolicySingleEvent.hpp | 1 - .../TemplateArgumentPolicySingleEvent.cpp | 150 ++++-------------- .../TemplateArgumentPolicySingleEvent.hpp | 16 +- 4 files changed, 57 insertions(+), 123 deletions(-) diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index c58761d..4270e44 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -7,6 +7,8 @@ */ #include + +#include #include std::string NameData::SimpleName() const { @@ -28,6 +30,15 @@ std::string NameData::ToString() const { str += std::any_cast>(name_element)->op; } } + + if (!templateArguments.empty()) { + str += '<'; + for(const std::shared_ptr& arg : templateArguments) { + str += arg->ToString(); + } + str += '>'; + } + return str; } @@ -44,7 +55,7 @@ std::ostream& operator<<(std::ostream& out, const NameData& nameData) { } if (!nameData.templateArguments.empty()) { out << '<'; - for(const std::shared_ptr arg : nameData.templateArguments) { + for(const std::shared_ptr& arg : nameData.templateArguments) { out << *arg; } out << '>'; diff --git a/src/policy_classes/NamePolicySingleEvent.hpp b/src/policy_classes/NamePolicySingleEvent.hpp index dfa29bf..c1d0ec4 100644 --- a/src/policy_classes/NamePolicySingleEvent.hpp +++ b/src/policy_classes/NamePolicySingleEvent.hpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp b/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp index 7d09e64..7d2c19a 100644 --- a/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp +++ b/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp @@ -4,21 +4,24 @@ */ #include +#include + +#include + +std::string TemplateArgumentData::ToString() const { + std::ostringstream out; + out << *this; + return out.str(); +} + std::ostream& operator<<(std::ostream& out, const TemplateArgumentData& argumentData) { - for(std::size_t pos = 0; pos < argumentData.data.size(); ++pos) { - if (pos != 0) - out << ' '; - const std::pair& element = argumentData.data[pos]; - if (element.second == TemplateArgumentData::NAME) - out << *std::any_cast>(element.first); - else if (element.second == TemplateArgumentData::POINTER) - out << '*'; - else if (element.second == TemplateArgumentData::REFERENCE) - out << '&'; - else if (element.second == TemplateArgumentData::RVALUE) - out << "&&"; - else - out << *std::any_cast>(element.first); + + for(std::size_t pos = 0; pos < argumentData.arguments.size(); ++pos) { + if (pos != 0) { + out << ", "; + } + + out << *argumentData.arguments.at(pos); } return out; @@ -33,12 +36,20 @@ TemplateArgumentPolicy::TemplateArgumentPolicy(std::initializer_listData(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); + if (typeid(NamePolicy) == typeid(*policy)) { + //data.arguments.push_back(policy->Data()); + } else if (typeid(ExpressionPolicy) == typeid(*policy)) { + data.arguments.push_back(policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); } void TemplateArgumentPolicy::NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]){} @@ -55,8 +66,7 @@ void TemplateArgumentPolicy::InitializeTemplateArgumentPolicyHandlers() { argumentDepth = ctx.depth; data = TemplateArgumentData{}; data.lineNumber = ctx.currentLineNumber; - CollectNamesHandler(); - CollectOthersHandler(); + CollectExpressionHandler(); } }; @@ -70,103 +80,13 @@ void TemplateArgumentPolicy::InitializeTemplateArgumentPolicyHandlers() { }; } -void TemplateArgumentPolicy::CollectNamesHandler() { +void TemplateArgumentPolicy::CollectExpressionHandler() { using namespace srcDispatch; - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - // C++ has depth of 2 others 1 - std::size_t elementStackSize = ctx.elementStack.size(); - if (argumentDepth && - (((argumentDepth + 2) == ctx.depth && elementStackSize > 1 && ctx.elementStack[elementStackSize - 2] == "expr") - || (argumentDepth + 1) == ctx.depth)) { - data.data.push_back(std::make_pair(nullptr, TemplateArgumentData::NAME)); - if (!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); - } - }; -} + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(!argumentDepth) return; + if((argumentDepth + 1) != ctx.depth) return; -void TemplateArgumentPolicy::CollectOthersHandler() { - using namespace srcDispatch; - openEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { - // C++ has depth of 2 others 1 - std::size_t elementStackSize = ctx.elementStack.size(); - if (argumentDepth && - (((argumentDepth + 2) == ctx.depth && elementStackSize > 1 && ctx.elementStack[elementStackSize - 2] == "expr") - || (argumentDepth + 1) == ctx.depth)) { - data.data.push_back(std::make_pair(std::make_shared(), TemplateArgumentData::LITERAL)); - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - (*std::any_cast>(data.data.back().first)) += ctx.currentToken; - }; - } - }; - - closeEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { - if (argumentDepth && (((argumentDepth + 2) == ctx.depth && ctx.elementStack.back() == "expr") - || (argumentDepth + 1) == ctx.depth)) { - NopCloseEvents({ParserState::tokenstring}); - } - }; - - openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { - // C++ has depth of 2 others 1 - std::size_t elementStackSize = ctx.elementStack.size(); - if (argumentDepth && - (((argumentDepth + 2) == ctx.depth && elementStackSize > 1 && ctx.elementStack[elementStackSize - 2] == "expr") - || (argumentDepth + 1) == ctx.depth)) { - data.data.push_back(std::make_pair(new std::string(), TemplateArgumentData::OPERATOR)); - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - (*std::any_cast>(data.data.back().first)) += ctx.currentToken; - }; - } - }; - - closeEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { - if (argumentDepth && (((argumentDepth + 2) == ctx.depth && ctx.elementStack.back() == "expr") - || (argumentDepth + 1) == ctx.depth)) { - NopCloseEvents({ParserState::tokenstring}); - } - }; - - openEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) { - // C++ has depth of 2 others 1 - std::size_t elementStackSize = ctx.elementStack.size(); - if (argumentDepth && (((argumentDepth + 2) == ctx.depth && elementStackSize > 1 && ctx.elementStack[elementStackSize - 2] == "expr") - || (argumentDepth + 1) == ctx.depth)) { - data.data.push_back(std::make_pair(nullptr, TemplateArgumentData::MODIFIER)); - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - if (ctx.currentToken == "*") - data.data.back().second = TemplateArgumentData::POINTER; - else if (ctx.currentToken == "&") - data.data.back().second = TemplateArgumentData::REFERENCE; - else if (ctx.currentToken == "&&") - data.data.back().second = TemplateArgumentData::RVALUE; - }; - } - }; - - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) { - if (argumentDepth && (((argumentDepth + 2) == ctx.depth && ctx.elementStack.back() == "expr") - || (argumentDepth + 1) == ctx.depth)) { - NopCloseEvents({ParserState::tokenstring}); - } - }; - - openEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { - // C++ has depth of 2 others 1 - std::size_t elementStackSize = ctx.elementStack.size(); - if (argumentDepth && (((argumentDepth + 2) == ctx.depth && elementStackSize > 1 && ctx.elementStack[elementStackSize - 2] == "expr") - || (argumentDepth + 1) == ctx.depth)) { - data.data.push_back(std::make_pair(new std::string(), TemplateArgumentData::CALL)); - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - (*std::any_cast>(data.data.back().first)) += ctx.currentToken; - }; - } - }; - - closeEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { - if (argumentDepth && (((argumentDepth + 2) == ctx.depth && ctx.elementStack.back() == "expr") - || (argumentDepth + 1) == ctx.depth)) { - NopCloseEvents({ParserState::tokenstring}); - } + if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(expressionPolicy); }; } diff --git a/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp b/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp index ce229d8..683ceb4 100644 --- a/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp +++ b/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp @@ -10,12 +10,16 @@ class NamePolicy; +class ExpressionPolicy; +struct ExpressionData; + struct TemplateArgumentData { - enum TemplateArgumentType { NAME, LITERAL, MODIFIER, POINTER, REFERENCE, RVALUE, OPERATOR, CALL }; unsigned int lineNumber; - std::vector> data; + std::vector> arguments; + + std::string ToString() const; friend std::ostream& operator<<(std::ostream& out, const TemplateArgumentData& argumentData); }; @@ -36,13 +40,13 @@ public srcDispatch::PolicyListener { private: void InitializeTemplateArgumentPolicyHandlers(); - void CollectNamesHandler(); - void CollectOthersHandler(); + void CollectExpressionHandler(); private: TemplateArgumentData data; - std::size_t argumentDepth; - NamePolicy * namePolicy; + std::size_t argumentDepth; + NamePolicy * namePolicy; + ExpressionPolicy* expressionPolicy; }; From 3f4d89ebcd973a9966dac74a4aae999e3380f5be Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 18 Nov 2024 14:08:43 +0900 Subject: [PATCH 070/149] Improve template collection --- src/policy_classes/CallPolicySingleEvent.hpp | 1 - .../ExpressionPolicySingleEvent.cpp | 6 +- src/policy_classes/NamePolicySingleEvent.cpp | 50 +++----- src/policy_classes/NamePolicySingleEvent.hpp | 32 ++--- .../TemplateArgumentListPolicySingleEvent.cpp | 110 ++++++++++++++++++ ...TemplateArgumentListPolicySingleEvent.hpp} | 24 ++-- .../TemplateArgumentPolicySingleEvent.cpp | 92 --------------- 7 files changed, 160 insertions(+), 155 deletions(-) create mode 100644 src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp rename src/policy_classes/{TemplateArgumentPolicySingleEvent.hpp => TemplateArgumentListPolicySingleEvent.hpp} (60%) delete mode 100644 src/policy_classes/TemplateArgumentPolicySingleEvent.cpp diff --git a/src/policy_classes/CallPolicySingleEvent.hpp b/src/policy_classes/CallPolicySingleEvent.hpp index d784dd7..4b5ae5c 100644 --- a/src/policy_classes/CallPolicySingleEvent.hpp +++ b/src/policy_classes/CallPolicySingleEvent.hpp @@ -8,7 +8,6 @@ #include #include -#include #include #include diff --git a/src/policy_classes/ExpressionPolicySingleEvent.cpp b/src/policy_classes/ExpressionPolicySingleEvent.cpp index cf248bb..33ad72f 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.cpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.cpp @@ -6,7 +6,11 @@ #include std::ostream& operator<<(std::ostream& out, const ExpressionData& ex) { + bool outputSpace = false; for (std::any item : ex.expr) { + if(outputSpace) { + out << ' '; + } if(item.type() == typeid(std::shared_ptr)) { out << *std::any_cast>(item); } else if(item.type() == typeid(std::shared_ptr)) { @@ -16,7 +20,7 @@ std::ostream& operator<<(std::ostream& out, const ExpressionData& ex) { } else if(item.type() == typeid(std::shared_ptr)) { out << *std::any_cast>(item); } - out << " "; + outputSpace = false; } return out; } diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index 4270e44..6f7e591 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -31,12 +31,8 @@ std::string NameData::ToString() const { } } - if (!templateArguments.empty()) { - str += '<'; - for(const std::shared_ptr& arg : templateArguments) { - str += arg->ToString(); - } - str += '>'; + if (templateArgumentList) { + str += templateArgumentList->ToString(); } return str; @@ -53,12 +49,8 @@ std::ostream& operator<<(std::ostream& out, const NameData& nameData) { out << std::any_cast>(name_element)->op; } } - if (!nameData.templateArguments.empty()) { - out << '<'; - for(const std::shared_ptr& arg : nameData.templateArguments) { - out << *arg; - } - out << '>'; + if (nameData.templateArgumentList) { + out << *nameData.templateArgumentList; } if (nameData.indices) { out << '[' << *nameData.indices << ']'; @@ -67,10 +59,10 @@ std::ostream& operator<<(std::ostream& out, const NameData& nameData) { } NamePolicy::~NamePolicy() { - if (namePolicy) delete namePolicy; - if (operatorPolicy) delete operatorPolicy; - if (templateArgumentPolicy) delete templateArgumentPolicy; - if (expressionPolicy) delete expressionPolicy; + if (namePolicy) delete namePolicy; + if (operatorPolicy) delete operatorPolicy; + if (templateArgumentListPolicy) delete templateArgumentListPolicy; + if (expressionPolicy) delete expressionPolicy; } @@ -80,8 +72,8 @@ void NamePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSA data.names.push_back(policy->Data()); } else if (typeid(OperatorPolicy) == typeid(*policy)) { data.names.push_back(policy->Data()); - } else if (typeid(TemplateArgumentPolicy) == typeid(*policy)) { - data.templateArguments.push_back(policy->Data()); + } else if (typeid(TemplateArgumentListPolicy) == typeid(*policy)) { + data.templateArgumentList = policy->Data(); } else if (typeid(ExpressionPolicy) == typeid(*policy)) { data.indices = policy->Data(); } else { @@ -101,7 +93,7 @@ void NamePolicy::InitializeNamePolicyHandlers() { data = NameData{}; data.lineNumber = ctx.currentLineNumber; CollectOperatorsHandlers(); - CollectTemplateArgumentsHandlers(); + CollectTemplateArgumentListHandlers(); CollectArrayIndicesHandlers(); } else if ((nameDepth + 1) == ctx.depth) { NopCloseEvents({ParserState::tokenstring}); @@ -136,22 +128,14 @@ void NamePolicy::CollectOperatorsHandlers() { } -void NamePolicy::CollectTemplateArgumentsHandlers() { +void NamePolicy::CollectTemplateArgumentListHandlers() { using namespace srcDispatch; openEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext& ctx) { - if (nameDepth && (nameDepth + 1) == ctx.depth) { - openEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { - if (nameDepth && (nameDepth + 2) == ctx.depth) { - if (!templateArgumentPolicy) templateArgumentPolicy = new TemplateArgumentPolicy{this}; - ctx.dispatcher->AddListenerDispatch(templateArgumentPolicy); - } - }; - } - }; - closeEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext& ctx) { - if (nameDepth && (nameDepth + 1) == ctx.depth) { - NopOpenEvents({ParserState::argument}); - } + if (!nameDepth) return; + if((nameDepth + 1) != ctx.depth) return; + + if (!templateArgumentListPolicy) templateArgumentListPolicy = new TemplateArgumentListPolicy{this}; + ctx.dispatcher->AddListenerDispatch(templateArgumentListPolicy); }; } diff --git a/src/policy_classes/NamePolicySingleEvent.hpp b/src/policy_classes/NamePolicySingleEvent.hpp index c1d0ec4..a0b5627 100644 --- a/src/policy_classes/NamePolicySingleEvent.hpp +++ b/src/policy_classes/NamePolicySingleEvent.hpp @@ -10,26 +10,26 @@ #include -#include +#include #include #include #include #include -struct ExpressionData; class ExpressionPolicy; +struct ExpressionData; -struct TemplateArgumentData; -class TemplateArgumentPolicy; +class TemplateArgumentListPolicy; +struct TemplateArgumentListData; struct NameData { unsigned int lineNumber; - std::string name; - std::vector names; - std::vector> templateArguments; - std::shared_ptr indices; + std::string name; + std::vector names; + std::shared_ptr templateArgumentList; + std::shared_ptr indices; std::string SimpleName() const; std::string ToString() const; @@ -43,12 +43,12 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - NameData data; - std::size_t nameDepth; - NamePolicy * namePolicy; - OperatorPolicy * operatorPolicy; - TemplateArgumentPolicy* templateArgumentPolicy; - ExpressionPolicy * expressionPolicy; + NameData data; + std::size_t nameDepth; + NamePolicy * namePolicy; + OperatorPolicy * operatorPolicy; + TemplateArgumentListPolicy* templateArgumentListPolicy; + ExpressionPolicy * expressionPolicy; public: NamePolicy(std::initializer_list listeners) @@ -57,7 +57,7 @@ public srcDispatch::PolicyListener { nameDepth(0), namePolicy(nullptr), operatorPolicy(nullptr), - templateArgumentPolicy(nullptr), + templateArgumentListPolicy(nullptr), expressionPolicy(nullptr) { InitializeNamePolicyHandlers(); } @@ -73,7 +73,7 @@ public srcDispatch::PolicyListener { private: void InitializeNamePolicyHandlers(); void CollectOperatorsHandlers(); - void CollectTemplateArgumentsHandlers(); + void CollectTemplateArgumentListHandlers(); void CollectArrayIndicesHandlers(); }; diff --git a/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp b/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp new file mode 100644 index 0000000..ef352a6 --- /dev/null +++ b/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp @@ -0,0 +1,110 @@ +/** + * @file TemplateArgumentListPolicySingleEvent.cpp + * + */ +#include + +#include + +#include + +std::string TemplateArgumentListData::ToString() const { + std::ostringstream out; + out << *this; + return out.str(); +} + +std::ostream& operator<<(std::ostream& out, const TemplateArgumentListData& argumentData) { + + out << '<'; + for(std::size_t pos = 0; pos < argumentData.arguments.size(); ++pos) { + if (pos != 0) { + out << ", "; + } + + out << *argumentData.arguments.at(pos); + } + out << '>'; + + return out; +} + +TemplateArgumentListPolicy::TemplateArgumentListPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + argumentListDepth(0), + namePolicy(nullptr) { + InitializeTemplateArgumentListPolicyHandlers(); +} + +TemplateArgumentListPolicy::~TemplateArgumentListPolicy() { + if (namePolicy) delete namePolicy; + if (expressionPolicy) delete expressionPolicy; +} + +void TemplateArgumentListPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(NamePolicy) == typeid(*policy)) { + //data.arguments.push_back(policy->Data()); + } else if (typeid(ExpressionPolicy) == typeid(*policy)) { + data.arguments.push_back(policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); +} + +void TemplateArgumentListPolicy::NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]){} + +std::any TemplateArgumentListPolicy::DataInner() const { + return std::make_shared(data); +} + +void TemplateArgumentListPolicy::InitializeTemplateArgumentListPolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext& ctx) { + if (!argumentListDepth) { + argumentListDepth = ctx.depth; + data = TemplateArgumentListData{}; + data.lineNumber = ctx.currentLineNumber; + CollectArgumentHandler(); + } + }; + + // end of policy + closeEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext& ctx) { + if (argumentListDepth && argumentListDepth == ctx.depth) { + argumentListDepth = 0; + NotifyAll(ctx); + InitializeTemplateArgumentListPolicyHandlers(); + } + }; +} + +void TemplateArgumentListPolicy::CollectArgumentHandler() { + using namespace srcDispatch; + + openEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { + if(!argumentListDepth) return; + if((argumentListDepth + 1) != ctx.depth) return; + + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(!argumentListDepth) return; + if((argumentListDepth + 2) != ctx.depth) return; + + if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; + ctx.dispatcher->AddListenerDispatch(expressionPolicy); + }; + + }; + + closeEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { + if(!argumentListDepth) return; + if((argumentListDepth + 1) != ctx.depth) return; + NopOpenEvents({ParserState::expr}); + }; + + + +} diff --git a/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp b/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp similarity index 60% rename from src/policy_classes/TemplateArgumentPolicySingleEvent.hpp rename to src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp index 683ceb4..5c0fc41 100644 --- a/src/policy_classes/TemplateArgumentPolicySingleEvent.hpp +++ b/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp @@ -1,9 +1,9 @@ /** - * @file TemplateArgumentPolicySingleEvent.hpp + * @file TemplateArgumentListPolicySingleEvent.hpp * */ -#ifndef INCLUDED_TEMPLATE1_ARGUMENT_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_TEMPLATE1_ARGUMENT_POLICY_SINGLE_EVENT_HPP +#ifndef INCLUDED_TEMPLATE_ARGUMENT_LIST_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_TEMPLATE_ARGUMENT_LIST_POLICY_SINGLE_EVENT_HPP #include #include @@ -14,24 +14,24 @@ class ExpressionPolicy; struct ExpressionData; -struct TemplateArgumentData { +struct TemplateArgumentListData { unsigned int lineNumber; std::vector> arguments; std::string ToString() const; - friend std::ostream& operator<<(std::ostream& out, const TemplateArgumentData& argumentData); + friend std::ostream& operator<<(std::ostream& out, const TemplateArgumentListData& argumentData); }; -class TemplateArgumentPolicy : +class TemplateArgumentListPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { public: - TemplateArgumentPolicy(std::initializer_list listeners); - ~TemplateArgumentPolicy(); + TemplateArgumentListPolicy(std::initializer_list listeners); + ~TemplateArgumentListPolicy(); virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; virtual void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override; @@ -39,12 +39,12 @@ public srcDispatch::PolicyListener { virtual std::any DataInner() const override; private: - void InitializeTemplateArgumentPolicyHandlers(); - void CollectExpressionHandler(); + void InitializeTemplateArgumentListPolicyHandlers(); + void CollectArgumentHandler(); private: - TemplateArgumentData data; - std::size_t argumentDepth; + TemplateArgumentListData data; + std::size_t argumentListDepth; NamePolicy * namePolicy; ExpressionPolicy* expressionPolicy; diff --git a/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp b/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp deleted file mode 100644 index 7d2c19a..0000000 --- a/src/policy_classes/TemplateArgumentPolicySingleEvent.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/** - * @file TemplateArgumentPolicySingleEvent.cpp - * - */ -#include - -#include - -#include - -std::string TemplateArgumentData::ToString() const { - std::ostringstream out; - out << *this; - return out.str(); -} - -std::ostream& operator<<(std::ostream& out, const TemplateArgumentData& argumentData) { - - for(std::size_t pos = 0; pos < argumentData.arguments.size(); ++pos) { - if (pos != 0) { - out << ", "; - } - - out << *argumentData.arguments.at(pos); - } - - return out; -} - -TemplateArgumentPolicy::TemplateArgumentPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - argumentDepth(0), - namePolicy(nullptr) { - InitializeTemplateArgumentPolicyHandlers(); -} - -TemplateArgumentPolicy::~TemplateArgumentPolicy() { - if (namePolicy) delete namePolicy; - if (expressionPolicy) delete expressionPolicy; -} - -void TemplateArgumentPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(NamePolicy) == typeid(*policy)) { - //data.arguments.push_back(policy->Data()); - } else if (typeid(ExpressionPolicy) == typeid(*policy)) { - data.arguments.push_back(policy->Data()); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); -} - -void TemplateArgumentPolicy::NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]){} - -std::any TemplateArgumentPolicy::DataInner() const { - return std::make_shared(data); -} - -void TemplateArgumentPolicy::InitializeTemplateArgumentPolicyHandlers() { - using namespace srcDispatch; - // start of policy - openEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { - if (!argumentDepth) { - argumentDepth = ctx.depth; - data = TemplateArgumentData{}; - data.lineNumber = ctx.currentLineNumber; - CollectExpressionHandler(); - } - }; - - // end of policy - closeEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { - if (argumentDepth && argumentDepth == ctx.depth) { - argumentDepth = 0; - NotifyAll(ctx); - InitializeTemplateArgumentPolicyHandlers(); - } - }; -} - -void TemplateArgumentPolicy::CollectExpressionHandler() { - using namespace srcDispatch; - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(!argumentDepth) return; - if((argumentDepth + 1) != ctx.depth) return; - - if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(expressionPolicy); - }; -} From 100734e465d9ef99977f2d64d5de5fed56894ea8 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 21 Nov 2024 11:00:10 +0900 Subject: [PATCH 071/149] Remove unused parameter warnings --- src/policy_classes/BlockPolicySingleEvent.hpp | 4 +--- src/policy_classes/CallPolicySingleEvent.hpp | 2 +- src/policy_classes/ClassPolicySingleEvent.hpp | 4 ++-- src/policy_classes/ConditionPolicySingleEvent.hpp | 2 +- src/policy_classes/ConditionalPolicySingleEvent.hpp | 2 +- src/policy_classes/ControlPolicySingleEvent.hpp | 2 +- src/policy_classes/DeclPolicySingleEvent.hpp | 4 ++-- src/policy_classes/DeclTypePolicySingleEvent.hpp | 4 ++-- src/policy_classes/ExprStmtPolicySingleEvent.hpp | 2 +- src/policy_classes/ExpressionPolicySingleEvent.hpp | 4 +--- src/policy_classes/FunctionPolicySingleEvent.hpp | 4 ++-- src/policy_classes/IncrPolicySingleEvent.hpp | 2 +- src/policy_classes/LiteralPolicySingleEvent.hpp | 4 +--- src/policy_classes/NamePolicySingleEvent.hpp | 2 +- src/policy_classes/OperatorPolicySingleEvent.hpp | 4 +--- src/policy_classes/ReturnPolicySingleEvent.hpp | 2 +- src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp | 2 -- src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp | 2 +- src/policy_classes/TypePolicySingleEvent.cpp | 2 -- src/policy_classes/TypePolicySingleEvent.hpp | 2 +- src/policy_classes/UnitPolicySingleEvent.hpp | 4 ++-- 21 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index c99e9f6..2ee9dc1 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -65,10 +65,8 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override; - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: void InitializeBlockPolicyHandlers(); diff --git a/src/policy_classes/CallPolicySingleEvent.hpp b/src/policy_classes/CallPolicySingleEvent.hpp index 4b5ae5c..8e7407b 100644 --- a/src/policy_classes/CallPolicySingleEvent.hpp +++ b/src/policy_classes/CallPolicySingleEvent.hpp @@ -63,7 +63,7 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override; virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: void InitializeCallPolicyHandlers(); diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index d7f5d8d..9edaf86 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -87,8 +87,6 @@ public srcDispatch::PolicyListener { if (classPolicy) delete classPolicy; } - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(NamePolicy) == typeid(*policy)) { data.name = policy->Data(); @@ -116,6 +114,8 @@ public srcDispatch::PolicyListener { ctx.dispatcher->RemoveListenerDispatch(nullptr); } + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + protected: std::any DataInner() const override { return std::make_shared(data); } diff --git a/src/policy_classes/ConditionPolicySingleEvent.hpp b/src/policy_classes/ConditionPolicySingleEvent.hpp index eb83e3f..07e7b38 100644 --- a/src/policy_classes/ConditionPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionPolicySingleEvent.hpp @@ -54,7 +54,7 @@ public srcDispatch::PolicyListener { } } - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: void InitializeConditionPolicyHandlers() { diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index 6155f00..9778357 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -59,7 +59,7 @@ public srcDispatch::PolicyListener { ctx.dispatcher->RemoveListener(nullptr); } - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} void InitializeConditionalPolicyHandlers() { using namespace srcDispatch; diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp index c9cb9cc..6b6e058 100644 --- a/src/policy_classes/ControlPolicySingleEvent.hpp +++ b/src/policy_classes/ControlPolicySingleEvent.hpp @@ -106,7 +106,7 @@ public srcDispatch::PolicyListener { ctx.dispatcher->RemoveListener(nullptr); } - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: void InitializeControlPolicyHandlers() { diff --git a/src/policy_classes/DeclPolicySingleEvent.hpp b/src/policy_classes/DeclPolicySingleEvent.hpp index b7172c9..59c4f3b 100644 --- a/src/policy_classes/DeclPolicySingleEvent.hpp +++ b/src/policy_classes/DeclPolicySingleEvent.hpp @@ -78,8 +78,6 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared(data); } - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { using namespace srcDispatch; if (typeid(TypePolicy) == typeid(*policy)) { @@ -99,6 +97,8 @@ public srcDispatch::PolicyListener { ctx.dispatcher->RemoveListener(nullptr); } + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + private: void InitializeDeclPolicyHandlers() { using namespace srcDispatch; diff --git a/src/policy_classes/DeclTypePolicySingleEvent.hpp b/src/policy_classes/DeclTypePolicySingleEvent.hpp index 02810c9..6b0507e 100644 --- a/src/policy_classes/DeclTypePolicySingleEvent.hpp +++ b/src/policy_classes/DeclTypePolicySingleEvent.hpp @@ -42,8 +42,6 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared>>(decls); } - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(DeclPolicy) == typeid(*policy)) { std::shared_ptr decl = policy->Data(); @@ -59,6 +57,8 @@ public srcDispatch::PolicyListener { ctx.dispatcher->RemoveListener(nullptr); } + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + private: void InitializeDeclTypePolicyHandlers() { using namespace srcDispatch; diff --git a/src/policy_classes/ExprStmtPolicySingleEvent.hpp b/src/policy_classes/ExprStmtPolicySingleEvent.hpp index c5766b8..6e321e4 100644 --- a/src/policy_classes/ExprStmtPolicySingleEvent.hpp +++ b/src/policy_classes/ExprStmtPolicySingleEvent.hpp @@ -52,7 +52,7 @@ public srcDispatch::PolicyListener { } } - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: void InitializeExprStmtPolicyHandlers() { diff --git a/src/policy_classes/ExpressionPolicySingleEvent.hpp b/src/policy_classes/ExpressionPolicySingleEvent.hpp index c38783d..52c8de0 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.hpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.hpp @@ -65,10 +65,8 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared(data); } - - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: void InitializeExpressionPolicyHandlers(); diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index 05af09a..5c97437 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -117,8 +117,6 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const override { return std::make_shared(data); } - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(TypePolicy) == typeid(*policy)) { data.returnType = policy->Data(); @@ -138,6 +136,8 @@ public srcDispatch::PolicyListener { ctx.dispatcher->RemoveListenerDispatch(nullptr); } + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + private: void InitializeFunctionPolicyHandlers() { using namespace srcDispatch; diff --git a/src/policy_classes/IncrPolicySingleEvent.hpp b/src/policy_classes/IncrPolicySingleEvent.hpp index a56324e..78e3b87 100644 --- a/src/policy_classes/IncrPolicySingleEvent.hpp +++ b/src/policy_classes/IncrPolicySingleEvent.hpp @@ -64,7 +64,7 @@ public srcDispatch::PolicyListener { ctx.dispatcher->RemoveListener(nullptr); } - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: void InitializeIncrPolicyHandlers() { diff --git a/src/policy_classes/LiteralPolicySingleEvent.hpp b/src/policy_classes/LiteralPolicySingleEvent.hpp index 3fe3ed5..994f4eb 100644 --- a/src/policy_classes/LiteralPolicySingleEvent.hpp +++ b/src/policy_classes/LiteralPolicySingleEvent.hpp @@ -45,10 +45,8 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const { return std::make_shared(data); } - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) {} - - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: void InitializeLiteralPolicyHandlers() { diff --git a/src/policy_classes/NamePolicySingleEvent.hpp b/src/policy_classes/NamePolicySingleEvent.hpp index a0b5627..9fd7d56 100644 --- a/src/policy_classes/NamePolicySingleEvent.hpp +++ b/src/policy_classes/NamePolicySingleEvent.hpp @@ -68,7 +68,7 @@ public srcDispatch::PolicyListener { std::any DataInner() const override { return std::make_shared(data); } virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: void InitializeNamePolicyHandlers(); diff --git a/src/policy_classes/OperatorPolicySingleEvent.hpp b/src/policy_classes/OperatorPolicySingleEvent.hpp index e885754..aea5327 100644 --- a/src/policy_classes/OperatorPolicySingleEvent.hpp +++ b/src/policy_classes/OperatorPolicySingleEvent.hpp @@ -45,10 +45,8 @@ public srcDispatch::PolicyListener { protected: std::any DataInner() const { return std::make_shared(data); } - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) {} - - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: void InitializeOperatorPolicyHandlers() { diff --git a/src/policy_classes/ReturnPolicySingleEvent.hpp b/src/policy_classes/ReturnPolicySingleEvent.hpp index 6b9cc58..4df8e5a 100644 --- a/src/policy_classes/ReturnPolicySingleEvent.hpp +++ b/src/policy_classes/ReturnPolicySingleEvent.hpp @@ -54,7 +54,7 @@ public srcDispatch::PolicyListener { } } - void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: void InitializeReturnPolicyHandlers() { diff --git a/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp b/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp index ef352a6..028cfad 100644 --- a/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp +++ b/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp @@ -54,8 +54,6 @@ void TemplateArgumentListPolicy::Notify(const PolicyDispatcher* policy, const sr ctx.dispatcher->RemoveListener(nullptr); } -void TemplateArgumentListPolicy::NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]){} - std::any TemplateArgumentListPolicy::DataInner() const { return std::make_shared(data); } diff --git a/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp b/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp index 5c0fc41..83a0440 100644 --- a/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp +++ b/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp @@ -33,7 +33,7 @@ public srcDispatch::PolicyListener { TemplateArgumentListPolicy(std::initializer_list listeners); ~TemplateArgumentListPolicy(); virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; - virtual void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override; + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} protected: virtual std::any DataInner() const override; diff --git a/src/policy_classes/TypePolicySingleEvent.cpp b/src/policy_classes/TypePolicySingleEvent.cpp index 9348ef3..dc0a993 100644 --- a/src/policy_classes/TypePolicySingleEvent.cpp +++ b/src/policy_classes/TypePolicySingleEvent.cpp @@ -63,8 +63,6 @@ void TypePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSA ctx.dispatcher->RemoveListenerDispatch(nullptr); } -void TypePolicy::NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]){} - std::any TypePolicy::DataInner() const { return std::make_shared(data); } diff --git a/src/policy_classes/TypePolicySingleEvent.hpp b/src/policy_classes/TypePolicySingleEvent.hpp index 9c0d631..56d343e 100644 --- a/src/policy_classes/TypePolicySingleEvent.hpp +++ b/src/policy_classes/TypePolicySingleEvent.hpp @@ -38,7 +38,7 @@ public srcDispatch::PolicyListener { TypePolicy(std::initializer_list listeners); ~TypePolicy(); virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; - virtual void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} protected: virtual std::any DataInner() const override; diff --git a/src/policy_classes/UnitPolicySingleEvent.hpp b/src/policy_classes/UnitPolicySingleEvent.hpp index b567c9c..73ab69a 100644 --- a/src/policy_classes/UnitPolicySingleEvent.hpp +++ b/src/policy_classes/UnitPolicySingleEvent.hpp @@ -43,14 +43,14 @@ class UnitPolicy : if(classPolicy) delete classPolicy; } - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) override {} //doesn't use other parsers - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { // Assumes at least one lister which should always be one policyListeners.back()->Notify(policy, ctx); ctx.dispatcher->RemoveListenerDispatch(nullptr); } + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + protected: std::any DataInner() const override { return std::any(); } From 8eb3634cb4ad1074080afffadd99195618ab9b27 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 21 Nov 2024 11:06:18 +0900 Subject: [PATCH 072/149] Remove more warnings --- src/policy_classes/BlockPolicySingleEvent.cpp | 2 +- src/policy_classes/ConditionalPolicySingleEvent.hpp | 4 ++-- src/policy_classes/IncrPolicySingleEvent.hpp | 4 ++-- src/policy_classes/LiteralPolicySingleEvent.hpp | 4 ++-- src/policy_classes/OperatorPolicySingleEvent.hpp | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp index 8df6091..5702ad5 100644 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -20,8 +20,8 @@ BlockPolicy::BlockPolicy(std::initializer_list lis data{}, blockDepth(0), declstmtPolicy(nullptr), - exprStmtPolicy(nullptr), returnPolicy(nullptr), + exprStmtPolicy(nullptr), blockPolicy(nullptr), ifStmtPolicy(nullptr), switchPolicy(nullptr), diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index 9778357..be72a95 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -45,9 +45,9 @@ public srcDispatch::PolicyListener { } protected: - std::any DataInner() const { return std::make_shared(data); } + std::any DataInner() const override { return std::make_shared(data); } - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(ConditionPolicy) == typeid(*policy)) { data.condition = policy->Data(); } else if (typeid(BlockPolicy) == typeid(*policy)) { diff --git a/src/policy_classes/IncrPolicySingleEvent.hpp b/src/policy_classes/IncrPolicySingleEvent.hpp index 78e3b87..1cd27e5 100644 --- a/src/policy_classes/IncrPolicySingleEvent.hpp +++ b/src/policy_classes/IncrPolicySingleEvent.hpp @@ -52,9 +52,9 @@ public srcDispatch::PolicyListener { } protected: - std::any DataInner() const { return std::make_shared(data); } + std::any DataInner() const override { return std::make_shared(data); } - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(ExpressionPolicy) == typeid(*policy)) { data.expr = policy->Data(); } else { diff --git a/src/policy_classes/LiteralPolicySingleEvent.hpp b/src/policy_classes/LiteralPolicySingleEvent.hpp index 994f4eb..561e6cf 100644 --- a/src/policy_classes/LiteralPolicySingleEvent.hpp +++ b/src/policy_classes/LiteralPolicySingleEvent.hpp @@ -44,8 +44,8 @@ public srcDispatch::PolicyListener { } protected: - std::any DataInner() const { return std::make_shared(data); } - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) {} + std::any DataInner() const override { return std::make_shared(data); } + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override {} void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: diff --git a/src/policy_classes/OperatorPolicySingleEvent.hpp b/src/policy_classes/OperatorPolicySingleEvent.hpp index aea5327..73b385b 100644 --- a/src/policy_classes/OperatorPolicySingleEvent.hpp +++ b/src/policy_classes/OperatorPolicySingleEvent.hpp @@ -44,8 +44,8 @@ public srcDispatch::PolicyListener { } protected: - std::any DataInner() const { return std::make_shared(data); } - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) {} + std::any DataInner() const override { return std::make_shared(data); } + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override {} void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} private: From 2d26750f58a9ca9e383dbe6426b391c2a96c51fb Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 26 Nov 2024 12:40:18 +0900 Subject: [PATCH 073/149] Collect globals --- src/policy_classes/UnitPolicySingleEvent.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/policy_classes/UnitPolicySingleEvent.hpp b/src/policy_classes/UnitPolicySingleEvent.hpp index 73ab69a..ccab5c0 100644 --- a/src/policy_classes/UnitPolicySingleEvent.hpp +++ b/src/policy_classes/UnitPolicySingleEvent.hpp @@ -10,6 +10,7 @@ #include +#include #include #include @@ -27,6 +28,7 @@ class UnitPolicy : public srcDispatch::PolicyListener { public: + DeclTypePolicy* declPolicy; FunctionPolicy* functionPolicy; ClassPolicy * classPolicy; @@ -39,6 +41,7 @@ class UnitPolicy : } ~UnitPolicy() { + if(declPolicy) delete declPolicy; if(functionPolicy) delete functionPolicy; if(classPolicy) delete classPolicy; } @@ -94,6 +97,14 @@ class UnitPolicy : closeEventMap[ParserState::constructor] = endFunction; closeEventMap[ParserState::destructor] = endFunction; + openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { + if(!declPolicy) declPolicy = new DeclTypePolicy{this}; + ctx.dispatcher->AddListenerDispatch(declPolicy); + }; + + closeEventMap[ParserState::declstmt] = [](srcSAXEventContext& ctx) { + }; + } }; From 33941b6a14295493a35f3e5b6a07e2f752050462 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 5 Dec 2024 10:40:37 +0900 Subject: [PATCH 074/149] Fix uninitialized data member --- src/policy_classes/UnitPolicySingleEvent.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/policy_classes/UnitPolicySingleEvent.hpp b/src/policy_classes/UnitPolicySingleEvent.hpp index ccab5c0..9dd98da 100644 --- a/src/policy_classes/UnitPolicySingleEvent.hpp +++ b/src/policy_classes/UnitPolicySingleEvent.hpp @@ -35,6 +35,7 @@ class UnitPolicy : public: UnitPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), + declPolicy(nullptr), functionPolicy(nullptr), classPolicy(nullptr) { InitializeUnitPolicyHandlers(); From f18386f2249a6fa797782f0de1b545e481b2a80a Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 5 Dec 2024 12:54:19 +0900 Subject: [PATCH 075/149] Use unique ptr instead of raw ptr --- src/dispatcher/srcDispatchUtilities.hpp | 7 +++++ src/policy_classes/UnitPolicySingleEvent.hpp | 30 ++++++++------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 13bd867..f2dd6d2 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -38,6 +38,7 @@ #define INCLUDED_SRCSAX_EVENT_DISPATCH_UTILITIES_HPP namespace srcDispatch { + class EventDispatcher; enum ElementState {open, close}; enum ParserState {decl, expr, parameter, declstmt, exprstmt, parameterlist, elseif, elsestmt, @@ -471,6 +472,12 @@ namespace srcDispatch { } }; + + template + constexpr std::unique_ptr make_unique_policy(std::initializer_list&& args) { + return std::make_unique(args); + } + } #endif diff --git a/src/policy_classes/UnitPolicySingleEvent.hpp b/src/policy_classes/UnitPolicySingleEvent.hpp index 9dd98da..bb6f7e1 100644 --- a/src/policy_classes/UnitPolicySingleEvent.hpp +++ b/src/policy_classes/UnitPolicySingleEvent.hpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -28,24 +29,17 @@ class UnitPolicy : public srcDispatch::PolicyListener { public: - DeclTypePolicy* declPolicy; - FunctionPolicy* functionPolicy; - ClassPolicy * classPolicy; + std::unique_ptr declPolicy; + std::unique_ptr functionPolicy; + std::unique_ptr classPolicy; public: UnitPolicy(std::initializer_list listeners) : - srcDispatch::PolicyDispatcher(listeners), - declPolicy(nullptr), - functionPolicy(nullptr), - classPolicy(nullptr) { + srcDispatch::PolicyDispatcher(listeners) { InitializeUnitPolicyHandlers(); } - ~UnitPolicy() { - if(declPolicy) delete declPolicy; - if(functionPolicy) delete functionPolicy; - if(classPolicy) delete classPolicy; - } + ~UnitPolicy() {} void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { // Assumes at least one lister which should always be one @@ -64,8 +58,8 @@ class UnitPolicy : // start of policy std::function startClassPolicy = [this](srcSAXEventContext& ctx) { - if(!classPolicy) classPolicy = new ClassPolicy{this}; - ctx.dispatcher->AddListenerDispatch(classPolicy); + if(!classPolicy) classPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(classPolicy.get()); }; openEventMap[ParserState::classn] = startClassPolicy; @@ -80,8 +74,8 @@ class UnitPolicy : // start function of policy std::function startFunction = [this](srcSAXEventContext& ctx) { - if(!functionPolicy) functionPolicy = new FunctionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(functionPolicy); + if(!functionPolicy) functionPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(functionPolicy.get()); }; @@ -99,8 +93,8 @@ class UnitPolicy : closeEventMap[ParserState::destructor] = endFunction; openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - if(!declPolicy) declPolicy = new DeclTypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(declPolicy); + if(!declPolicy) declPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(declPolicy.get()); }; closeEventMap[ParserState::declstmt] = [](srcSAXEventContext& ctx) { From 8bb10f6eb2af2d5163906d7214b65e6aaeb6edad Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 5 Dec 2024 13:42:09 +0900 Subject: [PATCH 076/149] Finish moving all raw pointer's of policy to unique ptr --- src/policy_classes/BlockPolicySingleEvent.cpp | 59 +++++++------------ src/policy_classes/BlockPolicySingleEvent.hpp | 18 +++--- src/policy_classes/CallPolicySingleEvent.cpp | 13 ++-- src/policy_classes/CallPolicySingleEvent.hpp | 8 +-- src/policy_classes/ClassPolicySingleEvent.hpp | 37 +++++------- .../ConditionPolicySingleEvent.hpp | 14 ++--- .../ConditionalPolicySingleEvent.hpp | 21 +++---- .../ControlPolicySingleEvent.hpp | 41 +++++-------- src/policy_classes/DeclPolicySingleEvent.hpp | 37 +++++------- .../DeclTypePolicySingleEvent.hpp | 10 ++-- .../ExprStmtPolicySingleEvent.hpp | 17 +++--- .../ExpressionPolicySingleEvent.cpp | 23 +++----- .../ExpressionPolicySingleEvent.hpp | 14 ++--- src/policy_classes/ForPolicySingleEvent.hpp | 21 +++---- .../FunctionPolicySingleEvent.hpp | 37 +++++------- .../IfStmtPolicySingleEvent.hpp | 29 ++++----- src/policy_classes/IncrPolicySingleEvent.hpp | 17 +++--- src/policy_classes/NamePolicySingleEvent.cpp | 23 +++----- src/policy_classes/NamePolicySingleEvent.hpp | 18 +++--- .../ReturnPolicySingleEvent.hpp | 17 +++--- .../TemplateArgumentListPolicySingleEvent.cpp | 12 ++-- .../TemplateArgumentListPolicySingleEvent.hpp | 7 +-- src/policy_classes/TypePolicySingleEvent.cpp | 13 ++-- src/policy_classes/TypePolicySingleEvent.hpp | 2 +- 24 files changed, 198 insertions(+), 310 deletions(-) diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp index 5702ad5..a03d52b 100644 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -18,30 +18,11 @@ BlockPolicy::BlockPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - blockDepth(0), - declstmtPolicy(nullptr), - returnPolicy(nullptr), - exprStmtPolicy(nullptr), - blockPolicy(nullptr), - ifStmtPolicy(nullptr), - switchPolicy(nullptr), - whilePolicy(nullptr), - forPolicy(nullptr), - doPolicy(nullptr) { + blockDepth(0) { InitializeBlockPolicyHandlers(); } -BlockPolicy::~BlockPolicy() { - if (declstmtPolicy) delete declstmtPolicy; - if (returnPolicy) delete returnPolicy; - if (exprStmtPolicy) delete exprStmtPolicy; - if (blockPolicy) delete blockPolicy; - if (ifStmtPolicy) delete ifStmtPolicy; - if (switchPolicy) delete switchPolicy; - if (whilePolicy) delete whilePolicy; - if (forPolicy) delete forPolicy; - if (doPolicy) delete doPolicy; -} +BlockPolicy::~BlockPolicy() {} std::any BlockPolicy::DataInner() const { return std::make_shared(data); } @@ -97,8 +78,8 @@ void BlockPolicy::CollectBlockHandlers() { data = BlockData{}; data.startLineNumber = ctx.currentLineNumber; } else { - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); + if (!blockPolicy) blockPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); } }; @@ -116,32 +97,32 @@ void BlockPolicy::CollectBlockHandlers() { void BlockPolicy::CollectReturnHandlers() { using namespace srcDispatch; openEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { - if (!returnPolicy) returnPolicy = new ReturnPolicy{this}; - ctx.dispatcher->AddListenerDispatch(returnPolicy); + if (!returnPolicy) returnPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(returnPolicy.get()); }; } void BlockPolicy::CollectExpressionHandlers() { using namespace srcDispatch; openEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { - if (!exprStmtPolicy) exprStmtPolicy = new ExprStmtPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprStmtPolicy); + if (!exprStmtPolicy) exprStmtPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(exprStmtPolicy.get()); }; } void BlockPolicy::CollectDeclstmtHandlers() { using namespace srcDispatch; openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - if (!declstmtPolicy) declstmtPolicy = new DeclTypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(declstmtPolicy); + if (!declstmtPolicy) declstmtPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(declstmtPolicy.get()); }; } void BlockPolicy::CollectIfStmtHandlers() { using namespace srcDispatch; openEventMap[ParserState::ifgroup] = [this](srcSAXEventContext& ctx) { - if (!ifStmtPolicy) ifStmtPolicy = new IfStmtPolicy{this}; - ctx.dispatcher->AddListenerDispatch(ifStmtPolicy); + if (!ifStmtPolicy) ifStmtPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(ifStmtPolicy.get()); }; } @@ -149,8 +130,8 @@ void BlockPolicy::CollectIfStmtHandlers() { void BlockPolicy::CollectSwitchHandlers() { using namespace srcDispatch; openEventMap[ParserState::switchstmt] = [this](srcSAXEventContext& ctx) { - if (!switchPolicy) switchPolicy = new SwitchPolicy{this}; - ctx.dispatcher->AddListenerDispatch(switchPolicy); + if (!switchPolicy) switchPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(switchPolicy.get()); }; } @@ -158,8 +139,8 @@ void BlockPolicy::CollectSwitchHandlers() { void BlockPolicy::CollectWhileHandlers() { using namespace srcDispatch; openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { - if (!whilePolicy) whilePolicy = new WhilePolicy{this}; - ctx.dispatcher->AddListenerDispatch(whilePolicy); + if (!whilePolicy) whilePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(whilePolicy.get()); }; } @@ -167,8 +148,8 @@ void BlockPolicy::CollectWhileHandlers() { void BlockPolicy::CollectForHandlers() { using namespace srcDispatch; openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { - if (!forPolicy) forPolicy = new ForPolicy{this}; - ctx.dispatcher->AddListenerDispatch(forPolicy); + if (!forPolicy) forPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(forPolicy.get()); }; } @@ -176,8 +157,8 @@ void BlockPolicy::CollectForHandlers() { void BlockPolicy::CollectDoHandlers() { using namespace srcDispatch; openEventMap[ParserState::dostmt] = [this](srcSAXEventContext& ctx) { - if (!doPolicy) doPolicy = new DoPolicy{this}; - ctx.dispatcher->AddListenerDispatch(doPolicy); + if (!doPolicy) doPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(doPolicy.get()); }; } diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index 2ee9dc1..43d1dcf 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -48,15 +48,15 @@ public srcDispatch::PolicyListener { BlockData data; std::size_t blockDepth; - DeclTypePolicy * declstmtPolicy; - ReturnPolicy * returnPolicy; - ExprStmtPolicy * exprStmtPolicy; - BlockPolicy * blockPolicy; - IfStmtPolicy * ifStmtPolicy; - SwitchPolicy * switchPolicy; - WhilePolicy * whilePolicy; - ForPolicy * forPolicy; - DoPolicy * doPolicy; + std::unique_ptr declstmtPolicy; + std::unique_ptr returnPolicy; + std::unique_ptr exprStmtPolicy; + std::unique_ptr blockPolicy; + std::unique_ptr ifStmtPolicy; + std::unique_ptr switchPolicy; + std::unique_ptr whilePolicy; + std::unique_ptr forPolicy; + std::unique_ptr doPolicy; public: BlockPolicy(std::initializer_list listeners); diff --git a/src/policy_classes/CallPolicySingleEvent.cpp b/src/policy_classes/CallPolicySingleEvent.cpp index c68a44f..b05e641 100644 --- a/src/policy_classes/CallPolicySingleEvent.cpp +++ b/src/policy_classes/CallPolicySingleEvent.cpp @@ -16,10 +16,7 @@ std::ostream& operator<<(std::ostream& out, const CallData &call) { return out; } -CallPolicy::~CallPolicy() { - if (namePolicy) delete namePolicy; - if (expressionPolicy) delete expressionPolicy; -} +CallPolicy::~CallPolicy() {} std::any CallPolicy::DataInner() const { return std::make_shared(data); } @@ -63,8 +60,8 @@ void CallPolicy::InitializeCallPolicyHandlers() { void CallPolicy::CollectNameHandlers() { using namespace srcDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if(!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); + if(!namePolicy) namePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); }; } @@ -72,8 +69,8 @@ void CallPolicy::CollectNameHandlers() { void CallPolicy::CollectCallArgumentHandlers() { using namespace srcDispatch; openEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { - if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(expressionPolicy); + if(!expressionPolicy) expressionPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(expressionPolicy.get()); }; } diff --git a/src/policy_classes/CallPolicySingleEvent.hpp b/src/policy_classes/CallPolicySingleEvent.hpp index 8e7407b..c17abd0 100644 --- a/src/policy_classes/CallPolicySingleEvent.hpp +++ b/src/policy_classes/CallPolicySingleEvent.hpp @@ -45,16 +45,14 @@ public srcDispatch::PolicyListener { private: CallData data; std::size_t callDepth; - NamePolicy * namePolicy; - ExpressionPolicy* expressionPolicy; + std::unique_ptr namePolicy; + std::unique_ptr expressionPolicy; public: CallPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - callDepth(0), - namePolicy(nullptr), - expressionPolicy(nullptr) { + callDepth(0) { InitializeCallPolicyHandlers(); } diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index 9edaf86..53f7a08 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -62,30 +62,21 @@ public srcDispatch::PolicyListener { std::size_t classDepth; ClassData::AccessSpecifier currentRegion; - NamePolicy * namePolicy; - DeclTypePolicy* declPolicy; - FunctionPolicy* functionPolicy; - ClassPolicy * classPolicy; + std::unique_ptr namePolicy; + std::unique_ptr declPolicy; + std::unique_ptr functionPolicy; + std::unique_ptr classPolicy; public: ClassPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, classDepth(0), - currentRegion(ClassData::PUBLIC), - namePolicy(nullptr), - declPolicy(nullptr), - functionPolicy(nullptr), - classPolicy(nullptr) { + currentRegion(ClassData::PUBLIC) { InitializeClassPolicyHandlers(); } - ~ClassPolicy() { - if (namePolicy) delete namePolicy; - if (declPolicy) delete declPolicy; - if (functionPolicy) delete functionPolicy; - if (classPolicy) delete classPolicy; - } + ~ClassPolicy() {} void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(NamePolicy) == typeid(*policy)) { @@ -146,8 +137,8 @@ public srcDispatch::PolicyListener { CollectSuperHanders(); CollectBlockHanders(); } else if ((classDepth + 3) == ctx.depth) { - if (!classPolicy) classPolicy = new ClassPolicy{this}; - ctx.dispatcher->AddListenerDispatch(classPolicy); + if (!classPolicy) classPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(classPolicy.get()); } }; @@ -170,8 +161,8 @@ public srcDispatch::PolicyListener { using namespace srcDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if ((classDepth + 1) == ctx.depth) { - if (!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); + if (!namePolicy) namePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); } }; closeEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { @@ -232,14 +223,14 @@ public srcDispatch::PolicyListener { // set up to listen to decl_stmt, member, and class policies openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { if ((classDepth + 3) == ctx.depth) { - if (!declPolicy) declPolicy = new DeclTypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(declPolicy); + if (!declPolicy) declPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(declPolicy.get()); } }; std::function functionEvent = [this](srcSAXEventContext& ctx) { if ((classDepth + 3) == ctx.depth) { - if (!functionPolicy) functionPolicy = new FunctionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(functionPolicy); + if (!functionPolicy) functionPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(functionPolicy.get()); } }; openEventMap[ParserState::function] = functionEvent; diff --git a/src/policy_classes/ConditionPolicySingleEvent.hpp b/src/policy_classes/ConditionPolicySingleEvent.hpp index 07e7b38..b66e1a1 100644 --- a/src/policy_classes/ConditionPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionPolicySingleEvent.hpp @@ -25,9 +25,9 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - std::shared_ptr data; - std::size_t conditionDepth; - ExpressionPolicy* exprPolicy; + std::shared_ptr data; + std::size_t conditionDepth; + std::unique_ptr exprPolicy; public: ConditionPolicy(std::initializer_list listeners) @@ -38,9 +38,7 @@ public srcDispatch::PolicyListener { InitializeConditionPolicyHandlers(); } - ~ConditionPolicy() { - if (exprPolicy) delete exprPolicy; - } + ~ConditionPolicy() {} protected: std::any DataInner() const override { return data; } @@ -81,8 +79,8 @@ public srcDispatch::PolicyListener { void CollectExpressionHandlers() { using namespace srcDispatch; openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprPolicy); + if (!exprPolicy) exprPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); }; } diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index be72a95..d3f58ff 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -26,23 +26,18 @@ public srcDispatch::PolicyListener { protected: ConditionalData data; std::size_t conditionalDepth; - ConditionPolicy* conditionPolicy; - BlockPolicy * blockPolicy; + std::unique_ptr conditionPolicy; + std::unique_ptr blockPolicy; public: ConditionalPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - conditionalDepth(0), - conditionPolicy(nullptr), - blockPolicy(nullptr) { + conditionalDepth(0) { InitializeConditionalPolicyHandlers(); } - ~ConditionalPolicy() { - if (conditionPolicy) delete conditionPolicy; - if (blockPolicy) delete blockPolicy; - } + ~ConditionalPolicy() {} protected: std::any DataInner() const override { return std::make_shared(data); } @@ -91,8 +86,8 @@ public srcDispatch::PolicyListener { if(!conditionalDepth) return; if((conditionalDepth + 1) != ctx.depth) return; - if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(conditionPolicy); + if (!conditionPolicy) conditionPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(conditionPolicy.get()); }; } @@ -102,8 +97,8 @@ public srcDispatch::PolicyListener { if(!conditionalDepth) return; if((conditionalDepth + 1) != ctx.depth) return; - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); + if (!blockPolicy) blockPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); }; } }; diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp index 6b6e058..4787a2f 100644 --- a/src/policy_classes/ControlPolicySingleEvent.hpp +++ b/src/policy_classes/ControlPolicySingleEvent.hpp @@ -60,31 +60,22 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - ControlData data; - std::size_t controlDepth; - DeclPolicy * declPolicy; - ExpressionPolicy* exprPolicy; - ConditionPolicy * conditionPolicy; - IncrPolicy * incrPolicy; + ControlData data; + std::size_t controlDepth; + std::unique_ptr declPolicy; + std::unique_ptr exprPolicy; + std::unique_ptr conditionPolicy; + std::unique_ptr incrPolicy; public: ControlPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - controlDepth(0), - declPolicy(nullptr), - exprPolicy(nullptr), - conditionPolicy(nullptr), - incrPolicy(nullptr) { + controlDepth(0) { InitializeControlPolicyHandlers(); } - ~ControlPolicy() { - if (declPolicy) delete declPolicy; - if (exprPolicy) delete exprPolicy; - if (conditionPolicy) delete conditionPolicy; - if (incrPolicy) delete incrPolicy; - } + ~ControlPolicy() {} protected: std::any DataInner() const override { return std::make_shared(data); } @@ -140,14 +131,14 @@ public srcDispatch::PolicyListener { openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { if(ctx.depth != (controlDepth + 2)) return; - if (!declPolicy) declPolicy = new DeclPolicy{this}; - ctx.dispatcher->AddListenerDispatch(declPolicy); + if (!declPolicy) declPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(declPolicy.get()); }; openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { if(ctx.depth != (controlDepth + 2)) return; - if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprPolicy); + if (!exprPolicy) exprPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); }; }; closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { @@ -162,8 +153,8 @@ public srcDispatch::PolicyListener { openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { if(ctx.depth != (controlDepth + 1)) return; - if (!conditionPolicy) conditionPolicy = new ConditionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(conditionPolicy); + if (!conditionPolicy) conditionPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(conditionPolicy.get()); }; } @@ -172,8 +163,8 @@ public srcDispatch::PolicyListener { openEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { if(ctx.depth != (controlDepth + 1)) return; openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprPolicy); + if (!exprPolicy) exprPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); }; }; closeEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { diff --git a/src/policy_classes/DeclPolicySingleEvent.hpp b/src/policy_classes/DeclPolicySingleEvent.hpp index 59c4f3b..3243d99 100644 --- a/src/policy_classes/DeclPolicySingleEvent.hpp +++ b/src/policy_classes/DeclPolicySingleEvent.hpp @@ -52,28 +52,21 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - DeclData data; - std::size_t declDepth; - TypePolicy * typePolicy; - NamePolicy * namePolicy; - ExpressionPolicy* exprPolicy; + DeclData data; + std::size_t declDepth; + std::unique_ptr typePolicy; + std::unique_ptr namePolicy; + std::unique_ptr exprPolicy; public: DeclPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - declDepth(0), - typePolicy(nullptr), - namePolicy(nullptr), - exprPolicy(nullptr) { + declDepth(0) { InitializeDeclPolicyHandlers(); } - ~DeclPolicy() { - if (typePolicy) delete typePolicy; - if (namePolicy) delete namePolicy; - if (exprPolicy) delete exprPolicy; - } + ~DeclPolicy() {} protected: std::any DataInner() const override { return std::make_shared(data); } @@ -152,8 +145,8 @@ public srcDispatch::PolicyListener { openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { if(!declDepth || (declDepth + 1) != ctx.depth) return; - if (!typePolicy) typePolicy = new TypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(typePolicy); + if (!typePolicy) typePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(typePolicy.get()); }; } @@ -162,8 +155,8 @@ public srcDispatch::PolicyListener { openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if(!declDepth || (declDepth + 1) != ctx.depth) return; - if (!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); + if (!namePolicy) namePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); }; } @@ -173,8 +166,8 @@ public srcDispatch::PolicyListener { if(!declDepth || (declDepth + 1) != ctx.depth) return; openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(!exprPolicy) exprPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprPolicy); + if(!exprPolicy) exprPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); }; }; closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { @@ -190,8 +183,8 @@ public srcDispatch::PolicyListener { if(!declDepth || (declDepth + 1) != ctx.depth) return; openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(!exprPolicy) exprPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprPolicy); + if(!exprPolicy) exprPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); }; }; closeEventMap[ParserState::range] = [this](srcSAXEventContext& ctx) { diff --git a/src/policy_classes/DeclTypePolicySingleEvent.hpp b/src/policy_classes/DeclTypePolicySingleEvent.hpp index 6b0507e..b67b985 100644 --- a/src/policy_classes/DeclTypePolicySingleEvent.hpp +++ b/src/policy_classes/DeclTypePolicySingleEvent.hpp @@ -24,7 +24,7 @@ public srcDispatch::PolicyListener { private: std::vector> decls; std::size_t declDepth; - DeclPolicy* declPolicy; + std::unique_ptr declPolicy; public: DeclTypePolicy(std::initializer_list listeners) @@ -35,9 +35,7 @@ public srcDispatch::PolicyListener { InitializeDeclTypePolicyHandlers(); } - ~DeclTypePolicy() { - if (declPolicy) delete declPolicy; - } + ~DeclTypePolicy() {} protected: std::any DataInner() const override { return std::make_shared>>(decls); } @@ -94,8 +92,8 @@ public srcDispatch::PolicyListener { openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { if(!declDepth || (declDepth + 1) != ctx.depth) return; - if (!declPolicy) declPolicy = new DeclPolicy{this}; - ctx.dispatcher->AddListenerDispatch(declPolicy); + if (!declPolicy) declPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(declPolicy.get()); }; } diff --git a/src/policy_classes/ExprStmtPolicySingleEvent.hpp b/src/policy_classes/ExprStmtPolicySingleEvent.hpp index 6e321e4..7263423 100644 --- a/src/policy_classes/ExprStmtPolicySingleEvent.hpp +++ b/src/policy_classes/ExprStmtPolicySingleEvent.hpp @@ -23,22 +23,19 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - std::shared_ptr data; - std::size_t exprStmtDepth; - ExpressionPolicy* exprPolicy; + std::shared_ptr data; + std::size_t exprStmtDepth; + std::unique_ptr exprPolicy; public: ExprStmtPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - exprStmtDepth(0), - exprPolicy(nullptr) { + exprStmtDepth(0) { InitializeExprStmtPolicyHandlers(); } - ~ExprStmtPolicy() { - if (exprPolicy) delete exprPolicy; - } + ~ExprStmtPolicy() {} protected: std::any DataInner() const override { return data; } @@ -79,8 +76,8 @@ public srcDispatch::PolicyListener { void CollectExpressionHandlers() { using namespace srcDispatch; openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprPolicy); + if (!exprPolicy) exprPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); }; } diff --git a/src/policy_classes/ExpressionPolicySingleEvent.cpp b/src/policy_classes/ExpressionPolicySingleEvent.cpp index 33ad72f..89e65fa 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.cpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.cpp @@ -25,12 +25,7 @@ std::ostream& operator<<(std::ostream& out, const ExpressionData& ex) { return out; } -ExpressionPolicy::~ExpressionPolicy() { - if(namePolicy) delete namePolicy; - if(operatorPolicy) delete operatorPolicy; - if(literalPolicy) delete literalPolicy; - if(callPolicy) delete callPolicy; -} +ExpressionPolicy::~ExpressionPolicy() {} void ExpressionPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { if(typeid(NamePolicy) == typeid(*policy)) { @@ -81,31 +76,31 @@ void ExpressionPolicy::InitializeExpressionPolicyHandlers() { void ExpressionPolicy::CollectNameHandlers() { using namespace srcDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if(!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); + if(!namePolicy) namePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); }; } void ExpressionPolicy::CollectCallHandlers() { using namespace srcDispatch; openEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { - if(!callPolicy) callPolicy = new CallPolicy{this}; - ctx.dispatcher->AddListenerDispatch(callPolicy); + if(!callPolicy) callPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(callPolicy.get()); }; } void ExpressionPolicy::CollectOperatorHandlers() { using namespace srcDispatch; openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { - if(!operatorPolicy) operatorPolicy = new OperatorPolicy{this}; - ctx.dispatcher->AddListenerDispatch(operatorPolicy); + if(!operatorPolicy) operatorPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(operatorPolicy.get()); }; } void ExpressionPolicy::CollectLiteralHandlers() { using namespace srcDispatch; openEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { - if(!literalPolicy) literalPolicy = new LiteralPolicy{this}; - ctx.dispatcher->AddListenerDispatch(literalPolicy); + if(!literalPolicy) literalPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(literalPolicy.get()); }; } diff --git a/src/policy_classes/ExpressionPolicySingleEvent.hpp b/src/policy_classes/ExpressionPolicySingleEvent.hpp index 52c8de0..c91d088 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.hpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.hpp @@ -44,20 +44,16 @@ public srcDispatch::PolicyListener { private: ExpressionData data; std::size_t exprDepth; - NamePolicy * namePolicy; - OperatorPolicy* operatorPolicy; - LiteralPolicy * literalPolicy; - CallPolicy * callPolicy; + std::unique_ptr namePolicy; + std::unique_ptr operatorPolicy; + std::unique_ptr literalPolicy; + std::unique_ptr callPolicy; public: ExpressionPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - exprDepth(0), - namePolicy(nullptr), - operatorPolicy(nullptr), - literalPolicy(nullptr), - callPolicy(nullptr) { + exprDepth(0) { InitializeExpressionPolicyHandlers(); } diff --git a/src/policy_classes/ForPolicySingleEvent.hpp b/src/policy_classes/ForPolicySingleEvent.hpp index a03cedd..30c20b4 100644 --- a/src/policy_classes/ForPolicySingleEvent.hpp +++ b/src/policy_classes/ForPolicySingleEvent.hpp @@ -43,24 +43,19 @@ public srcDispatch::PolicyListener { private: ForData data; std::size_t forDepth; - ControlPolicy * controlPolicy; - BlockPolicy * blockPolicy; + std::unique_ptr controlPolicy; + std::unique_ptr blockPolicy; public: ForPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - forDepth(0), - controlPolicy(nullptr), - blockPolicy(nullptr) { + forDepth(0) { InitializeForPolicyHandlers(); } - ~ForPolicy() { - if (controlPolicy) delete controlPolicy; - if (blockPolicy) delete blockPolicy; - } + ~ForPolicy() {} protected: std::any DataInner() const { return std::make_shared(data); } @@ -112,8 +107,8 @@ public srcDispatch::PolicyListener { if(!forDepth) return; if((forDepth + 1) != ctx.depth) return; - if (!controlPolicy) controlPolicy = new ControlPolicy{this}; - ctx.dispatcher->AddListenerDispatch(controlPolicy); + if (!controlPolicy) controlPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(controlPolicy.get()); }; } @@ -121,8 +116,8 @@ public srcDispatch::PolicyListener { using namespace srcDispatch; openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { if(forDepth && (forDepth + 1) == ctx.depth) { - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); + if (!blockPolicy) blockPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); } }; } diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index 5c97437..378368e 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -90,29 +90,20 @@ public srcDispatch::PolicyListener { FunctionData data; std::size_t functionDepth; - TypePolicy * typePolicy; - NamePolicy * namePolicy; - DeclTypePolicy* declPolicy; - BlockPolicy * blockPolicy; + std::unique_ptr typePolicy; + std::unique_ptr namePolicy; + std::unique_ptr declPolicy; + std::unique_ptr blockPolicy; public: FunctionPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - functionDepth(0), - typePolicy(nullptr), - namePolicy(nullptr), - declPolicy(nullptr), - blockPolicy(nullptr) { + functionDepth(0) { InitializeFunctionPolicyHandlers(); } - ~FunctionPolicy() { - if (typePolicy) delete typePolicy; - if (namePolicy) delete namePolicy; - if (declPolicy) delete declPolicy; - if (blockPolicy) delete blockPolicy; - } + ~FunctionPolicy() {} protected: std::any DataInner() const override { return std::make_shared(data); } @@ -209,8 +200,8 @@ public srcDispatch::PolicyListener { using namespace srcDispatch; openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { if (functionDepth && (functionDepth + 1) == ctx.depth) { - if (!typePolicy) typePolicy = new TypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(typePolicy); + if (!typePolicy) typePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(typePolicy.get()); } }; } @@ -219,8 +210,8 @@ public srcDispatch::PolicyListener { using namespace srcDispatch; openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if (functionDepth && (functionDepth + 1) == ctx.depth) { - if (!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); + if (!namePolicy) namePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); } }; } @@ -231,8 +222,8 @@ public srcDispatch::PolicyListener { if (functionDepth && (functionDepth + 1) == ctx.depth) { openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { if (functionDepth && (functionDepth + 2) == ctx.depth) { - if (!declPolicy) declPolicy = new DeclTypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(declPolicy); + if (!declPolicy) declPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(declPolicy.get()); } }; } @@ -277,8 +268,8 @@ public srcDispatch::PolicyListener { using namespace srcDispatch; openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { if (functionDepth && (functionDepth + 1) == ctx.depth) { - if (!blockPolicy) blockPolicy = new BlockPolicy{this}; - ctx.dispatcher->AddListenerDispatch(blockPolicy); + if (!blockPolicy) blockPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); } }; } diff --git a/src/policy_classes/IfStmtPolicySingleEvent.hpp b/src/policy_classes/IfStmtPolicySingleEvent.hpp index 8f0ecf4..520c042 100644 --- a/src/policy_classes/IfStmtPolicySingleEvent.hpp +++ b/src/policy_classes/IfStmtPolicySingleEvent.hpp @@ -40,26 +40,19 @@ public srcDispatch::PolicyListener { private: IfStmtData data; std::size_t ifStmtDepth; - IfPolicy * ifPolicy; - ElseIfPolicy * elseIfPolicy; - ElsePolicy * elsePolicy; + std::unique_ptr ifPolicy; + std::unique_ptr elseIfPolicy; + std::unique_ptr elsePolicy; public: IfStmtPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - ifStmtDepth(0), - ifPolicy(nullptr), - elseIfPolicy(nullptr), - elsePolicy(nullptr) { + ifStmtDepth(0) { InitializeIfStmtPolicyHandlers(); } - ~IfStmtPolicy() { - if (ifPolicy) delete ifPolicy; - if (elseIfPolicy) delete elseIfPolicy; - if (elsePolicy) delete elsePolicy; - } + ~IfStmtPolicy() {} protected: std::any DataInner() const { return std::make_shared(data); } @@ -112,8 +105,8 @@ public srcDispatch::PolicyListener { if(!ifStmtDepth) return; if((ifStmtDepth + 1) != ctx.depth) return; - if (!ifPolicy) ifPolicy = new IfPolicy{this}; - ctx.dispatcher->AddListenerDispatch(ifPolicy); + if (!ifPolicy) ifPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(ifPolicy.get()); }; } @@ -123,8 +116,8 @@ public srcDispatch::PolicyListener { if(!ifStmtDepth) return; if((ifStmtDepth + 1) != ctx.depth) return; - if (!elseIfPolicy) elseIfPolicy = new ElseIfPolicy{this}; - ctx.dispatcher->AddListenerDispatch(elseIfPolicy); + if (!elseIfPolicy) elseIfPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(elseIfPolicy.get()); }; } @@ -134,8 +127,8 @@ public srcDispatch::PolicyListener { if(!ifStmtDepth) return; if((ifStmtDepth + 1) != ctx.depth) return; - if (!elsePolicy) elsePolicy = new ElsePolicy{this}; - ctx.dispatcher->AddListenerDispatch(elsePolicy); + if (!elsePolicy) elsePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(elsePolicy.get()); }; } }; diff --git a/src/policy_classes/IncrPolicySingleEvent.hpp b/src/policy_classes/IncrPolicySingleEvent.hpp index 1cd27e5..daf54de 100644 --- a/src/policy_classes/IncrPolicySingleEvent.hpp +++ b/src/policy_classes/IncrPolicySingleEvent.hpp @@ -34,22 +34,19 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - IncrData data; - std::size_t incrDepth; - ExpressionPolicy* exprPolicy; + IncrData data; + std::size_t incrDepth; + std::unique_ptr exprPolicy; public: IncrPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - incrDepth(0), - exprPolicy(nullptr) { + incrDepth(0) { InitializeIncrPolicyHandlers(); } - ~IncrPolicy() { - if (exprPolicy) delete exprPolicy; - } + ~IncrPolicy() {} protected: std::any DataInner() const override { return std::make_shared(data); } @@ -95,8 +92,8 @@ public srcDispatch::PolicyListener { if(!incrDepth) return; if((incrDepth + 1) != ctx.depth) return; - if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprPolicy); + if (!exprPolicy) exprPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); }; } }; diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index 6f7e591..99dfcdc 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -58,12 +58,7 @@ std::ostream& operator<<(std::ostream& out, const NameData& nameData) { return out; } -NamePolicy::~NamePolicy() { - if (namePolicy) delete namePolicy; - if (operatorPolicy) delete operatorPolicy; - if (templateArgumentListPolicy) delete templateArgumentListPolicy; - if (expressionPolicy) delete expressionPolicy; -} +NamePolicy::~NamePolicy() {} void NamePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { @@ -97,8 +92,8 @@ void NamePolicy::InitializeNamePolicyHandlers() { CollectArrayIndicesHandlers(); } else if ((nameDepth + 1) == ctx.depth) { NopCloseEvents({ParserState::tokenstring}); - if (!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); + if (!namePolicy) namePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); } }; // end of policy @@ -122,8 +117,8 @@ void NamePolicy::CollectOperatorsHandlers() { if(!nameDepth) return; if((nameDepth + 1) != ctx.depth) return; - if(!operatorPolicy) operatorPolicy = new OperatorPolicy{this}; - ctx.dispatcher->AddListenerDispatch(operatorPolicy); + if(!operatorPolicy) operatorPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(operatorPolicy.get()); }; } @@ -134,8 +129,8 @@ void NamePolicy::CollectTemplateArgumentListHandlers() { if (!nameDepth) return; if((nameDepth + 1) != ctx.depth) return; - if (!templateArgumentListPolicy) templateArgumentListPolicy = new TemplateArgumentListPolicy{this}; - ctx.dispatcher->AddListenerDispatch(templateArgumentListPolicy); + if (!templateArgumentListPolicy) templateArgumentListPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(templateArgumentListPolicy.get()); }; } @@ -144,8 +139,8 @@ void NamePolicy::CollectArrayIndicesHandlers() { using namespace srcDispatch; openEventMap[ParserState::index] = [this](srcSAXEventContext& ctx) { openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(expressionPolicy); + if(!expressionPolicy) expressionPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(expressionPolicy.get()); }; }; } diff --git a/src/policy_classes/NamePolicySingleEvent.hpp b/src/policy_classes/NamePolicySingleEvent.hpp index 9fd7d56..937ab45 100644 --- a/src/policy_classes/NamePolicySingleEvent.hpp +++ b/src/policy_classes/NamePolicySingleEvent.hpp @@ -43,22 +43,18 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - NameData data; - std::size_t nameDepth; - NamePolicy * namePolicy; - OperatorPolicy * operatorPolicy; - TemplateArgumentListPolicy* templateArgumentListPolicy; - ExpressionPolicy * expressionPolicy; + NameData data; + std::size_t nameDepth; + std::unique_ptr namePolicy; + std::unique_ptr operatorPolicy; + std::unique_ptr templateArgumentListPolicy; + std::unique_ptr expressionPolicy; public: NamePolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - nameDepth(0), - namePolicy(nullptr), - operatorPolicy(nullptr), - templateArgumentListPolicy(nullptr), - expressionPolicy(nullptr) { + nameDepth(0) { InitializeNamePolicyHandlers(); } diff --git a/src/policy_classes/ReturnPolicySingleEvent.hpp b/src/policy_classes/ReturnPolicySingleEvent.hpp index 4df8e5a..8a3ddd5 100644 --- a/src/policy_classes/ReturnPolicySingleEvent.hpp +++ b/src/policy_classes/ReturnPolicySingleEvent.hpp @@ -25,22 +25,19 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - std::shared_ptr data; - std::size_t returnDepth; - ExpressionPolicy* exprPolicy; + std::shared_ptr data; + std::size_t returnDepth; + std::unique_ptr exprPolicy; public: ReturnPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - returnDepth(0), - exprPolicy(nullptr) { + returnDepth(0) { InitializeReturnPolicyHandlers(); } - ~ReturnPolicy() { - if (exprPolicy) delete exprPolicy; - } + ~ReturnPolicy() {} protected: std::any DataInner() const override { return data; } @@ -81,8 +78,8 @@ public srcDispatch::PolicyListener { void CollectExpressionHandlers() { using namespace srcDispatch; openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!exprPolicy) exprPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(exprPolicy); + if (!exprPolicy) exprPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); }; } diff --git a/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp b/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp index 028cfad..a592f02 100644 --- a/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp +++ b/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp @@ -32,15 +32,11 @@ std::ostream& operator<<(std::ostream& out, const TemplateArgumentListData& argu TemplateArgumentListPolicy::TemplateArgumentListPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - argumentListDepth(0), - namePolicy(nullptr) { + argumentListDepth(0) { InitializeTemplateArgumentListPolicyHandlers(); } -TemplateArgumentListPolicy::~TemplateArgumentListPolicy() { - if (namePolicy) delete namePolicy; - if (expressionPolicy) delete expressionPolicy; -} +TemplateArgumentListPolicy::~TemplateArgumentListPolicy() {} void TemplateArgumentListPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { if (typeid(NamePolicy) == typeid(*policy)) { @@ -91,8 +87,8 @@ void TemplateArgumentListPolicy::CollectArgumentHandler() { if(!argumentListDepth) return; if((argumentListDepth + 2) != ctx.depth) return; - if(!expressionPolicy) expressionPolicy = new ExpressionPolicy{this}; - ctx.dispatcher->AddListenerDispatch(expressionPolicy); + if(!expressionPolicy) expressionPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(expressionPolicy.get()); }; }; diff --git a/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp b/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp index 83a0440..e7bad96 100644 --- a/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp +++ b/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp @@ -43,10 +43,9 @@ public srcDispatch::PolicyListener { void CollectArgumentHandler(); private: - TemplateArgumentListData data; - std::size_t argumentListDepth; - NamePolicy * namePolicy; - ExpressionPolicy* expressionPolicy; + TemplateArgumentListData data; + std::size_t argumentListDepth; + std::unique_ptr expressionPolicy; }; diff --git a/src/policy_classes/TypePolicySingleEvent.cpp b/src/policy_classes/TypePolicySingleEvent.cpp index dc0a993..51dd3db 100644 --- a/src/policy_classes/TypePolicySingleEvent.cpp +++ b/src/policy_classes/TypePolicySingleEvent.cpp @@ -5,6 +5,8 @@ #include +#include + std::string TypeData::ToString() const { std::string type_str; for (std::size_t pos = 0; pos < types.size(); ++pos) { @@ -47,15 +49,12 @@ std::ostream& operator<<(std::ostream& out, const TypeData& typeData) { TypePolicy::TypePolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - typeDepth(0), - namePolicy(nullptr) { + typeDepth(0) { InitializeTypePolicyHandlers(); } -TypePolicy::~TypePolicy(){ - if (namePolicy) delete namePolicy; -} +TypePolicy::~TypePolicy() {} void TypePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { //this causes undefined behavior if types is empty @@ -96,8 +95,8 @@ void TypePolicy::CollectNamesHandler() { openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { if (typeDepth && (typeDepth + 1) == ctx.depth) { data.types.push_back(std::make_pair(std::shared_ptr(), TypeData::TYPENAME)); - if (!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); + if (!namePolicy) namePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); } }; } diff --git a/src/policy_classes/TypePolicySingleEvent.hpp b/src/policy_classes/TypePolicySingleEvent.hpp index 56d343e..6b24d2e 100644 --- a/src/policy_classes/TypePolicySingleEvent.hpp +++ b/src/policy_classes/TypePolicySingleEvent.hpp @@ -32,7 +32,7 @@ public srcDispatch::PolicyListener { private: TypeData data; std::size_t typeDepth; - NamePolicy * namePolicy; + std::unique_ptr namePolicy; public: TypePolicy(std::initializer_list listeners); From 02a32b5a7b57ac5698b9a6c40b0bdb6889642a7e Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 6 Dec 2024 17:13:21 +0900 Subject: [PATCH 077/149] Collect decl stmt in condition --- .../ConditionPolicySingleEvent.hpp | 45 +++++++++++++++---- .../ConditionalPolicySingleEvent.hpp | 6 +-- .../ControlPolicySingleEvent.hpp | 4 +- src/policy_classes/DoPolicySingleEvent.hpp | 4 +- .../ElseIfPolicySingleEvent.hpp | 4 +- src/policy_classes/ElsePolicySingleEvent.hpp | 4 +- src/policy_classes/IfPolicySingleEvent.hpp | 4 +- .../SwitchPolicySingleEvent.hpp | 4 +- src/policy_classes/WhilePolicySingleEvent.hpp | 4 +- 9 files changed, 54 insertions(+), 25 deletions(-) diff --git a/src/policy_classes/ConditionPolicySingleEvent.hpp b/src/policy_classes/ConditionPolicySingleEvent.hpp index b66e1a1..4d51051 100644 --- a/src/policy_classes/ConditionPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionPolicySingleEvent.hpp @@ -11,11 +11,30 @@ #include #include +#include #include #include #include +struct ConditionData { + std::shared_ptr expr; + std::vector> decls; + + friend std::ostream& operator<<(std::ostream& out, const ConditionData& condition) { + bool outputDecl = false; + for(const std::shared_ptr& decl : condition.decls) { + if(outputDecl) out << ", "; + out << *decl; + outputDecl = true; + } + + if(outputDecl) out << "; "; + out << *condition.expr; + + return out; + } +}; // Collect the expression in the return // @@ -25,31 +44,32 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - std::shared_ptr data; + ConditionData data; std::size_t conditionDepth; std::unique_ptr exprPolicy; - + std::unique_ptr declTypePolicy; public: ConditionPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{}, - conditionDepth(0), - exprPolicy(nullptr) { + conditionDepth(0) { InitializeConditionPolicyHandlers(); } ~ConditionPolicy() {} protected: - std::any DataInner() const override { return data; } + std::any DataInner() const override { return std::make_shared(data); } virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(ExpressionPolicy) == typeid(*policy)) { - data = policy->Data(); - ctx.dispatcher->RemoveListener(nullptr); + data.expr = policy->Data(); + } else if (typeid(DeclTypePolicy) == typeid(*policy)) { + data.decls = *policy->Data>>(); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } + ctx.dispatcher->RemoveListener(nullptr); } void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} @@ -61,8 +81,9 @@ public srcDispatch::PolicyListener { openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { if (!conditionDepth) { conditionDepth = ctx.depth; - data = std::make_shared(); + data = ConditionData{}; CollectExpressionHandlers(); + CollectDeclTypePolicyHandlers(); } }; @@ -84,6 +105,14 @@ public srcDispatch::PolicyListener { }; } + void CollectDeclTypePolicyHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { + if (!declTypePolicy) declTypePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(declTypePolicy.get()); + }; + } + }; #endif diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index d3f58ff..d9c9119 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -24,8 +24,8 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { protected: - ConditionalData data; - std::size_t conditionalDepth; + ConditionalData data; + std::size_t conditionalDepth; std::unique_ptr conditionPolicy; std::unique_ptr blockPolicy; @@ -44,7 +44,7 @@ public srcDispatch::PolicyListener { void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { if (typeid(ConditionPolicy) == typeid(*policy)) { - data.condition = policy->Data(); + data.condition = policy->Data(); } else if (typeid(BlockPolicy) == typeid(*policy)) { data.block = policy->Data(); } else { diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp index 4787a2f..cf92219 100644 --- a/src/policy_classes/ControlPolicySingleEvent.hpp +++ b/src/policy_classes/ControlPolicySingleEvent.hpp @@ -24,7 +24,7 @@ struct ControlData { unsigned int lineNumber; std::vector init; - std::shared_ptr condition; + std::shared_ptr condition; std::vector> incr; friend std::ostream& operator<<(std::ostream& out, const ControlData& controlData) { @@ -87,7 +87,7 @@ public srcDispatch::PolicyListener { } else if(typeid(ExpressionPolicy) == typeid(*policy)) { data.init.push_back(policy->Data()); } else if(typeid(ConditionPolicy) == typeid(*policy)) { - data.condition = policy->Data(); + data.condition = policy->Data(); } else if(typeid(IncrPolicy) == typeid(*policy)) { data.incr.push_back(policy->Data()); } else { diff --git a/src/policy_classes/DoPolicySingleEvent.hpp b/src/policy_classes/DoPolicySingleEvent.hpp index 32fb2d2..63bf32d 100644 --- a/src/policy_classes/DoPolicySingleEvent.hpp +++ b/src/policy_classes/DoPolicySingleEvent.hpp @@ -18,8 +18,8 @@ struct DoData { unsigned int startLineNumber; unsigned int endLineNumber; - std::shared_ptr condition; - std::shared_ptr block; + std::shared_ptr condition; + std::shared_ptr block; friend std::ostream& operator<<(std::ostream& out, const DoData& doData) { if(!doData.condition) return out; diff --git a/src/policy_classes/ElseIfPolicySingleEvent.hpp b/src/policy_classes/ElseIfPolicySingleEvent.hpp index 596070c..061184e 100644 --- a/src/policy_classes/ElseIfPolicySingleEvent.hpp +++ b/src/policy_classes/ElseIfPolicySingleEvent.hpp @@ -18,8 +18,8 @@ struct ElseIfData { unsigned int startLineNumber; unsigned int endLineNumber; - std::shared_ptr condition; - std::shared_ptr block; + std::shared_ptr condition; + std::shared_ptr block; friend std::ostream& operator<<(std::ostream& out, const ElseIfData& elseIfData) { if(!elseIfData.condition) return out; diff --git a/src/policy_classes/ElsePolicySingleEvent.hpp b/src/policy_classes/ElsePolicySingleEvent.hpp index 8d1a412..a512ca9 100644 --- a/src/policy_classes/ElsePolicySingleEvent.hpp +++ b/src/policy_classes/ElsePolicySingleEvent.hpp @@ -18,8 +18,8 @@ struct ElseData { unsigned int startLineNumber; unsigned int endLineNumber; - std::shared_ptr condition; - std::shared_ptr block; + std::shared_ptr condition; + std::shared_ptr block; friend std::ostream& operator<<(std::ostream& out, const ElseData& elseData) { if(!elseData.condition) return out; diff --git a/src/policy_classes/IfPolicySingleEvent.hpp b/src/policy_classes/IfPolicySingleEvent.hpp index 4a9b693..606c3f8 100644 --- a/src/policy_classes/IfPolicySingleEvent.hpp +++ b/src/policy_classes/IfPolicySingleEvent.hpp @@ -18,8 +18,8 @@ struct IfData { unsigned int startLineNumber; unsigned int endLineNumber; - std::shared_ptr condition; - std::shared_ptr block; + std::shared_ptr condition; + std::shared_ptr block; friend std::ostream& operator<<(std::ostream& out, const IfData& ifData) { if(!ifData.condition) return out; diff --git a/src/policy_classes/SwitchPolicySingleEvent.hpp b/src/policy_classes/SwitchPolicySingleEvent.hpp index 6d9664d..c35b7a4 100644 --- a/src/policy_classes/SwitchPolicySingleEvent.hpp +++ b/src/policy_classes/SwitchPolicySingleEvent.hpp @@ -18,8 +18,8 @@ struct SwitchData { unsigned int startLineNumber; unsigned int endLineNumber; - std::shared_ptr condition; - std::shared_ptr block; + std::shared_ptr condition; + std::shared_ptr block; friend std::ostream& operator<<(std::ostream& out, const SwitchData& switchData) { if(!switchData.condition) return out; diff --git a/src/policy_classes/WhilePolicySingleEvent.hpp b/src/policy_classes/WhilePolicySingleEvent.hpp index 5cf12d9..080bbd9 100644 --- a/src/policy_classes/WhilePolicySingleEvent.hpp +++ b/src/policy_classes/WhilePolicySingleEvent.hpp @@ -18,8 +18,8 @@ struct WhileData { unsigned int startLineNumber; unsigned int endLineNumber; - std::shared_ptr condition; - std::shared_ptr block; + std::shared_ptr condition; + std::shared_ptr block; friend std::ostream& operator<<(std::ostream& out, const WhileData& whileData) { if(!whileData.condition) return out; From 459314fc666727dc673418317d0930a27cbc19e1 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 9 Dec 2024 12:19:18 +0900 Subject: [PATCH 078/149] Turn on all warnings --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d4d430..8f9b27e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,8 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_definitions("-Wall") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) From c5c594cd5d3d68c3fc8d49b230958195afbaf7a4 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 21 Jan 2025 10:33:28 +0900 Subject: [PATCH 079/149] Improve spacing between constructs --- src/dispatcher/srcDispatchUtilities.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index f2dd6d2..5510d33 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -63,6 +63,7 @@ namespace srcDispatch { // do not put anything after these xmlattribute, tokenstring, empty, MAXENUMVALUE = empty}; + class srcSAXEventContext { public: srcSAXEventContext() = delete; From 24f0dc138d39046677496f28c098909917e38bf0 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 21 Jan 2025 16:22:47 +0900 Subject: [PATCH 080/149] Fix collection and reporting of multiple indices --- src/policy_classes/NamePolicySingleEvent.cpp | 38 +++++++++++--------- src/policy_classes/NamePolicySingleEvent.hpp | 8 ++--- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index 99dfcdc..244ffa5 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -12,7 +12,7 @@ #include std::string NameData::SimpleName() const { - if (!name.empty()) { + if(!name.empty()) { return ToString(); } @@ -31,7 +31,7 @@ std::string NameData::ToString() const { } } - if (templateArgumentList) { + if(templateArgumentList) { str += templateArgumentList->ToString(); } @@ -49,11 +49,12 @@ std::ostream& operator<<(std::ostream& out, const NameData& nameData) { out << std::any_cast>(name_element)->op; } } - if (nameData.templateArgumentList) { + if(nameData.templateArgumentList) { out << *nameData.templateArgumentList; } - if (nameData.indices) { - out << '[' << *nameData.indices << ']'; + + for(std::shared_ptr index : nameData.indices) { + out << '[' << *index << ']'; } return out; } @@ -63,14 +64,14 @@ NamePolicy::~NamePolicy() {} void NamePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(NamePolicy) == typeid(*policy)) { + if(typeid(NamePolicy) == typeid(*policy)) { data.names.push_back(policy->Data()); - } else if (typeid(OperatorPolicy) == typeid(*policy)) { + } else if(typeid(OperatorPolicy) == typeid(*policy)) { data.names.push_back(policy->Data()); - } else if (typeid(TemplateArgumentListPolicy) == typeid(*policy)) { + } else if(typeid(TemplateArgumentListPolicy) == typeid(*policy)) { data.templateArgumentList = policy->Data(); - } else if (typeid(ExpressionPolicy) == typeid(*policy)) { - data.indices = policy->Data(); + } else if(typeid(ExpressionPolicy) == typeid(*policy)) { + data.indices.push_back(policy->Data()); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } @@ -81,31 +82,34 @@ void NamePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSA void NamePolicy::InitializeNamePolicyHandlers() { using namespace srcDispatch; + // start of policy openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if (!nameDepth) { + if(!nameDepth) { nameDepth = ctx.depth; data = NameData{}; data.lineNumber = ctx.currentLineNumber; CollectOperatorsHandlers(); CollectTemplateArgumentListHandlers(); CollectArrayIndicesHandlers(); - } else if ((nameDepth + 1) == ctx.depth) { + } else if((nameDepth + 1) == ctx.depth) { NopCloseEvents({ParserState::tokenstring}); - if (!namePolicy) namePolicy = make_unique_policy({this}); + if(!namePolicy) namePolicy = make_unique_policy({this}); ctx.dispatcher->AddListenerDispatch(namePolicy.get()); } }; + // end of policy closeEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if (nameDepth && nameDepth == ctx.depth) { + if(nameDepth && nameDepth == ctx.depth) { nameDepth = 0; NotifyAll(ctx); InitializeNamePolicyHandlers(); } }; + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - if (nameDepth && nameDepth == ctx.depth) { + if(nameDepth && nameDepth == ctx.depth) { data.name += ctx.currentToken; } }; @@ -126,10 +130,10 @@ void NamePolicy::CollectOperatorsHandlers() { void NamePolicy::CollectTemplateArgumentListHandlers() { using namespace srcDispatch; openEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext& ctx) { - if (!nameDepth) return; + if(!nameDepth) return; if((nameDepth + 1) != ctx.depth) return; - if (!templateArgumentListPolicy) templateArgumentListPolicy = make_unique_policy({this}); + if(!templateArgumentListPolicy) templateArgumentListPolicy = make_unique_policy({this}); ctx.dispatcher->AddListenerDispatch(templateArgumentListPolicy.get()); }; } diff --git a/src/policy_classes/NamePolicySingleEvent.hpp b/src/policy_classes/NamePolicySingleEvent.hpp index 937ab45..0d70e55 100644 --- a/src/policy_classes/NamePolicySingleEvent.hpp +++ b/src/policy_classes/NamePolicySingleEvent.hpp @@ -26,10 +26,10 @@ struct TemplateArgumentListData; struct NameData { unsigned int lineNumber; - std::string name; - std::vector names; - std::shared_ptr templateArgumentList; - std::shared_ptr indices; + std::string name; + std::vector names; + std::shared_ptr templateArgumentList; + std::vector> indices; std::string SimpleName() const; std::string ToString() const; From a3980ce0043591a4148d03880ba39c7515cc2bcd Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 24 Jan 2025 10:54:28 +0900 Subject: [PATCH 081/149] Add diff stack to dispatcher and remove diff events --- src/dispatcher/srcDispatchUtilities.hpp | 14 ++++-- src/dispatcher/srcDispatcher.hpp | 57 +++++++++++-------------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 5510d33..4958cb7 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -56,14 +56,18 @@ namespace srcDispatch { // stereotype state stereotype, - // srcDiff states - diff_common, diff_insert, diff_delete, diff_ws, - archive, unit, returnstmt, // do not put anything after these xmlattribute, tokenstring, empty, MAXENUMVALUE = empty}; + enum DiffOperation { DELETE, INSERT, COMMON }; + struct Diff { + DiffOperation operation; + size_t depth; + }; + + class srcSAXEventContext { public: srcSAXEventContext() = delete; @@ -72,6 +76,7 @@ namespace srcDispatch { archiveBuffer{0}, dispatcher(dispatcher), elementStack(elementStack), + diffStack(), currentLineNumber{0}, triggerField(std::vector(MAXENUMVALUE, 0)), depth(0), @@ -89,7 +94,8 @@ namespace srcDispatch { xmlBufferPtr archiveBuffer; EventDispatcher * dispatcher; - const std::vector & elementStack; + const std::vector& elementStack; + std::vector diffStack; std::vector genericDepth; unsigned int currentLineNumber; std::vector triggerField; diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index e29088d..9e1d4ff 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -66,6 +66,8 @@ namespace srcDispatch { return listeners; } + const std::string DIFF_URI = "http://www.srcML.org/srcDiff"; + template class srcDispatcher : public srcSAXHandler, public EventDispatcher { #pragma GCC diagnostic push @@ -479,22 +481,6 @@ namespace srcDispatch { ++ctx.triggerField[ParserState::stereotype]; DispatchEvent(ParserState::stereotype, ElementState::open); } }, - { "diff:delete", [this]() { - ++ctx.triggerField[ParserState::diff_delete]; - DispatchEvent(ParserState::diff_delete, ElementState::open); - } }, - { "diff:insert", [this]() { - ++ctx.triggerField[ParserState::diff_insert]; - DispatchEvent(ParserState::diff_insert, ElementState::open); - } }, - { "diff:common", [this]() { - ++ctx.triggerField[ParserState::diff_common]; - DispatchEvent(ParserState::diff_common, ElementState::open); - } }, - { "diff:ws", [this]() { - ++ctx.triggerField[ParserState::diff_ws]; - DispatchEvent(ParserState::diff_ws, ElementState::open); - } }, { "unit", [this]() { if(ctx.triggerField[ParserState::unit] == 0) { ctx.triggerField[ParserState::archive] = 1; @@ -778,22 +764,6 @@ namespace srcDispatch { DispatchEvent(ParserState::stereotype, ElementState::close); --ctx.triggerField[ParserState::stereotype]; } }, - { "diff:delete", [this]() { - DispatchEvent(ParserState::diff_delete, ElementState::close); - --ctx.triggerField[ParserState::diff_delete]; - } }, - { "diff_insert", [this]() { - DispatchEvent(ParserState::diff_insert, ElementState::close); - --ctx.triggerField[ParserState::diff_insert]; - } }, - { "diff_common", [this]() { - DispatchEvent(ParserState::diff_common, ElementState::close); - --ctx.triggerField[ParserState::diff_common]; - } }, - { "diff_ws", [this]() { - DispatchEvent(ParserState::diff_ws, ElementState::close); - --ctx.triggerField[ParserState::diff_ws]; - } }, { "unit", [this]() { --ctx.triggerField[ParserState::unit]; DispatchEvent(ParserState::unit, ElementState::close); @@ -924,6 +894,21 @@ namespace srcDispatch { if(generateArchive) { ctx.write_start_tag(localname, prefix, URI, num_namespaces, namespaces, num_attributes, attributes); } + + if(URI == DIFF_URI) { + if(localname == std::string("ws")) return; + + static std::unordered_map diff_op_map = { + { "delete", DiffOperation::DELETE }, + { "insert", DiffOperation::INSERT }, + { "common", DiffOperation::COMMON }, + }; + + ctx.diffStack.emplace_back(diff_op_map[std::string(localname)], ctx.depth + 1); + + + return; + } ++ctx.depth; @@ -1068,6 +1053,14 @@ namespace srcDispatch { virtual void endElement(const char * localname, const char * prefix, const char * URI) override { + + if(URI == DIFF_URI) { + if(localname == std::string("ws")) return; + + ctx.diffStack.pop_back(); + return; + } + std::string localName; if(prefix) { localName += prefix; From 7c0e253f9acfbbe71830d3679aeda82308c68232 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 3 Feb 2025 11:58:45 +0900 Subject: [PATCH 082/149] Replace current line number with start/end and extract qualified name method --- src/dispatcher/srcDispatchUtilities.hpp | 12 +++- src/dispatcher/srcDispatcher.cpp | 25 -------- src/dispatcher/srcDispatcher.hpp | 18 ++---- src/policy_classes/BlockPolicySingleEvent.cpp | 4 +- src/policy_classes/CallPolicySingleEvent.cpp | 2 +- src/policy_classes/ClassPolicySingleEvent.hpp | 2 +- src/policy_classes/ConditionalPolicy.hpp | 58 +++++++++---------- .../ConditionalPolicySingleEvent.hpp | 4 +- src/policy_classes/DeclPolicySingleEvent.hpp | 2 +- src/policy_classes/DeclTypePolicy.hpp | 10 ++-- src/policy_classes/ExprPolicy.hpp | 10 ++-- .../ExpressionPolicySingleEvent.cpp | 2 +- src/policy_classes/ForPolicySingleEvent.hpp | 4 +- .../FunctionPolicySingleEvent.hpp | 2 +- .../FunctionSignaturePolicy.hpp | 4 +- .../IfStmtPolicySingleEvent.hpp | 4 +- src/policy_classes/IncrPolicySingleEvent.hpp | 2 +- .../LiteralPolicySingleEvent.hpp | 2 +- src/policy_classes/NamePolicySingleEvent.cpp | 2 +- .../OperatorPolicySingleEvent.hpp | 2 +- src/policy_classes/ParamTypePolicy.hpp | 2 +- src/policy_classes/ReturnPolicy.hpp | 2 +- .../TemplateArgumentListPolicySingleEvent.cpp | 2 +- src/policy_classes/TypePolicySingleEvent.cpp | 2 +- 24 files changed, 76 insertions(+), 103 deletions(-) delete mode 100644 src/dispatcher/srcDispatcher.cpp diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 5510d33..e4f5c1e 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -72,7 +72,8 @@ namespace srcDispatch { archiveBuffer{0}, dispatcher(dispatcher), elementStack(elementStack), - currentLineNumber{0}, + startLineNumber(0), + endLineNumber(0), triggerField(std::vector(MAXENUMVALUE, 0)), depth(0), isPrev(false), @@ -91,7 +92,8 @@ namespace srcDispatch { EventDispatcher * dispatcher; const std::vector & elementStack; std::vector genericDepth; - unsigned int currentLineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; std::vector triggerField; std::string currentFilePath, currentFileName, currentFileLanguage, currentsrcMLRevision, currentTag, currentToken, currentAttributeName, currentAttributeValue, currentFunctionName, @@ -479,6 +481,12 @@ namespace srcDispatch { return std::make_unique(args); } + constexpr std::string get_qualified_name(const char* localname, const char* prefix) { + if(prefix == nullptr) return localname; + return std::string(prefix) + ":" + localname; + } + + } #endif diff --git a/src/dispatcher/srcDispatcher.cpp b/src/dispatcher/srcDispatcher.cpp deleted file mode 100644 index 678ffc6..0000000 --- a/src/dispatcher/srcDispatcher.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @file srcDispatch.cpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include - -namespace srcDispatch { - -} diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index e29088d..0b98c4a 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -927,13 +927,7 @@ namespace srcDispatch { ++ctx.depth; - std::string localName; - if(prefix) { - localName += prefix; - localName += ':'; - } - localName += localname; - + std::string localName = get_qualified_name(localname, prefix); ctx.currentTag = localName; std::string name; @@ -957,18 +951,14 @@ namespace srcDispatch { if(localName != "") { // form attribute map for(int pos = 0; pos < num_attributes; ++pos) { - std::string attributeName; - if(attributes[pos].prefix) { - attributeName += attributes[pos].prefix; - attributeName += ':'; - } - attributeName += attributes[pos].localname; + + std::string attributeName = get_qualified_name(attributes[pos].localname, attributes[pos].prefix); if(strcmp(attributes[pos].localname, "start") == 0) { std::string posString; for(int i = 0; attributes[pos].value[i] != ':'; ++i) { posString+=attributes[pos].value[i]; } - ctx.currentLineNumber = std::stoi(posString); + ctx.startLineNumber = std::stoi(posString); } std::string attributeValue = attributes[pos].value; diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp index a03d52b..4b8dfe7 100644 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -76,7 +76,7 @@ void BlockPolicy::CollectBlockHandlers() { if(!blockDepth) { blockDepth = ctx.depth; data = BlockData{}; - data.startLineNumber = ctx.currentLineNumber; + data.startLineNumber = ctx.startLineNumber; } else { if (!blockPolicy) blockPolicy = make_unique_policy({this}); ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); @@ -86,7 +86,7 @@ void BlockPolicy::CollectBlockHandlers() { closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { if(blockDepth && blockDepth == ctx.depth) { blockDepth = 0; - data.endLineNumber = ctx.currentLineNumber; + data.endLineNumber = ctx.startLineNumber; NotifyAll(ctx); InitializeBlockPolicyHandlers(); } diff --git a/src/policy_classes/CallPolicySingleEvent.cpp b/src/policy_classes/CallPolicySingleEvent.cpp index b05e641..94887f7 100644 --- a/src/policy_classes/CallPolicySingleEvent.cpp +++ b/src/policy_classes/CallPolicySingleEvent.cpp @@ -40,7 +40,7 @@ void CallPolicy::InitializeCallPolicyHandlers() { if (!callDepth) { callDepth = ctx.depth; data = CallData{}; - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; CollectNameHandlers(); CollectCallArgumentHandlers(); } diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index 53f7a08..f339e41 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -119,7 +119,7 @@ public srcDispatch::PolicyListener { classDepth = ctx.depth; data = ClassData{}; data.namespaces = ctx.currentNamespaces; - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); if (stereotype_attr_itr != ctx.attributes.end()){ std::istringstream stereostring(stereotype_attr_itr->second); diff --git a/src/policy_classes/ConditionalPolicy.hpp b/src/policy_classes/ConditionalPolicy.hpp index 6abb113..5787cab 100644 --- a/src/policy_classes/ConditionalPolicy.hpp +++ b/src/policy_classes/ConditionalPolicy.hpp @@ -87,7 +87,7 @@ class ConditionalPolicy : public srcDispatch::EventListener, public srcDispatch: currentExprName = ctx.currentToken; if (ctx.IsOpen({ParserState::decl}) && ctx.IsClosed({ParserState::type}) && dvarSet.size() > 0 && insertDvar) { - dvarSet.back().dvars.insert( std::make_pair(ctx.currentToken, ctx.currentLineNumber) ); + dvarSet.back().dvars.insert( std::make_pair(ctx.currentToken, ctx.startLineNumber) ); } if ( ctx.IsClosed({ParserState::comment}) ) { @@ -102,8 +102,8 @@ class ConditionalPolicy : public srcDispatch::EventListener, public srcDispatch: // "a" with only def on line 4, and "i" use on 4 if (currentType.empty()) { - if (conditionalUses[ctx.currentToken].empty() || ctx.currentLineNumber != conditionalUses[ctx.currentToken].back()) { - conditionalUses[ctx.currentToken].push_back(ctx.currentLineNumber); + if (conditionalUses[ctx.currentToken].empty() || ctx.startLineNumber != conditionalUses[ctx.currentToken].back()) { + conditionalUses[ctx.currentToken].push_back(ctx.startLineNumber); } } else { currentType.clear(); @@ -112,60 +112,60 @@ class ConditionalPolicy : public srcDispatch::EventListener, public srcDispatch: // The following is for detecting possible uses within various Conditionals if ( ctx.IsOpen({ParserState::whilestmt}) && ctx.IsOpen({ParserState::condition}) ){ - if (conditionalUses[ctx.currentToken].empty() || ctx.currentLineNumber != conditionalUses[ctx.currentToken].back()) { - conditionalUses[ctx.currentToken].push_back(ctx.currentLineNumber); + if (conditionalUses[ctx.currentToken].empty() || ctx.startLineNumber != conditionalUses[ctx.currentToken].back()) { + conditionalUses[ctx.currentToken].push_back(ctx.startLineNumber); } } // The following is for detecting possible uses within various Conditionals if ( ctx.IsOpen({ParserState::forstmt}) ) { if ( ctx.And({ParserState::decl, ParserState::init, ParserState::expr}) ) { - if (conditionalUses[ctx.currentToken].empty() || ctx.currentLineNumber != conditionalUses[ctx.currentToken].back()) { - conditionalUses[ctx.currentToken].push_back(ctx.currentLineNumber); + if (conditionalUses[ctx.currentToken].empty() || ctx.startLineNumber != conditionalUses[ctx.currentToken].back()) { + conditionalUses[ctx.currentToken].push_back(ctx.startLineNumber); } } if ( ctx.IsOpen({ParserState::condition}) ){ - if (conditionalUses[ctx.currentToken].empty() || ctx.currentLineNumber != conditionalUses[ctx.currentToken].back()) { - conditionalUses[ctx.currentToken].push_back(ctx.currentLineNumber); + if (conditionalUses[ctx.currentToken].empty() || ctx.startLineNumber != conditionalUses[ctx.currentToken].back()) { + conditionalUses[ctx.currentToken].push_back(ctx.startLineNumber); } } if ( ctx.IsOpen({ParserState::incr}) || ctx.IsOpen({ParserState::decr}) ){ - if (conditionalDefs[ctx.currentToken].empty() || ctx.currentLineNumber != conditionalDefs[ctx.currentToken].back()) { - conditionalDefs[ctx.currentToken].push_back(ctx.currentLineNumber); + if (conditionalDefs[ctx.currentToken].empty() || ctx.startLineNumber != conditionalDefs[ctx.currentToken].back()) { + conditionalDefs[ctx.currentToken].push_back(ctx.startLineNumber); } - if (conditionalUses[ctx.currentToken].empty() || ctx.currentLineNumber != conditionalUses[ctx.currentToken].back()) { - conditionalUses[ctx.currentToken].push_back(ctx.currentLineNumber); + if (conditionalUses[ctx.currentToken].empty() || ctx.startLineNumber != conditionalUses[ctx.currentToken].back()) { + conditionalUses[ctx.currentToken].push_back(ctx.startLineNumber); } } } // The following is for detecting possible uses within various Conditionals if ( ctx.IsOpen({ParserState::dostmt}) && ctx.IsOpen({ParserState::condition}) ){ - if (conditionalUses[ctx.currentToken].empty() || ctx.currentLineNumber != conditionalUses[ctx.currentToken].back()) { - conditionalUses[ctx.currentToken].push_back(ctx.currentLineNumber); + if (conditionalUses[ctx.currentToken].empty() || ctx.startLineNumber != conditionalUses[ctx.currentToken].back()) { + conditionalUses[ctx.currentToken].push_back(ctx.startLineNumber); } } // Get uses or use/defs within switch conditions if ( ctx.IsOpen({ParserState::switchstmt}) && ctx.IsOpen({ParserState::condition}) ){ if ( ctx.IsOpen({ParserState::init}) ) { - if (switchUses[ctx.currentToken].empty() || ctx.currentLineNumber != switchUses[ctx.currentToken].back()) { - switchUses[ctx.currentToken].push_back(ctx.currentLineNumber); + if (switchUses[ctx.currentToken].empty() || ctx.startLineNumber != switchUses[ctx.currentToken].back()) { + switchUses[ctx.currentToken].push_back(ctx.startLineNumber); } } else { switchControlVars[switchDepth].insert(ctx.currentToken); - if (switchUses[ctx.currentToken].empty() || ctx.currentLineNumber != switchUses[ctx.currentToken].back()) { - switchUses[ctx.currentToken].push_back(ctx.currentLineNumber); + if (switchUses[ctx.currentToken].empty() || ctx.startLineNumber != switchUses[ctx.currentToken].back()) { + switchUses[ctx.currentToken].push_back(ctx.startLineNumber); } if (!currentExprOp.empty()) { // prefix : ++c - if (switchDefs[ctx.currentToken].empty() || ctx.currentLineNumber != switchDefs[ctx.currentToken].back()) { - switchDefs[ctx.currentToken].push_back(ctx.currentLineNumber); + if (switchDefs[ctx.currentToken].empty() || ctx.startLineNumber != switchDefs[ctx.currentToken].back()) { + switchDefs[ctx.currentToken].push_back(ctx.startLineNumber); } currentExprName = ""; @@ -181,8 +181,8 @@ class ConditionalPolicy : public srcDispatch::EventListener, public srcDispatch: closeEventMap[ParserState::switchcase] = [this](srcSAXEventContext &ctx) { if ( ctx.IsOpen({ParserState::switchstmt}) ){ for (auto varName : switchControlVars[switchDepth]) { - if (switchUses[varName].empty() || ctx.currentLineNumber != switchUses[varName].back()) { - switchUses[varName].push_back(ctx.currentLineNumber); + if (switchUses[varName].empty() || ctx.startLineNumber != switchUses[varName].back()) { + switchUses[varName].push_back(ctx.startLineNumber); } } } @@ -211,7 +211,7 @@ class ConditionalPolicy : public srcDispatch::EventListener, public srcDispatch: extractedToken == "/=" || extractedToken == "%=" || extractedToken == "=") { if ( (ctx.IsOpen({ParserState::decl}) && ctx.IsClosed({ParserState::name}) && ctx.IsClosed({ParserState::type})) && !currentExprName.empty()) { - dvarSet.push_back(DvarData(ctx.currentFunctionName, currentExprName, ctx.currentLineNumber)); + dvarSet.push_back(DvarData(ctx.currentFunctionName, currentExprName, ctx.startLineNumber)); insertDvar = true; } } @@ -239,12 +239,12 @@ class ConditionalPolicy : public srcDispatch::EventListener, public srcDispatch: currentExprOp = ctx.currentToken; if (!currentExprName.empty()) { // postfix : c++ - if (conditionalDefs[currentExprName].empty() || ctx.currentLineNumber != conditionalDefs[currentExprName].back()) { - conditionalDefs[currentExprName].push_back(ctx.currentLineNumber); + if (conditionalDefs[currentExprName].empty() || ctx.startLineNumber != conditionalDefs[currentExprName].back()) { + conditionalDefs[currentExprName].push_back(ctx.startLineNumber); } - if (conditionalUses[currentExprName].empty() || ctx.currentLineNumber != conditionalUses[currentExprName].back()) { - conditionalUses[currentExprName].push_back(ctx.currentLineNumber); + if (conditionalUses[currentExprName].empty() || ctx.startLineNumber != conditionalUses[currentExprName].back()) { + conditionalUses[currentExprName].push_back(ctx.startLineNumber); } currentExprName = ""; @@ -256,7 +256,7 @@ class ConditionalPolicy : public srcDispatch::EventListener, public srcDispatch: ctx.currentToken == "*=" || ctx.currentToken == "/=" || ctx.currentToken == "%=" || ctx.currentToken == "=") { if ( ctx.IsOpen({ParserState::decl}) && !currentExprName.empty() && !currentType.empty() ) { - dvarSet.push_back(DvarData(ctx.currentFunctionName, currentExprName, ctx.currentLineNumber)); + dvarSet.push_back(DvarData(ctx.currentFunctionName, currentExprName, ctx.startLineNumber)); } } }; diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index d9c9119..9c15f1c 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -63,7 +63,7 @@ public srcDispatch::PolicyListener { if (!conditionalDepth) { conditionalDepth = ctx.depth; data = ConditionalData{}; - data.startLineNumber = ctx.currentLineNumber; + data.startLineNumber = ctx.startLineNumber; CollectConditionHandlers(); CollectBlockHandlers(); } @@ -73,7 +73,7 @@ public srcDispatch::PolicyListener { closeEventMap[DispatchEvent] =[this](srcSAXEventContext& ctx) { if (conditionalDepth && conditionalDepth == ctx.depth) { conditionalDepth = 0; - data.endLineNumber = ctx.currentLineNumber; + data.endLineNumber = ctx.startLineNumber; NotifyAll(ctx); InitializeConditionalPolicyHandlers(); } diff --git a/src/policy_classes/DeclPolicySingleEvent.hpp b/src/policy_classes/DeclPolicySingleEvent.hpp index 3243d99..71b1600 100644 --- a/src/policy_classes/DeclPolicySingleEvent.hpp +++ b/src/policy_classes/DeclPolicySingleEvent.hpp @@ -102,7 +102,7 @@ public srcDispatch::PolicyListener { declDepth = ctx.depth; data = DeclData{}; - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; CollectSpecifiersHandlers(); CollectTypeHandlers(); diff --git a/src/policy_classes/DeclTypePolicy.hpp b/src/policy_classes/DeclTypePolicy.hpp index a8c3c9b..ec3832f 100644 --- a/src/policy_classes/DeclTypePolicy.hpp +++ b/src/policy_classes/DeclTypePolicy.hpp @@ -52,7 +52,7 @@ class DeclTypePolicy : public srcDispatch::EventListener, public srcDispatch::Po data.nameOfContainingFunction = ctx.currentFunctionName; - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; data.nameOfIdentifier = currentDeclName; @@ -67,15 +67,15 @@ class DeclTypePolicy : public srcDispatch::EventListener, public srcDispatch::Po } if(ctx.And({ParserState::parameter})){ - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; data.nameOfIdentifier = currentDeclName; // Used to mark line numbers where parameters are declared if (possibleDefs.size() == 0) { - possibleDefs.push_back(ctx.currentLineNumber); + possibleDefs.push_back(ctx.startLineNumber); } else { - if (possibleDefs.back() != ctx.currentLineNumber) { - possibleDefs.push_back(ctx.currentLineNumber); + if (possibleDefs.back() != ctx.startLineNumber) { + possibleDefs.push_back(ctx.startLineNumber); } } diff --git a/src/policy_classes/ExprPolicy.hpp b/src/policy_classes/ExprPolicy.hpp index 842f862..57e46d0 100644 --- a/src/policy_classes/ExprPolicy.hpp +++ b/src/policy_classes/ExprPolicy.hpp @@ -82,7 +82,7 @@ class ExprPolicy : public srcDispatch::EventListener, public srcDispatch::Policy ctx.currentToken == "-=" || ctx.currentToken == "*=" || ctx.currentToken == "/=" || ctx.currentToken == "%=" || ctx.currentToken == "--" || ctx.currentToken == "++"){ - currentExprOp = std::make_pair(ctx.currentToken, ctx.currentLineNumber); + currentExprOp = std::make_pair(ctx.currentToken, ctx.startLineNumber); auto it = exprDataSet.dataSet.find(currentExprName); if(it != exprDataSet.dataSet.end()){ @@ -98,8 +98,8 @@ class ExprPolicy : public srcDispatch::EventListener, public srcDispatch::Policy closeEventMap[ParserState::name] = [this](srcSAXEventContext& ctx){ - if(currentLine.empty() || currentLine.back() != ctx.currentLineNumber){ - currentLine.push_back(ctx.currentLineNumber); + if(currentLine.empty() || currentLine.back() != ctx.startLineNumber){ + currentLine.push_back(ctx.startLineNumber); } if(ctx.IsOpen({ParserState::exprstmt})){ @@ -107,14 +107,14 @@ class ExprPolicy : public srcDispatch::EventListener, public srcDispatch::Policy if(it != exprDataSet.dataSet.end()){ it->second.uses.insert(currentLine.back()); //assume it's a use - if ( (currentExprOp.first == "++" || currentExprOp.first == "--") && currentExprOp.second == ctx.currentLineNumber ) + if ( (currentExprOp.first == "++" || currentExprOp.first == "--") && currentExprOp.second == ctx.startLineNumber ) it->second.definitions.insert(currentLine.back()); }else{ data.nameOfIdentifier = currentExprName; data.uses.insert(currentLine.back()); - if ( (currentExprOp.first == "++" || currentExprOp.first == "--") && currentExprOp.second == ctx.currentLineNumber ) + if ( (currentExprOp.first == "++" || currentExprOp.first == "--") && currentExprOp.second == ctx.startLineNumber ) data.definitions.insert(currentLine.back()); exprDataSet.dataSet.insert(std::make_pair(currentExprName, data)); diff --git a/src/policy_classes/ExpressionPolicySingleEvent.cpp b/src/policy_classes/ExpressionPolicySingleEvent.cpp index 89e65fa..49494c0 100644 --- a/src/policy_classes/ExpressionPolicySingleEvent.cpp +++ b/src/policy_classes/ExpressionPolicySingleEvent.cpp @@ -51,7 +51,7 @@ void ExpressionPolicy::InitializeExpressionPolicyHandlers() { if(!exprDepth) { exprDepth = ctx.depth; data = ExpressionData{}; - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; CollectNameHandlers(); CollectCallHandlers(); CollectOperatorHandlers(); diff --git a/src/policy_classes/ForPolicySingleEvent.hpp b/src/policy_classes/ForPolicySingleEvent.hpp index 30c20b4..6232bec 100644 --- a/src/policy_classes/ForPolicySingleEvent.hpp +++ b/src/policy_classes/ForPolicySingleEvent.hpp @@ -83,7 +83,7 @@ public srcDispatch::PolicyListener { if (!forDepth) { forDepth = ctx.depth; data = ForData{}; - data.startLineNumber = ctx.currentLineNumber; + data.startLineNumber = ctx.startLineNumber; CollectControlHandlers(); CollectBlockHandlers(); } @@ -93,7 +93,7 @@ public srcDispatch::PolicyListener { closeEventMap[ParserState::forstmt] =[this](srcSAXEventContext& ctx) { if (forDepth && forDepth == ctx.depth) { forDepth = 0; - data.endLineNumber = ctx.currentLineNumber; + data.endLineNumber = ctx.startLineNumber; NotifyAll(ctx); InitializeForPolicyHandlers(); } diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index 378368e..e15dbe4 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -138,7 +138,7 @@ public srcDispatch::PolicyListener { functionDepth = ctx.depth; data = FunctionData{}; data.namespaces = ctx.currentNamespaces; - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; data.language = ctx.currentFileLanguage; data.filename = ctx.currentFilePath; std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); diff --git a/src/policy_classes/FunctionSignaturePolicy.hpp b/src/policy_classes/FunctionSignaturePolicy.hpp index 1005ad8..0800849 100644 --- a/src/policy_classes/FunctionSignaturePolicy.hpp +++ b/src/policy_classes/FunctionSignaturePolicy.hpp @@ -96,7 +96,7 @@ class FunctionSignaturePolicy : public srcDispatch::EventListener, public srcDis using namespace srcDispatch; openEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { ctx.dispatcher->AddListener(¶mpolicy); - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; }; closeEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx){ ctx.dispatcher->RemoveListener(¶mpolicy); @@ -109,7 +109,7 @@ class FunctionSignaturePolicy : public srcDispatch::EventListener, public srcDis }; openEventMap[ParserState::function] = [this](srcSAXEventContext& ctx) { - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; }; openEventMap[ParserState::index] = [this](srcSAXEventContext& ctx) { diff --git a/src/policy_classes/IfStmtPolicySingleEvent.hpp b/src/policy_classes/IfStmtPolicySingleEvent.hpp index 520c042..c38b79c 100644 --- a/src/policy_classes/IfStmtPolicySingleEvent.hpp +++ b/src/policy_classes/IfStmtPolicySingleEvent.hpp @@ -81,7 +81,7 @@ public srcDispatch::PolicyListener { if (!ifStmtDepth) { ifStmtDepth = ctx.depth; data = IfStmtData{}; - data.startLineNumber = ctx.currentLineNumber; + data.startLineNumber = ctx.startLineNumber; CollectIfHandlers(); CollectElseIfHandlers(); CollectElseHandlers(); @@ -92,7 +92,7 @@ public srcDispatch::PolicyListener { closeEventMap[ParserState::ifgroup] =[this](srcSAXEventContext& ctx) { if (ifStmtDepth && ifStmtDepth == ctx.depth) { ifStmtDepth = 0; - data.endLineNumber = ctx.currentLineNumber; + data.endLineNumber = ctx.startLineNumber; NotifyAll(ctx); InitializeIfStmtPolicyHandlers(); } diff --git a/src/policy_classes/IncrPolicySingleEvent.hpp b/src/policy_classes/IncrPolicySingleEvent.hpp index daf54de..b5f74e7 100644 --- a/src/policy_classes/IncrPolicySingleEvent.hpp +++ b/src/policy_classes/IncrPolicySingleEvent.hpp @@ -71,7 +71,7 @@ public srcDispatch::PolicyListener { if (!incrDepth) { incrDepth = ctx.depth; data = IncrData{}; - data.startLineNumber = ctx.currentLineNumber; + data.startLineNumber = ctx.startLineNumber; CollectExpressionHandlers(); } }; diff --git a/src/policy_classes/LiteralPolicySingleEvent.hpp b/src/policy_classes/LiteralPolicySingleEvent.hpp index 561e6cf..5be27f4 100644 --- a/src/policy_classes/LiteralPolicySingleEvent.hpp +++ b/src/policy_classes/LiteralPolicySingleEvent.hpp @@ -56,7 +56,7 @@ public srcDispatch::PolicyListener { if (!literalDepth) { literalDepth = ctx.depth; data = LiteralData{}; - data.startLineNumber = ctx.currentLineNumber; + data.startLineNumber = ctx.startLineNumber; CollectTokenHandlers(); } }; diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index 244ffa5..4a3c866 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -88,7 +88,7 @@ void NamePolicy::InitializeNamePolicyHandlers() { if(!nameDepth) { nameDepth = ctx.depth; data = NameData{}; - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; CollectOperatorsHandlers(); CollectTemplateArgumentListHandlers(); CollectArrayIndicesHandlers(); diff --git a/src/policy_classes/OperatorPolicySingleEvent.hpp b/src/policy_classes/OperatorPolicySingleEvent.hpp index 73b385b..5be240e 100644 --- a/src/policy_classes/OperatorPolicySingleEvent.hpp +++ b/src/policy_classes/OperatorPolicySingleEvent.hpp @@ -56,7 +56,7 @@ public srcDispatch::PolicyListener { if (!operatorDepth) { operatorDepth = ctx.depth; data = OperatorData{}; - data.startLineNumber = ctx.currentLineNumber; + data.startLineNumber = ctx.startLineNumber; CollectTokenHandlers(); } }; diff --git a/src/policy_classes/ParamTypePolicy.hpp b/src/policy_classes/ParamTypePolicy.hpp index 0d9d717..63862ec 100644 --- a/src/policy_classes/ParamTypePolicy.hpp +++ b/src/policy_classes/ParamTypePolicy.hpp @@ -66,7 +66,7 @@ class ParamTypePolicy : public srcDispatch::EventListener, public srcDispatch::P closeEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx){ if(ctx.And({ParserState::parameter})){ - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; data.nameOfIdentifier = currentDeclName; } }; diff --git a/src/policy_classes/ReturnPolicy.hpp b/src/policy_classes/ReturnPolicy.hpp index b9e21e9..76a6f84 100644 --- a/src/policy_classes/ReturnPolicy.hpp +++ b/src/policy_classes/ReturnPolicy.hpp @@ -33,7 +33,7 @@ class ReturnPolicy : public srcDispatch::EventListener, public srcDispatch::Poli closeEventMap[ParserState::name] = [this](srcSAXEventContext &ctx) { if(ctx.IsOpen({ParserState::returnstmt}) && ctx.IsClosed({ParserState::comment})){ - returnUses[ctx.currentToken].insert(ctx.currentLineNumber); + returnUses[ctx.currentToken].insert(ctx.startLineNumber); NotifyAll(ctx); } diff --git a/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp b/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp index a592f02..845e7ad 100644 --- a/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp +++ b/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp @@ -61,7 +61,7 @@ void TemplateArgumentListPolicy::InitializeTemplateArgumentListPolicyHandlers() if (!argumentListDepth) { argumentListDepth = ctx.depth; data = TemplateArgumentListData{}; - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; CollectArgumentHandler(); } }; diff --git a/src/policy_classes/TypePolicySingleEvent.cpp b/src/policy_classes/TypePolicySingleEvent.cpp index 51dd3db..a65f86e 100644 --- a/src/policy_classes/TypePolicySingleEvent.cpp +++ b/src/policy_classes/TypePolicySingleEvent.cpp @@ -73,7 +73,7 @@ void TypePolicy::InitializeTypePolicyHandlers() { if (!typeDepth) { typeDepth = ctx.depth; data = TypeData{}; - data.lineNumber = ctx.currentLineNumber; + data.lineNumber = ctx.startLineNumber; CollectNamesHandler(); CollectModifersHandler(); CollectSpecifiersHandler(); From 700dbd8429f353b2b5738a5f7f603ce32102231b Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 3 Feb 2025 12:00:17 +0900 Subject: [PATCH 083/149] Replace missed code with call to get_qualified_name --- src/dispatcher/srcDispatcher.hpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 0b98c4a..9d53862 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -1058,13 +1058,7 @@ namespace srcDispatch { virtual void endElement(const char * localname, const char * prefix, const char * URI) override { - std::string localName; - if(prefix) { - localName += prefix; - localName += ':'; - } - localName += localname; - + std::string localName = get_qualified_name(localname, prefix); ctx.currentTag = localName; std::unordered_map>::const_iterator process2 = process_map2.find(localname); From ca70eeaee4b29552c82fca196fc6294debd03a54 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 3 Feb 2025 13:06:12 +0900 Subject: [PATCH 084/149] Refactor start line number collection and get end line number --- src/dispatcher/srcDispatcher.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 9d53862..de4f1ab 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include namespace srcDispatch { @@ -954,14 +954,14 @@ namespace srcDispatch { std::string attributeName = get_qualified_name(attributes[pos].localname, attributes[pos].prefix); if(strcmp(attributes[pos].localname, "start") == 0) { - std::string posString; - for(int i = 0; attributes[pos].value[i] != ':'; ++i) { - posString+=attributes[pos].value[i]; - } - ctx.startLineNumber = std::stoi(posString); + int length = ::index(attributes[pos].value, ':') - attributes[pos].value; + ctx.startLineNumber = std::stoi(std::string(attributes[pos].value, length)); + } else if(strcmp(attributes[pos].localname, "end") == 0) { + int length = ::index(attributes[pos].value, ':') - attributes[pos].value; + ctx.endLineNumber = std::stoi(std::string(attributes[pos].value, length)); } - std::string attributeValue = attributes[pos].value; + std::string attributeValue = attributes[pos].value; ctx.attributes.emplace(attributeName, attributeValue); } From 32979eff78861712d9ba08857910e9d0e5cc3837 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 3 Feb 2025 13:31:28 +0900 Subject: [PATCH 085/149] Store ending line number in policy --- src/policy_classes/BlockPolicySingleEvent.cpp | 2 +- src/policy_classes/ConditionalPolicySingleEvent.hpp | 2 +- src/policy_classes/ForPolicySingleEvent.hpp | 2 +- src/policy_classes/IfStmtPolicySingleEvent.hpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp index 4b8dfe7..9fe813a 100644 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -86,7 +86,7 @@ void BlockPolicy::CollectBlockHandlers() { closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { if(blockDepth && blockDepth == ctx.depth) { blockDepth = 0; - data.endLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; NotifyAll(ctx); InitializeBlockPolicyHandlers(); } diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index 9c15f1c..245019e 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -73,7 +73,7 @@ public srcDispatch::PolicyListener { closeEventMap[DispatchEvent] =[this](srcSAXEventContext& ctx) { if (conditionalDepth && conditionalDepth == ctx.depth) { conditionalDepth = 0; - data.endLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; NotifyAll(ctx); InitializeConditionalPolicyHandlers(); } diff --git a/src/policy_classes/ForPolicySingleEvent.hpp b/src/policy_classes/ForPolicySingleEvent.hpp index 6232bec..8c76f60 100644 --- a/src/policy_classes/ForPolicySingleEvent.hpp +++ b/src/policy_classes/ForPolicySingleEvent.hpp @@ -93,7 +93,7 @@ public srcDispatch::PolicyListener { closeEventMap[ParserState::forstmt] =[this](srcSAXEventContext& ctx) { if (forDepth && forDepth == ctx.depth) { forDepth = 0; - data.endLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; NotifyAll(ctx); InitializeForPolicyHandlers(); } diff --git a/src/policy_classes/IfStmtPolicySingleEvent.hpp b/src/policy_classes/IfStmtPolicySingleEvent.hpp index c38b79c..1b577e3 100644 --- a/src/policy_classes/IfStmtPolicySingleEvent.hpp +++ b/src/policy_classes/IfStmtPolicySingleEvent.hpp @@ -92,7 +92,7 @@ public srcDispatch::PolicyListener { closeEventMap[ParserState::ifgroup] =[this](srcSAXEventContext& ctx) { if (ifStmtDepth && ifStmtDepth == ctx.depth) { ifStmtDepth = 0; - data.endLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; NotifyAll(ctx); InitializeIfStmtPolicyHandlers(); } From 88485681a412b1da0b8d658fede3f57b82c34cd2 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 3 Feb 2025 13:33:07 +0900 Subject: [PATCH 086/149] Use starting tag's ending line number --- src/policy_classes/BlockPolicySingleEvent.cpp | 2 +- src/policy_classes/ConditionalPolicySingleEvent.hpp | 2 +- src/policy_classes/ForPolicySingleEvent.hpp | 2 +- src/policy_classes/IfStmtPolicySingleEvent.hpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp index 9fe813a..4374c37 100644 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -77,6 +77,7 @@ void BlockPolicy::CollectBlockHandlers() { blockDepth = ctx.depth; data = BlockData{}; data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; } else { if (!blockPolicy) blockPolicy = make_unique_policy({this}); ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); @@ -86,7 +87,6 @@ void BlockPolicy::CollectBlockHandlers() { closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { if(blockDepth && blockDepth == ctx.depth) { blockDepth = 0; - data.endLineNumber = ctx.endLineNumber; NotifyAll(ctx); InitializeBlockPolicyHandlers(); } diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp index 245019e..36a0516 100644 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ b/src/policy_classes/ConditionalPolicySingleEvent.hpp @@ -64,6 +64,7 @@ public srcDispatch::PolicyListener { conditionalDepth = ctx.depth; data = ConditionalData{}; data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; CollectConditionHandlers(); CollectBlockHandlers(); } @@ -73,7 +74,6 @@ public srcDispatch::PolicyListener { closeEventMap[DispatchEvent] =[this](srcSAXEventContext& ctx) { if (conditionalDepth && conditionalDepth == ctx.depth) { conditionalDepth = 0; - data.endLineNumber = ctx.endLineNumber; NotifyAll(ctx); InitializeConditionalPolicyHandlers(); } diff --git a/src/policy_classes/ForPolicySingleEvent.hpp b/src/policy_classes/ForPolicySingleEvent.hpp index 8c76f60..37f5cd5 100644 --- a/src/policy_classes/ForPolicySingleEvent.hpp +++ b/src/policy_classes/ForPolicySingleEvent.hpp @@ -84,6 +84,7 @@ public srcDispatch::PolicyListener { forDepth = ctx.depth; data = ForData{}; data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; CollectControlHandlers(); CollectBlockHandlers(); } @@ -93,7 +94,6 @@ public srcDispatch::PolicyListener { closeEventMap[ParserState::forstmt] =[this](srcSAXEventContext& ctx) { if (forDepth && forDepth == ctx.depth) { forDepth = 0; - data.endLineNumber = ctx.endLineNumber; NotifyAll(ctx); InitializeForPolicyHandlers(); } diff --git a/src/policy_classes/IfStmtPolicySingleEvent.hpp b/src/policy_classes/IfStmtPolicySingleEvent.hpp index 1b577e3..d5763d2 100644 --- a/src/policy_classes/IfStmtPolicySingleEvent.hpp +++ b/src/policy_classes/IfStmtPolicySingleEvent.hpp @@ -82,6 +82,7 @@ public srcDispatch::PolicyListener { ifStmtDepth = ctx.depth; data = IfStmtData{}; data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; CollectIfHandlers(); CollectElseIfHandlers(); CollectElseHandlers(); @@ -92,7 +93,6 @@ public srcDispatch::PolicyListener { closeEventMap[ParserState::ifgroup] =[this](srcSAXEventContext& ctx) { if (ifStmtDepth && ifStmtDepth == ctx.depth) { ifStmtDepth = 0; - data.endLineNumber = ctx.endLineNumber; NotifyAll(ctx); InitializeIfStmtPolicyHandlers(); } From 95a3788234375058c11ed00038c0520ca6fa75ed Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 3 Feb 2025 16:26:23 +0900 Subject: [PATCH 087/149] Take out special-block events and currentFunction --- src/dispatcher/srcDispatchUtilities.hpp | 4 +- src/dispatcher/srcDispatcher.hpp | 77 ++----------------------- 2 files changed, 8 insertions(+), 73 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index e4f5c1e..299fa1d 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -46,7 +46,7 @@ namespace srcDispatch { name, function, functiondecl, constructor, constructordecl, destructordecl, destructor, argument, index, block, type, typeprev, init, op, literal, modifier, memberlist, classn, structn, namespacen, super_list, super, publicaccess, privateaccess, protectedaccess, preproc, whilestmt, forstmt, - ifstmt, nonterminal, macro, classblock, functionblock, constructorblock, ifblock, whileblock, forblock, + ifstmt, nonterminal, macro, switchstmt, switchcase, specifier, throws, typedefexpr, userdefined, comment, annotation, condition, dostmt, incr, decr, control, ifgroup, range, @@ -96,7 +96,7 @@ namespace srcDispatch { unsigned int endLineNumber; std::vector triggerField; std::string currentFilePath, currentFileName, currentFileLanguage, currentsrcMLRevision, - currentTag, currentToken, currentAttributeName, currentAttributeValue, currentFunctionName, + currentTag, currentToken, currentAttributeName, currentAttributeValue, currentClassName, currentFileChecksum; std::vector currentNamespaces; std::size_t depth; diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index de4f1ab..dcb86cb 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -252,14 +252,8 @@ namespace srcDispatch { DispatchEvent(ParserState::ifgroup, ElementState::open); } }, { "if", [this]() { - if(!ifelseflagopen) { - ifflagopen = true; - ++ctx.triggerField[ParserState::ifstmt]; - DispatchEvent(ParserState::ifstmt, ElementState::open); - } else { - ++ctx.triggerField[ParserState::elseif]; - DispatchEvent(ParserState::elseif, ElementState::open); - } + ++ctx.triggerField[ParserState::ifstmt]; + DispatchEvent(ParserState::ifstmt, ElementState::open); } }, { "else", [this]() { ++ctx.triggerField[ParserState::elsestmt]; @@ -375,32 +369,6 @@ namespace srcDispatch { } }, { "block", [this]() { ++ctx.triggerField[ParserState::block]; - if(constructorflagopen) { - constructorflagopen = false; - ++ctx.triggerField[ParserState::constructorblock]; - DispatchEvent(ParserState::constructorblock, ElementState::open); - } - if(functionflagopen) { - functionflagopen = false; - ++ctx.triggerField[ParserState::functionblock]; - DispatchEvent(ParserState::functionblock, ElementState::open); - } - if(classflagopen) { - classflagopen = false; //next time it's set to true, we definitely are in a new one. - ++ctx.triggerField[ParserState::classblock]; - } - if(whileflagopen) { - whileflagopen = false; - ++ctx.triggerField[ParserState::whileblock]; - } - if(ifelseflagopen) { - ifflagopen = false; - ++ctx.triggerField[ParserState::ifblock]; - } - if(forflagopen) { - forflagopen = false; - ++ctx.triggerField[ParserState::forblock]; - } DispatchEvent(ParserState::block, ElementState::open); } }, { "init", [this]() { @@ -562,22 +530,14 @@ namespace srcDispatch { --ctx.triggerField[ParserState::ifgroup]; } }, { "if", [this]() { - if(!ifelseflagopen) { - --ctx.triggerField[ParserState::ifblock]; - DispatchEvent(ParserState::ifstmt, ElementState::close); - --ctx.triggerField[ParserState::ifstmt]; - }else{ - --ctx.triggerField[ParserState::elseif]; - DispatchEvent(ParserState::elseif, ElementState::close); - ifelseflagopen = false; - } + DispatchEvent(ParserState::ifstmt, ElementState::close); + --ctx.triggerField[ParserState::ifstmt]; } }, { "else", [this]() { --ctx.triggerField[ParserState::elsestmt]; DispatchEvent(ParserState::elsestmt, ElementState::close); } }, { "for", [this]() { - --ctx.triggerField[ParserState::forblock]; DispatchEvent(ParserState::forstmt, ElementState::close); --ctx.triggerField[ParserState::forstmt]; } }, @@ -586,7 +546,6 @@ namespace srcDispatch { DispatchEvent(ParserState::control, ElementState::close); } }, { "while", [this]() { - --ctx.triggerField[ParserState::whileblock]; DispatchEvent(ParserState::whilestmt, ElementState::close); --ctx.triggerField[ParserState::whilestmt]; } }, @@ -610,27 +569,14 @@ namespace srcDispatch { --ctx.triggerField[ParserState::call]; } }, { "function", [this]() { - DispatchEvent(ParserState::functionblock, ElementState::close); - ctx.currentFunctionName.clear(); - --ctx.triggerField[ParserState::functionblock]; - DispatchEvent(ParserState::function, ElementState::close); --ctx.triggerField[ParserState::function]; } }, { "constructor", [this]() { - //This code causes problems for some reason. FIX. - DispatchEvent(ParserState::constructorblock, ElementState::close); - ctx.currentFunctionName.clear(); - --ctx.triggerField[ParserState::constructorblock]; - DispatchEvent(ParserState::constructor, ElementState::close); --ctx.triggerField[ParserState::constructor]; } }, { "destructor", [this]() { - //This code causes problems for some reason. FIX. -/* DispatchEvent(ParserState::functionblock, ElementState::close); - --ctx.triggerField[ParserState::functionblock];*/ - DispatchEvent(ParserState::destructor, ElementState::close); --ctx.triggerField[ParserState::destructor]; } }, @@ -647,15 +593,13 @@ namespace srcDispatch { --ctx.triggerField[ParserState::destructordecl]; } }, { "class", [this]() { - --ctx.triggerField[ParserState::classblock]; - DispatchEvent(ParserState::classn, ElementState::close); ctx.currentClassName.clear(); + DispatchEvent(ParserState::classn, ElementState::close); --ctx.triggerField[ParserState::classn]; } }, { "struct", [this]() { - --ctx.triggerField[ParserState::classblock]; - DispatchEvent(ParserState::structn, ElementState::close); ctx.currentClassName.clear(); + DispatchEvent(ParserState::structn, ElementState::close); --ctx.triggerField[ParserState::classn]; } }, { "namespace", [this]() { @@ -1024,15 +968,6 @@ namespace srcDispatch { collectedText->append(ch, len); } - if((ctx.And({ParserState::name, ParserState::function}) || ctx.And({ParserState::name, ParserState::constructor})) && ctx.Nor({ParserState::functionblock, ParserState::type, ParserState::parameterlist, ParserState::genericargumentlist, ParserState::constructorblock, ParserState::throws, ParserState::annotation})) { - ctx.currentFunctionName = std::all_of( - std::begin(ctx.currentToken), - std::end(ctx.currentToken), - [](char c) { - if(std::isalnum(c) || c == '_') return true; - return false; - }) ? ctx.currentToken : ""; - } process->second(); if (generateArchive) { ctx.write_content(ctx.currentToken); } } From 1a730246067a46728799f9631531d71619327b57 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 3 Feb 2025 16:51:10 +0900 Subject: [PATCH 088/149] Update srcSAX and remove uneeded flags --- src/dispatcher/srcDispatchUtilities.hpp | 6 ---- src/dispatcher/srcDispatcher.hpp | 40 +++++++++++++------------ srcSAX | 2 +- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 299fa1d..efcf3ad 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -481,12 +481,6 @@ namespace srcDispatch { return std::make_unique(args); } - constexpr std::string get_qualified_name(const char* localname, const char* prefix) { - if(prefix == nullptr) return localname; - return std::string(prefix) + ":" + localname; - } - - } #endif diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index dcb86cb..d959c1d 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -73,7 +73,6 @@ namespace srcDispatch { private: std::unordered_map< std::string, std::function> process_map, process_map2; - bool classflagopen, functionflagopen, constructorflagopen, whileflagopen, ifflagopen, elseflagopen, ifelseflagopen, forflagopen, switchflagopen; bool dispatching; bool generateArchive; @@ -151,13 +150,12 @@ namespace srcDispatch { } } - srcDispatcher(PolicyListener * listener, bool genArchive = false) : EventDispatcher(srcml_element_stack) { + srcDispatcher(PolicyListener * listener, bool genArchive = false) : EventDispatcher(element_stack) { elementListeners = CreateListeners(listener); numberAllocatedListeners = elementListeners.size(); dispatching = false; collectedText = std::optional(); generateArchive = genArchive; - classflagopen = functionflagopen = constructorflagopen = whileflagopen = ifflagopen = elseflagopen = ifelseflagopen = forflagopen = switchflagopen = false; if(genArchive) { ctx.archiveBuffer = xmlBufferCreate(); @@ -166,13 +164,13 @@ namespace srcDispatch { InitializeHandlers(); } - srcDispatcher(std::initializer_list listeners, bool genArchive = false) : EventDispatcher(srcml_element_stack) { + srcDispatcher(std::initializer_list listeners, bool genArchive = false) : EventDispatcher(element_stack) { elementListeners = listeners; numberAllocatedListeners = elementListeners.size(); dispatching = false; collectedText = std::optional(); generateArchive = genArchive; - classflagopen = functionflagopen = constructorflagopen = whileflagopen = ifflagopen = elseflagopen = ifelseflagopen = forflagopen = switchflagopen = false; + if(genArchive) { ctx.archiveBuffer = xmlBufferCreate(); ctx.writer = xmlNewTextWriterMemory(ctx.archiveBuffer, 0); @@ -255,6 +253,10 @@ namespace srcDispatch { ++ctx.triggerField[ParserState::ifstmt]; DispatchEvent(ParserState::ifstmt, ElementState::open); } }, + { "elseif", [this]() { + ++ctx.triggerField[ParserState::elseif]; + DispatchEvent(ParserState::elseif, ElementState::open); + } }, { "else", [this]() { ++ctx.triggerField[ParserState::elsestmt]; DispatchEvent(ParserState::elsestmt, ElementState::open); @@ -268,7 +270,6 @@ namespace srcDispatch { DispatchEvent(ParserState::control, ElementState::open); } }, { "while", [this]() { - whileflagopen = true; ++ctx.triggerField[ParserState::whilestmt]; DispatchEvent(ParserState::whilestmt, ElementState::open); } }, @@ -291,12 +292,10 @@ namespace srcDispatch { DispatchEvent(ParserState::call, ElementState::open); } }, { "function", [this]() { - functionflagopen = true; ++ctx.triggerField[ParserState::function]; DispatchEvent(ParserState::function, ElementState::open); } }, { "constructor", [this]() { - constructorflagopen = true; ++ctx.triggerField[ParserState::constructor]; DispatchEvent(ParserState::constructor, ElementState::open); } }, @@ -313,12 +312,10 @@ namespace srcDispatch { DispatchEvent(ParserState::constructordecl, ElementState::open); } }, { "class", [this]() { - classflagopen = true; ++ctx.triggerField[ParserState::classn]; DispatchEvent(ParserState::classn, ElementState::open); } }, { "struct", [this]() { - classflagopen = true; ++ctx.triggerField[ParserState::classn]; DispatchEvent(ParserState::structn, ElementState::open); } }, @@ -347,7 +344,6 @@ namespace srcDispatch { DispatchEvent(ParserState::privateaccess, ElementState::open); } }, { "destructor", [this]() { - //functionflagopen = true; ++ctx.triggerField[ParserState::destructor]; DispatchEvent(ParserState::destructor, ElementState::open); } }, @@ -532,7 +528,11 @@ namespace srcDispatch { { "if", [this]() { DispatchEvent(ParserState::ifstmt, ElementState::close); --ctx.triggerField[ParserState::ifstmt]; - } }, + } }, + { "elseif", [this]() { + DispatchEvent(ParserState::elseif, ElementState::close); + --ctx.triggerField[ParserState::elseif]; + } }, { "else", [this]() { --ctx.triggerField[ParserState::elsestmt]; DispatchEvent(ParserState::elsestmt, ElementState::close); @@ -871,9 +871,10 @@ namespace srcDispatch { ++ctx.depth; - std::string localName = get_qualified_name(localname, prefix); + std::string localName = srcSAXHandler::get_qualified_name(localname, prefix); ctx.currentTag = localName; + // Re-think this. At least use processed list later and think about having a special object. std::string name; if(num_attributes) { name = attributes[0].value; @@ -887,16 +888,17 @@ namespace srcDispatch { if(name == "operator" && (localName == "function" || localName == "function_decl")) { ctx.isOperator = true; } + if(name == "elseif" && localName == "if") { - ifelseflagopen = true; + localName = "elseif"; } - if(localName != "") { + // form attribute map for(int pos = 0; pos < num_attributes; ++pos) { - std::string attributeName = get_qualified_name(attributes[pos].localname, attributes[pos].prefix); + std::string attributeName = srcSAXHandler::get_qualified_name(attributes[pos].localname, attributes[pos].prefix); if(strcmp(attributes[pos].localname, "start") == 0) { int length = ::index(attributes[pos].value, ':') - attributes[pos].value; ctx.startLineNumber = std::stoi(std::string(attributes[pos].value, length)); @@ -922,10 +924,10 @@ namespace srcDispatch { ctx.currentNamespaces.emplace_back(); } - if(ctx.currentTag == "name" && nameCollectElements.contains(srcml_element_stack.back())) { + if(ctx.currentTag == "name" && nameCollectElements.contains(element_stack.back())) { collectedText = std::string(); } else if(collectedText && (ctx.currentTag == "block" || ctx.currentTag == "super_list")) { - if(srcml_element_stack.back() == "namespace") { + if(element_stack.back() == "namespace") { ctx.currentNamespaces.back() = *collectedText; } else { ctx.currentClassName = *collectedText; @@ -993,7 +995,7 @@ namespace srcDispatch { virtual void endElement(const char * localname, const char * prefix, const char * URI) override { - std::string localName = get_qualified_name(localname, prefix); + std::string localName = srcSAXHandler::get_qualified_name(localname, prefix); ctx.currentTag = localName; std::unordered_map>::const_iterator process2 = process_map2.find(localname); diff --git a/srcSAX b/srcSAX index d4e394e..e4495b5 160000 --- a/srcSAX +++ b/srcSAX @@ -1 +1 @@ -Subproject commit d4e394e2aa20b583492748f8daec5ec64fc9d536 +Subproject commit e4495b5d41dbe42d12e89ce7132418504c5b35fe From a77dd27699f7afe63a81ae3cd9c6e04d89113bb1 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 3 Feb 2025 17:25:34 +0900 Subject: [PATCH 089/149] Update srcSAX --- srcSAX | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srcSAX b/srcSAX index e4495b5..2eaca55 160000 --- a/srcSAX +++ b/srcSAX @@ -1 +1 @@ -Subproject commit e4495b5d41dbe42d12e89ce7132418504c5b35fe +Subproject commit 2eaca5524b070b85f2f35697eddcc3aed4e1150f From 7643d2b208122d1a97a9eb96cb637d525f9e0bfb Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 3 Feb 2025 18:47:21 +0900 Subject: [PATCH 090/149] Update srcSAX --- srcSAX | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srcSAX b/srcSAX index 2eaca55..6054efe 160000 --- a/srcSAX +++ b/srcSAX @@ -1 +1 @@ -Subproject commit 2eaca5524b070b85f2f35697eddcc3aed4e1150f +Subproject commit 6054efed88421622a058a207037d8d51c76fd899 From b805e836fa6ba15873efa56816ca7652724dd7d5 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 3 Feb 2025 20:46:46 +0900 Subject: [PATCH 091/149] Store when elseif is called so can call write close callback --- src/dispatcher/srcDispatcher.hpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index d959c1d..30acf2f 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -74,6 +74,8 @@ namespace srcDispatch { private: std::unordered_map< std::string, std::function> process_map, process_map2; + std::vector elseif_positions; + bool dispatching; bool generateArchive; ParserState currentPState; @@ -150,12 +152,12 @@ namespace srcDispatch { } } - srcDispatcher(PolicyListener * listener, bool genArchive = false) : EventDispatcher(element_stack) { + srcDispatcher(PolicyListener * listener, bool genArchive = false) + : EventDispatcher(element_stack), + elseif_positions(), dispatching(false), generateArchive(genArchive), collectedText(std::optional()) { + elementListeners = CreateListeners(listener); numberAllocatedListeners = elementListeners.size(); - dispatching = false; - collectedText = std::optional(); - generateArchive = genArchive; if(genArchive) { ctx.archiveBuffer = xmlBufferCreate(); @@ -164,12 +166,12 @@ namespace srcDispatch { InitializeHandlers(); } - srcDispatcher(std::initializer_list listeners, bool genArchive = false) : EventDispatcher(element_stack) { + srcDispatcher(std::initializer_list listeners, bool genArchive = false) + : EventDispatcher(element_stack), + elseif_positions(), dispatching(false), generateArchive(genArchive), collectedText(std::optional()) { + elementListeners = listeners; numberAllocatedListeners = elementListeners.size(); - dispatching = false; - collectedText = std::optional(); - generateArchive = genArchive; if(genArchive) { ctx.archiveBuffer = xmlBufferCreate(); @@ -891,6 +893,7 @@ namespace srcDispatch { if(name == "elseif" && localName == "if") { localName = "elseif"; + elseif_positions.push_back(element_stack.size()); } if(localName != "") { @@ -912,7 +915,7 @@ namespace srcDispatch { } - std::unordered_map>::const_iterator process = process_map.find(localname); + std::unordered_map>::const_iterator process = process_map.find(localName); if (process != process_map.end()) { process->second(); } @@ -996,9 +999,15 @@ namespace srcDispatch { virtual void endElement(const char * localname, const char * prefix, const char * URI) override { std::string localName = srcSAXHandler::get_qualified_name(localname, prefix); + + if(!elseif_positions.empty() && element_stack.size() == elseif_positions.back()) { + localName = "elseif"; + elseif_positions.pop_back(); + } + ctx.currentTag = localName; - std::unordered_map>::const_iterator process2 = process_map2.find(localname); + std::unordered_map>::const_iterator process2 = process_map2.find(localName); if (process2 != process_map2.end()) { process2->second(); } From eb80e07d4532406188b2b5f6448e5c0bb60d7608 Mon Sep 17 00:00:00 2001 From: Ender Date: Mon, 3 Feb 2025 22:07:06 -0500 Subject: [PATCH 092/149] Updated srcSAX --- srcSAX | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srcSAX b/srcSAX index 6054efe..6dc4d70 160000 --- a/srcSAX +++ b/srcSAX @@ -1 +1 @@ -Subproject commit 6054efed88421622a058a207037d8d51c76fd899 +Subproject commit 6dc4d70a0d31c0d70840c64cb8e0c4ac277fd333 From a33532cdc3744c2a36b1627c44e1525f77601f40 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D" Date: Wed, 5 Feb 2025 12:02:37 +0900 Subject: [PATCH 093/149] Add case policy --- src/policy_classes/BlockPolicySingleEvent.cpp | 15 +++- src/policy_classes/BlockPolicySingleEvent.hpp | 6 +- src/policy_classes/CasePolicySingleEvent.hpp | 88 +++++++++++++++++++ srcSAX | 2 +- 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 src/policy_classes/CasePolicySingleEvent.hpp diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp index 4374c37..7ca3556 100644 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -48,7 +48,9 @@ void BlockPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcS data.conditionals.push_back(policy->Data()); } else if (typeid(DoPolicy) == typeid(*policy)) { data.conditionals.push_back(policy->Data()); - } else { + } else if (typeid(CasePolicy) == typeid(*policy)) { + data.cases.push_back(policy->Data()); + } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } @@ -67,6 +69,7 @@ void BlockPolicy::InitializeBlockPolicyHandlers() { CollectWhileHandlers(); CollectForHandlers(); CollectDoHandlers(); + CollectCaseHandlers(); } @@ -162,3 +165,13 @@ void BlockPolicy::CollectDoHandlers() { }; } + +void BlockPolicy::CollectCaseHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::switchcase] = [this](srcSAXEventContext& ctx) { + if (!casePolicy) casePolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(casePolicy.get()); + }; + +} + diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index 43d1dcf..95c7462 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -12,6 +12,7 @@ #include #include #include +#include class IfStmtPolicy; class SwitchPolicy; @@ -36,8 +37,9 @@ struct BlockData { std::vector> blocks; std::vector conditionals; -}; + std::vector> cases; +}; class BlockPolicy : public srcDispatch::EventListener, @@ -57,6 +59,7 @@ public srcDispatch::PolicyListener { std::unique_ptr whilePolicy; std::unique_ptr forPolicy; std::unique_ptr doPolicy; + std::unique_ptr casePolicy; public: BlockPolicy(std::initializer_list listeners); @@ -80,6 +83,7 @@ public srcDispatch::PolicyListener { void CollectWhileHandlers(); void CollectForHandlers(); void CollectDoHandlers(); + void CollectCaseHandlers(); }; diff --git a/src/policy_classes/CasePolicySingleEvent.hpp b/src/policy_classes/CasePolicySingleEvent.hpp new file mode 100644 index 0000000..d14aac1 --- /dev/null +++ b/src/policy_classes/CasePolicySingleEvent.hpp @@ -0,0 +1,88 @@ +/** + * @file CasePolicySingleEvent.hpp + * + * + */ +#ifndef INCLUDED_CASE_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_CASE_POLICY_SINGLE_EVENT_HPP + +#include +#include +#include + +#include + +#include +#include +#include + + +// Collect the expression in the return +// +class CasePolicy : +public srcDispatch::EventListener, +public srcDispatch::PolicyDispatcher, +public srcDispatch::PolicyListener { + +private: + std::shared_ptr data; + std::size_t caseDepth; + std::unique_ptr exprPolicy; + +public: + CasePolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), + data{}, + caseDepth(0) { + InitializeCasePolicyHandlers(); + } + + ~CasePolicy() {} + +protected: + std::any DataInner() const override { return data; } + + virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { + if (typeid(ExpressionPolicy) == typeid(*policy)) { + data = policy->Data(); + ctx.dispatcher->RemoveListener(nullptr); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + +private: + void InitializeCasePolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[ParserState::switchcase] = [this](srcSAXEventContext& ctx) { + if (!caseDepth) { + caseDepth = ctx.depth; + data = std::make_shared(); + CollectExpressionHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::switchcase] = [this](srcSAXEventContext& ctx) { + if (caseDepth && caseDepth == ctx.depth) { + caseDepth = 0; + NotifyAll(ctx); + InitializeCasePolicyHandlers(); + } + }; + } + + void CollectExpressionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if (!exprPolicy) exprPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); + }; + } + +}; + +#endif diff --git a/srcSAX b/srcSAX index 6dc4d70..93cbbee 160000 --- a/srcSAX +++ b/srcSAX @@ -1 +1 @@ -Subproject commit 6dc4d70a0d31c0d70840c64cb8e0c4ac277fd333 +Subproject commit 93cbbee89957ea1dc8c744c72b7a835016ad0fd3 From b9e7c01c1b49485e136217829dc7608bebf924e7 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 21 Apr 2025 15:20:36 +0900 Subject: [PATCH 094/149] Update diff to include if replace/convert --- src/dispatcher/srcDispatchUtilities.hpp | 5 +++++ src/dispatcher/srcDispatcher.hpp | 26 ++++++++++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 4958cb7..9b25bca 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -63,8 +63,13 @@ namespace srcDispatch { enum DiffOperation { DELETE, INSERT, COMMON }; struct Diff { + Diff(DiffOperation operation, size_t depth, bool isReplace, bool isConvert) + : operation(operation), depth(depth), isReplace(false), isConvert(false) {} + DiffOperation operation; size_t depth; + bool isReplace; + bool isConvert; }; diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 9e1d4ff..28b5e42 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -61,10 +61,10 @@ namespace srcDispatch { listeners.emplace_back(new policy({policyListener})); return CreateListenersImpl(policyListener, listeners); } - template<> - std::list CreateListenersImpl<>(PolicyListener * listener [[maybe_unused]], std::list & listeners) { - return listeners; - } + // template<> + // std::list CreateListenersImpl<>(PolicyListener * listener [[maybe_unused]], std::list & listeners) { + // return listeners; + // } const std::string DIFF_URI = "http://www.srcML.org/srcDiff"; @@ -153,7 +153,7 @@ namespace srcDispatch { } } - srcDispatcher(PolicyListener * listener, bool genArchive = false) : EventDispatcher(srcml_element_stack) { + srcDispatcher(PolicyListener * listener, bool genArchive = false) : EventDispatcher(element_stack) { elementListeners = CreateListeners(listener); numberAllocatedListeners = elementListeners.size(); dispatching = false; @@ -168,7 +168,7 @@ namespace srcDispatch { InitializeHandlers(); } - srcDispatcher(std::initializer_list listeners, bool genArchive = false) : EventDispatcher(srcml_element_stack) { + srcDispatcher(std::initializer_list listeners, bool genArchive = false) : EventDispatcher(element_stack) { elementListeners = listeners; numberAllocatedListeners = elementListeners.size(); dispatching = false; @@ -904,7 +904,15 @@ namespace srcDispatch { { "common", DiffOperation::COMMON }, }; - ctx.diffStack.emplace_back(diff_op_map[std::string(localname)], ctx.depth + 1); + bool isReplace = false; + bool isConvert = false; + if(num_attributes) { + isReplace = attributes[0].value == std::string("replace"); + isConvert = attributes[0].value == std::string("convert"); + + } + + ctx.diffStack.emplace_back(diff_op_map[std::string(localname)], ctx.depth + 1, isReplace, isConvert); return; @@ -973,10 +981,10 @@ namespace srcDispatch { ctx.currentNamespaces.emplace_back(); } - if(ctx.currentTag == "name" && nameCollectElements.contains(srcml_element_stack.back())) { + if(ctx.currentTag == "name" && nameCollectElements.contains(element_stack.back())) { collectedText = std::string(); } else if(collectedText && (ctx.currentTag == "block" || ctx.currentTag == "super_list")) { - if(srcml_element_stack.back() == "namespace") { + if(element_stack.back() == "namespace") { ctx.currentNamespaces.back() = *collectedText; } else { ctx.currentClassName = *collectedText; From bfe71a6f79f83550b35dd957482b83f5502dc99a Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 21 Apr 2025 15:27:07 +0900 Subject: [PATCH 095/149] Fix warning breaking build --- src/CMakeLists.txt | 2 ++ src/dispatcher/srcDispatcher.hpp | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 88ef82b..9cac515 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,6 +28,8 @@ file(GLOB POLICY_CLASSES_HEADER policy_classes/*.hpp) # find needed libraries find_package(LibXml2 REQUIRED) +add_compile_options(-Wno-unused-function) + add_library(srcdispatch ${DISPATCHER_SOURCE} ${DISPATCHER_HEADER} ${POLICY_CLASSES_SOURCE} ${POLICY_CLASSES_HEADER}) target_link_libraries(srcdispatch PRIVATE LibXml2::LibXml2) diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 28b5e42..68a182c 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -61,10 +61,10 @@ namespace srcDispatch { listeners.emplace_back(new policy({policyListener})); return CreateListenersImpl(policyListener, listeners); } - // template<> - // std::list CreateListenersImpl<>(PolicyListener * listener [[maybe_unused]], std::list & listeners) { - // return listeners; - // } + template<> + std::list CreateListenersImpl<>(PolicyListener * listener [[maybe_unused]], std::list & listeners) { + return listeners; + } const std::string DIFF_URI = "http://www.srcML.org/srcDiff"; From d5b80e6eefd7adb35978c271d15cefa866f4cea3 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 25 Apr 2025 08:54:03 +0900 Subject: [PATCH 096/149] Fix bug where friends are not collected and mark if it is --- src/policy_classes/ClassPolicySingleEvent.hpp | 3 ++- src/policy_classes/FunctionPolicySingleEvent.hpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index f339e41..993c9d6 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -228,7 +228,8 @@ public srcDispatch::PolicyListener { } }; std::function functionEvent = [this](srcSAXEventContext& ctx) { - if ((classDepth + 3) == ctx.depth) { + if ((classDepth + 3) == ctx.depth + || ((classDepth + 4) == ctx.depth && ctx.elementStack.back() == "friend")) { if (!functionPolicy) functionPolicy = make_unique_policy({this}); ctx.dispatcher->AddListenerDispatch(functionPolicy.get()); } diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp index e15dbe4..06d50ff 100644 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ b/src/policy_classes/FunctionPolicySingleEvent.hpp @@ -40,6 +40,7 @@ struct FunctionData { bool isOverride; bool isConstExpr; bool isDelete; + bool isFriend; std::set stereotypes; @@ -141,6 +142,7 @@ public srcDispatch::PolicyListener { data.lineNumber = ctx.startLineNumber; data.language = ctx.currentFileLanguage; data.filename = ctx.currentFilePath; + data.isFriend = ctx.elementStack.back() == "friend"; std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); if (stereotype_attr_itr != ctx.attributes.end()){ std::istringstream stereostring(stereotype_attr_itr->second); From 3680fe3366f86b810fb266c66cdeff38f4ceb2fb Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 30 Apr 2025 12:50:22 +0900 Subject: [PATCH 097/149] Log if block is a pseudo block --- src/dispatcher/srcDispatchUtilities.hpp | 2 +- src/dispatcher/srcDispatcher.hpp | 3 +++ src/policy_classes/BlockPolicySingleEvent.cpp | 1 + src/policy_classes/BlockPolicySingleEvent.hpp | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index efcf3ad..dcb94d3 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -101,7 +101,7 @@ namespace srcDispatch { std::vector currentNamespaces; std::size_t depth; std::map attributes; - bool isPrev, isOperator, endArchive; + bool isPrev, isOperator, isPseudo, endArchive; /** * write_start_tag diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 30acf2f..f37f5c5 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -890,6 +890,9 @@ namespace srcDispatch { if(name == "operator" && (localName == "function" || localName == "function_decl")) { ctx.isOperator = true; } + if(name == "pseudo" && localName == "block") { + ctx.isPseudo = true; + } if(name == "elseif" && localName == "if") { localName = "elseif"; diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp index 7ca3556..c20f3a2 100644 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ b/src/policy_classes/BlockPolicySingleEvent.cpp @@ -81,6 +81,7 @@ void BlockPolicy::CollectBlockHandlers() { data = BlockData{}; data.startLineNumber = ctx.startLineNumber; data.endLineNumber = ctx.endLineNumber; + data.isPseudo = ctx.isPseudo; } else { if (!blockPolicy) blockPolicy = make_unique_policy({this}); ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp index 95c7462..c3b86b4 100644 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ b/src/policy_classes/BlockPolicySingleEvent.hpp @@ -31,6 +31,8 @@ struct BlockData { unsigned int startLineNumber; unsigned int endLineNumber; + bool isPseudo; + std::vector> locals; std::vector> returns; std::vector> expr_stmts; From 5a51438e0c2d2ffd7d24af5c936267d865eccedf Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 2 May 2025 10:03:38 +0900 Subject: [PATCH 098/149] Add change to DiffOperation --- src/dispatcher/srcDispatchUtilities.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 864a298..bf5a085 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -61,7 +61,7 @@ namespace srcDispatch { // do not put anything after these xmlattribute, tokenstring, empty, MAXENUMVALUE = empty}; - enum DiffOperation { DELETE, INSERT, COMMON }; + enum DiffOperation { DELETE, INSERT, COMMON, CHANGE }; struct Diff { Diff(DiffOperation operation, size_t depth, bool isReplace, bool isConvert) : operation(operation), depth(depth), isReplace(false), isConvert(false) {} From 581d9ff7be99656b73ccb436bdf967a7bfb67bb7 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 5 May 2025 17:24:31 +0900 Subject: [PATCH 099/149] Fixes to dispatcher for detecting archive and common should be first --- src/dispatcher/srcDispatchUtilities.hpp | 11 ++++++----- src/dispatcher/srcDispatcher.hpp | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index bf5a085..e6dc76c 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -61,10 +61,10 @@ namespace srcDispatch { // do not put anything after these xmlattribute, tokenstring, empty, MAXENUMVALUE = empty}; - enum DiffOperation { DELETE, INSERT, COMMON, CHANGE }; + enum DiffOperation { COMMON, DELETE, INSERT, CHANGE }; struct Diff { - Diff(DiffOperation operation, size_t depth, bool isReplace, bool isConvert) - : operation(operation), depth(depth), isReplace(false), isConvert(false) {} + Diff(DiffOperation operation, size_t depth = 0, bool isReplace = false, bool isConvert = false) + : operation(operation), depth(depth), isReplace(isReplace), isConvert(isConvert) {} DiffOperation operation; size_t depth; @@ -81,11 +81,12 @@ namespace srcDispatch { archiveBuffer{0}, dispatcher(dispatcher), elementStack(elementStack), - diffStack(), + diffStack{COMMON}, startLineNumber(0), endLineNumber(0), triggerField(std::vector(MAXENUMVALUE, 0)), depth(0), + isArchive(false), isPrev(false), isOperator(false), endArchive(false) {} @@ -113,7 +114,7 @@ namespace srcDispatch { std::vector currentNamespaces; std::size_t depth; std::map attributes; - bool isPrev, isOperator, isPseudo, endArchive; + bool isArchive, isPrev, isOperator, isPseudo, endArchive; /** * write_start_tag diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 67e985d..c8060eb 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -802,7 +802,7 @@ namespace srcDispatch { virtual void startUnit(const char * localname, const char * prefix, const char * URI, int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, const struct srcsax_attribute * attributes) override { - + ctx.isArchive = is_archive; if (generateArchive) { ctx.write_start_tag(localname, prefix, URI, num_namespaces, namespaces, num_attributes, attributes); } From b3ff5ce73e00c04a9c80a6770423e974f788c33a Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 5 May 2025 17:52:02 +0900 Subject: [PATCH 100/149] Fix header of type policy --- src/policy_classes/TypePolicySingleEvent.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/policy_classes/TypePolicySingleEvent.hpp b/src/policy_classes/TypePolicySingleEvent.hpp index 6b24d2e..98367ee 100644 --- a/src/policy_classes/TypePolicySingleEvent.hpp +++ b/src/policy_classes/TypePolicySingleEvent.hpp @@ -2,8 +2,8 @@ * @file TypePolicySingleEvent.hpp * */ -#ifndef INCLUDED_TYPE1_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_TYPE1_POLICY_SINGLE_EVENT_HPP +#ifndef INCLUDED_TYPE_POLICY_SINGLE_EVENT_HPP +#define INCLUDED_TYPE_POLICY_SINGLE_EVENT_HPP #include From b03c8f35c6421624832f7c302e692a2151762b10 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 6 May 2025 17:24:33 +0900 Subject: [PATCH 101/149] Add NONE type to diff types --- src/dispatcher/srcDispatchUtilities.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index e6dc76c..5612987 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -61,7 +61,7 @@ namespace srcDispatch { // do not put anything after these xmlattribute, tokenstring, empty, MAXENUMVALUE = empty}; - enum DiffOperation { COMMON, DELETE, INSERT, CHANGE }; + enum DiffOperation { COMMON, DELETE, INSERT, CHANGE, NONE }; struct Diff { Diff(DiffOperation operation, size_t depth = 0, bool isReplace = false, bool isConvert = false) : operation(operation), depth(depth), isReplace(isReplace), isConvert(isConvert) {} From db6c0ac0a45dbb2a53fd5995887756f6be55986c Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 12 May 2025 11:36:37 +0900 Subject: [PATCH 102/149] Update dispatcher to also handle constructor style C++ initialization --- src/policy_classes/DeclPolicySingleEvent.hpp | 62 ++++++++++++++++++-- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/src/policy_classes/DeclPolicySingleEvent.hpp b/src/policy_classes/DeclPolicySingleEvent.hpp index 71b1600..d701983 100644 --- a/src/policy_classes/DeclPolicySingleEvent.hpp +++ b/src/policy_classes/DeclPolicySingleEvent.hpp @@ -21,22 +21,41 @@ struct DeclData { unsigned int lineNumber; - std::shared_ptr type; - std::shared_ptr name; - std::shared_ptr init; - std::shared_ptr range; - bool isStatic; + std::shared_ptr type; + std::shared_ptr name; + std::shared_ptr init; + std::vector> arguments; + std::shared_ptr range; + + bool isStatic; friend std::ostream& operator<<(std::ostream& out, const DeclData& declData) { if(declData.type) { out << declData.type->ToString(); } + if (declData.name) { out << ' ' << *declData.name; } + if (declData.init) { out << " = " << *declData.init; } + + if (!declData.arguments.empty()) { + + out << '('; + bool outputComma = false; + for(const std::shared_ptr& argument : declData.arguments) { + if(outputComma) { + out << ", "; + } + out << *argument; + outputComma = true; + } + out << ')'; + } + if (declData.range) { out << " : " << *declData.range; } @@ -80,8 +99,12 @@ public srcDispatch::PolicyListener { } else if (typeid(ExpressionPolicy) == typeid(*policy)) { if(ctx.IsOpen(ParserState::range)) { data.range = policy->Data(); - } else { + } else if(ctx.IsOpen(ParserState::init)) { data.init = policy->Data(); + } else if(ctx.IsOpen(ParserState::argumentlist)) { + data.arguments.emplace_back(policy->Data()); + } else { + throw std::string("Unhandled ExpressionPolicy condition"); } } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); @@ -108,6 +131,7 @@ public srcDispatch::PolicyListener { CollectTypeHandlers(); CollectNameHandlers(); CollectInitHandlers(); + CollectArgumentList(); CollectRangeHandlers(); }; @@ -177,6 +201,32 @@ public srcDispatch::PolicyListener { }; } + + void CollectArgumentList() { + using namespace srcDispatch; + openEventMap[ParserState::argumentlist] = [this](srcSAXEventContext &ctx) { + if (!declDepth || (declDepth + 1) != ctx.depth) { + return; + } + + openEventMap[ParserState::argument] = [this](srcSAXEventContext &ctx) { + if (!exprPolicy) { + exprPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); + }; + + closeEventMap[ParserState::argument] = [this](srcSAXEventContext &ctx) { + NopOpenEvents({ParserState::expr}); + }; + + }; + + closeEventMap[ParserState::argumentlist] = [this](srcSAXEventContext &ctx) { + NopOpenEvents({ParserState::argument}); + }; + } + void CollectRangeHandlers() { using namespace srcDispatch; openEventMap[ParserState::range] = [this](srcSAXEventContext& ctx) { From 61b8e262d8057312e33e088942c0b2ecd2b2c9f8 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Sat, 17 May 2025 04:07:12 +0900 Subject: [PATCH 103/149] Add allowance for detecting class with in language other than C/C++ --- src/policy_classes/ClassPolicySingleEvent.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index 993c9d6..613d384 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -222,29 +222,31 @@ public srcDispatch::PolicyListener { NopCloseEvents({ParserState::name, ParserState::super_list, ParserState::tokenstring}); // set up to listen to decl_stmt, member, and class policies openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - if ((classDepth + 3) == ctx.depth) { + if ((classDepth + 3) == ctx.depth || ((classDepth + 2) == ctx.depth && ctx.currentFileLanguage != "C" && ctx.currentFileLanguage != "C++" )) { if (!declPolicy) declPolicy = make_unique_policy({this}); ctx.dispatcher->AddListenerDispatch(declPolicy.get()); } }; std::function functionEvent = [this](srcSAXEventContext& ctx) { if ((classDepth + 3) == ctx.depth - || ((classDepth + 4) == ctx.depth && ctx.elementStack.back() == "friend")) { + || ((classDepth + 4) == ctx.depth && ctx.elementStack.back() == "friend") + || ((classDepth + 2) == ctx.depth && ctx.currentFileLanguage != "C" && ctx.currentFileLanguage != "C++" )) { if (!functionPolicy) functionPolicy = make_unique_policy({this}); ctx.dispatcher->AddListenerDispatch(functionPolicy.get()); } }; - openEventMap[ParserState::function] = functionEvent; - openEventMap[ParserState::functiondecl] = functionEvent; - openEventMap[ParserState::constructor] = functionEvent; + openEventMap[ParserState::function] = functionEvent; + openEventMap[ParserState::functiondecl] = functionEvent; + openEventMap[ParserState::constructor] = functionEvent; openEventMap[ParserState::constructordecl] = functionEvent; std::function destructorEvent = [this](srcSAXEventContext& ctx) { - if ((classDepth + 3) == ctx.depth) { + if ((classDepth + 3) == ctx.depth + || ((classDepth + 2) == ctx.depth && ctx.currentFileLanguage != "C" && ctx.currentFileLanguage != "C++" )) { data.hasDestructor = true; } }; - openEventMap[ParserState::destructor] = destructorEvent; + openEventMap[ParserState::destructor] = destructorEvent; openEventMap[ParserState::destructordecl] = destructorEvent; } }; From 8d7687558e5c15b78e67041b660c4d3ae8562f13 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Sun, 18 May 2025 22:40:23 +0900 Subject: [PATCH 104/149] Make indices an optional variable --- src/policy_classes/NamePolicySingleEvent.cpp | 37 +++++++++++--------- src/policy_classes/NamePolicySingleEvent.hpp | 8 ++--- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index 4a3c866..9c5bd5c 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -22,20 +22,10 @@ std::string NameData::SimpleName() const { std::string NameData::ToString() const { - std::string str = name; - for(const std::any& name_element : names) { - if(name_element.type() == typeid(std::shared_ptr)) { - str += std::any_cast>(name_element)->ToString(); - } else { - str += std::any_cast>(name_element)->op; - } - } - - if(templateArgumentList) { - str += templateArgumentList->ToString(); - } + std::ostringstream out; + out << *this; - return str; + return out.str(); } @@ -53,9 +43,23 @@ std::ostream& operator<<(std::ostream& out, const NameData& nameData) { out << *nameData.templateArgumentList; } - for(std::shared_ptr index : nameData.indices) { - out << '[' << *index << ']'; + if(nameData.indices) { + out << '['; + + bool printComma = false; + for (const std::shared_ptr& index : *nameData.indices) { + + if(printComma) { + out << ", "; + } + + out << *index; + printComma = true; + } + + out << ']'; } + return out; } @@ -71,7 +75,7 @@ void NamePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSA } else if(typeid(TemplateArgumentListPolicy) == typeid(*policy)) { data.templateArgumentList = policy->Data(); } else if(typeid(ExpressionPolicy) == typeid(*policy)) { - data.indices.push_back(policy->Data()); + data.indices->push_back(policy->Data()); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); } @@ -142,6 +146,7 @@ void NamePolicy::CollectTemplateArgumentListHandlers() { void NamePolicy::CollectArrayIndicesHandlers() { using namespace srcDispatch; openEventMap[ParserState::index] = [this](srcSAXEventContext& ctx) { + data.indices = std::vector>(); openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { if(!expressionPolicy) expressionPolicy = make_unique_policy({this}); ctx.dispatcher->AddListenerDispatch(expressionPolicy.get()); diff --git a/src/policy_classes/NamePolicySingleEvent.hpp b/src/policy_classes/NamePolicySingleEvent.hpp index 0d70e55..6c8385f 100644 --- a/src/policy_classes/NamePolicySingleEvent.hpp +++ b/src/policy_classes/NamePolicySingleEvent.hpp @@ -26,10 +26,10 @@ struct TemplateArgumentListData; struct NameData { unsigned int lineNumber; - std::string name; - std::vector names; - std::shared_ptr templateArgumentList; - std::vector> indices; + std::string name; + std::vector names; + std::shared_ptr templateArgumentList; + std::optional>> indices; std::string SimpleName() const; std::string ToString() const; From e2682bc3d798cd229c63716fe05b57316a472c7b Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Sun, 18 May 2025 22:46:01 +0900 Subject: [PATCH 105/149] Make sure not to overwrite indices if multiple --- src/policy_classes/NamePolicySingleEvent.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp index 9c5bd5c..6c2bd67 100644 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ b/src/policy_classes/NamePolicySingleEvent.cpp @@ -146,7 +146,9 @@ void NamePolicy::CollectTemplateArgumentListHandlers() { void NamePolicy::CollectArrayIndicesHandlers() { using namespace srcDispatch; openEventMap[ParserState::index] = [this](srcSAXEventContext& ctx) { - data.indices = std::vector>(); + if(!data.indices) { + data.indices = std::vector>(); + } openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { if(!expressionPolicy) expressionPolicy = make_unique_policy({this}); ctx.dispatcher->AddListenerDispatch(expressionPolicy.get()); From 337d3aeffad76c2854596eabae522f2b6c766a09 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 19 May 2025 11:23:55 +0900 Subject: [PATCH 106/149] Extract access specifier out of Class --- src/policy_classes/AccessSpecifier.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/policy_classes/AccessSpecifier.hpp diff --git a/src/policy_classes/AccessSpecifier.hpp b/src/policy_classes/AccessSpecifier.hpp new file mode 100644 index 0000000..911cc47 --- /dev/null +++ b/src/policy_classes/AccessSpecifier.hpp @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file AccessSpecifier.hpp + * + * @copyright Copyright (C) 2025-2025 srcML, LLC. (www.srcML.org) + * + * This file is part of the srcML Infrastructure. + */ + +#ifndef INCLUDED_ACCESS_SPECIFIER_HPP +#define INCLUDED_ACCESS_SPECIFIER_HPP + +enum AccessSpecifier { + PUBLIC = 0, + PRIVATE = 1, + PROTECTED = 2 +}; + +#endif From 470763023445ae7a22bc7004637e5eab692aea9b Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 19 May 2025 11:24:22 +0900 Subject: [PATCH 107/149] Add access specifier include to class --- src/policy_classes/ClassPolicySingleEvent.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index 613d384..59d5eb6 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -7,6 +7,7 @@ #include +#include #include #include #include @@ -22,7 +23,6 @@ struct ParentData; struct ClassData { enum ClassType : std::size_t { CLASS, STRUCT }; //UNION, ENUM? - enum AccessSpecifier { PUBLIC = 0, PRIVATE = 1, PROTECTED = 2 }; std::vector namespaces; @@ -48,7 +48,7 @@ struct ClassData { struct ParentData { std::string name; bool isVirtual; - ClassData::AccessSpecifier accessSpecifier; + AccessSpecifier accessSpecifier; }; From a52cd2c366aea72a98fef3cd849ec3dc87f227df Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 19 May 2025 11:26:46 +0900 Subject: [PATCH 108/149] Remove more reference to old Class Access specifier enum --- src/policy_classes/ClassPolicySingleEvent.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index 59d5eb6..2dd6919 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -60,7 +60,7 @@ public srcDispatch::PolicyListener { private: ClassData data; std::size_t classDepth; - ClassData::AccessSpecifier currentRegion; + AccessSpecifier currentRegion; std::unique_ptr namePolicy; std::unique_ptr declPolicy; From 1358a29d2594cf4f6f039bbeb4a9014fed3eabc2 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 19 May 2025 11:28:41 +0900 Subject: [PATCH 109/149] Remove more reference to old Class Access specifier enum --- src/policy_classes/ClassPolicySingleEvent.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index 2dd6919..cc4ff05 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -72,7 +72,7 @@ public srcDispatch::PolicyListener { : srcDispatch::PolicyDispatcher(listeners), data{}, classDepth(0), - currentRegion(ClassData::PUBLIC) { + currentRegion(PUBLIC) { InitializeClassPolicyHandlers(); } @@ -187,18 +187,18 @@ public srcDispatch::PolicyListener { openEventMap[ParserState::super_list] = [this](srcSAXEventContext& ctx) { if ((classDepth + 1) == ctx.depth) { openEventMap[ParserState::super] = [this](srcSAXEventContext& ctx) { - data.parents.emplace_back(ParentData{ "", false, ClassData::PUBLIC }); + data.parents.emplace_back(ParentData{ "", false, PUBLIC }); }; closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { if (ctx.And({ ParserState::specifier })) { if (ctx.currentToken == "virtual") { data.parents.back().isVirtual = true; } else if (ctx.currentToken == "public") { - data.parents.back().accessSpecifier = ClassData::PUBLIC; + data.parents.back().accessSpecifier = PUBLIC; } else if (ctx.currentToken == "private") { - data.parents.back().accessSpecifier = ClassData::PRIVATE; + data.parents.back().accessSpecifier = PRIVATE; } else if (ctx.currentToken == "protected") { - data.parents.back().accessSpecifier = ClassData::PROTECTED; + data.parents.back().accessSpecifier = PROTECTED; } } else if (ctx.And({ ParserState::name })) { data.parents.back().name += ctx.currentToken; @@ -254,19 +254,19 @@ public srcDispatch::PolicyListener { // should always be in a region once block starts, so should not have to close openEventMap[ParserState::publicaccess] = [this](srcSAXEventContext& ctx) { if ((classDepth + 2) == ctx.depth) { - currentRegion = ClassData::PUBLIC; + currentRegion = PUBLIC; } }; openEventMap[ParserState::protectedaccess] = [this](srcSAXEventContext& ctx) { if ((classDepth + 2) == ctx.depth) { - currentRegion = ClassData::PROTECTED; + currentRegion = PROTECTED; } }; openEventMap[ParserState::privateaccess] = [this](srcSAXEventContext& ctx) { if ((classDepth + 2) == ctx.depth) { - currentRegion = ClassData::PRIVATE; + currentRegion = PRIVATE; } }; From ef86f99aa55acceda50870ee0f20a53d71a5d080 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 19 May 2025 11:48:50 +0900 Subject: [PATCH 110/149] Flush out more of how access works as part of function/decl --- src/policy_classes/AccessSpecifier.hpp | 7 ++++--- src/policy_classes/ClassPolicySingleEvent.hpp | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/policy_classes/AccessSpecifier.hpp b/src/policy_classes/AccessSpecifier.hpp index 911cc47..ef4b8bb 100644 --- a/src/policy_classes/AccessSpecifier.hpp +++ b/src/policy_classes/AccessSpecifier.hpp @@ -11,9 +11,10 @@ #define INCLUDED_ACCESS_SPECIFIER_HPP enum AccessSpecifier { - PUBLIC = 0, - PRIVATE = 1, - PROTECTED = 2 + NONE = 0, + PUBLIC = 1, + PRIVATE = 2, + PROTECTED = 3 }; #endif diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp index cc4ff05..c2ff3ec 100644 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ b/src/policy_classes/ClassPolicySingleEvent.hpp @@ -58,8 +58,8 @@ public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { private: - ClassData data; - std::size_t classDepth; + ClassData data; + std::size_t classDepth; AccessSpecifier currentRegion; std::unique_ptr namePolicy; From 5b976caf203475c2fbd485ec3638bbc3bccc5bfc Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 28 May 2025 14:39:54 +0900 Subject: [PATCH 111/149] Handle goto, break, continue, label, and throw --- src/dispatcher/srcDispatchUtilities.hpp | 1 + src/dispatcher/srcDispatcher.hpp | 40 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 5612987..680f293 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -48,6 +48,7 @@ namespace srcDispatch { super_list, super, publicaccess, privateaccess, protectedaccess, preproc, whilestmt, forstmt, ifstmt, nonterminal, macro, switchstmt, switchcase, specifier, throws, typedefexpr, userdefined, comment, annotation, condition, + gotostmt, breakstmt, continuestmt, label, throwstmt, dostmt, incr, decr, control, ifgroup, range, // NLP states diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index c8060eb..9243edb 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -459,6 +459,10 @@ namespace srcDispatch { ++ctx.triggerField[ParserState::throws]; DispatchEvent(ParserState::throws, ElementState::open); } }, + { "throw", [this]() { + ++ctx.triggerField[ParserState::throwstmt]; + DispatchEvent(ParserState::throwstmt, ElementState::open); + } }, { "annotation", [this]() { ++ctx.triggerField[ParserState::annotation]; DispatchEvent(ParserState::annotation, ElementState::open); @@ -467,6 +471,22 @@ namespace srcDispatch { ++ctx.triggerField[ParserState::returnstmt]; DispatchEvent(ParserState::returnstmt, ElementState::open); } }, + { "goto", [this]() { + ++ctx.triggerField[ParserState::gotostmt]; + DispatchEvent(ParserState::gotostmt, ElementState::open); + } }, + { "break", [this]() { + ++ctx.triggerField[ParserState::breakstmt]; + DispatchEvent(ParserState::breakstmt, ElementState::open); + } }, + { "continue", [this]() { + ++ctx.triggerField[ParserState::continuestmt]; + DispatchEvent(ParserState::continuestmt, ElementState::open); + } }, + { "label", [this]() { + ++ctx.triggerField[ParserState::label]; + DispatchEvent(ParserState::label, ElementState::open); + } }, { "comment", [this]() { ++ctx.triggerField[ParserState::comment]; DispatchEvent(ParserState::comment, ElementState::open); @@ -722,10 +742,30 @@ namespace srcDispatch { --ctx.triggerField[ParserState::returnstmt]; DispatchEvent(ParserState::returnstmt, ElementState::close); } }, + { "goto", [this]() { + --ctx.triggerField[ParserState::gotostmt]; + DispatchEvent(ParserState::gotostmt, ElementState::close); + } }, + { "break", [this]() { + --ctx.triggerField[ParserState::breakstmt]; + DispatchEvent(ParserState::breakstmt, ElementState::close); + } }, + { "continue", [this]() { + --ctx.triggerField[ParserState::continuestmt]; + DispatchEvent(ParserState::continuestmt, ElementState::close); + } }, + { "label", [this]() { + --ctx.triggerField[ParserState::label]; + DispatchEvent(ParserState::label, ElementState::close); + } }, { "throws", [this]() { --ctx.triggerField[ParserState::throws]; DispatchEvent(ParserState::throws, ElementState::close); } }, + { "throw", [this]() { + --ctx.triggerField[ParserState::throwstmt]; + DispatchEvent(ParserState::throwstmt, ElementState::close); + } }, { "annotation", [this]() { --ctx.triggerField[ParserState::annotation]; DispatchEvent(ParserState::annotation, ElementState::close); From d3f521475bcfc24730cf7d6434adc2bc5a1d5ed7 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 28 May 2025 15:25:09 +0900 Subject: [PATCH 112/149] Add handlers for try/catch --- src/dispatcher/srcDispatchUtilities.hpp | 2 +- src/dispatcher/srcDispatcher.hpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 680f293..0a907a0 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -48,7 +48,7 @@ namespace srcDispatch { super_list, super, publicaccess, privateaccess, protectedaccess, preproc, whilestmt, forstmt, ifstmt, nonterminal, macro, switchstmt, switchcase, specifier, throws, typedefexpr, userdefined, comment, annotation, condition, - gotostmt, breakstmt, continuestmt, label, throwstmt, + gotostmt, breakstmt, continuestmt, label, throwstmt, trystmt, catchstmt, dostmt, incr, decr, control, ifgroup, range, // NLP states diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 9243edb..2376d38 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -463,6 +463,14 @@ namespace srcDispatch { ++ctx.triggerField[ParserState::throwstmt]; DispatchEvent(ParserState::throwstmt, ElementState::open); } }, + { "try", [this]() { + ++ctx.triggerField[ParserState::trystmt]; + DispatchEvent(ParserState::trystmt, ElementState::open); + } }, + { "catch", [this]() { + ++ctx.triggerField[ParserState::catchstmt]; + DispatchEvent(ParserState::catchstmt, ElementState::open); + } }, { "annotation", [this]() { ++ctx.triggerField[ParserState::annotation]; DispatchEvent(ParserState::annotation, ElementState::open); @@ -766,6 +774,14 @@ namespace srcDispatch { --ctx.triggerField[ParserState::throwstmt]; DispatchEvent(ParserState::throwstmt, ElementState::close); } }, + { "try", [this]() { + --ctx.triggerField[ParserState::trystmt]; + DispatchEvent(ParserState::trystmt, ElementState::close); + } }, + { "catch", [this]() { + --ctx.triggerField[ParserState::catchstmt]; + DispatchEvent(ParserState::catchstmt, ElementState::close); + } }, { "annotation", [this]() { --ctx.triggerField[ParserState::annotation]; DispatchEvent(ParserState::annotation, ElementState::close); From 0b8200f170d79797024081636ed1a0832da960c0 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 29 May 2025 16:48:30 +0900 Subject: [PATCH 113/149] Remove uneeded nop and add methods to get pstate and estate --- src/dispatcher/srcDispatchUtilities.hpp | 125 +----------------------- src/dispatcher/srcDispatcher.hpp | 9 ++ 2 files changed, 10 insertions(+), 124 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 0a907a0..03809f1 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -300,130 +300,7 @@ namespace srcDispatch { private: void DefaultEventHandlers() { - using namespace srcDispatch; - - NopOpenEvents({ - ParserState::declstmt, - ParserState::exprstmt, - ParserState::parameterlist, - ParserState::condition, - ParserState::dostmt, - ParserState::incr, - ParserState::decr, - ParserState::ifstmt, - ParserState::forstmt, - ParserState::control, - ParserState::whilestmt, - ParserState::switchstmt, - ParserState::switchcase, - ParserState::templates, - ParserState::argumentlist, - ParserState::genericargumentlist, - ParserState::call, - ParserState::function, - ParserState::constructor, - ParserState::functiondecl, - ParserState::destructordecl, - ParserState::constructordecl, - ParserState::classn, - ParserState::structn, - ParserState::publicaccess, - ParserState::protectedaccess, - ParserState::privateaccess, - ParserState::destructor, - ParserState::parameter, - ParserState::super, - ParserState::super_list, - ParserState::memberlist, - ParserState::index, - ParserState::op, - ParserState::block, - ParserState::init, - ParserState::argument, - ParserState::literal, - ParserState::modifier, - ParserState::decl, - ParserState::type, - ParserState::typedefexpr, - ParserState::expr, - ParserState::name, - ParserState::macro, - ParserState::specifier, - ParserState::snoun, - ParserState::propersnoun, - ParserState::sadjective, - ParserState::spronoun, - ParserState::sverb, - ParserState::returnstmt, - ParserState::throws, - ParserState::comment, - ParserState::stereotype, - ParserState::annotation, - ParserState::archive, - }); - - NopCloseEvents({ - ParserState::declstmt, - ParserState::exprstmt, - ParserState::parameterlist, - ParserState::condition, - ParserState::dostmt, - ParserState::incr, - ParserState::decr, - ParserState::ifstmt, - ParserState::forstmt, - ParserState::control, - ParserState::whilestmt, - ParserState::switchstmt, - ParserState::switchcase, - ParserState::templates, - ParserState::argumentlist, - ParserState::genericargumentlist, - ParserState::call, - ParserState::function, - ParserState::constructor, - ParserState::destructor, - ParserState::functiondecl, - ParserState::constructordecl, - ParserState::destructordecl, - ParserState::classn, - ParserState::structn, - ParserState::publicaccess, - ParserState::protectedaccess, - ParserState::privateaccess, - ParserState::parameter, - ParserState::super, - ParserState::super_list, - ParserState::memberlist, - ParserState::index, - ParserState::op, - ParserState::block, - ParserState::init, - ParserState::argument, - ParserState::literal, - ParserState::modifier, - ParserState::decl, - ParserState::type, - ParserState::typedefexpr, - ParserState::expr, - ParserState::name, - ParserState::macro, - ParserState::tokenstring, - ParserState::specifier, - ParserState::snoun, - ParserState::propersnoun, - ParserState::sadjective, - ParserState::spronoun, - ParserState::sverb, - ParserState::stereotype, - ParserState::returnstmt, - ParserState::throws, - ParserState::comment, - ParserState::annotation, - ParserState::archive, - }); - - } + } }; class EventDispatcher { diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 2376d38..75b7296 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -89,6 +89,15 @@ namespace srcDispatch { std::optional collectedText; protected: + + ParserState CurrentPState() const { + return currentPState; + } + + ElementState CurrentEState() const { + return currentEState; + } + void DispatchEvent(ParserState pstate, ElementState estate) override { dispatching = true; From dc4176c8bc99a3083a33dd93b0243ecdc106ad11 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 2 Jun 2025 12:02:46 +0900 Subject: [PATCH 114/149] Fix some style issues --- src/dispatcher/srcDispatchUtilities.hpp | 27 +++++++++++++------------ src/dispatcher/srcDispatcher.hpp | 1 - 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 03809f1..59bd523 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -133,13 +133,13 @@ namespace srcDispatch { * Overide for desired behaviour. */ void write_start_tag(const char* localname, const char* prefix, const char* URI [[maybe_unused]], - int num_namespaces [[maybe_unused]], const struct srcsax_namespace * namespaces [[maybe_unused]], int num_attributes, - const struct srcsax_attribute * attributes) { - xmlTextWriterStartElementNS(writer, (const xmlChar *)prefix, (const xmlChar *)localname, 0); + int num_namespaces [[maybe_unused]], const struct srcsax_namespace* namespaces [[maybe_unused]], int num_attributes, + const struct srcsax_attribute* attributes) { + xmlTextWriterStartElementNS(writer, (const xmlChar*)prefix, (const xmlChar*)localname, 0); for(int pos = 0; pos < num_attributes; ++pos) { std::string str(attributes[pos].localname); - xmlTextWriterWriteAttributeNS(writer, (const xmlChar *)attributes[pos].prefix, (const xmlChar *)attributes[pos].localname, - (const xmlChar *)attributes[pos].uri, (const xmlChar *)attributes[pos].value); + xmlTextWriterWriteAttributeNS(writer, (const xmlChar*)attributes[pos].prefix, (const xmlChar*)attributes[pos].localname, + (const xmlChar*)attributes[pos].uri, (const xmlChar )attributes[pos].value); } } /** @@ -148,7 +148,7 @@ namespace srcDispatch { * * Write out the provided text content, escaping everything but ". */ - void write_content(const std::string &text_content) { + void write_content(const std::string& text_content) { if(!text_content.empty()) { /* Normal output of text is for the most part @@ -230,6 +230,7 @@ namespace srcDispatch { class EventError : public std::runtime_error { public: EventError(const std::string& msg) : std::runtime_error(msg) {} }; + class EventListener { typedef std::unordered_map, std::hash> EventMap; protected: @@ -246,8 +247,8 @@ namespace srcDispatch { void SetDispatched(bool isDispatched) { dispatched = isDispatched; } - virtual const EventMap & GetOpenEventMap() const { return openEventMap; } - virtual const EventMap & GetCloseEventMap() const { return closeEventMap; } + virtual const EventMap& GetOpenEventMap() const { return openEventMap; } + virtual const EventMap& GetCloseEventMap() const { return closeEventMap; } virtual void HandleEvent() { dispatched = true; } virtual void HandleEvent(srcDispatch::ParserState pstate, srcDispatch::ElementState estate, srcDispatch::srcSAXEventContext& ctx) { @@ -316,7 +317,7 @@ namespace srcDispatch { srcSAXEventContext ctx; std::list elementListeners; - EventDispatcher(const std::vector & elementStack) + EventDispatcher(const std::vector& elementStack) : ctx(this, elementStack), elementListeners() {} virtual ~EventDispatcher() {} virtual void DispatchEvent(ParserState, ElementState) = 0; @@ -332,12 +333,12 @@ namespace srcDispatch { PolicyListener() {} virtual ~PolicyListener() {} - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventContext & ctx) = 0; - virtual void NotifyWrite(const PolicyDispatcher * policy, srcSAXEventContext & ctx) = 0; + virtual void Notify(const PolicyDispatcher* policy, const srcSAXEventContext& ctx) = 0; + virtual void NotifyWrite(const PolicyDispatcher* policy, srcSAXEventContext& ctx) = 0; }; class PolicyDispatcher{ public: - PolicyDispatcher(std::initializer_list listeners) : policyListeners(listeners){} + PolicyDispatcher(std::initializer_list listeners) : policyListeners(listeners){} virtual ~PolicyDispatcher() {} virtual void AddListener(PolicyListener* listener){ policyListeners.push_back(listener); @@ -355,7 +356,7 @@ namespace srcDispatch { std::list policyListeners; virtual std::any DataInner() const = 0; //TODO: These may not need to be synchronous or even called in the same method (i.e., notifyall) - virtual void NotifyAll(/*const*/ srcSAXEventContext & ctx) { + virtual void NotifyAll(/*const*/ srcSAXEventContext& ctx) { for(std::list::iterator listener = policyListeners.begin(); listener != policyListeners.end(); ++listener){ (*listener)->Notify(this, ctx); } diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 75b7296..58c8695 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -18,7 +18,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - #ifndef INCLUDED_SRCDISPATCHER_HPP #define INCLUDED_SRCDISPATCHER_HPP From 9ddc65940153d5d61250b6b7043f323b755ff8a4 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 2 Jun 2025 12:04:47 +0900 Subject: [PATCH 115/149] Remove accidental removal of pointer --- src/dispatcher/srcDispatchUtilities.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 59bd523..495b612 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -139,7 +139,7 @@ namespace srcDispatch { for(int pos = 0; pos < num_attributes; ++pos) { std::string str(attributes[pos].localname); xmlTextWriterWriteAttributeNS(writer, (const xmlChar*)attributes[pos].prefix, (const xmlChar*)attributes[pos].localname, - (const xmlChar*)attributes[pos].uri, (const xmlChar )attributes[pos].value); + (const xmlChar*)attributes[pos].uri, (const xmlChar*)attributes[pos].value); } } /** From a2189285a1f21bdd584bccfb0246365d68eede6a Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 2 Jun 2025 12:28:52 +0900 Subject: [PATCH 116/149] Add accessors for ctx --- src/dispatcher/srcDispatchUtilities.hpp | 21 +++++++++++++++++++++ src/dispatcher/srcDispatcher.hpp | 9 --------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 495b612..ef86ee2 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -317,10 +317,31 @@ namespace srcDispatch { srcSAXEventContext ctx; std::list elementListeners; + ParserState currentPState; + ElementState currentEState; + EventDispatcher(const std::vector& elementStack) : ctx(this, elementStack), elementListeners() {} virtual ~EventDispatcher() {} virtual void DispatchEvent(ParserState, ElementState) = 0; + +public: + const srcSAXEventContext& GetContext() const { + return ctx; + } + + srcSAXEventContext& GetContext() { + return ctx; + } + + ParserState CurrentPState() const { + return currentPState; + } + + ElementState CurrentEState() const { + return currentEState; + } + }; class PolicyError : public std::runtime_error { diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index 58c8695..b53750d 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -79,8 +79,6 @@ namespace srcDispatch { bool dispatching; bool generateArchive; - ParserState currentPState; - ElementState currentEState; std::size_t numberAllocatedListeners; @@ -89,13 +87,6 @@ namespace srcDispatch { protected: - ParserState CurrentPState() const { - return currentPState; - } - - ElementState CurrentEState() const { - return currentEState; - } void DispatchEvent(ParserState pstate, ElementState estate) override { From b585701cbdbc55689c90e02c115977cad30422c9 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 2 Jun 2025 15:33:45 +0900 Subject: [PATCH 117/149] Introduce some fixes for delta to work --- src/dispatcher/srcDispatchUtilities.hpp | 20 +++++++++----------- src/dispatcher/srcDispatcherSingleEvent.hpp | 3 +++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index ef86ee2..b879156 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -41,15 +41,13 @@ namespace srcDispatch { class EventDispatcher; enum ElementState {open, close}; - enum ParserState {decl, expr, parameter, declstmt, exprstmt, parameterlist, elseif, elsestmt, - argumentlist, argumentlisttemplate, call, templates, ctrlflow, endflow, genericargumentlist, - name, function, functiondecl, constructor, constructordecl, destructordecl, destructor, - argument, index, block, type, typeprev, init, op, literal, modifier, memberlist, classn, structn, namespacen, - super_list, super, publicaccess, privateaccess, protectedaccess, preproc, whilestmt, forstmt, - ifstmt, nonterminal, macro, - switchstmt, switchcase, specifier, throws, typedefexpr, userdefined, comment, annotation, condition, - gotostmt, breakstmt, continuestmt, label, throwstmt, trystmt, catchstmt, - dostmt, incr, decr, control, ifgroup, range, + enum ParserState {decl, expr, parameter, declstmt, exprstmt, parameterlist, elseif, elsestmt, argumentlist, argumentlisttemplate, + call, templates, ctrlflow, endflow, genericargumentlist, name, function, functiondecl, constructor, constructordecl, + destructordecl, destructor, argument, index, block, type, typeprev, init, op, literal, + modifier, memberlist, classn, structn, namespacen, super_list, super, publicaccess, privateaccess, protectedaccess, + preproc, whilestmt, forstmt, ifstmt, nonterminal, macro, switchstmt, switchcase, specifier, throws, + typedefexpr, userdefined, comment, annotation, condition, gotostmt, breakstmt, continuestmt, label, throwstmt, + trystmt, catchstmt, dostmt, incr, decr, control, ifgroup, range, returnstmt, // NLP states snoun, propersnoun, spronoun, sadjective, sverb, @@ -57,7 +55,7 @@ namespace srcDispatch { // stereotype state stereotype, - archive, unit, returnstmt, + archive, unit, // do not put anything after these xmlattribute, tokenstring, empty, MAXENUMVALUE = empty}; @@ -390,7 +388,7 @@ namespace srcDispatch { }; template - constexpr std::unique_ptr make_unique_policy(std::initializer_list&& args) { + constexpr std::unique_ptr make_unique_policy(const std::initializer_list& args) { return std::make_unique(args); } diff --git a/src/dispatcher/srcDispatcherSingleEvent.hpp b/src/dispatcher/srcDispatcherSingleEvent.hpp index 1a2e344..593239a 100644 --- a/src/dispatcher/srcDispatcherSingleEvent.hpp +++ b/src/dispatcher/srcDispatcherSingleEvent.hpp @@ -57,6 +57,9 @@ namespace srcDispatch { protected: virtual void DispatchEvent(srcDispatch::ParserState pstate, srcDispatch::ElementState estate) override { + srcDispatcher::currentPState = pstate; + srcDispatcher::currentEState = estate; + while(!dispatched) { dispatched = true; From 0d7105ed2d76f6d5a5410498b04ed23eba233051 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 3 Jun 2025 15:30:58 +0900 Subject: [PATCH 118/149] Add an offset to EventListener --- src/dispatcher/srcDispatchUtilities.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index b879156..46039d6 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -232,17 +232,23 @@ namespace srcDispatch { class EventListener { typedef std::unordered_map, std::hash> EventMap; protected: + std::size_t depth; + std::size_t offset; + bool dispatched; EventMap openEventMap, closeEventMap; - public: - EventListener() : dispatched(false) { + EventListener() : depth(0), offset(0), dispatched(false){ DefaultEventHandlers(); } virtual ~EventListener() {} + void SetOffset(std::size_t offset) { + this->offset = offset; + } + void SetDispatched(bool isDispatched) { dispatched = isDispatched; } virtual const EventMap& GetOpenEventMap() const { return openEventMap; } From c912a4e76113af6e6a916ed2273d09b715215671 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 3 Jun 2025 15:49:31 +0900 Subject: [PATCH 119/149] Make SetOffset virtual --- src/dispatcher/srcDispatchUtilities.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 46039d6..f9c3170 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -245,7 +245,7 @@ namespace srcDispatch { } virtual ~EventListener() {} - void SetOffset(std::size_t offset) { + virtual void SetOffset(std::size_t offset) { this->offset = offset; } From 5e3643e6446c212146e9cfafb8e1d7920568a316 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Tue, 3 Jun 2025 20:42:01 +0900 Subject: [PATCH 120/149] Add depth get/set and offset get --- src/dispatcher/srcDispatchUtilities.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index f9c3170..5cd7afa 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -245,6 +245,18 @@ namespace srcDispatch { } virtual ~EventListener() {} + std::size_t GetDepth() const { + return depth; + } + + virtual void SetDepth(std::size_t depth) { + this->depth = depth; + } + + std::size_t GetOffset() const { + return offset; + } + virtual void SetOffset(std::size_t offset) { this->offset = offset; } From ae11af4d72b733965802db3ece2dee5c39dc7503 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 4 Jun 2025 13:04:24 +0900 Subject: [PATCH 121/149] Remove offset and depth access --- src/dispatcher/srcDispatchUtilities.hpp | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 5cd7afa..31b9106 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -233,33 +233,17 @@ namespace srcDispatch { typedef std::unordered_map, std::hash> EventMap; protected: std::size_t depth; - std::size_t offset; bool dispatched; EventMap openEventMap, closeEventMap; public: - EventListener() : depth(0), offset(0), dispatched(false){ + EventListener() : depth(0), dispatched(false){ DefaultEventHandlers(); } - virtual ~EventListener() {} - - std::size_t GetDepth() const { - return depth; - } - - virtual void SetDepth(std::size_t depth) { - this->depth = depth; - } - std::size_t GetOffset() const { - return offset; - } - - virtual void SetOffset(std::size_t offset) { - this->offset = offset; - } + virtual ~EventListener() {} void SetDispatched(bool isDispatched) { dispatched = isDispatched; } From 263d6d963d7841f1999a3816b6d54d1d8ac2fd41 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 08:57:02 +0900 Subject: [PATCH 122/149] Switch out policies --- src/policy_classes/AccessSpecifier.hpp | 20 - src/policy_classes/BlockPolicySingleEvent.cpp | 178 --------- src/policy_classes/BlockPolicySingleEvent.hpp | 92 ----- src/policy_classes/CallPolicySingleEvent.cpp | 76 ---- src/policy_classes/CallPolicySingleEvent.hpp | 72 ---- src/policy_classes/CasePolicySingleEvent.hpp | 88 ----- src/policy_classes/ClassPolicy.hpp | 159 -------- src/policy_classes/ClassPolicySingleEvent.hpp | 286 -------------- src/policy_classes/CollectNLContext.hpp | 187 --------- .../ConditionPolicySingleEvent.hpp | 118 ------ src/policy_classes/ConditionalPolicy.hpp | 265 ------------- .../ConditionalPolicySingleEvent.hpp | 106 ----- .../ControlPolicySingleEvent.hpp | 178 --------- src/policy_classes/ConvertPlexerPolicy.hpp | 262 +++++++++++++ src/policy_classes/DeclDS.hpp | 74 ---- src/policy_classes/DeclPolicySingleEvent.hpp | 250 ------------ src/policy_classes/DeclTypePolicy.hpp | 228 ----------- .../DeclTypePolicySingleEvent.hpp | 102 ----- src/policy_classes/DeltaElement.hpp | 90 +++++ src/policy_classes/DeltaElement.tcc | 345 +++++++++++++++++ src/policy_classes/DoPolicySingleEvent.hpp | 36 -- .../ElseIfPolicySingleEvent.hpp | 36 -- src/policy_classes/ElsePolicySingleEvent.hpp | 36 -- src/policy_classes/ExprPolicy.hpp | 149 ------- .../ExprStmtPolicySingleEvent.hpp | 86 ----- .../ExpressionPolicySingleEvent.cpp | 106 ----- .../ExpressionPolicySingleEvent.hpp | 75 ---- src/policy_classes/ForPolicySingleEvent.hpp | 126 ------ src/policy_classes/FunctionCallPolicy.hpp | 100 ----- .../FunctionPolicySingleEvent.hpp | 281 -------------- .../FunctionSignaturePolicy.hpp | 180 --------- src/policy_classes/IfPolicySingleEvent.hpp | 36 -- .../IfStmtPolicySingleEvent.hpp | 136 ------- src/policy_classes/IncrPolicySingleEvent.hpp | 101 ----- .../LiteralPolicySingleEvent.hpp | 82 ---- src/policy_classes/NamePolicySingleEvent.cpp | 158 -------- src/policy_classes/NamePolicySingleEvent.hpp | 76 ---- .../OperatorPolicySingleEvent.hpp | 82 ---- src/policy_classes/ParamTypePolicy.hpp | 134 ------- src/policy_classes/ReturnPolicy.hpp | 44 --- .../ReturnPolicySingleEvent.hpp | 88 ----- src/policy_classes/SNLPolicy.hpp | 100 ----- src/policy_classes/StereotypePolicy.hpp | 89 ----- .../SwitchPolicySingleEvent.hpp | 35 -- .../TemplateArgumentListPolicySingleEvent.cpp | 104 ----- .../TemplateArgumentListPolicySingleEvent.hpp | 52 --- src/policy_classes/TypePolicySingleEvent.cpp | 143 ------- src/policy_classes/TypePolicySingleEvent.hpp | 54 --- src/policy_classes/UnitPolicySingleEvent.hpp | 106 ----- src/policy_classes/WhilePolicySingleEvent.hpp | 36 -- src/policy_classes/dispatcher | 0 src/policy_classes/srcDiffBlockPolicy.cpp | 362 ++++++++++++++++++ src/policy_classes/srcDiffBlockPolicy.hpp | 125 ++++++ src/policy_classes/srcDiffCallPolicy.cpp | 121 ++++++ src/policy_classes/srcDiffCallPolicy.hpp | 84 ++++ src/policy_classes/srcDiffCasePolicy.hpp | 47 +++ src/policy_classes/srcDiffCatchPolicy.hpp | 133 +++++++ src/policy_classes/srcDiffClassPolicy.cpp | 19 + src/policy_classes/srcDiffClassPolicy.hpp | 345 +++++++++++++++++ src/policy_classes/srcDiffConditionPolicy.hpp | 157 ++++++++ .../srcDiffConditionalPolicy.hpp | 115 ++++++ src/policy_classes/srcDiffControlPolicy.hpp | 166 ++++++++ src/policy_classes/srcDiffDeclPolicy.hpp | 312 +++++++++++++++ src/policy_classes/srcDiffDeclStmtPolicy.hpp | 119 ++++++ src/policy_classes/srcDiffDoPolicy.hpp | 47 +++ src/policy_classes/srcDiffElseIfPolicy.hpp | 47 +++ src/policy_classes/srcDiffElsePolicy.hpp | 48 +++ src/policy_classes/srcDiffExprStmtPolicy.hpp | 46 +++ src/policy_classes/srcDiffExprTypePolicy.hpp | 94 +++++ .../srcDiffExpressionPolicy.cpp | 162 ++++++++ .../srcDiffExpressionPolicy.hpp | 87 +++++ src/policy_classes/srcDiffForPolicy.hpp | 133 +++++++ src/policy_classes/srcDiffFunctionPolicy.hpp | 352 +++++++++++++++++ .../srcDiffGenericArgumentsPolicy.cpp | 126 ++++++ .../srcDiffGenericArgumentsPolicy.hpp | 63 +++ src/policy_classes/srcDiffGenericPolicy.cpp | 111 ++++++ src/policy_classes/srcDiffGenericPolicy.hpp | 65 ++++ src/policy_classes/srcDiffGotoPolicy.hpp | 123 ++++++ src/policy_classes/srcDiffIfPolicy.hpp | 47 +++ src/policy_classes/srcDiffIfStmtPolicy.hpp | 154 ++++++++ src/policy_classes/srcDiffIncrPolicy.hpp | 126 ++++++ src/policy_classes/srcDiffInitPolicy.hpp | 154 ++++++++ src/policy_classes/srcDiffLabelPolicy.hpp | 106 +++++ src/policy_classes/srcDiffLiteralPolicy.hpp | 107 ++++++ src/policy_classes/srcDiffNamePolicy.cpp | 189 +++++++++ src/policy_classes/srcDiffNamePolicy.hpp | 82 ++++ src/policy_classes/srcDiffOperatorPolicy.hpp | 107 ++++++ src/policy_classes/srcDiffReturnPolicy.hpp | 47 +++ src/policy_classes/srcDiffSwitchPolicy.hpp | 47 +++ src/policy_classes/srcDiffThrowPolicy.hpp | 47 +++ src/policy_classes/srcDiffTryPolicy.hpp | 125 ++++++ src/policy_classes/srcDiffTypePolicy.cpp | 161 ++++++++ src/policy_classes/srcDiffTypePolicy.hpp | 64 ++++ src/policy_classes/srcDiffUnitPolicy.hpp | 161 ++++++++ src/policy_classes/srcDiffWhilePolicy.hpp | 47 +++ 95 files changed, 6077 insertions(+), 5346 deletions(-) delete mode 100644 src/policy_classes/AccessSpecifier.hpp delete mode 100644 src/policy_classes/BlockPolicySingleEvent.cpp delete mode 100644 src/policy_classes/BlockPolicySingleEvent.hpp delete mode 100644 src/policy_classes/CallPolicySingleEvent.cpp delete mode 100644 src/policy_classes/CallPolicySingleEvent.hpp delete mode 100644 src/policy_classes/CasePolicySingleEvent.hpp delete mode 100644 src/policy_classes/ClassPolicy.hpp delete mode 100644 src/policy_classes/ClassPolicySingleEvent.hpp delete mode 100644 src/policy_classes/CollectNLContext.hpp delete mode 100644 src/policy_classes/ConditionPolicySingleEvent.hpp delete mode 100644 src/policy_classes/ConditionalPolicy.hpp delete mode 100644 src/policy_classes/ConditionalPolicySingleEvent.hpp delete mode 100644 src/policy_classes/ControlPolicySingleEvent.hpp create mode 100644 src/policy_classes/ConvertPlexerPolicy.hpp delete mode 100644 src/policy_classes/DeclDS.hpp delete mode 100644 src/policy_classes/DeclPolicySingleEvent.hpp delete mode 100644 src/policy_classes/DeclTypePolicy.hpp delete mode 100644 src/policy_classes/DeclTypePolicySingleEvent.hpp create mode 100644 src/policy_classes/DeltaElement.hpp create mode 100644 src/policy_classes/DeltaElement.tcc delete mode 100644 src/policy_classes/DoPolicySingleEvent.hpp delete mode 100644 src/policy_classes/ElseIfPolicySingleEvent.hpp delete mode 100644 src/policy_classes/ElsePolicySingleEvent.hpp delete mode 100644 src/policy_classes/ExprPolicy.hpp delete mode 100644 src/policy_classes/ExprStmtPolicySingleEvent.hpp delete mode 100644 src/policy_classes/ExpressionPolicySingleEvent.cpp delete mode 100644 src/policy_classes/ExpressionPolicySingleEvent.hpp delete mode 100644 src/policy_classes/ForPolicySingleEvent.hpp delete mode 100644 src/policy_classes/FunctionCallPolicy.hpp delete mode 100644 src/policy_classes/FunctionPolicySingleEvent.hpp delete mode 100644 src/policy_classes/FunctionSignaturePolicy.hpp delete mode 100644 src/policy_classes/IfPolicySingleEvent.hpp delete mode 100644 src/policy_classes/IfStmtPolicySingleEvent.hpp delete mode 100644 src/policy_classes/IncrPolicySingleEvent.hpp delete mode 100644 src/policy_classes/LiteralPolicySingleEvent.hpp delete mode 100644 src/policy_classes/NamePolicySingleEvent.cpp delete mode 100644 src/policy_classes/NamePolicySingleEvent.hpp delete mode 100644 src/policy_classes/OperatorPolicySingleEvent.hpp delete mode 100644 src/policy_classes/ParamTypePolicy.hpp delete mode 100644 src/policy_classes/ReturnPolicy.hpp delete mode 100644 src/policy_classes/ReturnPolicySingleEvent.hpp delete mode 100644 src/policy_classes/SNLPolicy.hpp delete mode 100644 src/policy_classes/StereotypePolicy.hpp delete mode 100644 src/policy_classes/SwitchPolicySingleEvent.hpp delete mode 100644 src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp delete mode 100644 src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp delete mode 100644 src/policy_classes/TypePolicySingleEvent.cpp delete mode 100644 src/policy_classes/TypePolicySingleEvent.hpp delete mode 100644 src/policy_classes/UnitPolicySingleEvent.hpp delete mode 100644 src/policy_classes/WhilePolicySingleEvent.hpp create mode 100644 src/policy_classes/dispatcher create mode 100644 src/policy_classes/srcDiffBlockPolicy.cpp create mode 100644 src/policy_classes/srcDiffBlockPolicy.hpp create mode 100644 src/policy_classes/srcDiffCallPolicy.cpp create mode 100644 src/policy_classes/srcDiffCallPolicy.hpp create mode 100644 src/policy_classes/srcDiffCasePolicy.hpp create mode 100644 src/policy_classes/srcDiffCatchPolicy.hpp create mode 100644 src/policy_classes/srcDiffClassPolicy.cpp create mode 100644 src/policy_classes/srcDiffClassPolicy.hpp create mode 100644 src/policy_classes/srcDiffConditionPolicy.hpp create mode 100644 src/policy_classes/srcDiffConditionalPolicy.hpp create mode 100644 src/policy_classes/srcDiffControlPolicy.hpp create mode 100644 src/policy_classes/srcDiffDeclPolicy.hpp create mode 100644 src/policy_classes/srcDiffDeclStmtPolicy.hpp create mode 100644 src/policy_classes/srcDiffDoPolicy.hpp create mode 100644 src/policy_classes/srcDiffElseIfPolicy.hpp create mode 100644 src/policy_classes/srcDiffElsePolicy.hpp create mode 100644 src/policy_classes/srcDiffExprStmtPolicy.hpp create mode 100644 src/policy_classes/srcDiffExprTypePolicy.hpp create mode 100644 src/policy_classes/srcDiffExpressionPolicy.cpp create mode 100644 src/policy_classes/srcDiffExpressionPolicy.hpp create mode 100644 src/policy_classes/srcDiffForPolicy.hpp create mode 100644 src/policy_classes/srcDiffFunctionPolicy.hpp create mode 100644 src/policy_classes/srcDiffGenericArgumentsPolicy.cpp create mode 100644 src/policy_classes/srcDiffGenericArgumentsPolicy.hpp create mode 100644 src/policy_classes/srcDiffGenericPolicy.cpp create mode 100644 src/policy_classes/srcDiffGenericPolicy.hpp create mode 100644 src/policy_classes/srcDiffGotoPolicy.hpp create mode 100644 src/policy_classes/srcDiffIfPolicy.hpp create mode 100644 src/policy_classes/srcDiffIfStmtPolicy.hpp create mode 100644 src/policy_classes/srcDiffIncrPolicy.hpp create mode 100644 src/policy_classes/srcDiffInitPolicy.hpp create mode 100644 src/policy_classes/srcDiffLabelPolicy.hpp create mode 100644 src/policy_classes/srcDiffLiteralPolicy.hpp create mode 100644 src/policy_classes/srcDiffNamePolicy.cpp create mode 100644 src/policy_classes/srcDiffNamePolicy.hpp create mode 100644 src/policy_classes/srcDiffOperatorPolicy.hpp create mode 100644 src/policy_classes/srcDiffReturnPolicy.hpp create mode 100644 src/policy_classes/srcDiffSwitchPolicy.hpp create mode 100644 src/policy_classes/srcDiffThrowPolicy.hpp create mode 100644 src/policy_classes/srcDiffTryPolicy.hpp create mode 100644 src/policy_classes/srcDiffTypePolicy.cpp create mode 100644 src/policy_classes/srcDiffTypePolicy.hpp create mode 100644 src/policy_classes/srcDiffUnitPolicy.hpp create mode 100644 src/policy_classes/srcDiffWhilePolicy.hpp diff --git a/src/policy_classes/AccessSpecifier.hpp b/src/policy_classes/AccessSpecifier.hpp deleted file mode 100644 index ef4b8bb..0000000 --- a/src/policy_classes/AccessSpecifier.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -/** - * @file AccessSpecifier.hpp - * - * @copyright Copyright (C) 2025-2025 srcML, LLC. (www.srcML.org) - * - * This file is part of the srcML Infrastructure. - */ - -#ifndef INCLUDED_ACCESS_SPECIFIER_HPP -#define INCLUDED_ACCESS_SPECIFIER_HPP - -enum AccessSpecifier { - NONE = 0, - PUBLIC = 1, - PRIVATE = 2, - PROTECTED = 3 -}; - -#endif diff --git a/src/policy_classes/BlockPolicySingleEvent.cpp b/src/policy_classes/BlockPolicySingleEvent.cpp deleted file mode 100644 index c20f3a2..0000000 --- a/src/policy_classes/BlockPolicySingleEvent.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/** - * @file BlockPolicySingleEvent.hpp - * - * MODIFIED FOR STEREOCODE - * - */ - -#include - -#include - -#include -#include -#include -#include -#include - -BlockPolicy::BlockPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - blockDepth(0) { - InitializeBlockPolicyHandlers(); -} - -BlockPolicy::~BlockPolicy() {} - -std::any BlockPolicy::DataInner() const { return std::make_shared(data); } - -void BlockPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(DeclTypePolicy) == typeid(*policy)) { - std::shared_ptr>> decl_data = policy->Data>>(); - for(std::shared_ptr decl : *decl_data) { - data.locals.push_back(decl); - } - } else if (typeid(ReturnPolicy) == typeid(*policy)) { - data.returns.push_back(policy->Data()); - } else if (typeid(ExprStmtPolicy) == typeid(*policy)) { - data.expr_stmts.push_back(policy->Data()); - } else if (typeid(BlockPolicy) == typeid(*policy)) { - data.blocks.push_back(policy->Data()); - } else if (typeid(IfStmtPolicy) == typeid(*policy)) { - data.conditionals.push_back(policy->Data()); - } else if (typeid(SwitchPolicy) == typeid(*policy)) { - data.conditionals.push_back(policy->Data()); - } else if (typeid(WhilePolicy) == typeid(*policy)) { - data.conditionals.push_back(policy->Data()); - } else if (typeid(ForPolicy) == typeid(*policy)) { - data.conditionals.push_back(policy->Data()); - } else if (typeid(DoPolicy) == typeid(*policy)) { - data.conditionals.push_back(policy->Data()); - } else if (typeid(CasePolicy) == typeid(*policy)) { - data.cases.push_back(policy->Data()); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListenerDispatch(nullptr); -} - -void BlockPolicy::InitializeBlockPolicyHandlers() { - using namespace srcDispatch; - - CollectBlockHandlers(); - CollectDeclstmtHandlers(); - CollectReturnHandlers(); - CollectExpressionHandlers(); - CollectIfStmtHandlers(); - CollectSwitchHandlers(); - CollectWhileHandlers(); - CollectForHandlers(); - CollectDoHandlers(); - CollectCaseHandlers(); - -} - -void BlockPolicy::CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(!blockDepth) { - blockDepth = ctx.depth; - data = BlockData{}; - data.startLineNumber = ctx.startLineNumber; - data.endLineNumber = ctx.endLineNumber; - data.isPseudo = ctx.isPseudo; - } else { - if (!blockPolicy) blockPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); - } - }; - - closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(blockDepth && blockDepth == ctx.depth) { - blockDepth = 0; - NotifyAll(ctx); - InitializeBlockPolicyHandlers(); - } - }; - -} - -void BlockPolicy::CollectReturnHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { - if (!returnPolicy) returnPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(returnPolicy.get()); - }; -} - -void BlockPolicy::CollectExpressionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { - if (!exprStmtPolicy) exprStmtPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(exprStmtPolicy.get()); - }; -} - -void BlockPolicy::CollectDeclstmtHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - if (!declstmtPolicy) declstmtPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(declstmtPolicy.get()); - }; -} - -void BlockPolicy::CollectIfStmtHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::ifgroup] = [this](srcSAXEventContext& ctx) { - if (!ifStmtPolicy) ifStmtPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(ifStmtPolicy.get()); - }; - -} - -void BlockPolicy::CollectSwitchHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::switchstmt] = [this](srcSAXEventContext& ctx) { - if (!switchPolicy) switchPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(switchPolicy.get()); - }; - -} - -void BlockPolicy::CollectWhileHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { - if (!whilePolicy) whilePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(whilePolicy.get()); - }; - -} - -void BlockPolicy::CollectForHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { - if (!forPolicy) forPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(forPolicy.get()); - }; - -} - -void BlockPolicy::CollectDoHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::dostmt] = [this](srcSAXEventContext& ctx) { - if (!doPolicy) doPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(doPolicy.get()); - }; - -} - -void BlockPolicy::CollectCaseHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::switchcase] = [this](srcSAXEventContext& ctx) { - if (!casePolicy) casePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(casePolicy.get()); - }; - -} - diff --git a/src/policy_classes/BlockPolicySingleEvent.hpp b/src/policy_classes/BlockPolicySingleEvent.hpp deleted file mode 100644 index c3b86b4..0000000 --- a/src/policy_classes/BlockPolicySingleEvent.hpp +++ /dev/null @@ -1,92 +0,0 @@ -/** - * @file BlockPolicySingleEvent.hpp - * - * MODIFIED FOR STEREOCODE - * - */ -#ifndef INCLUDED_BLOCK_POLICY_SINGE_EVENT_HPP -#define INCLUDED_BLOCK_POLICY_SINGE_EVENT_HPP - -#include - -#include -#include -#include -#include - -class IfStmtPolicy; -class SwitchPolicy; -class WhilePolicy; -class ForPolicy; -class DoPolicy; - -#include -#include -#include -#include -#include - -struct BlockData { - - unsigned int startLineNumber; - unsigned int endLineNumber; - - bool isPseudo; - - std::vector> locals; - std::vector> returns; - std::vector> expr_stmts; - - std::vector> blocks; - std::vector conditionals; - - std::vector> cases; -}; - -class BlockPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - BlockData data; - std::size_t blockDepth; - - std::unique_ptr declstmtPolicy; - std::unique_ptr returnPolicy; - std::unique_ptr exprStmtPolicy; - std::unique_ptr blockPolicy; - std::unique_ptr ifStmtPolicy; - std::unique_ptr switchPolicy; - std::unique_ptr whilePolicy; - std::unique_ptr forPolicy; - std::unique_ptr doPolicy; - std::unique_ptr casePolicy; - -public: - BlockPolicy(std::initializer_list listeners); - - ~BlockPolicy(); - -protected: - std::any DataInner() const override; - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeBlockPolicyHandlers(); - - void CollectBlockHandlers(); - void CollectReturnHandlers(); - void CollectExpressionHandlers(); - void CollectDeclstmtHandlers(); - void CollectIfStmtHandlers(); - void CollectSwitchHandlers(); - void CollectWhileHandlers(); - void CollectForHandlers(); - void CollectDoHandlers(); - void CollectCaseHandlers(); - -}; - -#endif diff --git a/src/policy_classes/CallPolicySingleEvent.cpp b/src/policy_classes/CallPolicySingleEvent.cpp deleted file mode 100644 index 94887f7..0000000 --- a/src/policy_classes/CallPolicySingleEvent.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @file CallPolicySingleEvent.cpp - * - */ -#include - -std::ostream& operator<<(std::ostream& out, const CallData &call) { - out << *(call.name) << "("; - bool printComma=false; - for (std::shared_ptr arg : call.arguments) { - if (printComma) out << ", "; - out << *arg; - printComma = true; - } - out << ")"; - return out; -} - -CallPolicy::~CallPolicy() {} - -std::any CallPolicy::DataInner() const { return std::make_shared(data); } - -void CallPolicy::Notify(const srcDispatch::PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - using namespace srcDispatch; - if (typeid(NamePolicy) == typeid(*policy)) { - data.name = policy->Data(); - } else if (typeid(ExpressionPolicy) == typeid(*policy)) { - data.arguments.push_back(policy->Data()); - } else { - throw PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); -} - -void CallPolicy::InitializeCallPolicyHandlers() { - using namespace srcDispatch; - // start of policy - openEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { - if (!callDepth) { - callDepth = ctx.depth; - data = CallData{}; - data.lineNumber = ctx.startLineNumber; - CollectNameHandlers(); - CollectCallArgumentHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { - if (callDepth && callDepth == ctx.depth) { - callDepth = 0; - NotifyAll(ctx); - InitializeCallPolicyHandlers(); - } - }; -} - - -void CallPolicy::CollectNameHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if(!namePolicy) namePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(namePolicy.get()); - }; -} - - -void CallPolicy::CollectCallArgumentHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { - if(!expressionPolicy) expressionPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(expressionPolicy.get()); - }; -} - diff --git a/src/policy_classes/CallPolicySingleEvent.hpp b/src/policy_classes/CallPolicySingleEvent.hpp deleted file mode 100644 index c17abd0..0000000 --- a/src/policy_classes/CallPolicySingleEvent.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/** - * @file CallPolicySingleEvent.hpp - * - */ -#ifndef INCLUDED_CALL_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_CALL_POLICY_SINGLE_EVENT_HPP - -#include - -#include -#include - -#include -#include -#include - -// -// Collects information -// foo(x) -// obj.foo(x) -// -// Gets the name and list of arguments -// - -struct ExpressionData; -class ExpressionPolicy; - -struct NameData; -class NamePolicy; - -struct CallData { - - unsigned int lineNumber; - std::shared_ptr name; - std::vector> arguments; //expressions - - friend std::ostream& operator<<(std::ostream& out, const CallData &call); -}; - -class CallPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - CallData data; - std::size_t callDepth; - std::unique_ptr namePolicy; - std::unique_ptr expressionPolicy; - -public: - CallPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - callDepth(0) { - InitializeCallPolicyHandlers(); - } - - ~CallPolicy(); - -protected: - std::any DataInner() const override; - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeCallPolicyHandlers(); - void CollectNameHandlers(); - void CollectCallArgumentHandlers(); -}; - -#endif diff --git a/src/policy_classes/CasePolicySingleEvent.hpp b/src/policy_classes/CasePolicySingleEvent.hpp deleted file mode 100644 index d14aac1..0000000 --- a/src/policy_classes/CasePolicySingleEvent.hpp +++ /dev/null @@ -1,88 +0,0 @@ -/** - * @file CasePolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_CASE_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_CASE_POLICY_SINGLE_EVENT_HPP - -#include -#include -#include - -#include - -#include -#include -#include - - -// Collect the expression in the return -// -class CasePolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - std::shared_ptr data; - std::size_t caseDepth; - std::unique_ptr exprPolicy; - -public: - CasePolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - caseDepth(0) { - InitializeCasePolicyHandlers(); - } - - ~CasePolicy() {} - -protected: - std::any DataInner() const override { return data; } - - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { - if (typeid(ExpressionPolicy) == typeid(*policy)) { - data = policy->Data(); - ctx.dispatcher->RemoveListener(nullptr); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeCasePolicyHandlers() { - using namespace srcDispatch; - // start of policy - openEventMap[ParserState::switchcase] = [this](srcSAXEventContext& ctx) { - if (!caseDepth) { - caseDepth = ctx.depth; - data = std::make_shared(); - CollectExpressionHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::switchcase] = [this](srcSAXEventContext& ctx) { - if (caseDepth && caseDepth == ctx.depth) { - caseDepth = 0; - NotifyAll(ctx); - InitializeCasePolicyHandlers(); - } - }; - } - - void CollectExpressionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!exprPolicy) exprPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); - }; - } - -}; - -#endif diff --git a/src/policy_classes/ClassPolicy.hpp b/src/policy_classes/ClassPolicy.hpp deleted file mode 100644 index 2a43557..0000000 --- a/src/policy_classes/ClassPolicy.hpp +++ /dev/null @@ -1,159 +0,0 @@ -/** - * @file ClassPolicy.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef INCLUDED_CLASS_POLICY_HPP -#define INCLUDED_CLASS_POLICY_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -class ClassPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { - public: - - struct ClassData { - void Clear() { - className = ""; - methods.clear(); - members.clear(); - isStruct = false; - } - - std::string className; - bool isStruct = false; //False -> Class; True -> Struct - std::vector methods; - std::vector members; - }; - - ~ClassPolicy() { - delete funcSigPolicy; - delete declTypePolicy; - } - - ClassPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners) { - funcSigPolicy = new FunctionSignaturePolicy({this}); - declTypePolicy = new DeclTypePolicy({this}); - - InitializeEventHandlers(); - } - - void NotifyWrite(const PolicyDispatcher * policy, srcDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers - void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { - if (typeid(FunctionSignaturePolicy) == typeid(*policy)) { - SignatureData signatureData = *policy->Data(); - data_stack.top().methods.push_back(signatureData); - } - - else if (typeid(DeclTypePolicy) == typeid(*policy)) { - if(!(ctx.IsOpen(srcDispatch::ParserState::function))) { - DeclData declarationData = *policy->Data(); - data_stack.top().members.push_back(declarationData); - } - } - } - - protected: - - void * DataInner() const override { - return new std::vector(data); - } - - private: - - std::stack data_stack; - - std::vector data; - - FunctionSignaturePolicy *funcSigPolicy; - DeclTypePolicy *declTypePolicy; - - bool gotClassName = true; - - void InitializeEventHandlers() { - using namespace srcDispatch; - - //Classes - openEventMap[ParserState::classn] = [this](srcSAXEventContext &ctx) { - if(data_stack.empty()) { - ctx.dispatcher->AddListenerDispatch(funcSigPolicy); - ctx.dispatcher->AddListenerDispatch(declTypePolicy); - } - - ClassData current; - current.isStruct = false; - data_stack.push(current); - - gotClassName = false; - }; - closeEventMap[ParserState::classn] = [this](srcSAXEventContext &ctx) { - data.push_back(data_stack.top()); - data_stack.pop(); - - if(data_stack.empty()) { - ctx.dispatcher->RemoveListenerDispatch(funcSigPolicy); - ctx.dispatcher->RemoveListenerDispatch(declTypePolicy); - - NotifyAll(ctx); - data.clear(); - } - }; - - //Structs - openEventMap[ParserState::structn] = [this](srcSAXEventContext &ctx) { - if(data_stack.empty()) { - ctx.dispatcher->AddListenerDispatch(funcSigPolicy); - ctx.dispatcher->AddListenerDispatch(declTypePolicy); - } - - ClassData current; - current.isStruct = true; - data_stack.push(current); - - gotClassName = false; - }; - closeEventMap[ParserState::structn] = [this](srcSAXEventContext &ctx) { - data.push_back(data_stack.top()); - data_stack.pop(); - - if(data_stack.empty()) { - ctx.dispatcher->RemoveListenerDispatch(funcSigPolicy); - ctx.dispatcher->RemoveListenerDispatch(declTypePolicy); - - NotifyAll(ctx); - data.clear(); - } - }; - - closeEventMap[ParserState::name] = [this](srcSAXEventContext& ctx){ - if((ctx.IsOpen(ParserState::structn) || ctx.IsOpen(ParserState::classn)) && !gotClassName) { - data_stack.top().className = ctx.currentToken; - gotClassName = true; - } - }; - - } -}; - -#endif \ No newline at end of file diff --git a/src/policy_classes/ClassPolicySingleEvent.hpp b/src/policy_classes/ClassPolicySingleEvent.hpp deleted file mode 100644 index c2ff3ec..0000000 --- a/src/policy_classes/ClassPolicySingleEvent.hpp +++ /dev/null @@ -1,286 +0,0 @@ -/** - * @file ClassPolicySingleEvent.hpp - * - */ -#ifndef INCLUDED_CLASS_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_CLASS_POLICY_SINGLE_EVENT_HPP - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - - -struct ParentData; - -struct ClassData { - enum ClassType : std::size_t { CLASS, STRUCT }; //UNION, ENUM? - - std::vector namespaces; - - unsigned int lineNumber; - std::string language; - std::string filename; - ClassType type; - std::set stereotypes; - std::shared_ptr name; - std::vector parents; - - std::vector> fields[3]; - std::vector> constructors[3]; - std::vector> operators[3]; - std::vector> methods[3]; - std::vector> innerClasses[3]; - - bool hasDestructor; - bool isGeneric; - bool hasPureVirtual; -}; - -struct ParentData { - std::string name; - bool isVirtual; - AccessSpecifier accessSpecifier; -}; - - -class ClassPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - ClassData data; - std::size_t classDepth; - AccessSpecifier currentRegion; - - std::unique_ptr namePolicy; - std::unique_ptr declPolicy; - std::unique_ptr functionPolicy; - std::unique_ptr classPolicy; - -public: - ClassPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - classDepth(0), - currentRegion(PUBLIC) { - InitializeClassPolicyHandlers(); - } - - ~ClassPolicy() {} - - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(NamePolicy) == typeid(*policy)) { - data.name = policy->Data(); - } else if (typeid(DeclTypePolicy) == typeid(*policy)) { - std::shared_ptr>> decl_data = policy->Data>>(); - for (std::shared_ptr decl : *decl_data) { - data.fields[currentRegion].emplace_back(decl); - } - } else if (typeid(FunctionPolicy) == typeid(*policy)) { - std::shared_ptr f_data = policy->Data(); - if (f_data->isPureVirtual) - data.hasPureVirtual = true; - if (f_data->type == FunctionData::CONSTRUCTOR) - data.constructors[currentRegion].emplace_back(f_data); - else if (f_data->type == FunctionData::OPERATOR) - data.operators[currentRegion].emplace_back(f_data); - else - data.methods[currentRegion].emplace_back(f_data); - } else if (typeid(ClassPolicy) == typeid(*policy)) { - data.innerClasses[currentRegion].emplace_back(policy->Data()); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListenerDispatch(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -protected: - std::any DataInner() const override { return std::make_shared(data); } - -private: - void InitializeClassPolicyHandlers() { - using namespace srcDispatch; - // start of policy - std::function startPolicy = [this](srcSAXEventContext& ctx) { - if (!classDepth) { - classDepth = ctx.depth; - data = ClassData{}; - data.namespaces = ctx.currentNamespaces; - data.lineNumber = ctx.startLineNumber; - std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); - if (stereotype_attr_itr != ctx.attributes.end()){ - std::istringstream stereostring(stereotype_attr_itr->second); - data.stereotypes = std::set(std::istream_iterator(stereostring), std::istream_iterator()); - } - if (ctx.currentTag == "class") - data.type = ClassData::CLASS; - else if (ctx.currentTag == "struct") - data.type = ClassData::STRUCT; - data.name = nullptr; - data.language = ctx.currentFileLanguage; - data.filename = ctx.currentFilePath; - CollectNameHandlers(); - CollectGenericHandlers(); - CollectSuperHanders(); - CollectBlockHanders(); - } else if ((classDepth + 3) == ctx.depth) { - if (!classPolicy) classPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(classPolicy.get()); - } - }; - - // end of policy - std::function endPolicy = [this](srcSAXEventContext& ctx) { - if (classDepth && classDepth == ctx.depth) { - classDepth = 0; - NotifyAll(ctx); - InitializeClassPolicyHandlers(); - } - }; - openEventMap[ParserState::classn] = startPolicy; - closeEventMap[ParserState::classn] = endPolicy; - - openEventMap[ParserState::structn] = startPolicy; - closeEventMap[ParserState::structn] = endPolicy; - } - - void CollectNameHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if ((classDepth + 1) == ctx.depth) { - if (!namePolicy) namePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(namePolicy.get()); - } - }; - closeEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if ((classDepth + 1) == ctx.depth) { - NopOpenEvents({ParserState::name}); - NopCloseEvents({ParserState::name}); - } - }; - } - - void CollectGenericHandlers() { - using namespace srcDispatch; - closeEventMap[ParserState::templates] = [this](srcSAXEventContext& ctx) { - if ((classDepth + 1) == ctx.depth) { - data.isGeneric = true; - } - }; - } - - void CollectSuperHanders() { - using namespace srcDispatch; - openEventMap[ParserState::super_list] = [this](srcSAXEventContext& ctx) { - if ((classDepth + 1) == ctx.depth) { - openEventMap[ParserState::super] = [this](srcSAXEventContext& ctx) { - data.parents.emplace_back(ParentData{ "", false, PUBLIC }); - }; - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - if (ctx.And({ ParserState::specifier })) { - if (ctx.currentToken == "virtual") { - data.parents.back().isVirtual = true; - } else if (ctx.currentToken == "public") { - data.parents.back().accessSpecifier = PUBLIC; - } else if (ctx.currentToken == "private") { - data.parents.back().accessSpecifier = PRIVATE; - } else if (ctx.currentToken == "protected") { - data.parents.back().accessSpecifier = PROTECTED; - } - } else if (ctx.And({ ParserState::name })) { - data.parents.back().name += ctx.currentToken; - } - }; - } - }; - closeEventMap[ParserState::super_list] = [this](srcSAXEventContext& ctx) { - if ((classDepth + 1) == ctx.depth) { - NopOpenEvents({ParserState::super_list, ParserState::super}); - NopCloseEvents({ParserState::super_list, ParserState::tokenstring}); - } - }; - } - - void CollectBlockHanders() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if ((classDepth + 1) == ctx.depth) { - NopOpenEvents({ParserState::name, ParserState::super_list, ParserState::super}); - NopCloseEvents({ParserState::name, ParserState::super_list, ParserState::tokenstring}); - // set up to listen to decl_stmt, member, and class policies - openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - if ((classDepth + 3) == ctx.depth || ((classDepth + 2) == ctx.depth && ctx.currentFileLanguage != "C" && ctx.currentFileLanguage != "C++" )) { - if (!declPolicy) declPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(declPolicy.get()); - } - }; - std::function functionEvent = [this](srcSAXEventContext& ctx) { - if ((classDepth + 3) == ctx.depth - || ((classDepth + 4) == ctx.depth && ctx.elementStack.back() == "friend") - || ((classDepth + 2) == ctx.depth && ctx.currentFileLanguage != "C" && ctx.currentFileLanguage != "C++" )) { - if (!functionPolicy) functionPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(functionPolicy.get()); - } - }; - openEventMap[ParserState::function] = functionEvent; - openEventMap[ParserState::functiondecl] = functionEvent; - openEventMap[ParserState::constructor] = functionEvent; - openEventMap[ParserState::constructordecl] = functionEvent; - - std::function destructorEvent = [this](srcSAXEventContext& ctx) { - if ((classDepth + 3) == ctx.depth - || ((classDepth + 2) == ctx.depth && ctx.currentFileLanguage != "C" && ctx.currentFileLanguage != "C++" )) { - data.hasDestructor = true; - } - }; - openEventMap[ParserState::destructor] = destructorEvent; - openEventMap[ParserState::destructordecl] = destructorEvent; - } - }; - - // should always be in a region once block starts, so should not have to close - openEventMap[ParserState::publicaccess] = [this](srcSAXEventContext& ctx) { - if ((classDepth + 2) == ctx.depth) { - currentRegion = PUBLIC; - } - }; - - openEventMap[ParserState::protectedaccess] = [this](srcSAXEventContext& ctx) { - if ((classDepth + 2) == ctx.depth) { - currentRegion = PROTECTED; - } - }; - - openEventMap[ParserState::privateaccess] = [this](srcSAXEventContext& ctx) { - if ((classDepth + 2) == ctx.depth) { - currentRegion = PRIVATE; - } - }; - - closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if ((classDepth + 1) == ctx.depth) { - NopOpenEvents({ParserState::block, ParserState::function, ParserState::functiondecl, - ParserState::constructor, ParserState::constructordecl, ParserState::destructor, ParserState::destructordecl, - ParserState::declstmt, - ParserState::publicaccess, ParserState::protectedaccess, ParserState::privateaccess}); - NopCloseEvents({ParserState::block}); - } - }; - } - -}; - -#endif diff --git a/src/policy_classes/CollectNLContext.hpp b/src/policy_classes/CollectNLContext.hpp deleted file mode 100644 index 4d7548a..0000000 --- a/src/policy_classes/CollectNLContext.hpp +++ /dev/null @@ -1,187 +0,0 @@ -/** - * @file CollectNLContext.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include -#include -#include -#include - -#ifndef NLCONTEXTPOLICY -#define NLCONTEXTPOLICY -class NLContextPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { - public: - struct NLSet{ - NLSet(std::string idname, std::string acategory, std::string acontext, std::string astereo){ - name = idname; - category = acategory; - context = acontext; - stereotype = astereo; - } - std::string category; - std::string name; - std::string context; - std::string stereotype; - }; - struct NLContextData{ - NLContextData(){} - void clear(){ - category.clear(); - identifiername.clear(); - } - std::string category; - std::string identifiername; - std::list nlsetmap; - }; - std::map identifierposmap; - NLContextData data; - ~NLContextPolicy(){} - NLContextPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ - sourcenlpolicy.AddListener(this); - exprpolicy.AddListener(this); - stereotypepolicy.AddListener(this); - InitializeEventHandlers(); - } - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { - using namespace srcDispatch; - if(ctx.IsOpen(ParserState::declstmt) && ctx.IsClosed(ParserState::exprstmt)){ - sourcenlpdata = *policy->Data(); - std::string top; - if(!context.empty()){ - top = context.top(); - } - auto it = identifierposmap.find(sourcenlpdata.identifiername); - if(it == identifierposmap.end()){ - identifierposmap.insert(std::make_pair(sourcenlpdata.identifiername, sourcenlpdata.category)); - }else{ - if(it->second != sourcenlpdata.category){ - it->second = "multiple"; - } - } - //std::cerr<<"Def: "<Data(); - std::string top; - if(!context.empty()){ - top = context.top(); - }else{ - top = "none"; - } - std::string stereo; - if(!stereotype.stereotypes.empty()){ - stereo = stereotype.stereotypes.front(); - }else{ - stereo = "none"; - } - for(auto deal : exprdata.dataset){ - auto it = identifierposmap.find(deal.second.nameofidentifier); - if(it != identifierposmap.end()){ - std::string categorystr; - if(it->second.empty()){ - categorystr = "none"; - }else{ - categorystr = it->second; - } - NLSet nlset = NLSet(deal.second.nameofidentifier,categorystr,top,stereo); - data.nlsetmap.push_back(nlset); - } - } - } - if(ctx.IsOpen(ParserState::stereotype)){ - stereotype = *policy->Data(); - } - //datatotest.push_back(SourceNLData); - } - protected: - void * DataInner() const override { - return new NLContextData(data); - } - private: - SourceNLPolicy sourcenlpolicy; - SourceNLPolicy::SourceNLData sourcenlpdata; - ExprPolicy exprpolicy; - ExprPolicy::ExprDataSet exprdata; - StereotypePolicy stereotypepolicy; - StereotypePolicy::StereotypeData stereotype; - std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; - std::stack context; - void InitializeEventHandlers(){ - using namespace srcDispatch; - openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - ctx.dispatcher->AddListenerDispatch(&sourcenlpolicy); - }; - closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx){ - ctx.dispatcher->RemoveListenerDispatch(&sourcenlpolicy); - ///data.clear(); - }; - - openEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { - ctx.dispatcher->AddListenerDispatch(&exprpolicy); - }; - closeEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx){ - ctx.dispatcher->RemoveListenerDispatch(&exprpolicy); - //data.clear(); - }; - - openEventMap[ParserState::stereotype] = [this](srcSAXEventContext& ctx){ - ctx.dispatcher->AddListenerDispatch(&stereotypepolicy); - }; - closeEventMap[ParserState::stereotype] = [this](srcSAXEventContext& ctx){ - ctx.dispatcher->RemoveListenerDispatch(&stereotypepolicy); - }; - - openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { - context.push("while"); - }; - closeEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx){ - context.pop(); - }; - - openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { - context.push("for"); - }; - closeEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx){ - context.pop(); - }; - - openEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx) { - context.push("if"); - }; - closeEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx){ - context.pop(); - }; - - /* - openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { - context.push("else if"); - }; - openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { - context.push("else"); - };*/ - - closeEventMap[ParserState::archive] = [this](srcSAXEventContext& ctx){ - NotifyAll(ctx); - }; - - } -}; -#endif \ No newline at end of file diff --git a/src/policy_classes/ConditionPolicySingleEvent.hpp b/src/policy_classes/ConditionPolicySingleEvent.hpp deleted file mode 100644 index 4d51051..0000000 --- a/src/policy_classes/ConditionPolicySingleEvent.hpp +++ /dev/null @@ -1,118 +0,0 @@ -/** - * @file ConditionPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_CONDITION_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_CONDITION_POLICY_SINGLE_EVENT_HPP - -#include -#include -#include - -#include -#include - -#include -#include -#include - -struct ConditionData { - std::shared_ptr expr; - std::vector> decls; - - friend std::ostream& operator<<(std::ostream& out, const ConditionData& condition) { - bool outputDecl = false; - for(const std::shared_ptr& decl : condition.decls) { - if(outputDecl) out << ", "; - out << *decl; - outputDecl = true; - } - - if(outputDecl) out << "; "; - out << *condition.expr; - - return out; - } -}; - -// Collect the expression in the return -// -class ConditionPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - ConditionData data; - std::size_t conditionDepth; - std::unique_ptr exprPolicy; - std::unique_ptr declTypePolicy; -public: - ConditionPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - conditionDepth(0) { - InitializeConditionPolicyHandlers(); - } - - ~ConditionPolicy() {} - -protected: - std::any DataInner() const override { return std::make_shared(data); } - - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(ExpressionPolicy) == typeid(*policy)) { - data.expr = policy->Data(); - } else if (typeid(DeclTypePolicy) == typeid(*policy)) { - data.decls = *policy->Data>>(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeConditionPolicyHandlers() { - using namespace srcDispatch; - // start of policy - openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if (!conditionDepth) { - conditionDepth = ctx.depth; - data = ConditionData{}; - CollectExpressionHandlers(); - CollectDeclTypePolicyHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if (conditionDepth && conditionDepth == ctx.depth) { - conditionDepth = 0; - NotifyAll(ctx); - InitializeConditionPolicyHandlers(); - } - }; - } - - void CollectExpressionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!exprPolicy) exprPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); - }; - } - - void CollectDeclTypePolicyHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - if (!declTypePolicy) declTypePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(declTypePolicy.get()); - }; - } - -}; - -#endif diff --git a/src/policy_classes/ConditionalPolicy.hpp b/src/policy_classes/ConditionalPolicy.hpp deleted file mode 100644 index 5787cab..0000000 --- a/src/policy_classes/ConditionalPolicy.hpp +++ /dev/null @@ -1,265 +0,0 @@ -#include -#include -#include -#include -#include -#include -#ifndef CONDITIONALPOLICY -#define CONDITIONALPOLICY -struct DvarData{ - DvarData(std::string func, std::string name, unsigned int line) { - function = func; - lhsName = name; - lhsDefLine = line; - dvars.clear(); - } - std::string function, lhsName; - unsigned int lhsDefLine; - std::set> dvars; -}; - -class ConditionalPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { - public: - ConditionalPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ - InitializeEventHandlers(); - } - ~ConditionalPolicy(){} - - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - - std::unordered_map>* GetConditionalUses() { - return &conditionalUses; - } - std::unordered_map>* GetConditionalDefs() { - return &conditionalDefs; - } - - std::unordered_map>* GetSwitchUses() { - return &switchUses; - } - std::unordered_map>* GetSwitchDefs() { - return &switchDefs; - } - - std::string GetVarName() { - return currentExprName; - } - - void EditDepth(int d) { - - if (switchControlVars.size() > 0 && d < 0) { - switchControlVars.erase(switchDepth); - } - switchDepth += d; - if (switchDepth < 0) switchDepth = 0; - } - - void DeleteUsesCollection(std::string name) { conditionalUses.erase(name); } - void DeleteDefsCollection(std::string name) { conditionalDefs.erase(name); } - - std::vector* GetPossibleDvars() { return &dvarSet; } - - const std::string& GetLastFunction() { return recentFunction; } - - protected: - std::any DataInner() const override {} - - private: - std::unordered_map> conditionalUses, conditionalDefs; - std::unordered_map> switchUses, switchDefs; - std::unordered_map< unsigned int, std::set > switchControlVars; - unsigned int switchDepth = 0; - std::string currentExprName = "", currentExprOp = "", currentType = ""; - std::vector dvarSet; - std::string recentFunction; - bool insertDvar = false; - - void InitializeEventHandlers(){ - using namespace srcDispatch; - - closeEventMap[ParserState::function] = [this](srcSAXEventContext &ctx) { - NotifyAll(ctx); - }; - - closeEventMap[ParserState::name] = [this](srcSAXEventContext &ctx) { - recentFunction = ctx.currentFunctionName; - currentExprName = ctx.currentToken; - - if (ctx.IsOpen({ParserState::decl}) && ctx.IsClosed({ParserState::type}) && dvarSet.size() > 0 && insertDvar) { - dvarSet.back().dvars.insert( std::make_pair(ctx.currentToken, ctx.startLineNumber) ); - } - - if ( ctx.IsClosed({ParserState::comment}) ) { - // The following is for detecting possible uses within various Conditionals - if ( (ctx.IsOpen({ParserState::ifstmt}) || ctx.IsOpen({ParserState::elseif})) && ctx.IsOpen({ParserState::condition}) ) { - // switch using data-type capturing: - // xml will appear as `inti` - // using this switch when I hit the name when I've detected - // a type within an if-stmt I wont add the line as a use of - // a line where it is being declared: - // `4 | if (int a = i; i < 10) {...}` I want to mark: - // "a" with only def on line 4, and "i" use on 4 - - if (currentType.empty()) { - if (conditionalUses[ctx.currentToken].empty() || ctx.startLineNumber != conditionalUses[ctx.currentToken].back()) { - conditionalUses[ctx.currentToken].push_back(ctx.startLineNumber); - } - } else { - currentType.clear(); - } - } - - // The following is for detecting possible uses within various Conditionals - if ( ctx.IsOpen({ParserState::whilestmt}) && ctx.IsOpen({ParserState::condition}) ){ - if (conditionalUses[ctx.currentToken].empty() || ctx.startLineNumber != conditionalUses[ctx.currentToken].back()) { - conditionalUses[ctx.currentToken].push_back(ctx.startLineNumber); - } - } - - // The following is for detecting possible uses within various Conditionals - if ( ctx.IsOpen({ParserState::forstmt}) ) { - if ( ctx.And({ParserState::decl, ParserState::init, ParserState::expr}) ) { - if (conditionalUses[ctx.currentToken].empty() || ctx.startLineNumber != conditionalUses[ctx.currentToken].back()) { - conditionalUses[ctx.currentToken].push_back(ctx.startLineNumber); - } - } - - if ( ctx.IsOpen({ParserState::condition}) ){ - if (conditionalUses[ctx.currentToken].empty() || ctx.startLineNumber != conditionalUses[ctx.currentToken].back()) { - conditionalUses[ctx.currentToken].push_back(ctx.startLineNumber); - } - } - - if ( ctx.IsOpen({ParserState::incr}) || ctx.IsOpen({ParserState::decr}) ){ - if (conditionalDefs[ctx.currentToken].empty() || ctx.startLineNumber != conditionalDefs[ctx.currentToken].back()) { - conditionalDefs[ctx.currentToken].push_back(ctx.startLineNumber); - } - - if (conditionalUses[ctx.currentToken].empty() || ctx.startLineNumber != conditionalUses[ctx.currentToken].back()) { - conditionalUses[ctx.currentToken].push_back(ctx.startLineNumber); - } - } - } - - // The following is for detecting possible uses within various Conditionals - if ( ctx.IsOpen({ParserState::dostmt}) && ctx.IsOpen({ParserState::condition}) ){ - if (conditionalUses[ctx.currentToken].empty() || ctx.startLineNumber != conditionalUses[ctx.currentToken].back()) { - conditionalUses[ctx.currentToken].push_back(ctx.startLineNumber); - } - } - - // Get uses or use/defs within switch conditions - if ( ctx.IsOpen({ParserState::switchstmt}) && ctx.IsOpen({ParserState::condition}) ){ - if ( ctx.IsOpen({ParserState::init}) ) { - if (switchUses[ctx.currentToken].empty() || ctx.startLineNumber != switchUses[ctx.currentToken].back()) { - switchUses[ctx.currentToken].push_back(ctx.startLineNumber); - } - } else { - switchControlVars[switchDepth].insert(ctx.currentToken); - - if (switchUses[ctx.currentToken].empty() || ctx.startLineNumber != switchUses[ctx.currentToken].back()) { - switchUses[ctx.currentToken].push_back(ctx.startLineNumber); - } - - if (!currentExprOp.empty()) { - // prefix : ++c - if (switchDefs[ctx.currentToken].empty() || ctx.startLineNumber != switchDefs[ctx.currentToken].back()) { - switchDefs[ctx.currentToken].push_back(ctx.startLineNumber); - } - - currentExprName = ""; - currentExprOp = ""; - } - } - - } - } - }; - - // Assume switch cases are a use of the condition value - closeEventMap[ParserState::switchcase] = [this](srcSAXEventContext &ctx) { - if ( ctx.IsOpen({ParserState::switchstmt}) ){ - for (auto varName : switchControlVars[switchDepth]) { - if (switchUses[varName].empty() || ctx.startLineNumber != switchUses[varName].back()) { - switchUses[varName].push_back(ctx.startLineNumber); - } - } - } - }; - - closeEventMap[ParserState::type] = [this](srcSAXEventContext& ctx){ - if (ctx.And({ParserState::ifstmt, ParserState::condition})) { - currentType = ctx.currentToken; - } - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - std::string token = ctx.currentToken; - std::string extractedToken = ""; - - // Extract white-spaces from token - for (int i = 0; i < token.length(); ++i) { - if (std::isalnum(token[i]) || token[i] == '=' || token[i] == '-' || - token[i] == '+' || token[i] == '*' || token[i] == '/' || - token[i] == '%' || token[i] == '&') { - extractedToken += token[i]; - } - } - - if (extractedToken == "+=" || extractedToken == "-=" || extractedToken == "*=" || - extractedToken == "/=" || extractedToken == "%=" || extractedToken == "=") { - - if ( (ctx.IsOpen({ParserState::decl}) && ctx.IsClosed({ParserState::name}) && ctx.IsClosed({ParserState::type})) && !currentExprName.empty()) { - dvarSet.push_back(DvarData(ctx.currentFunctionName, currentExprName, ctx.startLineNumber)); - insertDvar = true; - } - } - }; - - closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx [[maybe_unused]]){ - insertDvar = false; - }; - - closeEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ - // Long or-statement allows various declaration operators to get planted into - // a slices def data output - // if (ctx.currentToken == "=" || ctx.currentToken == "++" || ctx.currentToken == "+=" || - // ctx.currentToken == "--" || ctx.currentToken == "-=" || ctx.currentToken == "*=" || - // ctx.currentToken == "/=" || ctx.currentToken == "%=" || ctx.currentToken == "&=" || - // ctx.currentToken == "|=" || ctx.currentToken == "^=" || ctx.currentToken == "<<=" || - // ctx.currentToken == ">>=") - bool isMutatorOp = (ctx.currentToken == "+=" || ctx.currentToken == "-=" || - ctx.currentToken == "*=" || ctx.currentToken == "/=" || - ctx.currentToken == "%=" || ctx.currentToken == "++" || - ctx.currentToken == "--"); - - // Within conditional blocks find use/defs - if ( isMutatorOp ) { - currentExprOp = ctx.currentToken; - if (!currentExprName.empty()) { - // postfix : c++ - if (conditionalDefs[currentExprName].empty() || ctx.startLineNumber != conditionalDefs[currentExprName].back()) { - conditionalDefs[currentExprName].push_back(ctx.startLineNumber); - } - - if (conditionalUses[currentExprName].empty() || ctx.startLineNumber != conditionalUses[currentExprName].back()) { - conditionalUses[currentExprName].push_back(ctx.startLineNumber); - } - - currentExprName = ""; - currentExprOp = ""; - } - } - - if (ctx.currentToken == "+=" || ctx.currentToken == "-=" || - ctx.currentToken == "*=" || ctx.currentToken == "/=" || - ctx.currentToken == "%=" || ctx.currentToken == "=") { - if ( ctx.IsOpen({ParserState::decl}) && !currentExprName.empty() && !currentType.empty() ) { - dvarSet.push_back(DvarData(ctx.currentFunctionName, currentExprName, ctx.startLineNumber)); - } - } - }; - } -}; -#endif \ No newline at end of file diff --git a/src/policy_classes/ConditionalPolicySingleEvent.hpp b/src/policy_classes/ConditionalPolicySingleEvent.hpp deleted file mode 100644 index 36a0516..0000000 --- a/src/policy_classes/ConditionalPolicySingleEvent.hpp +++ /dev/null @@ -1,106 +0,0 @@ -/** - * @file ConditionalPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_CONDITIONAL_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_CONDITIONAL_POLICY_SINGLE_EVENT_HPP - -#include -#include -#include - -#include -#include - -#include -#include -#include - -template -class ConditionalPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -protected: - ConditionalData data; - std::size_t conditionalDepth; - std::unique_ptr conditionPolicy; - std::unique_ptr blockPolicy; - -public: - ConditionalPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - conditionalDepth(0) { - InitializeConditionalPolicyHandlers(); - } - - ~ConditionalPolicy() {} - -protected: - std::any DataInner() const override { return std::make_shared(data); } - - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(ConditionPolicy) == typeid(*policy)) { - data.condition = policy->Data(); - } else if (typeid(BlockPolicy) == typeid(*policy)) { - data.block = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - - void InitializeConditionalPolicyHandlers() { - using namespace srcDispatch; - - openEventMap[DispatchEvent] = [this](srcSAXEventContext& ctx) { - if (!conditionalDepth) { - conditionalDepth = ctx.depth; - data = ConditionalData{}; - data.startLineNumber = ctx.startLineNumber; - data.endLineNumber = ctx.endLineNumber; - CollectConditionHandlers(); - CollectBlockHandlers(); - } - }; - - // end of policy - closeEventMap[DispatchEvent] =[this](srcSAXEventContext& ctx) { - if (conditionalDepth && conditionalDepth == ctx.depth) { - conditionalDepth = 0; - NotifyAll(ctx); - InitializeConditionalPolicyHandlers(); - } - }; - } - - void CollectConditionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if(!conditionalDepth) return; - if((conditionalDepth + 1) != ctx.depth) return; - - if (!conditionPolicy) conditionPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(conditionPolicy.get()); - }; - } - - void CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(!conditionalDepth) return; - if((conditionalDepth + 1) != ctx.depth) return; - - if (!blockPolicy) blockPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); - }; - } -}; - -#endif diff --git a/src/policy_classes/ControlPolicySingleEvent.hpp b/src/policy_classes/ControlPolicySingleEvent.hpp deleted file mode 100644 index cf92219..0000000 --- a/src/policy_classes/ControlPolicySingleEvent.hpp +++ /dev/null @@ -1,178 +0,0 @@ -/** - * @file ControlPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_CONTROL_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_CONTROL_POLICY_SINGLE_EVENT_HPP - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -struct ControlData { - - unsigned int lineNumber; - - std::vector init; - std::shared_ptr condition; - std::vector> incr; - - friend std::ostream& operator<<(std::ostream& out, const ControlData& controlData) { - - bool outputDeclComma = false; - for(const std::any& item : controlData.init) { - if(outputDeclComma) out << ", "; - if(item.type() == typeid(std::shared_ptr)) - out << *std::any_cast>(item); - else { - out << *std::any_cast>(item); - } - outputDeclComma = true; - } - - if(controlData.condition) out << *controlData.condition << "; "; - - bool outputExprComma = false; - for(const std::shared_ptr& expr : controlData.incr) { - if(outputExprComma) out << ", "; - out << *expr; - outputExprComma = true; - } - return out; - } -}; - -// Collect the expression in the return -// -class ControlPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - ControlData data; - std::size_t controlDepth; - std::unique_ptr declPolicy; - std::unique_ptr exprPolicy; - std::unique_ptr conditionPolicy; - std::unique_ptr incrPolicy; - -public: - ControlPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - controlDepth(0) { - InitializeControlPolicyHandlers(); - } - - ~ControlPolicy() {} - -protected: - std::any DataInner() const override { return std::make_shared(data); } - - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - using namespace srcDispatch; - if(typeid(DeclPolicy) == typeid(*policy)) { - data.init.push_back(policy->Data()); - } else if(typeid(ExpressionPolicy) == typeid(*policy)) { - data.init.push_back(policy->Data()); - } else if(typeid(ConditionPolicy) == typeid(*policy)) { - data.condition = policy->Data(); - } else if(typeid(IncrPolicy) == typeid(*policy)) { - data.incr.push_back(policy->Data()); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeControlPolicyHandlers() { - using namespace srcDispatch; - // start of policy - openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { - if (!controlDepth) { - controlDepth = ctx.depth; - data = ControlData{}; - CollectInitHandlers(); - CollectConditionHandlers(); - CollectIncrHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { - if (controlDepth && controlDepth == ctx.depth) { - controlDepth = 0; - NotifyAll(ctx); - InitializeControlPolicyHandlers(); - } - }; - } - - void CollectInitHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { - if(ctx.depth != (controlDepth + 1)) return; - - openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { - if(ctx.depth != (controlDepth + 2)) return; - - if (!declPolicy) declPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(declPolicy.get()); - }; - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(ctx.depth != (controlDepth + 2)) return; - - if (!exprPolicy) exprPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); - }; - }; - closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { - if(ctx.depth != (controlDepth + 1)) return; - NopOpenEvents({ParserState::decl, ParserState::expr}); - }; - - } - - void CollectConditionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if(ctx.depth != (controlDepth + 1)) return; - - if (!conditionPolicy) conditionPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(conditionPolicy.get()); - }; - } - - void CollectIncrHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { - if(ctx.depth != (controlDepth + 1)) return; - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!exprPolicy) exprPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); - }; - }; - closeEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { - if(ctx.depth != (controlDepth + 1)) return; - NopOpenEvents({ParserState::expr}); - }; - } - -}; - -#endif diff --git a/src/policy_classes/ConvertPlexerPolicy.hpp b/src/policy_classes/ConvertPlexerPolicy.hpp new file mode 100644 index 0000000..d7af739 --- /dev/null +++ b/src/policy_classes/ConvertPlexerPolicy.hpp @@ -0,0 +1,262 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file ConvertPlexerPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_CONVERT_PLEXER_POLICY_HPP +#define INCLUDED_CONVERT_PLEXER_POLICY_HPP + +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +// #define CONVERT_DEBUG + +namespace srcDiffDispatch { + + struct ConvertData { + DeltaElement construct; + }; + + class ConvertPlexerPolicy : + public srcDispatch::EventListener, + public srcDispatch::EventDispatcher, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + protected: + ConvertData data; + + std::stack dispatcherStack; + + std::unique_ptr originalPolicy; + std::unique_ptr modifiedPolicy; + + std::stack dispatchingState; + + std::stack originalPolicyStack; + std::stack modifiedPolicyStack; +public: + static std::size_t s_index; + std::size_t index; +protected: + static std::unordered_map(std::initializer_list listeners)> + > policyFactory; + public: + ConvertPlexerPolicy(std::initializer_list listeners) + : srcDispatch::EventDispatcher({}), srcDispatch::PolicyDispatcher(listeners), data(), + dispatcherStack(), dispatchingState(), originalPolicy(), modifiedPolicy(), originalPolicyStack(), modifiedPolicyStack() { + dispatchingState.push(srcDispatch::NONE); + index = ++s_index; + } + + ~ConvertPlexerPolicy() {} + + void Stop() { + dispatched = true; + EventDispatcher* currentDispatcher = dispatcherStack.top()->GetContext().dispatcher; + dispatcherStack.top()->GetContext().dispatcher = dispatcherStack.top(); + NotifyAll(dispatcherStack.top()->GetContext()); + dispatcherStack.top()->GetContext().dispatcher = currentDispatcher; + } + + virtual void AddListener(EventListener* listener) override { +#ifdef CONVERT_DEBUG + std::cerr << "ADD: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << ' ' << dispatchingState.top() << '\n'; +#endif + if(dispatchingState.top() == srcDispatch::DELETE) { +#ifdef CONVERT_DEBUG + std::cerr << "ADD: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << '\n'; +#endif + originalPolicyStack.top()->SetDispatched(false); + originalPolicyStack.push(listener); + } else if(dispatchingState.top() == srcDispatch::INSERT) { +#ifdef CONVERT_DEBUG + std::cerr << "ADD: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << '\n'; +#endif + modifiedPolicyStack.top()->SetDispatched(false); + modifiedPolicyStack.push(listener); + } + } + + virtual void AddListenerDispatch(EventListener* listener) override { + AddListener(listener); + dispatched = false; + } + + virtual void AddListenerNoDispatch(EventListener* listener) override { + throw std::string("AddListenerNoDispatch not implemented"); + } + + virtual void RemoveListener(EventListener* listener) override { + if(dispatchingState.top() == srcDispatch::DELETE) { +#ifdef CONVERT_DEBUG + std::cerr << "REMOVE: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << '\n'; +#endif + originalPolicyStack.top()->SetDispatched(false); + originalPolicyStack.pop(); + } else if(dispatchingState.top() == srcDispatch::INSERT) { +#ifdef CONVERT_DEBUG + std::cerr << "REMOVE: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << '\n'; +#endif + modifiedPolicyStack.top()->SetDispatched(false); + modifiedPolicyStack.pop(); + } + } + + virtual void RemoveListenerDispatch(EventListener* listener) override { + RemoveListener(listener); + dispatched = false; + } + + virtual void RemoveListenerNoDispatch(EventListener* listener) override { + throw std::string("RemoveListenerNoDispatch not implemented"); + } + + virtual void DispatchEvent(srcDispatch::ParserState, srcDispatch::ElementState) override { + } + + virtual void HandleEvent(srcDispatch::ParserState pstate, srcDispatch::ElementState estate, srcDispatch::srcSAXEventContext& ctx) override { +#ifdef CONVERT_DEBUG + std::cerr << "HERE: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << ' ' << pstate << ":" << estate << '\n'; + std::cerr << "HERE: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << ' ' << ctx.diffStack.back().operation << '\n'; + std::cerr << "HERE: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << ' ' << ctx.currentTag << '\n'; + std::cerr << "HERE: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << ' ' << ctx.depth << '\n'; + std::cerr << "HERE: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << ' ' << depth << '\n'; +#endif + + dispatcherStack.push(ctx.dispatcher); + ctx.dispatcher = this; + while(!dispatched) { + + dispatched = true; + + if( dispatchingState.size() && dispatchingState.top() != srcDispatch::INSERT + && (ctx.diffStack.back().operation != srcDispatch::INSERT || (depth && ctx.depth > depth))) { + + if(!originalPolicy) { + originalPolicy = policyFactory[pstate]({this}); + originalPolicyStack.push(originalPolicy.get()); + } + +#ifdef CONVERT_DEBUG + std::cerr << "HERE: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << ' ' << originalPolicyStack.size() << '\n'; +#endif + + dispatchingState.push(srcDispatch::DELETE); + originalPolicyStack.top()->HandleEvent(pstate, estate, ctx); + dispatchingState.pop(); + if(dispatchingState.size() == 1) { + originalPolicyStack.top()->SetDispatched(false); + } + } + +#ifdef CONVERT_DEBUG + std::cerr << "HERE: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << '\n'; +#endif + + if( dispatchingState.size() && dispatchingState.top() != srcDispatch::DELETE + && (ctx.diffStack.back().operation != srcDispatch::DELETE || (depth && ctx.depth > depth))) { + + if(!modifiedPolicy) { + modifiedPolicy = policyFactory[pstate]({this}); + modifiedPolicyStack.push(modifiedPolicy.get()); + + if(pstate != srcDispatch::ParserState::ifgroup) { + depth = ctx.diffStack.back().depth + 1; + } else { + depth = ctx.diffStack.back().depth + 2; + } + } + +#ifdef CONVERT_DEBUG + std::cerr << "HERE: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << ' ' << modifiedPolicyStack.size() << '\n'; +#endif + + dispatchingState.push(srcDispatch::INSERT); + modifiedPolicyStack.top()->HandleEvent(pstate, estate, ctx); + dispatchingState.pop(); + if(dispatchingState.size() == 1) { + modifiedPolicyStack.top()->SetDispatched(false); + } + } + } + ctx.dispatcher = dispatcherStack.top(); + dispatcherStack.pop(); + } + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { +#ifdef CONVERT_DEBUG + std::cerr << "HERE: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << ' ' << '\n'; +#endif + + std::any anyData; + if(typeid(WhilePolicy) == typeid(*policy)) { + anyData = policy->Data(); + } else if(typeid(ForPolicy) == typeid(*policy)) { + anyData = policy->Data(); + } else if(typeid(IfStmtPolicy) == typeid(*policy)) { + anyData = policy->Data(); + } else if(typeid(DeclStmtPolicy) == typeid(*policy)) { + anyData = policy->Data(); + } else if(typeid(ExprStmtPolicy) == typeid(*policy)) { + anyData = policy->Data(); + } else if(typeid(ReturnPolicy) == typeid(*policy)) { + anyData = policy->Data(); + } + + data.construct.Update(ctx.diffStack.back().operation, anyData); + if(data.construct.HasOriginal() && data.construct.HasModified()) { + +#ifdef CONVERT_DEBUG + std::cerr << "HERE: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << ' ' << '\n'; +#endif + + Stop(); + } + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + }; + + std::unordered_map(std::initializer_list listeners)> + >ConvertPlexerPolicy::policyFactory = { + { srcDispatch::ParserState::ifgroup, [](std::initializer_list listeners) { return srcDispatch::make_unique_policy(listeners); } }, + { srcDispatch::ParserState::whilestmt, [](std::initializer_list listeners) { return srcDispatch::make_unique_policy (listeners); } }, + { srcDispatch::ParserState::forstmt, [](std::initializer_list listeners) { return srcDispatch::make_unique_policy (listeners); } }, + + { srcDispatch::ParserState::declstmt, [](std::initializer_list listeners) { return srcDispatch::make_unique_policy (listeners); } }, + { srcDispatch::ParserState::exprstmt, [](std::initializer_list listeners) { return srcDispatch::make_unique_policy (listeners); } }, + { srcDispatch::ParserState::returnstmt, [](std::initializer_list listeners) { return srcDispatch::make_unique_policy (listeners); } }, + + }; + + std::size_t ConvertPlexerPolicy::s_index = 0; +} + +#endif diff --git a/src/policy_classes/DeclDS.hpp b/src/policy_classes/DeclDS.hpp deleted file mode 100644 index 25f664f..0000000 --- a/src/policy_classes/DeclDS.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/** - * @file DeclTypePolicy.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef INCLUDED_DECL_DS_HPP -#define INCLUDED_DECL_DS_HPP -struct SignatureData; -struct DeclData{ - DeclData(): lineNumber{0}, isConstValue{false}, isConstAlias{false}, isAliasToConst{false}, isReference{false}, - isPointer{false}, isStatic{false}, isClassMember{false}, usesSubscript{false}, hasSideEffect{false}, - numOfContainingFunctionParams{0}{} - void clear(){ - lineNumber = -1; - isFinal = false; - isStatic = false; - isPointer = false; - nameOfType.clear(); - namespaces.clear(); - isLocalVar = false; - isReference = false; - isParameter = false; - isConstValue = false; - isConstAlias = false; - isClassMember = false; - usesSubscript = false; - hasSideEffect = false; - sLexicalCategory.clear(); - nameOfIdentifier.clear(); - nameOfContainingFile.clear(); - nameOfContainingClass.clear(); - numOfContainingFunctionParams = 0; - nameOfContainingFunction.clear(); - } - unsigned int lineNumber; - int numOfContainingFunctionParams; - bool isFinal; - bool isConstValue; - bool isStatic; - bool isPointer; - bool isReference; - bool isConstAlias; - bool isClassMember; - bool usesSubscript; - bool hasSideEffect; - bool isAliasToConst; - bool isParameter; - bool isLocalVar; - - std::string nameOfType; - std::string sLexicalCategory; - std::string nameOfIdentifier; - std::string nameOfContainingFile; - std::string nameOfContainingClass; - std::string nameOfContainingFunction; - - std::vector namespaces; -}; - -#endif \ No newline at end of file diff --git a/src/policy_classes/DeclPolicySingleEvent.hpp b/src/policy_classes/DeclPolicySingleEvent.hpp deleted file mode 100644 index d701983..0000000 --- a/src/policy_classes/DeclPolicySingleEvent.hpp +++ /dev/null @@ -1,250 +0,0 @@ -/** - * @file DeclPolicySingleEvent.hpp - * - * - * MODIFIED from srcDispatch - * This collects the initializer - * - */ -#ifndef INCLUDED_DECL_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_DECL_POLICY_SINGLE_EVENT_HPP - -#include - -#include -#include -#include - -#include -#include - -struct DeclData { - - unsigned int lineNumber; - std::shared_ptr type; - std::shared_ptr name; - std::shared_ptr init; - std::vector> arguments; - std::shared_ptr range; - - bool isStatic; - - friend std::ostream& operator<<(std::ostream& out, const DeclData& declData) { - if(declData.type) { - out << declData.type->ToString(); - } - - if (declData.name) { - out << ' ' << *declData.name; - } - - if (declData.init) { - out << " = " << *declData.init; - } - - if (!declData.arguments.empty()) { - - out << '('; - bool outputComma = false; - for(const std::shared_ptr& argument : declData.arguments) { - if(outputComma) { - out << ", "; - } - out << *argument; - outputComma = true; - } - out << ')'; - } - - if (declData.range) { - out << " : " << *declData.range; - } - return out; - } -}; - - - -class DeclPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - DeclData data; - std::size_t declDepth; - std::unique_ptr typePolicy; - std::unique_ptr namePolicy; - std::unique_ptr exprPolicy; - -public: - DeclPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - declDepth(0) { - InitializeDeclPolicyHandlers(); - } - - ~DeclPolicy() {} - -protected: - std::any DataInner() const override { return std::make_shared(data); } - - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - using namespace srcDispatch; - if (typeid(TypePolicy) == typeid(*policy)) { - data.type = std::shared_ptr(policy->Data()); - } else if (typeid(NamePolicy) == typeid(*policy)) { - data.name = policy->Data(); - } else if (typeid(ExpressionPolicy) == typeid(*policy)) { - if(ctx.IsOpen(ParserState::range)) { - data.range = policy->Data(); - } else if(ctx.IsOpen(ParserState::init)) { - data.init = policy->Data(); - } else if(ctx.IsOpen(ParserState::argumentlist)) { - data.arguments.emplace_back(policy->Data()); - } else { - throw std::string("Unhandled ExpressionPolicy condition"); - } - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeDeclPolicyHandlers() { - using namespace srcDispatch; - - // start of policy - openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { - if(declDepth) return; - - declDepth = ctx.depth; - data = DeclData{}; - data.lineNumber = ctx.startLineNumber; - - CollectSpecifiersHandlers(); - CollectTypeHandlers(); - CollectNameHandlers(); - CollectInitHandlers(); - CollectArgumentList(); - CollectRangeHandlers(); - }; - - // close policy - closeEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { - if(!declDepth || declDepth != ctx.depth) return; - - declDepth = 0; - NotifyAll(ctx); - data = DeclData{}; - InitializeDeclPolicyHandlers(); - }; - - } - - void CollectSpecifiersHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { - if(!declDepth || (declDepth + 1) != ctx.depth) return; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - if (ctx.currentToken == "static") - data.isStatic = true; - }; - }; - closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { - if(!declDepth || (declDepth + 1) != ctx.depth) return; - - NopCloseEvents({ParserState::tokenstring}); - }; - } - - void CollectTypeHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - if(!declDepth || (declDepth + 1) != ctx.depth) return; - - if (!typePolicy) typePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(typePolicy.get()); - }; - } - - void CollectNameHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if(!declDepth || (declDepth + 1) != ctx.depth) return; - - if (!namePolicy) namePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(namePolicy.get()); - }; - } - - void CollectInitHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { - if(!declDepth || (declDepth + 1) != ctx.depth) return; - - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(!exprPolicy) exprPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); - }; - }; - closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { - if(!declDepth || (declDepth + 1) != ctx.depth) return; - - NopOpenEvents({ParserState::expr}); - }; - } - - - void CollectArgumentList() { - using namespace srcDispatch; - openEventMap[ParserState::argumentlist] = [this](srcSAXEventContext &ctx) { - if (!declDepth || (declDepth + 1) != ctx.depth) { - return; - } - - openEventMap[ParserState::argument] = [this](srcSAXEventContext &ctx) { - if (!exprPolicy) { - exprPolicy = make_unique_policy({this}); - } - ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); - }; - - closeEventMap[ParserState::argument] = [this](srcSAXEventContext &ctx) { - NopOpenEvents({ParserState::expr}); - }; - - }; - - closeEventMap[ParserState::argumentlist] = [this](srcSAXEventContext &ctx) { - NopOpenEvents({ParserState::argument}); - }; - } - - void CollectRangeHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::range] = [this](srcSAXEventContext& ctx) { - if(!declDepth || (declDepth + 1) != ctx.depth) return; - - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(!exprPolicy) exprPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); - }; - }; - closeEventMap[ParserState::range] = [this](srcSAXEventContext& ctx) { - if(!declDepth || (declDepth + 1) != ctx.depth) return; - - NopOpenEvents({ParserState::expr}); - }; - } - - -}; - -#endif diff --git a/src/policy_classes/DeclTypePolicy.hpp b/src/policy_classes/DeclTypePolicy.hpp deleted file mode 100644 index ec3832f..0000000 --- a/src/policy_classes/DeclTypePolicy.hpp +++ /dev/null @@ -1,228 +0,0 @@ -/** - * @file DeclTypePolicy.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef INCLUDED_DECL_TYPE_POLICY_HPP -#define INCLUDED_DECL_TYPE_POLICY_HPP - -#include -#include -#include -#include -class DeclTypePolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { - public: - DeclData data; - ~DeclTypePolicy(){} - DeclTypePolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ - InitializeEventHandlers(); - } - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - - void Finalize(srcDispatch::srcSAXEventContext& ctx){ - using namespace srcDispatch; - - if( ctx.And({ParserState::declstmt}) || ctx.And({ParserState::forstmt, ParserState::control, ParserState::init}) || - ctx.And({ParserState::switchstmt, ParserState::condition}) ){ - if(ctx.IsOpen(ParserState::classblock) && ctx.Nor({ParserState::function, ParserState::constructor, ParserState::destructor})){ - data.isClassMember = true; - data.nameOfContainingClass = ctx.currentClassName; - } - - data.nameOfContainingFile = ctx.currentFilePath; - - if(ctx.currentFunctionName.empty() && !ctx.currentClassName.empty()){ - data.nameOfContainingClass = ctx.currentClassName; - } - - data.nameOfContainingFunction = ctx.currentFunctionName; - - data.lineNumber = ctx.startLineNumber; - data.nameOfIdentifier = currentDeclName; - - - data.isLocalVar = true; - if(ctx.currentFileLanguage == "Java" && !data.isFinal){ - data.isReference = true; - } - - currentDeclName.clear(); - NotifyAll(ctx); - data.clear(); - } - - if(ctx.And({ParserState::parameter})){ - data.lineNumber = ctx.startLineNumber; - data.nameOfIdentifier = currentDeclName; - - // Used to mark line numbers where parameters are declared - if (possibleDefs.size() == 0) { - possibleDefs.push_back(ctx.startLineNumber); - } else { - if (possibleDefs.back() != ctx.startLineNumber) { - possibleDefs.push_back(ctx.startLineNumber); - } - } - - data.isParameter = true; - data.nameOfContainingFunction = ctx.currentFunctionName; - data.nameOfContainingFile = ctx.currentFilePath; - if (ctx.currentFileLanguage == "Java" && !data.isFinal){ - data.isReference = true; - } - NotifyAll(ctx); - data.clear(); - } - } - - std::vector* GetPossibleDefs() { - return &possibleDefs; - } - std::vector* GetParamNames() { - return ¶mNames; - } - protected: - std::any DataInner() const override { - return std::make_shared(data); - } - private: - std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; - std::vector possibleDefs; - std::vector paramNames; - - void InitializeEventHandlers(){ - using namespace srcDispatch; - openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ - bool isDeclToken = ( ctx.And({ParserState::type, ParserState::declstmt}) && - ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist}) || - ctx.IsOpen({ParserState::init}) ); - bool isParamToken = ( ctx.And({ParserState::type, ParserState::parameter}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist}) ); - - if(isDeclToken || isParamToken){ - data.namespaces.push_back(ctx.currentToken); - } - }; - - openEventMap[ParserState::index] = [this](srcSAXEventContext& ctx [[maybe_unused]]){ - data.usesSubscript = true; - }; - - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx){ - if( ctx.IsOpen(ParserState::declstmt) || ctx.IsOpen({ParserState::init}) || ctx.IsOpen(ParserState::parameter) ){ - if(currentModifier == "*"){ - data.isPointer = true; - } - if(currentModifier == "&"){ - data.isReference = true; - } - } - }; - - closeEventMap[ParserState::type] = [this](srcSAXEventContext& ctx){ - // Capture the data-type when a condition is met - if( ctx.And({ParserState::declstmt}) || ctx.IsOpen({ParserState::init}) || - ctx.And({ParserState::switchstmt, ParserState::condition, ParserState::decl}) ){ - data.nameOfType = currentTypeName; - } - - if(ctx.And({ParserState::parameter})){ - data.nameOfType = currentTypeName; - currentTypeName.clear(); - } - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - //TODO: possibly, this if-statement is suppressing more than just unmarked whitespace. Investigate. - if(!(ctx.currentToken.empty() || ctx.currentToken[0] == ' ')){ - if(ctx.And({ParserState::name, ParserState::type, ParserState::decl, ParserState::declstmt}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist, ParserState::index})){ - currentTypeName = ctx.currentToken; - } - if(ctx.And({ParserState::name, ParserState::type, ParserState::decl, ParserState::parameter}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist, ParserState::index})){ - currentTypeName = ctx.currentToken; // parameter data type - } - - bool openConditional = ctx.IsOpen(ParserState::ifstmt) || ctx.IsOpen(ParserState::forstmt) || - ctx.IsOpen(ParserState::whilestmt) || ctx.IsOpen(ParserState::switchstmt); - - if( openConditional && ctx.And({ParserState::name, ParserState::type, ParserState::decl}) && - ctx.Nor({ParserState::index, ParserState::argumentlist, ParserState::specifier, ParserState::modifier}) ) { - currentTypeName = ctx.currentToken; - } - - - if( ctx.And({ParserState::name, ParserState::decl, ParserState::declstmt}) && - ctx.Nor({ParserState::type, ParserState::index/*skip array portion*/, ParserState::argumentlist/*skip init list portion*/, ParserState::init, ParserState::specifier, ParserState::modifier}) ){ - currentDeclName = ctx.currentToken; - } - if( ctx.IsOpen(ParserState::forstmt) && ctx.And({ParserState::name, ParserState::decl}) && - ctx.Nor({ParserState::type, ParserState::index, ParserState::argumentlist, ParserState::specifier, ParserState::modifier, ParserState::expr}) ) { - currentDeclName = ctx.currentToken; - } - if( ctx.IsOpen(ParserState::switchstmt) && ctx.And({ParserState::name, ParserState::decl}) && - ctx.Nor({ParserState::type, ParserState::index, ParserState::argumentlist, ParserState::specifier, ParserState::modifier, ParserState::expr}) ) { - currentDeclName = ctx.currentToken; - } - - if(ctx.And({ParserState::name, ParserState::decl, ParserState::parameter}) && - ctx.Nor({ParserState::type, ParserState::index/*skip array portion*/, ParserState::argumentlist/*skip init list portion*/, - ParserState::init, ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - currentDeclName = ctx.currentToken; // parameter variable name - - if (paramNames.size() == 0) { - paramNames.push_back(ctx.currentToken); - } else { - if (paramNames.back() != ctx.currentToken) { - paramNames.push_back(ctx.currentToken); - } - } - } - - if( ctx.And({ParserState::specifier, ParserState::decl, ParserState::declstmt}) || ctx.And({ParserState::specifier, ParserState::decl, ParserState::parameter}) ){ - currentSpecifier = ctx.currentToken; - } - - if( ctx.And({ParserState::modifier, ParserState::type, ParserState::declstmt}) || ctx.And({ParserState::modifier, ParserState::type, ParserState::parameter}) ){ - currentModifier = ctx.currentToken; - } - } - }; - - closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx){ - if( ctx.IsOpen(ParserState::declstmt) || ctx.IsOpen({ParserState::init}) || ctx.IsOpen(ParserState::parameter) ){ - if(currentSpecifier == "const"){ - if(data.isPointer){ - data.isConstAlias = true; - }else{ - data.isConstValue = true; - } - } - if(currentSpecifier == "final"){ - data.isFinal = true; - } - if(currentSpecifier == "static"){ - data.isStatic = true; - } - } - - currentSpecifier.clear(); - }; - - } -}; - -#endif \ No newline at end of file diff --git a/src/policy_classes/DeclTypePolicySingleEvent.hpp b/src/policy_classes/DeclTypePolicySingleEvent.hpp deleted file mode 100644 index b67b985..0000000 --- a/src/policy_classes/DeclTypePolicySingleEvent.hpp +++ /dev/null @@ -1,102 +0,0 @@ -/** - * @file DeclTypePolicySingleEvent.hpp - * - * - * MODIFIED from srcDispatch - * This collects the initializer - * - */ -#ifndef INCLUDED_DECL_TYPE_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_DECL_TYPE_POLICY_SINGLE_EVENT_HPP - -#include - -#include - -#include -#include - -class DeclTypePolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - std::vector> decls; - std::size_t declDepth; - std::unique_ptr declPolicy; - -public: - DeclTypePolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - decls{}, - declDepth(0), - declPolicy(nullptr) { - InitializeDeclTypePolicyHandlers(); - } - - ~DeclTypePolicy() {} - -protected: - std::any DataInner() const override { return std::make_shared>>(decls); } - - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(DeclPolicy) == typeid(*policy)) { - std::shared_ptr decl = policy->Data(); - if(decls.size()) { - decl->type = decls.back()->type; - decl->isStatic = decls.back()->isStatic; - } - decls.push_back(decl); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeDeclTypePolicyHandlers() { - using namespace srcDispatch; - - // start of policy - std::function startDeclType = [this](srcSAXEventContext& ctx) { - if (!declDepth) { - declDepth = ctx.depth; - CollectDeclHandlers(); - } - }; - - - openEventMap[ParserState::declstmt] = startDeclType; - openEventMap[ParserState::parameter] = startDeclType; - - // end of policy - std::function endDeclType = [this](srcSAXEventContext& ctx) { - if (!declDepth || declDepth != ctx.depth) return; - - declDepth = 0; - NotifyAll(ctx); - decls.clear(); - InitializeDeclTypePolicyHandlers(); - }; - - closeEventMap[ParserState::declstmt] = endDeclType; - closeEventMap[ParserState::parameter] = endDeclType; - } - - void CollectDeclHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { - if(!declDepth || (declDepth + 1) != ctx.depth) return; - - if (!declPolicy) declPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(declPolicy.get()); - }; - } - -}; - -#endif diff --git a/src/policy_classes/DeltaElement.hpp b/src/policy_classes/DeltaElement.hpp new file mode 100644 index 0000000..51e1564 --- /dev/null +++ b/src/policy_classes/DeltaElement.hpp @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file DeltaElement.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_DELTA_ELEMENT_HPP +#define INCLUDED_DELTA_ELEMENT_HPP + +#include + +#include +#include +#include + +namespace srcDiffDispatch { + +template +class DeltaElement { + +private: + std::optional original; + std::optional modified; + + srcDispatch::DiffOperation operation; + +protected: + +public: + DeltaElement(); + DeltaElement(const type& element); + DeltaElement(srcDispatch::DiffOperation operation, const type& element = type()); + + DeltaElement copyAs(srcDispatch::DiffOperation operation) const; + + bool IsCommon() const; + bool IsDelete() const; + bool IsInsert() const; + bool IsChange() const; + + bool HasOriginal() const; + bool HasModified() const; + + const std::type_info& OriginalType() const; + const std::type_info& ModifiedType() const; + + const type& GetOriginal() const; + type& GetOriginal(); + void SetOriginal(const type& original); + + const type& GetModified() const; + type& GetModified(); + void SetModified(const type& modified); + + const type& GetElement() const; + type& GetElement(); + + const auto operator->() const; + auto operator->(); + + srcDispatch::DiffOperation GetOperation() const; + void SetOperation(srcDispatch::DiffOperation operation); + + bool IsOfOperation(srcDispatch::DiffOperation operation) const; + const type& GetOfOperation(srcDispatch::DiffOperation operation) const; + + void Update(srcDispatch::DiffOperation operation, const type& element); + + template + void Append(srcDispatch::DiffOperation operation, const std::string& str); + void Clear(); + + operator bool() const; + + + std::string GetOriginalStr() const; + std::string GetModifiedStr() const; + + template + std::string ToString(srcDispatch::DiffOperation operation = srcDispatch::NONE) const; +}; + +} + +#include + +#endif diff --git a/src/policy_classes/DeltaElement.tcc b/src/policy_classes/DeltaElement.tcc new file mode 100644 index 0000000..520a3c5 --- /dev/null +++ b/src/policy_classes/DeltaElement.tcc @@ -0,0 +1,345 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file DeltaElement.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#include + +#ifdef __linux__ + #include +#endif + +#include +#include +#include + +template +struct Value { + Value(type& value) : value(value) {} + type& value; +}; + +template +struct Value> { + Value(std::shared_ptr& value) : value(*value) {} + type& value; +}; + +template +struct ValueConst { + ValueConst(const type& value) : value(value) {} + const type& value; +}; + +template +struct ValueConst> { + ValueConst(const std::shared_ptr& value) : value(*value) {} + const type& value; +}; + +template +std::ostream& operator<<(std::ostream& out, const srcDiffDispatch::DeltaElement& element) { + assert(element.GetOperation() != srcDispatch::NONE); + + return out << element.ToString(srcDispatch::NONE); +} + +namespace srcDiffDispatch { + +template +DeltaElement::DeltaElement() + : original(), modified(), operation(srcDispatch::NONE) { +} + +template +DeltaElement::DeltaElement(const type& element) + : original(element), modified(), operation(srcDispatch::COMMON) { +} + +template +DeltaElement::DeltaElement(srcDispatch::DiffOperation operation, const type& element) + : operation(srcDispatch::NONE) { + Update(operation, element); +} +template +DeltaElement DeltaElement::copyAs(srcDispatch::DiffOperation operation) const { + if constexpr (std::is_same_v>) { + return DeltaElement(operation, std::make_shared(this->GetElement()->copyAs())); + } else { + return DeltaElement(operation, this->GetElement()->copyAs()); + } +} + +template +bool DeltaElement::IsCommon() const { + return operation == srcDispatch::COMMON; +} + +template +bool DeltaElement::IsDelete() const { + return operation == srcDispatch::DELETE; +} + +template +bool DeltaElement::IsInsert() const { + return operation == srcDispatch::INSERT; +} + +template +bool DeltaElement::IsChange() const { + return operation == srcDispatch::CHANGE; +} + +template +bool DeltaElement::HasOriginal() const { + return bool(original); +} + +template +bool DeltaElement::HasModified() const { + return bool(modified); +} + +template +const std::type_info& DeltaElement::OriginalType() const { + return original->type(); +} + +template +const std::type_info& DeltaElement::ModifiedType() const { + return modified->type(); +} + +template +const type& DeltaElement::GetOriginal() const { + assert(HasOriginal()); + return *original; +} + +template +type& DeltaElement::GetOriginal() { + assert(HasOriginal()); + return *original; +} + +template +void DeltaElement::SetOriginal(const type& original) { + this->original = original; +} + +template +const type& DeltaElement::GetModified() const { + assert(HasModified()); + return *modified; +} + +template +type& DeltaElement::GetModified() { + assert(HasModified()); + return *modified; +} + +template +void DeltaElement::SetModified(const type& modified) { + this->modified = modified; +} + +template +const type& DeltaElement::GetElement() const { + if(operation == srcDispatch::COMMON) return *original; + if(operation == srcDispatch::DELETE) return *original; + + return *modified; +} + +template +type& DeltaElement::GetElement() { + if(operation == srcDispatch::COMMON) return *original; + if(operation == srcDispatch::DELETE) return *original; + + return *modified; +} + +template +const auto DeltaElement::operator->() const { + if constexpr (std::is_same_v>) { + return &*GetElement(); + } else { + return &GetElement(); + } +} + +template +auto DeltaElement::operator->() { + if constexpr (std::is_same_v> ) { + return &*GetElement(); + } else { + return &GetElement(); + } +} + +template +srcDispatch::DiffOperation DeltaElement::GetOperation() const { + return operation; +} + +template +void DeltaElement::SetOperation(enum srcDispatch::DiffOperation operation) { + this->operation = operation; +} + +template +bool DeltaElement::IsOfOperation(srcDispatch::DiffOperation operation) const { + if(this->operation == srcDispatch::NONE) return false; + if(this->operation == srcDispatch::COMMON) return true; + if(this->operation == srcDispatch::CHANGE) return true; + + return this->operation == operation; +} + +template +const type& DeltaElement::GetOfOperation(srcDispatch::DiffOperation operation) const { + assert(IsOfOperation(operation)); + + if(this->operation == srcDispatch::COMMON) return *original; + if(this->operation == srcDispatch::CHANGE) return operation == srcDispatch::DELETE? *original : *modified; + if(operation == srcDispatch::DELETE) return *original; + return *modified; +} + +template +void DeltaElement::Update(srcDispatch::DiffOperation operation, const type& element) { + + if( (this->operation == srcDispatch::DELETE && operation == srcDispatch::INSERT) + || (this->operation == srcDispatch::INSERT && operation == srcDispatch::DELETE)) { + this->operation = srcDispatch::CHANGE; + } else if(this->operation != srcDispatch::CHANGE) { + this->operation = operation; + } + + if(operation == srcDispatch::COMMON) { + original = element; + } else if(operation == srcDispatch::DELETE) { + original = element; + } else if(operation == srcDispatch::INSERT) { + modified = element; + } else if(operation == srcDispatch::CHANGE) { + original = element; + modified = element; + } + +} + +template +template +void DeltaElement::Append(srcDispatch::DiffOperation operation, const std::string& str) { + + if(this->operation == srcDispatch::DELETE && operation == srcDispatch::INSERT) { + this->operation = srcDispatch::CHANGE; + } else if(this->operation != srcDispatch::CHANGE) { + this->operation = operation; + } + + if constexpr (!std::is_same_v) { + static const any_type null_any_type; + any_type* innerOriginal = original? std::any_cast(&*original) : nullptr; + any_type* innerModified = modified? std::any_cast(&*modified) : nullptr; + + if(operation == srcDispatch::COMMON) { + Value(*innerOriginal).value += str; + } else if(operation == srcDispatch::DELETE) { + Value(*innerOriginal).value += str; + } else if(operation == srcDispatch::INSERT) { + Value(*innerModified).value += str; + } else if(operation == srcDispatch::CHANGE) { + Value(*innerOriginal).value += str; + Value(*innerModified).value += str; + } + + } else { + + if(operation == srcDispatch::COMMON) { + Value(original).value += str; + } else if(operation == srcDispatch::DELETE) { + Value(original).value += str; + } else if(operation == srcDispatch::INSERT) { + Value(modified).value += str; + } else if(operation == srcDispatch::CHANGE) { + Value(original).value += str; + Value(modified).value += str; + } + + } + +} + +template +void DeltaElement::Clear() { + original = std::optional(); + modified = std::optional(); +} + +template +DeltaElement::operator bool() const { + return operation != srcDispatch::NONE; +} + +template +template +std::string DeltaElement::ToString(srcDispatch::DiffOperation operation) const { + + if(this->operation == srcDispatch::NONE) return ""; + + std::string originalStr; + std::string modifiedStr; + + if constexpr (!std::is_same_v) { + + DeltaElement innerElement(this->operation); + if(original) { + innerElement.GetOriginal() = std::any_cast(*original); + } + + if(modified) { + innerElement.GetModified() = std::any_cast(*modified); + } + + return innerElement.ToString(operation); + } else { + + if constexpr (std::is_same_v || std::is_same_v>) { + if(HasOriginal()) { + originalStr = ValueConst(*original).value; + } + } else { + const type& element = HasOriginal()? *original : *modified; + originalStr = ValueConst(*element).value.ToString(srcDispatch::DELETE); + } + + if constexpr (std::is_same_v || std::is_same_v>) { + if(HasModified() || this->operation == srcDispatch::COMMON) { + const type& element = this->operation == srcDispatch::COMMON? *original : *modified; + modifiedStr = ValueConst(element).value; + } + } else { + const type& element = HasModified()? *modified : *original; + modifiedStr = ValueConst(element).value.ToString(srcDispatch::INSERT); + } + + if(operation == srcDispatch::DELETE) { + return originalStr; + } else if(operation == srcDispatch::INSERT) { + return modifiedStr; + } else if(originalStr != modifiedStr) { + return originalStr + '|' + modifiedStr; + } + } + + return originalStr; +} + +} diff --git a/src/policy_classes/DoPolicySingleEvent.hpp b/src/policy_classes/DoPolicySingleEvent.hpp deleted file mode 100644 index 63bf32d..0000000 --- a/src/policy_classes/DoPolicySingleEvent.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file DoPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_DO_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_DO_POLICY_SINGLE_EVENT_HPP - -#include -#include - -#include -#include -#include - -struct DoData { - - unsigned int startLineNumber; - unsigned int endLineNumber; - - std::shared_ptr condition; - std::shared_ptr block; - - friend std::ostream& operator<<(std::ostream& out, const DoData& doData) { - if(!doData.condition) return out; - return out << *doData.condition; - } -}; - -class DoPolicy : public ConditionalPolicy { -public: - DoPolicy(std::initializer_list listeners) - : ConditionalPolicy(listeners) {} -}; - -#endif diff --git a/src/policy_classes/ElseIfPolicySingleEvent.hpp b/src/policy_classes/ElseIfPolicySingleEvent.hpp deleted file mode 100644 index 061184e..0000000 --- a/src/policy_classes/ElseIfPolicySingleEvent.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file ElseIfPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_ELSEIF_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_ELSEIF_POLICY_SINGLE_EVENT_HPP - -#include -#include - -#include -#include -#include - -struct ElseIfData { - - unsigned int startLineNumber; - unsigned int endLineNumber; - - std::shared_ptr condition; - std::shared_ptr block; - - friend std::ostream& operator<<(std::ostream& out, const ElseIfData& elseIfData) { - if(!elseIfData.condition) return out; - return out << *elseIfData.condition; - } -}; - -class ElseIfPolicy : public ConditionalPolicy { -public: - ElseIfPolicy(std::initializer_list listeners) - : ConditionalPolicy(listeners) {} -}; - -#endif diff --git a/src/policy_classes/ElsePolicySingleEvent.hpp b/src/policy_classes/ElsePolicySingleEvent.hpp deleted file mode 100644 index a512ca9..0000000 --- a/src/policy_classes/ElsePolicySingleEvent.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file ElsePolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_ELSE_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_ELSE_POLICY_SINGLE_EVENT_HPP - -#include -#include - -#include -#include -#include - -struct ElseData { - - unsigned int startLineNumber; - unsigned int endLineNumber; - - std::shared_ptr condition; - std::shared_ptr block; - - friend std::ostream& operator<<(std::ostream& out, const ElseData& elseData) { - if(!elseData.condition) return out; - return out << *elseData.condition; - } -}; - -class ElsePolicy : public ConditionalPolicy { -public: - ElsePolicy(std::initializer_list listeners) - : ConditionalPolicy(listeners) {} -}; - -#endif diff --git a/src/policy_classes/ExprPolicy.hpp b/src/policy_classes/ExprPolicy.hpp deleted file mode 100644 index 57e46d0..0000000 --- a/src/policy_classes/ExprPolicy.hpp +++ /dev/null @@ -1,149 +0,0 @@ -/** - * @file ExprPolicy.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include -#include -#ifndef EXPRPOLICY -#define EXPRPOLICY -class ExprPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { - public: - struct ExprData{ - ExprData() {lhs = false;} - void clear(){ - definitions.clear(); - uses.clear(); - lhs = false; - } - bool lhs; - std::string nameOfIdentifier; - std::set definitions; - std::set uses; //could be used multiple times in same expr - }; - struct ExprDataSet{ - ExprDataSet() = default; - ExprDataSet(std::map dat){ - dataSet = dat; - } - void clear(){ - dataSet.clear(); - } - std::string lhsName; - std::map dataSet; - }; - ~ExprPolicy(){} - ExprPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ - InitializeEventHandlers(); - } - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - protected: - std::any DataInner() const override { - return std::make_shared(exprDataSet); - } - private: - ExprData data; - ExprDataSet exprDataSet; - std::string currentTypeName, currentExprName, currentModifier, currentSpecifier; - std::pair currentExprOp; - std::vector currentLine; - - void InitializeEventHandlers(){ - using namespace srcDispatch; - - closeEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ - // Long or-statement allows various declaration operators to get planted into - // a slices def data output - // if (ctx.currentToken == "=" || ctx.currentToken == "++" || ctx.currentToken == "+=" || - // ctx.currentToken == "--" || ctx.currentToken == "-=" || ctx.currentToken == "*=" || - // ctx.currentToken == "/=" || ctx.currentToken == "%=" || ctx.currentToken == "&=" || - // ctx.currentToken == "|=" || ctx.currentToken == "^=" || ctx.currentToken == "<<=" || - // ctx.currentToken == ">>=") - - if (ctx.currentToken == "=" || ctx.currentToken == "+=" || - ctx.currentToken == "-=" || ctx.currentToken == "*=" || - ctx.currentToken == "/=" || ctx.currentToken == "%=" || - ctx.currentToken == "--" || ctx.currentToken == "++"){ - currentExprOp = std::make_pair(ctx.currentToken, ctx.startLineNumber); - auto it = exprDataSet.dataSet.find(currentExprName); - - if(it != exprDataSet.dataSet.end()){ - exprDataSet.lhsName = currentExprName; - it->second.lhs = true; - it->second.uses.erase(currentLine.back()); - it->second.definitions.insert(currentLine.back()); - }else{ - std::cerr<<"No such thing as: "<second.uses.insert(currentLine.back()); //assume it's a use - - if ( (currentExprOp.first == "++" || currentExprOp.first == "--") && currentExprOp.second == ctx.startLineNumber ) - it->second.definitions.insert(currentLine.back()); - }else{ - data.nameOfIdentifier = currentExprName; - - data.uses.insert(currentLine.back()); - - if ( (currentExprOp.first == "++" || currentExprOp.first == "--") && currentExprOp.second == ctx.startLineNumber ) - data.definitions.insert(currentLine.back()); - - exprDataSet.dataSet.insert(std::make_pair(currentExprName, data)); - } - } - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - //TODO: possibly, this if-statement is suppressing more than just unmarked whitespace. Investigate. - if(!(ctx.currentToken.empty() || ctx.currentToken == " ")){ - if(ctx.And({ParserState::name, ParserState::expr, ParserState::exprstmt}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::op})){ - currentExprName = ctx.currentToken; - } - if(ctx.And({ParserState::specifier, ParserState::expr, ParserState::exprstmt})){ - currentSpecifier = ctx.currentToken; - } - if(ctx.And({ParserState::modifier, ParserState::exprstmt})){ - currentModifier = ctx.currentToken; - } - } - }; - closeEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx){ - NotifyAll(ctx); - currentLine.pop_back(); - currentLine.clear(); - exprDataSet.dataSet.clear(); - data.clear(); - }; - - } -}; -#endif \ No newline at end of file diff --git a/src/policy_classes/ExprStmtPolicySingleEvent.hpp b/src/policy_classes/ExprStmtPolicySingleEvent.hpp deleted file mode 100644 index 7263423..0000000 --- a/src/policy_classes/ExprStmtPolicySingleEvent.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/** - * @file ExprStmtPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_EXPR_STMT_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_EXPR_STMT_POLICY_SINGLE_EVENT_HPP - -#include -#include -#include - -#include - -#include -#include -#include - - -class ExprStmtPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - std::shared_ptr data; - std::size_t exprStmtDepth; - std::unique_ptr exprPolicy; - -public: - ExprStmtPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - exprStmtDepth(0) { - InitializeExprStmtPolicyHandlers(); - } - - ~ExprStmtPolicy() {} - -protected: - std::any DataInner() const override { return data; } - - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(ExpressionPolicy) == typeid(*policy)) { - data = policy->Data(); - ctx.dispatcher->RemoveListener(nullptr); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeExprStmtPolicyHandlers() { - using namespace srcDispatch; - // start of policy - openEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { - if (!exprStmtDepth) { - exprStmtDepth = ctx.depth; - data = std::make_shared(); - CollectExpressionHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { - if (exprStmtDepth && exprStmtDepth == ctx.depth) { - exprStmtDepth = 0; - NotifyAll(ctx); - InitializeExprStmtPolicyHandlers(); - } - }; - } - - void CollectExpressionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!exprPolicy) exprPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); - }; - } - -}; - -#endif diff --git a/src/policy_classes/ExpressionPolicySingleEvent.cpp b/src/policy_classes/ExpressionPolicySingleEvent.cpp deleted file mode 100644 index 49494c0..0000000 --- a/src/policy_classes/ExpressionPolicySingleEvent.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/** - * @file ExpressionPolicy.cpp - * - */ - -#include - -std::ostream& operator<<(std::ostream& out, const ExpressionData& ex) { - bool outputSpace = false; - for (std::any item : ex.expr) { - if(outputSpace) { - out << ' '; - } - if(item.type() == typeid(std::shared_ptr)) { - out << *std::any_cast>(item); - } else if(item.type() == typeid(std::shared_ptr)) { - out << *std::any_cast>(item); - } else if(item.type() == typeid(std::shared_ptr)) { - out << *std::any_cast>(item); - } else if(item.type() == typeid(std::shared_ptr)) { - out << *std::any_cast>(item); - } - outputSpace = false; - } - return out; -} - -ExpressionPolicy::~ExpressionPolicy() {} - -void ExpressionPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if(typeid(NamePolicy) == typeid(*policy)) { - data.expr.push_back(policy->Data()); - } else if(typeid(OperatorPolicy) == typeid(*policy)) { - data.expr.push_back(policy->Data()); - } else if(typeid(LiteralPolicy) == typeid(*policy)) { - data.expr.push_back(policy->Data()); - } else if(typeid(CallPolicy) == typeid(*policy)) { - data.expr.push_back(policy->Data()); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - //Operators are added in CollectOtherHandlers() - ctx.dispatcher->RemoveListenerDispatch(nullptr); -} - -void ExpressionPolicy::InitializeExpressionPolicyHandlers() { - using namespace srcDispatch; - // start of policy - std::function expressionStart = [this](srcSAXEventContext& ctx) { - if(!exprDepth) { - exprDepth = ctx.depth; - data = ExpressionData{}; - data.lineNumber = ctx.startLineNumber; - CollectNameHandlers(); - CollectCallHandlers(); - CollectOperatorHandlers(); - CollectLiteralHandlers(); - } - }; - - // end of policy - std::function expressionEnd = [this](srcSAXEventContext& ctx) { - if(exprDepth && exprDepth == ctx.depth) { - exprDepth = 0; - NotifyAll(ctx); - InitializeExpressionPolicyHandlers(); - } - }; - - openEventMap[ParserState::expr] = expressionStart; - closeEventMap[ParserState::expr] = expressionEnd; -} - - -void ExpressionPolicy::CollectNameHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if(!namePolicy) namePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(namePolicy.get()); - }; -} - -void ExpressionPolicy::CollectCallHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { - if(!callPolicy) callPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(callPolicy.get()); - }; -} - -void ExpressionPolicy::CollectOperatorHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { - if(!operatorPolicy) operatorPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(operatorPolicy.get()); - }; -} - -void ExpressionPolicy::CollectLiteralHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { - if(!literalPolicy) literalPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(literalPolicy.get()); - }; -} diff --git a/src/policy_classes/ExpressionPolicySingleEvent.hpp b/src/policy_classes/ExpressionPolicySingleEvent.hpp deleted file mode 100644 index c91d088..0000000 --- a/src/policy_classes/ExpressionPolicySingleEvent.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @file ExpressionPolicy.hpp - * - */ -#ifndef INCLUDED_EXPRESSION_POLICY_SINGE_EVENT_HPP -#define INCLUDED_EXPRESSION_POLICY_SINGE_EVENT_HPP - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -struct CallData; -class CallPolicy; - -struct NameData; -class NamePolicy; - -//A vector of elements in the expression. -//Names, operators, calls in the correct order. -//Need for determining variable use, variable modification, calls - -struct ExpressionData { - - unsigned int lineNumber; - std::vector expr; - - friend std::ostream& operator<<(std::ostream& out, const ExpressionData& ex); -}; - -class ExpressionPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - ExpressionData data; - std::size_t exprDepth; - std::unique_ptr namePolicy; - std::unique_ptr operatorPolicy; - std::unique_ptr literalPolicy; - std::unique_ptr callPolicy; - -public: - ExpressionPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - exprDepth(0) { - InitializeExpressionPolicyHandlers(); - } - - ~ExpressionPolicy(); - -protected: - std::any DataInner() const override { return std::make_shared(data); } - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeExpressionPolicyHandlers(); - void CollectCallHandlers(); - void CollectNameHandlers(); - void CollectOperatorHandlers(); - void CollectLiteralHandlers(); -}; - -#endif diff --git a/src/policy_classes/ForPolicySingleEvent.hpp b/src/policy_classes/ForPolicySingleEvent.hpp deleted file mode 100644 index 37f5cd5..0000000 --- a/src/policy_classes/ForPolicySingleEvent.hpp +++ /dev/null @@ -1,126 +0,0 @@ -/** - * @file ForPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_FOR_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_FOR_POLICY_SINGLE_EVENT_HPP - -#include -#include -#include - -#include -#include - -#include -#include -#include - -class BlockPolicy; -struct BlockData; - -struct ForData { - - unsigned int startLineNumber; - unsigned int endLineNumber; - - std::shared_ptr control; - std::shared_ptr block; - - friend std::ostream& operator<<(std::ostream& out, const ForData& forData) { - if(!forData.control) return out; - return out << *forData.control; - } -}; - - -class ForPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - ForData data; - std::size_t forDepth; - std::unique_ptr controlPolicy; - std::unique_ptr blockPolicy; - -public: - - ForPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - forDepth(0) { - InitializeForPolicyHandlers(); - } - - ~ForPolicy() {} - -protected: - std::any DataInner() const { return std::make_shared(data); } - - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(ControlPolicy) == typeid(*policy)) { - data.control = policy->Data(); - } else if (typeid(BlockPolicy) == typeid(*policy)) { - data.block = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers - -private: - - void InitializeForPolicyHandlers() { - using namespace srcDispatch; - - openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { \ - if (!forDepth) { - forDepth = ctx.depth; - data = ForData{}; - data.startLineNumber = ctx.startLineNumber; - data.endLineNumber = ctx.endLineNumber; - CollectControlHandlers(); - CollectBlockHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::forstmt] =[this](srcSAXEventContext& ctx) { - if (forDepth && forDepth == ctx.depth) { - forDepth = 0; - NotifyAll(ctx); - InitializeForPolicyHandlers(); - } - }; - } - - - void CollectControlHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { - if(!forDepth) return; - if((forDepth + 1) != ctx.depth) return; - - if (!controlPolicy) controlPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(controlPolicy.get()); - }; - } - - void CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if(forDepth && (forDepth + 1) == ctx.depth) { - if (!blockPolicy) blockPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); - } - }; - } -}; - -#endif diff --git a/src/policy_classes/FunctionCallPolicy.hpp b/src/policy_classes/FunctionCallPolicy.hpp deleted file mode 100644 index cea3d45..0000000 --- a/src/policy_classes/FunctionCallPolicy.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @file FunctionCallPolicy.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include -#include -/* - *Record current function being called - *Record argument names and positions - */ -#ifndef CALLPOLICY -#define CALLPOLICY -class FunctionCallPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { - /* - {CalledFunction1{arg1, line#}, {arg2, line#}, ..., {argn, line#}, - NestedCalledFunction1{arg1, line#},{arg2, line#}, ..., {argn, line#} - } - */ - public: - struct FunctionCallData{ - void clear(){ - fnName.clear(); - callargumentlist.clear(); - } - std::string fnName; - std::vector callargumentlist; - }; - ~FunctionCallPolicy(){} - FunctionCallPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ - InitializeEventHandlers(); - } - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - protected: - std::any DataInner() const override { - return std::make_shared(data); - } - private: - FunctionCallData data; - std::string currentTypeName, currentCallName, currentModifier, currentSpecifier; - std::string fullFuncIdentifier; - void InitializeEventHandlers(){ - using namespace srcDispatch; - - openEventMap[ParserState::argumentlist] = [this](srcSAXEventContext& ctx [[maybe_unused]]) { - data.callargumentlist.push_back("("); - data.callargumentlist.push_back(fullFuncIdentifier); - data.fnName = fullFuncIdentifier; - fullFuncIdentifier = ""; - }; - closeEventMap[ParserState::argumentlist] = [this](srcSAXEventContext& ctx){ - if(ctx.triggerField[ParserState::call] == 1){ //TODO: Fix - data.callargumentlist.push_back(")"); - NotifyAll(ctx); - data.clear(); - }else{ - data.callargumentlist.push_back(")"); - } - }; - - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx [[maybe_unused]]){ - if(currentModifier == "*"){} - else if(currentModifier == "&"){} - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - if(ctx.IsOpen(ParserState::name) && ctx.IsGreaterThan(ParserState::call,ParserState::argumentlist) && ctx.IsClosed(ParserState::genericargumentlist)){ - data.fnName = ctx.currentToken; - fullFuncIdentifier += ctx.currentToken; - } - - if(ctx.And({ParserState::name, ParserState::argument, ParserState::argumentlist}) && ctx.IsEqualTo(ParserState::call,ParserState::argumentlist) && ctx.IsClosed(ParserState::genericargumentlist)){ - data.callargumentlist.push_back(ctx.currentToken); - } - - if(ctx.And({ParserState::literal, ParserState::argument, ParserState::argumentlist}) && ctx.IsEqualTo(ParserState::call,ParserState::argumentlist) && ctx.IsClosed(ParserState::genericargumentlist)){ - data.callargumentlist.push_back("*LITERAL*"); //Illegal c++ identifier as marker for literals - } - }; - } -}; -#endif \ No newline at end of file diff --git a/src/policy_classes/FunctionPolicySingleEvent.hpp b/src/policy_classes/FunctionPolicySingleEvent.hpp deleted file mode 100644 index 06d50ff..0000000 --- a/src/policy_classes/FunctionPolicySingleEvent.hpp +++ /dev/null @@ -1,281 +0,0 @@ -/** - * @file FunctionPolicySingleEvent.hpp - * - * MODIFIED FOR STEREOCODE - * - */ -#ifndef INCLUDED_FUNCTION_POLICY_SINGE_EVENT_HPP -#define INCLUDED_FUNCTION_POLICY_SINGE_EVENT_HPP - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -struct FunctionData { - enum FunctionType { CONSTRUCTOR, DESTRUCTOR, OPERATOR, FUNCTION }; - - std::vector namespaces; - - unsigned int lineNumber; - std::string language; - std::string filename; - FunctionType type; - - bool isDecl; - bool isVirtual; - bool isPureVirtual; - bool isConst; - bool isStatic; - bool isInline; - bool isFinal; - bool isOverride; - bool isConstExpr; - bool isDelete; - bool isFriend; - - std::set stereotypes; - - std::shared_ptr returnType; - std::shared_ptr name; - std::vector> parameters; - std::shared_ptr block; - - - std::string ToString() const { - std::string signature = name->ToString(); - signature += '('; - for(std::size_t pos = 0; pos < parameters.size(); ++pos) { - if (pos > 0) { - signature += ", "; - } - signature += parameters[pos]->type->ToString(); - } - signature += ')'; - if (isConst) { - signature += " const"; - } - return signature; - } - - friend std::ostream& operator<<(std::ostream& out, const FunctionData& functionData) { - if (functionData.returnType) { - out << *functionData.returnType << ' ' << *functionData.name; - } - out << '('; - for(std::size_t pos = 0; pos < functionData.parameters.size(); ++pos) { - if (pos != 0) - out << ", "; - out << *functionData.parameters[pos]; - } - out << ')'; - return out; - } -}; - - -class FunctionPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - FunctionData data; - std::size_t functionDepth; - - std::unique_ptr typePolicy; - std::unique_ptr namePolicy; - std::unique_ptr declPolicy; - std::unique_ptr blockPolicy; - -public: - FunctionPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - functionDepth(0) { - InitializeFunctionPolicyHandlers(); - } - - ~FunctionPolicy() {} - -protected: - std::any DataInner() const override { return std::make_shared(data); } - - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(TypePolicy) == typeid(*policy)) { - data.returnType = policy->Data(); - } else if (typeid(NamePolicy) == typeid(*policy)) { - data.name = policy->Data(); - } else if (typeid(DeclTypePolicy) == typeid(*policy)) { - std::shared_ptr>> decl_data = policy->Data>>(); - for(std::shared_ptr decl : *decl_data) { - data.parameters.push_back(decl); - } - } else if (typeid(BlockPolicy) == typeid(*policy)) { - data.block = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListenerDispatch(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeFunctionPolicyHandlers() { - using namespace srcDispatch; - // start of policy - std::function startFunction = [this](srcSAXEventContext& ctx) { - if (!functionDepth) { - functionDepth = ctx.depth; - data = FunctionData{}; - data.namespaces = ctx.currentNamespaces; - data.lineNumber = ctx.startLineNumber; - data.language = ctx.currentFileLanguage; - data.filename = ctx.currentFilePath; - data.isFriend = ctx.elementStack.back() == "friend"; - std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); - if (stereotype_attr_itr != ctx.attributes.end()){ - std::istringstream stereostring(stereotype_attr_itr->second); - data.stereotypes = std::set(std::istream_iterator(stereostring), std::istream_iterator()); - } - if (ctx.currentTag == "function" || ctx.currentTag == "function_decl") { - if (ctx.isOperator) - data.type = FunctionData::OPERATOR; - else - data.type = FunctionData::FUNCTION; - } else if (ctx.currentTag == "constructor" || ctx.currentTag == "constructor_decl") { - data.type = FunctionData::CONSTRUCTOR; - } else if (ctx.currentTag == "destructor" || ctx.currentTag == "destructor_decl") { - data.type = FunctionData::DESTRUCTOR; - } - - data.isDecl = ctx.currentTag == "function_decl" - || ctx.currentTag == "constructor_decl" - || ctx.currentTag == "destructor_decl"; - - CollectXMLAttributeHandlers(); - CollectTypeHandlers(); - CollectNameHandlers(); - CollectParameterHandlers(); - CollectOtherHandlers(); - CollectBlockHandlers(); - } - }; - - // end of policy - std::function endFunction = [this](srcSAXEventContext& ctx) { - if (functionDepth && functionDepth == ctx.depth) { - functionDepth = 0; - NotifyAll(ctx); - InitializeFunctionPolicyHandlers(); - } - }; - - openEventMap[ParserState::function] = startFunction; - openEventMap[ParserState::functiondecl] = startFunction; - openEventMap[ParserState::constructor] = startFunction; - openEventMap[ParserState::constructordecl] = startFunction; - openEventMap[ParserState::destructor] = startFunction; - openEventMap[ParserState::destructordecl] = startFunction; - - closeEventMap[ParserState::function] = endFunction; - closeEventMap[ParserState::functiondecl] = endFunction; - closeEventMap[ParserState::constructor] = endFunction; - closeEventMap[ParserState::constructordecl] = endFunction; - closeEventMap[ParserState::destructor] = endFunction; - closeEventMap[ParserState::destructordecl] = endFunction; - } - - void CollectXMLAttributeHandlers() {} - - void CollectTypeHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - if (!typePolicy) typePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(typePolicy.get()); - } - }; - } - - void CollectNameHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - if (!namePolicy) namePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(namePolicy.get()); - } - }; - } - - void CollectParameterHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 2) == ctx.depth) { - if (!declPolicy) declPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(declPolicy.get()); - } - }; - } - }; - - closeEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - NopOpenEvents({ParserState::parameter}); - } - }; - } - - void CollectOtherHandlers() { - using namespace srcDispatch; - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - if (ctx.And({ParserState::specifier})) { - if (ctx.currentToken == "virtual") - data.isVirtual = true; - else if (ctx.currentToken == "static") - data.isStatic = true; - else if (ctx.currentToken == "const") - data.isConst = true; - else if (ctx.currentToken == "final") - data.isFinal = true; - else if (ctx.currentToken == "override") - data.isOverride = true; - else if (ctx.currentToken == "delete") - data.isDelete = true; - else if (ctx.currentToken == "inline") - data.isInline = true; - else if (ctx.currentToken == "constexpr") - data.isConstExpr = true; - } else if (ctx.And({ParserState::literal})) { - data.isPureVirtual = true; - } - } - }; - } - - void CollectBlockHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - if (functionDepth && (functionDepth + 1) == ctx.depth) { - if (!blockPolicy) blockPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); - } - }; - } - -}; - -#endif diff --git a/src/policy_classes/FunctionSignaturePolicy.hpp b/src/policy_classes/FunctionSignaturePolicy.hpp deleted file mode 100644 index 0800849..0000000 --- a/src/policy_classes/FunctionSignaturePolicy.hpp +++ /dev/null @@ -1,180 +0,0 @@ -/** - * @file FunctionSignaturePolicy.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include -#include -#ifndef FUNCTIONSIGNATUREPOLICY -#define FUNCTIONSIGNATUREPOLICY -struct SignatureData{ - SignatureData():isConst{false}, constPointerReturn{false}, isMethod{false}, isStatic{false}, pointerToConstReturn{false}, - hasAliasedReturn{false}, hasSideEffect{false}, hasArrayReturn{false}{} - int lineNumber; - bool isConst; - bool isMethod; - bool isStatic; - std::string name; - bool hasArrayReturn; - bool hasSideEffect; - bool isConstructor; - bool hasAliasedReturn; - std::string returnType; - bool constPointerReturn; - bool pointerToConstReturn; - std::string sLexicalCategory; - std::string returnTypeModifier; - std::vector parameters; - std::string nameOfContainingFile; - std::string nameOfContainingClass; - std::vector functionNamespaces; - std::vector returnTypeNamespaces; - void clear(){ - name.clear(); - hasArrayReturn = false; - isConst = false; - isMethod = false; - isStatic = false; - returnType.clear(); - parameters.clear(); - hasSideEffect = false; - isConstructor = false; - sLexicalCategory.clear(); - hasAliasedReturn = false; - functionNamespaces.clear(); - returnTypeModifier.clear(); - constPointerReturn = false; - nameOfContainingFile.clear(); - returnTypeNamespaces.clear(); - pointerToConstReturn = false; - nameOfContainingClass.clear(); - } -}; -class FunctionSignaturePolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener{ - public: - ~FunctionSignaturePolicy(){} - FunctionSignaturePolicy(std::initializer_list listeners = {}) : srcDispatch::PolicyDispatcher(listeners){ - currentArgPosition = 1; - parampolicy.AddListener(this); - InitializeEventHandlers(); - } - void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override { - paramdata = policy->Data(); - data.parameters.push_back(*paramdata); - } - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - protected: - std::any DataInner() const override { - return std::make_shared(data); - } - private: - bool seenModifier; - ParamTypePolicy parampolicy; - std::shared_ptr paramdata; - SignatureData data; - size_t currentArgPosition; - std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; - - void InitializeEventHandlers(){ - using namespace srcDispatch; - openEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { - ctx.dispatcher->AddListener(¶mpolicy); - data.lineNumber = ctx.startLineNumber; - }; - closeEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx){ - ctx.dispatcher->RemoveListener(¶mpolicy); - if(ctx.IsOpen(ParserState::classn)){ - data.isMethod = true; - data.nameOfContainingClass = ctx.currentClassName; - } - data.name = ctx.currentFunctionName; - - }; - - openEventMap[ParserState::function] = [this](srcSAXEventContext& ctx) { - data.lineNumber = ctx.startLineNumber; - }; - - openEventMap[ParserState::index] = [this](srcSAXEventContext& ctx) { - if(ctx.IsOpen(ParserState::type) && ctx.Nor({ParserState::functionblock, ParserState::parameterlist, ParserState::declstmt})){ - data.hasArrayReturn = true; - } - }; - - openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::type, ParserState::function}) && ctx.Nor({ParserState::parameterlist, ParserState::functionblock, ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - data.returnTypeNamespaces.push_back(ctx.currentToken); - } - if(ctx.IsOpen(ParserState::function) && ctx.Nor({ParserState::type, ParserState::parameterlist, ParserState::functionblock, ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - data.functionNamespaces.push_back(ctx.currentToken); - } - }; - - openEventMap[ParserState::functionblock] = [this](srcSAXEventContext& ctx) { - NotifyAll(ctx); - seenModifier = false; - data.clear(); - }; - - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) { - if(currentModifier == "*") { - if(ctx.And({ParserState::type, ParserState::function}) && ctx.IsClosed(ParserState::parameterlist)){ - seenModifier = true; - data.hasAliasedReturn = true; - } - } - else if(currentModifier == "&") {} - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::name, ParserState::type, ParserState::function}) && ctx.Nor({ParserState::functionblock, ParserState::parameterlist, ParserState::genericargumentlist, ParserState::index})){ - data.returnType = ctx.currentToken; - } - if(ctx.And({ParserState::modifier, ParserState::type, ParserState::function}) && ctx.Nor({ParserState::parameterlist, ParserState::genericargumentlist})){ - data.returnTypeModifier = ctx.currentToken; - } - if(ctx.And({ParserState::specifier, ParserState::function}) && ctx.Nor({ParserState::parameterlist, ParserState::functionblock, ParserState::genericargumentlist})){ - currentSpecifier = ctx.currentToken; - } - if(ctx.And({ParserState::modifier, ParserState::function}) && ctx.Nor({ParserState::parameterlist, ParserState::functionblock, ParserState::genericargumentlist})){ - currentModifier = ctx.currentToken; - } - }; - - closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { - if(currentSpecifier == "const" && ctx.Nor({ParserState::parameterlist, ParserState::type})){ - data.isConst = true; - } - if(currentSpecifier == "const" && ctx.IsOpen(ParserState::function) && ctx.IsOpen(ParserState::type)){ - if(!seenModifier){ - data.pointerToConstReturn = true; - }else{ - data.constPointerReturn = true; - } - } - if(currentSpecifier == "static" && ctx.Nor({ParserState::parameterlist, ParserState::type})){ - data.isStatic = true; - } - currentSpecifier.clear(); - }; - } - -}; -#endif \ No newline at end of file diff --git a/src/policy_classes/IfPolicySingleEvent.hpp b/src/policy_classes/IfPolicySingleEvent.hpp deleted file mode 100644 index 606c3f8..0000000 --- a/src/policy_classes/IfPolicySingleEvent.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file IfPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_IF_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_IF_POLICY_SINGLE_EVENT_HPP - -#include -#include - -#include -#include -#include - -struct IfData { - - unsigned int startLineNumber; - unsigned int endLineNumber; - - std::shared_ptr condition; - std::shared_ptr block; - - friend std::ostream& operator<<(std::ostream& out, const IfData& ifData) { - if(!ifData.condition) return out; - return out << *ifData.condition; - } -}; - -class IfPolicy : public ConditionalPolicy { -public: - IfPolicy(std::initializer_list listeners) - : ConditionalPolicy(listeners) {} -}; - -#endif diff --git a/src/policy_classes/IfStmtPolicySingleEvent.hpp b/src/policy_classes/IfStmtPolicySingleEvent.hpp deleted file mode 100644 index d5763d2..0000000 --- a/src/policy_classes/IfStmtPolicySingleEvent.hpp +++ /dev/null @@ -1,136 +0,0 @@ -/** - * @file IfStmtPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_IF_STMT_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_IF_STMT_POLICY_SINGLE_EVENT_HPP - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -struct IfStmtData { - - unsigned int startLineNumber; - unsigned int endLineNumber; - - std::vector clauses; - - friend std::ostream& operator<<(std::ostream& out, const IfStmtData& ifStmtData) { - if(ifStmtData.clauses.empty()) return out; - if(ifStmtData.clauses.front().type() != typeid(std::shared_ptr)) return out; - return out << *std::any_cast>(ifStmtData.clauses.front()); - } -}; - -class IfStmtPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - IfStmtData data; - std::size_t ifStmtDepth; - std::unique_ptr ifPolicy; - std::unique_ptr elseIfPolicy; - std::unique_ptr elsePolicy; - -public: - IfStmtPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - ifStmtDepth(0) { - InitializeIfStmtPolicyHandlers(); - } - - ~IfStmtPolicy() {} - -protected: - std::any DataInner() const { return std::make_shared(data); } - - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(IfPolicy) == typeid(*policy)) { - data.clauses.push_back(policy->Data()); - } else if (typeid(ElseIfPolicy) == typeid(*policy)) { - data.clauses.push_back(policy->Data()); - } else if (typeid(ElsePolicy) == typeid(*policy)) { - data.clauses.push_back(policy->Data()); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} //doesn't use other parsers - -private: - void InitializeIfStmtPolicyHandlers() { - using namespace srcDispatch; - - openEventMap[ParserState::ifgroup] = [this](srcSAXEventContext& ctx) { - if (!ifStmtDepth) { - ifStmtDepth = ctx.depth; - data = IfStmtData{}; - data.startLineNumber = ctx.startLineNumber; - data.endLineNumber = ctx.endLineNumber; - CollectIfHandlers(); - CollectElseIfHandlers(); - CollectElseHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::ifgroup] =[this](srcSAXEventContext& ctx) { - if (ifStmtDepth && ifStmtDepth == ctx.depth) { - ifStmtDepth = 0; - NotifyAll(ctx); - InitializeIfStmtPolicyHandlers(); - } - }; - } - - void CollectIfHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx) { - if(!ifStmtDepth) return; - if((ifStmtDepth + 1) != ctx.depth) return; - - if (!ifPolicy) ifPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(ifPolicy.get()); - }; - } - - void CollectElseIfHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::elseif] = [this](srcSAXEventContext& ctx) { - if(!ifStmtDepth) return; - if((ifStmtDepth + 1) != ctx.depth) return; - - if (!elseIfPolicy) elseIfPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(elseIfPolicy.get()); - }; - } - - void CollectElseHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::elsestmt] = [this](srcSAXEventContext& ctx) { - if(!ifStmtDepth) return; - if((ifStmtDepth + 1) != ctx.depth) return; - - if (!elsePolicy) elsePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(elsePolicy.get()); - }; - } -}; - -#endif diff --git a/src/policy_classes/IncrPolicySingleEvent.hpp b/src/policy_classes/IncrPolicySingleEvent.hpp deleted file mode 100644 index b5f74e7..0000000 --- a/src/policy_classes/IncrPolicySingleEvent.hpp +++ /dev/null @@ -1,101 +0,0 @@ -/** - * @file IncrPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_INCR_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_INCR_POLICY_SINGLE_EVENT_HPP - -#include -#include -#include - -#include -#include - -#include -#include -#include - -struct IncrData { - - unsigned int startLineNumber; - std::shared_ptr expr; - - friend std::ostream& operator<<(std::ostream& out, const IncrData& incrData) { - if(!incrData.expr) return out; - return out << *incrData.expr; - } -}; - -class IncrPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - IncrData data; - std::size_t incrDepth; - std::unique_ptr exprPolicy; - -public: - IncrPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - incrDepth(0) { - InitializeIncrPolicyHandlers(); - } - - ~IncrPolicy() {} - -protected: - std::any DataInner() const override { return std::make_shared(data); } - - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(ExpressionPolicy) == typeid(*policy)) { - data.expr = policy->Data(); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeIncrPolicyHandlers() { - using namespace srcDispatch; - - openEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { - if (!incrDepth) { - incrDepth = ctx.depth; - data = IncrData{}; - data.startLineNumber = ctx.startLineNumber; - CollectExpressionHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::incr] =[this](srcSAXEventContext& ctx) { - if (incrDepth && incrDepth == ctx.depth) { - incrDepth = 0; - NotifyAll(ctx); - InitializeIncrPolicyHandlers(); - } - }; - } - - void CollectExpressionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(!incrDepth) return; - if((incrDepth + 1) != ctx.depth) return; - - if (!exprPolicy) exprPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); - }; - } -}; - -#endif diff --git a/src/policy_classes/LiteralPolicySingleEvent.hpp b/src/policy_classes/LiteralPolicySingleEvent.hpp deleted file mode 100644 index 5be27f4..0000000 --- a/src/policy_classes/LiteralPolicySingleEvent.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @file LiteralPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_LITERAL_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_LITERAL_POLICY_SINGLE_EVENT_HPP - -#include -#include -#include - -#include -#include - -struct LiteralData { - - unsigned int startLineNumber; - std::string literal; - - friend std::ostream& operator<<(std::ostream& out, const LiteralData& literalData) { - return out << literalData.literal; - } -}; - -class LiteralPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - LiteralData data; - std::size_t literalDepth; - -public: - LiteralPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - literalDepth(0) { - InitializeLiteralPolicyHandlers(); - } - - ~LiteralPolicy() { - } - -protected: - std::any DataInner() const override { return std::make_shared(data); } - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override {} - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeLiteralPolicyHandlers() { - using namespace srcDispatch; - - openEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { - if (!literalDepth) { - literalDepth = ctx.depth; - data = LiteralData{}; - data.startLineNumber = ctx.startLineNumber; - CollectTokenHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::literal] =[this](srcSAXEventContext& ctx) { - if (literalDepth && literalDepth == ctx.depth) { - literalDepth = 0; - NotifyAll(ctx); - InitializeLiteralPolicyHandlers(); - } - }; - } - - void CollectTokenHandlers() { - using namespace srcDispatch; - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - data.literal += ctx.currentToken; - }; - } -}; - -#endif diff --git a/src/policy_classes/NamePolicySingleEvent.cpp b/src/policy_classes/NamePolicySingleEvent.cpp deleted file mode 100644 index 6c2bd67..0000000 --- a/src/policy_classes/NamePolicySingleEvent.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/** - * @file NamePolicySingleEvent.cpp - * - * MODIFIED from srcDispatch - * This collects the expression in the index - * - */ -#include - - -#include -#include - -std::string NameData::SimpleName() const { - if(!name.empty()) { - return ToString(); - } - - assert(names.back().type() == typeid(std::shared_ptr)); - return std::any_cast>(names.back())->SimpleName(); -} - -std::string NameData::ToString() const { - - std::ostringstream out; - out << *this; - - return out.str(); -} - - -std::ostream& operator<<(std::ostream& out, const NameData& nameData) { - out << nameData.name; - - for(const std::any& name_element : nameData.names) { - if(name_element.type() == typeid(std::shared_ptr)) { - out << *std::any_cast>(name_element); - } else { - out << std::any_cast>(name_element)->op; - } - } - if(nameData.templateArgumentList) { - out << *nameData.templateArgumentList; - } - - if(nameData.indices) { - out << '['; - - bool printComma = false; - for (const std::shared_ptr& index : *nameData.indices) { - - if(printComma) { - out << ", "; - } - - out << *index; - printComma = true; - } - - out << ']'; - } - - return out; -} - -NamePolicy::~NamePolicy() {} - - -void NamePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - - if(typeid(NamePolicy) == typeid(*policy)) { - data.names.push_back(policy->Data()); - } else if(typeid(OperatorPolicy) == typeid(*policy)) { - data.names.push_back(policy->Data()); - } else if(typeid(TemplateArgumentListPolicy) == typeid(*policy)) { - data.templateArgumentList = policy->Data(); - } else if(typeid(ExpressionPolicy) == typeid(*policy)) { - data.indices->push_back(policy->Data()); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); -} - - -void NamePolicy::InitializeNamePolicyHandlers() { - using namespace srcDispatch; - - // start of policy - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if(!nameDepth) { - nameDepth = ctx.depth; - data = NameData{}; - data.lineNumber = ctx.startLineNumber; - CollectOperatorsHandlers(); - CollectTemplateArgumentListHandlers(); - CollectArrayIndicesHandlers(); - } else if((nameDepth + 1) == ctx.depth) { - NopCloseEvents({ParserState::tokenstring}); - if(!namePolicy) namePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(namePolicy.get()); - } - }; - - // end of policy - closeEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if(nameDepth && nameDepth == ctx.depth) { - nameDepth = 0; - NotifyAll(ctx); - InitializeNamePolicyHandlers(); - } - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - if(nameDepth && nameDepth == ctx.depth) { - data.name += ctx.currentToken; - } - }; -} - -void NamePolicy::CollectOperatorsHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { - if(!nameDepth) return; - if((nameDepth + 1) != ctx.depth) return; - - if(!operatorPolicy) operatorPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(operatorPolicy.get()); - }; -} - - -void NamePolicy::CollectTemplateArgumentListHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext& ctx) { - if(!nameDepth) return; - if((nameDepth + 1) != ctx.depth) return; - - if(!templateArgumentListPolicy) templateArgumentListPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(templateArgumentListPolicy.get()); - }; -} - - -void NamePolicy::CollectArrayIndicesHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::index] = [this](srcSAXEventContext& ctx) { - if(!data.indices) { - data.indices = std::vector>(); - } - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(!expressionPolicy) expressionPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(expressionPolicy.get()); - }; - }; -} - diff --git a/src/policy_classes/NamePolicySingleEvent.hpp b/src/policy_classes/NamePolicySingleEvent.hpp deleted file mode 100644 index 6c8385f..0000000 --- a/src/policy_classes/NamePolicySingleEvent.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @file NamePolicySingleEvent.hpp - * - * MODIFIED from srcDispatch - * This collects the expression in the index - * - */ -#ifndef INCLUDED_NAME_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_NAME_POLICY_SINGLE_EVENT_HPP - -#include - -#include -#include - -#include -#include -#include - -class ExpressionPolicy; -struct ExpressionData; - -class TemplateArgumentListPolicy; -struct TemplateArgumentListData; - -struct NameData { - - unsigned int lineNumber; - std::string name; - std::vector names; - std::shared_ptr templateArgumentList; - std::optional>> indices; - - std::string SimpleName() const; - std::string ToString() const; - friend std::ostream& operator<<(std::ostream& out, const NameData& nameData); -}; - - -class NamePolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - NameData data; - std::size_t nameDepth; - std::unique_ptr namePolicy; - std::unique_ptr operatorPolicy; - std::unique_ptr templateArgumentListPolicy; - std::unique_ptr expressionPolicy; - -public: - NamePolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - nameDepth(0) { - InitializeNamePolicyHandlers(); - } - - ~NamePolicy(); - -protected: - - std::any DataInner() const override { return std::make_shared(data); } - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeNamePolicyHandlers(); - void CollectOperatorsHandlers(); - void CollectTemplateArgumentListHandlers(); - void CollectArrayIndicesHandlers(); -}; - -#endif diff --git a/src/policy_classes/OperatorPolicySingleEvent.hpp b/src/policy_classes/OperatorPolicySingleEvent.hpp deleted file mode 100644 index 5be240e..0000000 --- a/src/policy_classes/OperatorPolicySingleEvent.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/** - * @file OperatorPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_OPERATOR_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_OPERATOR_POLICY_SINGLE_EVENT_HPP - -#include -#include -#include - -#include -#include - -struct OperatorData { - - unsigned int startLineNumber; - std::string op; - - friend std::ostream& operator<<(std::ostream& out, const OperatorData& operatorData) { - return out << operatorData.op; - } -}; - -class OperatorPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - OperatorData data; - std::size_t operatorDepth; - -public: - OperatorPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - operatorDepth(0) { - InitializeOperatorPolicyHandlers(); - } - - ~OperatorPolicy() { - } - -protected: - std::any DataInner() const override { return std::make_shared(data); } - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override {} - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeOperatorPolicyHandlers() { - using namespace srcDispatch; - - openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { - if (!operatorDepth) { - operatorDepth = ctx.depth; - data = OperatorData{}; - data.startLineNumber = ctx.startLineNumber; - CollectTokenHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::op] =[this](srcSAXEventContext& ctx) { - if (operatorDepth && operatorDepth == ctx.depth) { - operatorDepth = 0; - NotifyAll(ctx); - InitializeOperatorPolicyHandlers(); - } - }; - } - - void CollectTokenHandlers() { - using namespace srcDispatch; - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - data.op += ctx.currentToken; - }; - } -}; - -#endif diff --git a/src/policy_classes/ParamTypePolicy.hpp b/src/policy_classes/ParamTypePolicy.hpp deleted file mode 100644 index 63862ec..0000000 --- a/src/policy_classes/ParamTypePolicy.hpp +++ /dev/null @@ -1,134 +0,0 @@ -/** - * @file ParamTypePolicy.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef INCLUDED_PARAM_TYPE_POLICY_HPP -#define INCLUDED_PARAM_TYPE_POLICY_HPP - -#include -#include -#include -#include -class ParamTypePolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener{ - public: - ParamTypePolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ - InitializeEventHandlers(); - } - ~ParamTypePolicy(){} - - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - protected: - std::any DataInner() const override { - return std::make_shared(data); - } - private: - DeclData data; - std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; - - void InitializeEventHandlers(){ - using namespace srcDispatch; - openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::type, ParserState::parameter}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - data.namespaces.push_back(ctx.currentToken); - } - }; - - openEventMap[ParserState::index] = [this](srcSAXEventContext& ctx [[maybe_unused]]){ - data.usesSubscript = true; - }; - - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx){ - if(ctx.IsOpen(ParserState::parameter)){ - if(currentModifier == "*"){ - data.isPointer = true; - } - else if(currentModifier == "&"){ - data.isReference = true; - } - } - }; - - closeEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::parameter})){ - data.lineNumber = ctx.startLineNumber; - data.nameOfIdentifier = currentDeclName; - } - }; - - closeEventMap[ParserState::type] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::parameter})){ - data.nameOfType = currentTypeName; - currentTypeName.clear(); - } - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - //TODO: possibly, this if-statement is suppressing more than just unmarked whitespace. Investigate. - if(!(ctx.currentToken.empty() || ctx.currentToken[0] == ' ')){ - - if(ctx.And({ParserState::name, ParserState::type, ParserState::decl, ParserState::parameter}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist, ParserState::index})){ - currentTypeName = ctx.currentToken; // parameter data type - } - if(ctx.And({ParserState::name, ParserState::decl, ParserState::parameter}) && - ctx.Nor({ParserState::type, ParserState::index/*skip array portion*/, ParserState::argumentlist/*skip init list portion*/, - ParserState::init, ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - currentDeclName = ctx.currentToken; // parameter variable name - } - if(ctx.And({ParserState::specifier, ParserState::decl, ParserState::parameter})){ - currentSpecifier = ctx.currentToken; - } - if(ctx.And({ParserState::modifier, ParserState::type, ParserState::parameter})){ - currentModifier = ctx.currentToken; - } - } - }; - closeEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx){ - data.isParameter = true; - data.nameOfContainingFunction = ctx.currentFunctionName; - data.nameOfContainingFile = ctx.currentFilePath; - if (ctx.currentFileLanguage == "Java" && !data.isFinal){ - data.isReference = true; - } - NotifyAll(ctx); - data.clear(); - }; - closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx){ - if(ctx.IsOpen(ParserState::parameter)){ - if(currentSpecifier == "const"){ - if(data.isPointer){ - data.isConstAlias = true; - }else{ - data.isConstValue = true; - } - } - if(currentSpecifier == "final"){ - data.isFinal = true; - } - if(currentSpecifier == "static"){ - data.isStatic = true; - } - } - currentSpecifier.clear(); - }; - - } -}; - -#endif - diff --git a/src/policy_classes/ReturnPolicy.hpp b/src/policy_classes/ReturnPolicy.hpp deleted file mode 100644 index 76a6f84..0000000 --- a/src/policy_classes/ReturnPolicy.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -#include -#include -#include -#ifndef RETURNPOLICY -#define RETURNPOLICY -class ReturnPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { - public: - - ReturnPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ - InitializeEventHandlers(); - } - ~ReturnPolicy(){} - - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} // doesn't use other parsers - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} // doesn't use other parsers - - void ClearCollection() { returnUses.clear(); } - - std::unordered_map>* GetReturnUses() { - return &returnUses; - } - protected: - std::any DataInner() const override {} - - private: - std::unordered_map> returnUses; // variablename | line number - - void InitializeEventHandlers(){ - using namespace srcDispatch; - - closeEventMap[ParserState::name] = [this](srcSAXEventContext &ctx) { - if(ctx.IsOpen({ParserState::returnstmt}) && ctx.IsClosed({ParserState::comment})){ - returnUses[ctx.currentToken].insert(ctx.startLineNumber); - - NotifyAll(ctx); - } - }; - - } -}; -#endif \ No newline at end of file diff --git a/src/policy_classes/ReturnPolicySingleEvent.hpp b/src/policy_classes/ReturnPolicySingleEvent.hpp deleted file mode 100644 index 8a3ddd5..0000000 --- a/src/policy_classes/ReturnPolicySingleEvent.hpp +++ /dev/null @@ -1,88 +0,0 @@ -/** - * @file ReturnPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_RETURN_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_RETURN_POLICY_SINGLE_EVENT_HPP - -#include -#include -#include - -#include - -#include -#include -#include - - -// Collect the expression in the return -// -class ReturnPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - std::shared_ptr data; - std::size_t returnDepth; - std::unique_ptr exprPolicy; - -public: - ReturnPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - returnDepth(0) { - InitializeReturnPolicyHandlers(); - } - - ~ReturnPolicy() {} - -protected: - std::any DataInner() const override { return data; } - - virtual void Notify(const PolicyDispatcher * policy, const srcDispatch::srcSAXEventContext & ctx) override { - if (typeid(ExpressionPolicy) == typeid(*policy)) { - data = policy->Data(); - ctx.dispatcher->RemoveListener(nullptr); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -private: - void InitializeReturnPolicyHandlers() { - using namespace srcDispatch; - // start of policy - openEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { - if (!returnDepth) { - returnDepth = ctx.depth; - data = std::make_shared(); - CollectExpressionHandlers(); - } - }; - - // end of policy - closeEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { - if (returnDepth && returnDepth == ctx.depth) { - returnDepth = 0; - NotifyAll(ctx); - InitializeReturnPolicyHandlers(); - } - }; - } - - void CollectExpressionHandlers() { - using namespace srcDispatch; - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!exprPolicy) exprPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); - }; - } - -}; - -#endif diff --git a/src/policy_classes/SNLPolicy.hpp b/src/policy_classes/SNLPolicy.hpp deleted file mode 100644 index 9d856a4..0000000 --- a/src/policy_classes/SNLPolicy.hpp +++ /dev/null @@ -1,100 +0,0 @@ -/** - * @file SNLPolicy.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include - -#ifndef SOURCENLPOLICY -#define SOURCENLPOLICY -class SourceNLPolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { - public: - struct SourceNLData{ - SourceNLData(){} - void clear(){ - category.clear(); - identifiername.clear(); - } - std::string category; - std::string identifiername; - }; - SourceNLData data; - ~SourceNLPolicy(){} - SourceNLPolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ - InitializeEventHandlers(); - } - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - protected: - void * DataInner() const override { - return new SourceNLData(data); - } - private: - std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; - void InitializeEventHandlers(){ - using namespace srcDispatch; - closeEventMap[ParserState::snoun] = [this](srcSAXEventContext& ctx){ - //std::cerr< -#include -#include -#include -#include -#include - -#ifndef STEREOTYPEPOLICY -#define STEREOTYPEPOLICY -class StereotypePolicy : public srcDispatch::EventListener, public srcDispatch::PolicyDispatcher, public srcDispatch::PolicyListener { - public: - struct StereotypeData{ - StereotypeData() {} - void clear(){stereotypes.clear();} - std::vector stereotypes; - }; - ~StereotypePolicy(){} - StereotypePolicy(std::initializer_list listeners = {}): srcDispatch::PolicyDispatcher(listeners){ - InitializeEventHandlers(); - } - void Notify(const PolicyDispatcher * policy [[maybe_unused]], const srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - void NotifyWrite(const PolicyDispatcher * policy [[maybe_unused]], srcDispatch::srcSAXEventContext & ctx [[maybe_unused]]) override {} //doesn't use other parsers - protected: - void * DataInner() const override { - return new StereotypeData(data); - } - private: - StereotypeData data; - std::string currentStereotype; - void InitializeEventHandlers(){ - using namespace srcDispatch; - closeEventMap[ParserState::stereotype] = [this](srcSAXEventContext& ctx){ - std::string word; - for(char ch : currentStereotype){ - switch(ch){ - //it's a space, so push back stereotype and clear word - case ' ':{ - data.stereotypes.push_back(word); - word.clear(); - break; - } - //it's the end of the string, so push back whatever is in word - case 0:{ - data.stereotypes.push_back(word); - break; - } - //append ch to word and keep going - default:{ - if(std::isalnum(ch)){ - word+=ch; - } - break; - } - } - } - NotifyAll(ctx); - data.clear(); - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - //TODO: possibly, this if-statement is suppressing more than just unmarked whitespace. Investigate. - if(!(ctx.currentToken.empty() || ctx.currentToken == " ")){ - if(ctx.IsOpen(ParserState::stereotype)){ - currentStereotype = ctx.currentToken; - } - } - }; - } -}; -#endif \ No newline at end of file diff --git a/src/policy_classes/SwitchPolicySingleEvent.hpp b/src/policy_classes/SwitchPolicySingleEvent.hpp deleted file mode 100644 index c35b7a4..0000000 --- a/src/policy_classes/SwitchPolicySingleEvent.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/** - * @file SwitchPolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_SWITCH_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_SWITCH_POLICY_SINGLE_EVENT_HPP - -#include -#include - -#include -#include -#include - -struct SwitchData { - - unsigned int startLineNumber; - unsigned int endLineNumber; - - std::shared_ptr condition; - std::shared_ptr block; - - friend std::ostream& operator<<(std::ostream& out, const SwitchData& switchData) { - if(!switchData.condition) return out; - return out << *switchData.condition; - } -}; - -class SwitchPolicy : public ConditionalPolicy { -public: - SwitchPolicy(std::initializer_list listeners) - : ConditionalPolicy(listeners) {} -}; -#endif diff --git a/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp b/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp deleted file mode 100644 index 845e7ad..0000000 --- a/src/policy_classes/TemplateArgumentListPolicySingleEvent.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/** - * @file TemplateArgumentListPolicySingleEvent.cpp - * - */ -#include - -#include - -#include - -std::string TemplateArgumentListData::ToString() const { - std::ostringstream out; - out << *this; - return out.str(); -} - -std::ostream& operator<<(std::ostream& out, const TemplateArgumentListData& argumentData) { - - out << '<'; - for(std::size_t pos = 0; pos < argumentData.arguments.size(); ++pos) { - if (pos != 0) { - out << ", "; - } - - out << *argumentData.arguments.at(pos); - } - out << '>'; - - return out; -} - -TemplateArgumentListPolicy::TemplateArgumentListPolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - argumentListDepth(0) { - InitializeTemplateArgumentListPolicyHandlers(); -} - -TemplateArgumentListPolicy::~TemplateArgumentListPolicy() {} - -void TemplateArgumentListPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(NamePolicy) == typeid(*policy)) { - //data.arguments.push_back(policy->Data()); - } else if (typeid(ExpressionPolicy) == typeid(*policy)) { - data.arguments.push_back(policy->Data()); - } else { - throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); - } - - ctx.dispatcher->RemoveListener(nullptr); -} - -std::any TemplateArgumentListPolicy::DataInner() const { - return std::make_shared(data); -} - -void TemplateArgumentListPolicy::InitializeTemplateArgumentListPolicyHandlers() { - using namespace srcDispatch; - // start of policy - openEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext& ctx) { - if (!argumentListDepth) { - argumentListDepth = ctx.depth; - data = TemplateArgumentListData{}; - data.lineNumber = ctx.startLineNumber; - CollectArgumentHandler(); - } - }; - - // end of policy - closeEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext& ctx) { - if (argumentListDepth && argumentListDepth == ctx.depth) { - argumentListDepth = 0; - NotifyAll(ctx); - InitializeTemplateArgumentListPolicyHandlers(); - } - }; -} - -void TemplateArgumentListPolicy::CollectArgumentHandler() { - using namespace srcDispatch; - - openEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { - if(!argumentListDepth) return; - if((argumentListDepth + 1) != ctx.depth) return; - - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if(!argumentListDepth) return; - if((argumentListDepth + 2) != ctx.depth) return; - - if(!expressionPolicy) expressionPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(expressionPolicy.get()); - }; - - }; - - closeEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { - if(!argumentListDepth) return; - if((argumentListDepth + 1) != ctx.depth) return; - NopOpenEvents({ParserState::expr}); - }; - - - -} diff --git a/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp b/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp deleted file mode 100644 index e7bad96..0000000 --- a/src/policy_classes/TemplateArgumentListPolicySingleEvent.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/** - * @file TemplateArgumentListPolicySingleEvent.hpp - * - */ -#ifndef INCLUDED_TEMPLATE_ARGUMENT_LIST_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_TEMPLATE_ARGUMENT_LIST_POLICY_SINGLE_EVENT_HPP - -#include -#include - -class NamePolicy; - -class ExpressionPolicy; -struct ExpressionData; - - -struct TemplateArgumentListData { - - unsigned int lineNumber; - std::vector> arguments; - - std::string ToString() const; - friend std::ostream& operator<<(std::ostream& out, const TemplateArgumentListData& argumentData); -}; - - -class TemplateArgumentListPolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -public: - TemplateArgumentListPolicy(std::initializer_list listeners); - ~TemplateArgumentListPolicy(); - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -protected: - virtual std::any DataInner() const override; - -private: - void InitializeTemplateArgumentListPolicyHandlers(); - void CollectArgumentHandler(); - -private: - TemplateArgumentListData data; - std::size_t argumentListDepth; - std::unique_ptr expressionPolicy; - -}; - -#endif diff --git a/src/policy_classes/TypePolicySingleEvent.cpp b/src/policy_classes/TypePolicySingleEvent.cpp deleted file mode 100644 index a65f86e..0000000 --- a/src/policy_classes/TypePolicySingleEvent.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/** - * @file TypePolicySingleEvent.cpp - * - */ - -#include - -#include - -std::string TypeData::ToString() const { - std::string type_str; - for (std::size_t pos = 0; pos < types.size(); ++pos) { - if (pos != 0) type_str += ' '; - const std::pair& type = types[pos]; - if (type.second == TypeData::POINTER) { - type_str += '*'; - } else if (type.second == TypeData::REFERENCE) { - type_str += '&'; - } else if (type.second == TypeData::RVALUE) { - type_str += "&&"; - } else if (type.second == TypeData::SPECIFIER) { - type_str += *std::any_cast>(type.first); - } else if (type.second == TypeData::TYPENAME) { - type_str += std::any_cast>(type.first)->ToString(); - } - } - return type_str; -} - -std::ostream& operator<<(std::ostream& out, const TypeData& typeData) { - for(std::size_t pos = 0; pos < typeData.types.size(); ++pos) { - if (pos != 0) out << ' '; - const std::pair& type = typeData.types[pos]; - if (type.second == TypeData::POINTER) { - out << '*'; - } else if (type.second == TypeData::REFERENCE) { - out << '&'; - } else if (type.second == TypeData::RVALUE) { - out << "&&"; - } else if (type.second == TypeData::SPECIFIER) { - out << *std::any_cast>(type.first); - } else if (type.second == TypeData::TYPENAME) { - out << *std::any_cast>(type.first); - } - } - return out; -} - -TypePolicy::TypePolicy(std::initializer_list listeners) - : srcDispatch::PolicyDispatcher(listeners), - data{}, - typeDepth(0) { - - InitializeTypePolicyHandlers(); -} - -TypePolicy::~TypePolicy() {} - -void TypePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - //this causes undefined behavior if types is empty - data.types.back().first = policy->Data(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); -} - -std::any TypePolicy::DataInner() const { - return std::make_shared(data); -} - -void TypePolicy::InitializeTypePolicyHandlers() { - using namespace srcDispatch; - // start of policy - openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - if (!typeDepth) { - typeDepth = ctx.depth; - data = TypeData{}; - data.lineNumber = ctx.startLineNumber; - CollectNamesHandler(); - CollectModifersHandler(); - CollectSpecifiersHandler(); - } - }; - - // end of policy - closeEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - if (typeDepth && typeDepth == ctx.depth) { - typeDepth = 0; - NotifyAll(ctx); - InitializeTypePolicyHandlers(); - } - }; -} - -void TypePolicy::CollectNamesHandler() { - using namespace srcDispatch; - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - if (typeDepth && (typeDepth + 1) == ctx.depth) { - data.types.push_back(std::make_pair(std::shared_ptr(), TypeData::TYPENAME)); - if (!namePolicy) namePolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(namePolicy.get()); - } - }; -} - -void TypePolicy::CollectModifersHandler() { - using namespace srcDispatch; - openEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) { - if (typeDepth && (typeDepth + 1) == ctx.depth) { - data.types.push_back(std::make_pair(nullptr, TypeData::NONE)); - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - if (ctx.currentToken == "*") - data.types.back().second = TypeData::POINTER; - else if (ctx.currentToken == "&") - data.types.back().second = TypeData::REFERENCE; - else if (ctx.currentToken == "&&") - data.types.back().second = TypeData::RVALUE; - }; - } - }; - - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) { - if (typeDepth && (typeDepth + 1) == ctx.depth) { - NopCloseEvents({ParserState::tokenstring}); - } - }; -} - -void TypePolicy::CollectSpecifiersHandler() { - using namespace srcDispatch; - openEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { - if (typeDepth && (typeDepth + 1) == ctx.depth) { - data.types.push_back(std::make_pair(std::make_shared(""), TypeData::SPECIFIER)); - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - (*std::any_cast>(data.types.back().first)) += ctx.currentToken; - }; - } - }; - - closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { - if (typeDepth && (typeDepth + 1) == ctx.depth) { - NopCloseEvents({ParserState::tokenstring}); - } - }; -} diff --git a/src/policy_classes/TypePolicySingleEvent.hpp b/src/policy_classes/TypePolicySingleEvent.hpp deleted file mode 100644 index 98367ee..0000000 --- a/src/policy_classes/TypePolicySingleEvent.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/** - * @file TypePolicySingleEvent.hpp - * - */ -#ifndef INCLUDED_TYPE_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_TYPE_POLICY_SINGLE_EVENT_HPP - -#include - -#include - -#include - -class NamePolicy; - - -struct TypeData { - enum TypeType { TYPENAME, POINTER, REFERENCE, RVALUE, SPECIFIER, NONE }; - - unsigned int lineNumber; - std::vector> types; - std::string ToString() const; - friend std::ostream& operator<<(std::ostream& out, const TypeData& typeData); -}; - - -class TypePolicy : -public srcDispatch::EventListener, -public srcDispatch::PolicyDispatcher, -public srcDispatch::PolicyListener { - -private: - TypeData data; - std::size_t typeDepth; - std::unique_ptr namePolicy; - -public: - TypePolicy(std::initializer_list listeners); - ~TypePolicy(); - virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -protected: - virtual std::any DataInner() const override; - -private: - void InitializeTypePolicyHandlers(); - void CollectNamesHandler(); - void CollectModifersHandler(); - void CollectSpecifiersHandler(); - -}; - -#endif diff --git a/src/policy_classes/UnitPolicySingleEvent.hpp b/src/policy_classes/UnitPolicySingleEvent.hpp deleted file mode 100644 index bb6f7e1..0000000 --- a/src/policy_classes/UnitPolicySingleEvent.hpp +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Policy for srcDispatch - * Listens for both classes and functions - * Calls the ClassPolicySingleEvent for class - * Calls the FunctionPolicySingleEvent for function - * - */ -#ifndef INCLUDED_UNIT_POLICY_HPP -#define INCLUDED_UNIT_POLICY_HPP - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - - -class UnitPolicy : - public srcDispatch::EventListener, - public srcDispatch::PolicyDispatcher, - public srcDispatch::PolicyListener { - -public: - std::unique_ptr declPolicy; - std::unique_ptr functionPolicy; - std::unique_ptr classPolicy; - -public: - UnitPolicy(std::initializer_list listeners) : - srcDispatch::PolicyDispatcher(listeners) { - InitializeUnitPolicyHandlers(); - } - - ~UnitPolicy() {} - - void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - // Assumes at least one lister which should always be one - policyListeners.back()->Notify(policy, ctx); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - } - - void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - -protected: - std::any DataInner() const override { return std::any(); } - -private: - void InitializeUnitPolicyHandlers() { - using namespace srcDispatch; - - // start of policy - std::function startClassPolicy = [this](srcSAXEventContext& ctx) { - if(!classPolicy) classPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(classPolicy.get()); - }; - - openEventMap[ParserState::classn] = startClassPolicy; - openEventMap[ParserState::structn] = startClassPolicy; - - // end of policy - std::function endClassPolicy = [](srcSAXEventContext& ctx) { - }; - - closeEventMap[ParserState::classn] = endClassPolicy; - closeEventMap[ParserState::structn] = endClassPolicy; - - // start function of policy - std::function startFunction = [this](srcSAXEventContext& ctx) { - if(!functionPolicy) functionPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(functionPolicy.get()); - }; - - - openEventMap[ParserState::function] = startFunction; - openEventMap[ParserState::constructor] = startFunction; - openEventMap[ParserState::destructor] = startFunction; - - // end of policy - std::function endFunction = [](srcSAXEventContext& ctx) { - }; - - - closeEventMap[ParserState::function] = endFunction; - closeEventMap[ParserState::constructor] = endFunction; - closeEventMap[ParserState::destructor] = endFunction; - - openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - if(!declPolicy) declPolicy = make_unique_policy({this}); - ctx.dispatcher->AddListenerDispatch(declPolicy.get()); - }; - - closeEventMap[ParserState::declstmt] = [](srcSAXEventContext& ctx) { - }; - - } -}; - -#endif diff --git a/src/policy_classes/WhilePolicySingleEvent.hpp b/src/policy_classes/WhilePolicySingleEvent.hpp deleted file mode 100644 index 080bbd9..0000000 --- a/src/policy_classes/WhilePolicySingleEvent.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * @file WhilePolicySingleEvent.hpp - * - * - */ -#ifndef INCLUDED_WHILE_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_WHILE_POLICY_SINGLE_EVENT_HPP - -#include -#include - -#include -#include -#include - -struct WhileData { - - unsigned int startLineNumber; - unsigned int endLineNumber; - - std::shared_ptr condition; - std::shared_ptr block; - - friend std::ostream& operator<<(std::ostream& out, const WhileData& whileData) { - if(!whileData.condition) return out; - return out << *whileData.condition; - } -}; - -class WhilePolicy : public ConditionalPolicy { -public: - WhilePolicy(std::initializer_list listeners) - : ConditionalPolicy(listeners) {} -}; - -#endif diff --git a/src/policy_classes/dispatcher b/src/policy_classes/dispatcher new file mode 100644 index 0000000..e69de29 diff --git a/src/policy_classes/srcDiffBlockPolicy.cpp b/src/policy_classes/srcDiffBlockPolicy.cpp new file mode 100644 index 0000000..ac3b15d --- /dev/null +++ b/src/policy_classes/srcDiffBlockPolicy.cpp @@ -0,0 +1,362 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffBlockPolicy.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace srcDiffDispatch { + + BlockPolicy::BlockPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeBlockPolicyHandlers(); + } + + BlockPolicy::~BlockPolicy() {} + + std::any BlockPolicy::DataInner() const { return std::make_shared(data); } + + void BlockPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if(typeid(DeclStmtPolicy) == typeid(*policy)) { + data.statements.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(ExprStmtPolicy) == typeid(*policy)) { + data.statements.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(ReturnPolicy) == typeid(*policy)) { + data.statements.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(IfStmtPolicy) == typeid(*policy)) { + data.statements.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(SwitchPolicy) == typeid(*policy)) { + data.statements.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(WhilePolicy) == typeid(*policy)) { + data.statements.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(ForPolicy) == typeid(*policy)) { + data.statements.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(DoPolicy) == typeid(*policy)) { + data.statements.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(TryPolicy) == typeid(*policy)) { + data.statements.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(ThrowPolicy) == typeid(*policy)) { + data.statements.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(GotoPolicy) == typeid(*policy)) { + data.statements.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(ConvertPlexerPolicy) == typeid(*policy)) { + data.statements.push_back(policy->Data()->construct); + } else if(typeid(ClassPolicy) == typeid(*policy)) { + srcDispatch::DiffOperation operation = ctx.diffStack.back().isConvert? srcDispatch::COMMON : ctx.diffStack.back().operation; + data.localClasses.emplace_back(operation, policy->Data()); + } else if(typeid(BlockPolicy) == typeid(*policy)) { + data.blocks.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(CasePolicy) == typeid(*policy)) { + data.cases.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(LabelPolicy) == typeid(*policy)) { + data.labels.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } + + void BlockPolicy::InitializeBlockPolicyHandlers() { + using namespace srcDispatch; + + CollectBlockHandlers(); + CollectDeclstmtHandlers(); + CollectExpressionHandlers(); + CollectReturnHandlers(); + CollectIfStmtHandlers(); + CollectSwitchHandlers(); + CollectWhileHandlers(); + CollectForHandlers(); + CollectDoHandlers(); + CollectTryHandlers(); + CollectThrowHandlers(); + CollectGotoHandlers(); + CollectClassHandlers(); + CollectCaseHandlers(); + CollectLabelHandlers(); + } + + template + bool BlockPolicy::ConvertRegistrationCheck(srcDispatch::srcSAXEventContext& ctx) { + if(!ctx.diffStack.back().isConvert) return false; + + if(!plexer) { + plexer = srcDispatch::make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(plexer.get()); + + return true; + } + + void BlockPolicy::CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) + { + if(!depth) { + depth = ctx.depth; + data = BlockData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + } else { + if(!blockPolicy) + blockPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); + } + }; + + closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeBlockPolicyHandlers(); + }; + } + + void BlockPolicy::CollectDeclstmtHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + if(ConvertRegistrationCheck(ctx)) return; + + if(!declstmtPolicy) { + declstmtPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(declstmtPolicy.get()); + }; + + closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(plexer) { + plexer.reset(); + } + }; + } + + void BlockPolicy::CollectExpressionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + if(ConvertRegistrationCheck(ctx)) return; + + if(!exprStmtPolicy) { + exprStmtPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(exprStmtPolicy.get()); + }; + + closeEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(plexer) { + plexer.reset(); + } + }; + } + + void BlockPolicy::CollectReturnHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + if(ConvertRegistrationCheck(ctx)) return; + + if(!returnPolicy) { + returnPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(returnPolicy.get()); + }; + + closeEventMap[ParserState::returnstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(plexer) { + plexer.reset(); + } + }; + } + + void BlockPolicy::CollectIfStmtHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::ifgroup] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + if(ConvertRegistrationCheck(ctx)) return; + + if(!ifStmtPolicy) { + ifStmtPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(ifStmtPolicy.get()); + }; + + closeEventMap[ParserState::ifgroup] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(plexer) { + plexer.reset(); + } + }; + } + + void BlockPolicy::CollectSwitchHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::switchstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!switchPolicy) { + switchPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(switchPolicy.get()); + }; + } + + void BlockPolicy::CollectWhileHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + if(ConvertRegistrationCheck(ctx)) return; + + if(!whilePolicy) { + whilePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(whilePolicy.get()); + }; + + closeEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(plexer) { + plexer.reset(); + } + }; + } + + void BlockPolicy::CollectForHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + if(ConvertRegistrationCheck(ctx)) return; + + if(!forPolicy) { + forPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(forPolicy.get()); + }; + + closeEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(plexer) { + plexer.reset(); + } + }; + } + + void BlockPolicy::CollectDoHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::dostmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!doPolicy) { + doPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(doPolicy.get()); + }; + } + + void BlockPolicy::CollectTryHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::trystmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!tryPolicy) { + tryPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(tryPolicy.get()); + }; + } + + void BlockPolicy::CollectThrowHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::throwstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!throwPolicy) { + throwPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(throwPolicy.get()); + }; + } + + void BlockPolicy::CollectGotoHandlers() { + using namespace srcDispatch; + std::function startGoto = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!gotoPolicy) { + gotoPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(gotoPolicy.get()); + }; + + openEventMap[ParserState::gotostmt] = startGoto; + openEventMap[ParserState::breakstmt] = startGoto; + openEventMap[ParserState::continuestmt] = startGoto; + } + + void BlockPolicy::CollectClassHandlers() { + using namespace srcDispatch; + std::function startClassPolicy = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if (!classPolicy) { + classPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(classPolicy.get()); + }; + + openEventMap[ParserState::classn] = startClassPolicy; + openEventMap[ParserState::structn] = startClassPolicy; + } + + void BlockPolicy::CollectCaseHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::switchcase] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!casePolicy) { + casePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(casePolicy.get()); + }; + } + + void BlockPolicy::CollectLabelHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::label] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!labelPolicy) { + labelPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(labelPolicy.get()); + }; + } + +} diff --git a/src/policy_classes/srcDiffBlockPolicy.hpp b/src/policy_classes/srcDiffBlockPolicy.hpp new file mode 100644 index 0000000..74e5a72 --- /dev/null +++ b/src/policy_classes/srcDiffBlockPolicy.hpp @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffBlockPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_BLOCK_POLICY_HPP +#define INCLUDED_SRCDIFF_BLOCK_POLICY_HPP + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace srcDiffDispatch { + + class IfStmtPolicy; + class SwitchPolicy; + class WhilePolicy; + class ForPolicy; + class DoPolicy; + class TryPolicy; + + class ClassPolicy; + struct ClassData; + + class ConvertPlexerPolicy; + + struct BlockData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::vector> statements; + std::vector>> localClasses; + std::vector>> labels; + std::vector>> cases; + std::vector>> blocks; + + }; + + class BlockPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + BlockData data; + + std::unique_ptr blockPolicy; + + std::unique_ptr declstmtPolicy; + std::unique_ptr exprStmtPolicy; + std::unique_ptr returnPolicy; + + std::unique_ptr gotoPolicy; + std::unique_ptr labelPolicy; + std::unique_ptr throwPolicy; + + std::unique_ptr ifStmtPolicy; + + std::unique_ptr forPolicy; + std::unique_ptr whilePolicy; + std::unique_ptr doPolicy; + + std::unique_ptr tryPolicy; + + std::unique_ptr switchPolicy; + std::unique_ptr casePolicy; + + std::unique_ptr classPolicy; + + std::unique_ptr plexer; + + public: + BlockPolicy(std::initializer_list listeners); + + ~BlockPolicy(); + + protected: + std::any DataInner() const override; + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeBlockPolicyHandlers(); + + void CollectBlockHandlers(); + void CollectDeclstmtHandlers(); + void CollectExpressionHandlers(); + void CollectReturnHandlers(); + void CollectIfStmtHandlers(); + void CollectSwitchHandlers(); + void CollectWhileHandlers(); + void CollectForHandlers(); + void CollectDoHandlers(); + void CollectTryHandlers(); + void CollectThrowHandlers(); + void CollectGotoHandlers(); + void CollectClassHandlers(); + void CollectCaseHandlers(); + void CollectLabelHandlers(); + + template + bool ConvertRegistrationCheck(srcDispatch::srcSAXEventContext& ctx); + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffCallPolicy.cpp b/src/policy_classes/srcDiffCallPolicy.cpp new file mode 100644 index 0000000..9ce66cd --- /dev/null +++ b/src/policy_classes/srcDiffCallPolicy.cpp @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffCallPolicy.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#include +#include + +namespace srcDiffDispatch { + + std::string CallData::ToString(srcDispatch::DiffOperation operation) const { + + std::string str = name.ToString(operation); + + if(name.IsOfOperation(operation)) { + str += '('; + } + + bool printComma = false; + for (const DeltaElement>& arg : arguments) { + + bool outputRaw = arg.IsOfOperation(operation); + if(outputRaw) { + if(printComma) { + str += ", "; + } + printComma = true; + } + str += arg.ToString(operation); + + } + + if(name.IsOfOperation(operation)) { + str += ')'; + } + + return str; + } + + std::shared_ptr CallData::copyAs(srcDispatch::DiffOperation operation) const { + std::shared_ptr data = std::make_shared(); + data->lineNumber = lineNumber; + + data->name = name.GetElement()->copyAs(operation); + + for (const DeltaElement>& argument : arguments) { + data->arguments.emplace_back(DeltaElement(operation, argument.GetElement()->copyAs(operation))); + } + + return data; + } + + CallPolicy::~CallPolicy() {} + + std::any CallPolicy::DataInner() const { return std::make_shared(data); } + + void CallPolicy::Notify(const srcDispatch::PolicyDispatcher *policy, const srcDispatch::srcSAXEventContext& ctx) { + using namespace srcDispatch; + if(typeid(NamePolicy) == typeid(*policy)) { + data.name = DeltaElement(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(ExpressionPolicy) == typeid(*policy)) { + data.arguments.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else { + throw PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void CallPolicy::InitializeCallPolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = CallData{}; + data.lineNumber = ctx.startLineNumber; + CollectNameHandlers(); + CollectCallArgumentHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeCallPolicyHandlers(); + }; + } + + void CallPolicy::CollectNameHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!namePolicy) { + namePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); + }; + } + + void CallPolicy::CollectCallArgumentHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!expressionPolicy) { + expressionPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(expressionPolicy.get()); + }; + } + +} diff --git a/src/policy_classes/srcDiffCallPolicy.hpp b/src/policy_classes/srcDiffCallPolicy.hpp new file mode 100644 index 0000000..e41405c --- /dev/null +++ b/src/policy_classes/srcDiffCallPolicy.hpp @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffCallPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_CALL_POLICY_HPP +#define INCLUDED_SRCDIFF_CALL_POLICY_HPP + +#include +#include +#include +#include + +#include +#include +#include + +// +// Collects information +// foo(x) +// obj.foo(x) +// +// Gets the name and list of arguments +// + +namespace srcDiffDispatch { + + struct ExpressionData; + class ExpressionPolicy; + + struct NameData; + class NamePolicy; + + struct CallData { + + unsigned int lineNumber; + DeltaElement> name; + std::vector>> arguments; // expressions + + std::shared_ptr copyAs(srcDispatch::DiffOperation operation) const; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const; + }; + + class CallPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + CallData data; + + std::unique_ptr namePolicy; + std::unique_ptr expressionPolicy; + + public: + CallPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeCallPolicyHandlers(); + } + + ~CallPolicy(); + + protected: + std::any DataInner() const override; + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeCallPolicyHandlers(); + void CollectNameHandlers(); + void CollectCallArgumentHandlers(); + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffCasePolicy.hpp b/src/policy_classes/srcDiffCasePolicy.hpp new file mode 100644 index 0000000..30acc6c --- /dev/null +++ b/src/policy_classes/srcDiffCasePolicy.hpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffCasePolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_CASE_POLICY_HPP +#define INCLUDED_SRCDIFF_CASE_POLICY_HPP + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct CaseData { + DeltaElement> expr; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return expr.ToString(operation); + } + }; + + // Collect the expression in the return + class CasePolicy : public ExprTypePolicy { + public: + CasePolicy(std::initializer_list listeners) + : ExprTypePolicy(listeners) { + } + + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffCatchPolicy.hpp b/src/policy_classes/srcDiffCatchPolicy.hpp new file mode 100644 index 0000000..ef5deda --- /dev/null +++ b/src/policy_classes/srcDiffCatchPolicy.hpp @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffCatchPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_CATCH_POLICY_HPP +#define INCLUDED_SRCDIFF_CATCH_POLICY_HPP + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct CatchData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::vector>> parameters; + DeltaElement> block; + }; + + class CatchPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + CatchData data; + + std::unique_ptr declPolicy; + std::unique_ptr blockPolicy; + + public: + CatchPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeCatchPolicyHandlers(); + } + + ~CatchPolicy() {} + + protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if(typeid(DeclPolicy) == typeid(*policy)) { + data.parameters.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(BlockPolicy) == typeid(*policy)) { + data.block.Update(ctx.diffStack.back().operation, policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} // doesn't use other parsers + + private: + void InitializeCatchPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::catchstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = CatchData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectParametersHandlers(); + CollectBlockHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::catchstmt] = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeCatchPolicyHandlers(); + }; + } + + void CollectParametersHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { + if(!declPolicy) { + declPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(declPolicy.get()); + }; + }; + + closeEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + NopOpenEvents({ParserState::parameter}); + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!blockPolicy) { + blockPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); + }; + } + + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffClassPolicy.cpp b/src/policy_classes/srcDiffClassPolicy.cpp new file mode 100644 index 0000000..642b07c --- /dev/null +++ b/src/policy_classes/srcDiffClassPolicy.cpp @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffBlockPolicy.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#include + +namespace srcDiffDispatch { + +const std::unordered_map ClassPolicy::stateToTypeMapper = { + {srcDispatch::ParserState::classn, ClassData::CLASS}, + {srcDispatch::ParserState::structn, ClassData::STRUCT}, +}; + +} diff --git a/src/policy_classes/srcDiffClassPolicy.hpp b/src/policy_classes/srcDiffClassPolicy.hpp new file mode 100644 index 0000000..10e7017 --- /dev/null +++ b/src/policy_classes/srcDiffClassPolicy.hpp @@ -0,0 +1,345 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffClassPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_CLASS_POLICY_HPP +#define INCLUDED_SRCDIFF_CLASS_POLICY_HPP + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace srcDiffDispatch { + + struct ParentData; + + struct ClassData { + enum ClassType : std::size_t { CLASS, STRUCT }; + + std::vector namespaces; + + unsigned int lineNumber; + + std::string language; + std::string filename; + + /*** @todo implement */ + std::set stereotypes; + + std::vector>> generics; + DeltaElement type; + DeltaElement> name; + std::vector>> parents; + + std::vector>> fields; + std::vector>> constructors; + DeltaElement> destructor; + + std::vector>> operators; + std::vector>> methods; + std::vector>> innerClasses; + + DeltaElement isAbstract; + }; + + struct ParentData { + DeltaElement> name; + DeltaElement isVirtual; + DeltaElement accessSpecifier; + }; + + class ClassPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + ClassData data; + + DeltaElement currentRegion; + + std::unique_ptr genericPolicy; + std::unique_ptr namePolicy; + std::unique_ptr declStmtPolicy; + std::unique_ptr functionPolicy; + std::unique_ptr classPolicy; + + static const std::unordered_map stateToTypeMapper; + + public: + ClassPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{}, currentRegion() { + InitializeClassPolicyHandlers(); + } + + ~ClassPolicy() {} + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + if(typeid(GenericPolicy) == typeid(*policy)) { + data.generics.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(NamePolicy) == typeid(*policy)) { + if(ctx.And({srcDispatch::ParserState::super})) { + data.parents.back()->name.Update(ctx.diffStack.back().operation, policy->Data()); + } else { + data.name = DeltaElement(ctx.diffStack.back().operation, policy->Data()); + } + } else if(typeid(DeclStmtPolicy) == typeid(*policy)) { + data.fields.emplace_back(ctx.diffStack.back().operation, policy->Data()); + if(currentRegion) { + for (DeltaElement>& decl : data.fields.back()->decls) { + decl->accessSpecifier = currentRegion; + } + } + } else if(typeid(FunctionPolicy) == typeid(*policy)) { + + std::shared_ptr f_data = policy->Data(); + FunctionData::FunctionType f_type = f_data->type.GetElement(); + if(currentRegion) { + f_data->accessSpecifier = currentRegion; + } + if(f_data->isPureVirtual) { + data.isAbstract.Update(ctx.diffStack.back().operation, true); + } + + if(f_type == FunctionData::CONSTRUCTOR) { + data.constructors.emplace_back(ctx.diffStack.back().operation, f_data); + } else if(f_type == FunctionData::DESTRUCTOR) { + data.destructor.Update(ctx.diffStack.back().operation, f_data); + } else if(f_type == FunctionData::OPERATOR) { + data.operators.emplace_back(ctx.diffStack.back().operation, f_data); + } else { + data.methods.emplace_back(ctx.diffStack.back().operation, f_data); + } + } else if(typeid(ClassPolicy) == typeid(*policy)) { + srcDispatch::DiffOperation operation = ctx.diffStack.back().isConvert? srcDispatch::COMMON : ctx.diffStack.back().operation; + data.innerClasses.emplace_back(operation, policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + private: + void InitializeClassPolicyHandlers() { + using namespace srcDispatch; + // start of policy + std::function startPolicy = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = ClassData{}; + data.namespaces = ctx.currentNamespaces; + data.lineNumber = ctx.startLineNumber; + std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); + if(stereotype_attr_itr != ctx.attributes.end()) { + std::istringstream stereostring(stereotype_attr_itr->second); + data.stereotypes = std::set(std::istream_iterator(stereostring), std::istream_iterator()); + } + + data.type = DeltaElement(ctx.diffStack.back().operation, stateToTypeMapper.at(ctx.dispatcher->CurrentPState())); + data.name = DeltaElement>(); + data.language = ctx.currentFileLanguage; + data.filename = ctx.currentFilePath; + CollectGenericHandlers(); + CollectNameHandlers(); + CollectSuperHanders(); + CollectBlockHanders(); + } else { + + if(ctx.diffStack.back().isConvert && ctx.diffStack.back().operation == srcDispatch::INSERT) { + data.type.Update(ctx.diffStack.back().operation, stateToTypeMapper.at(ctx.dispatcher->CurrentPState())); + } else { + + if(!classPolicy) { + classPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(classPolicy.get()); + } + } + }; + + // end of policy + std::function endPolicy = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeClassPolicyHandlers(); + }; + openEventMap[ParserState::classn] = startPolicy; + closeEventMap[ParserState::classn] = endPolicy; + + openEventMap[ParserState::structn] = startPolicy; + closeEventMap[ParserState::structn] = endPolicy; + } + + void CollectGenericHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::templates] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!genericPolicy) { + genericPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(genericPolicy.get()); + }; + } + + void CollectNameHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!namePolicy) { + namePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); + }; + closeEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + NopOpenEvents({ParserState::name}); + NopCloseEvents({ParserState::name}); + }; + } + + void CollectSuperHanders() { + using namespace srcDispatch; + openEventMap[ParserState::super_list] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + openEventMap[ParserState::super] = [this](srcSAXEventContext& ctx) { + data.parents.emplace_back(ctx.diffStack.back().operation, + std::make_shared( + ParentData{DeltaElement>(), DeltaElement(), DeltaElement()} + ) + ); + + openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { + if(!namePolicy) { + namePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); + }; + + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { + if(ctx.And({ParserState::specifier})) { + if(ctx.currentToken == "virtual") { + data.parents.back()->isVirtual.Update(ctx.diffStack.back().operation, true); + } else if(ctx.currentToken == "public") { + data.parents.back()->accessSpecifier.Update(ctx.diffStack.back().operation, PUBLIC); + } else if(ctx.currentToken == "private") { + data.parents.back()->accessSpecifier.Update(ctx.diffStack.back().operation, PRIVATE); + } else if(ctx.currentToken == "protected") { + data.parents.back()->accessSpecifier.Update(ctx.diffStack.back().operation, PROTECTED); + } + } + }; + }; + closeEventMap[ParserState::super] = [this](srcSAXEventContext& ctx) { + NopCloseEvents({ParserState::tokenstring}); + }; + }; + + closeEventMap[ParserState::super_list] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + NopOpenEvents({ParserState::super}); + }; + } + + void CollectBlockHanders() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + NopOpenEvents({ParserState::name, ParserState::super_list, ParserState::super}); + NopCloseEvents({ParserState::name, ParserState::super_list, ParserState::tokenstring}); + + openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { + if(!declStmtPolicy) { + declStmtPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(declStmtPolicy.get()); + }; + + std::function functionEvent = [this](srcSAXEventContext& ctx) { + if(!functionPolicy) { + functionPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(functionPolicy.get()); + }; + + openEventMap[ParserState::function] = functionEvent; + openEventMap[ParserState::functiondecl] = functionEvent; + openEventMap[ParserState::constructor] = functionEvent; + openEventMap[ParserState::constructordecl] = functionEvent; + openEventMap[ParserState::destructor] = functionEvent; + openEventMap[ParserState::destructordecl] = functionEvent; + }; + + openEventMap[ParserState::publicaccess] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(ctx.diffStack.back().isConvert) { + currentRegion.Update(ctx.diffStack.back().operation, PUBLIC); + } else { + currentRegion = DeltaElement(ctx.diffStack.back().operation, PUBLIC); + } + }; + + openEventMap[ParserState::protectedaccess] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(ctx.diffStack.back().isConvert) { + currentRegion.Update(ctx.diffStack.back().operation, PROTECTED); + } else { + currentRegion = DeltaElement(ctx.diffStack.back().operation, PROTECTED); + } + }; + + openEventMap[ParserState::privateaccess] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(ctx.diffStack.back().isConvert) { + currentRegion.Update(ctx.diffStack.back().operation, PRIVATE); + } else { + currentRegion = DeltaElement(ctx.diffStack.back().operation, PRIVATE); + } + }; + + closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + NopOpenEvents({ParserState::block, ParserState::function, ParserState::functiondecl, + ParserState::constructor, ParserState::constructordecl, ParserState::destructor, ParserState::destructordecl, + ParserState::declstmt, + ParserState::publicaccess, ParserState::protectedaccess, ParserState::privateaccess}); + NopCloseEvents({ParserState::block}); + }; + } + }; +} + +#endif diff --git a/src/policy_classes/srcDiffConditionPolicy.hpp b/src/policy_classes/srcDiffConditionPolicy.hpp new file mode 100644 index 0000000..19fcfee --- /dev/null +++ b/src/policy_classes/srcDiffConditionPolicy.hpp @@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffConditionPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_CONDITION_POLICY_HPP +#define INCLUDED_SRCDIFF_CONDITION_POLICY_HPP + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct ConditionData { + std::vector> conditions; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + if(conditions.empty()) return ""; + + std::string str; + bool printComma = false; + for (const DeltaElement& condition : conditions) { + + bool outputRaw = condition.IsOfOperation(operation); + if(outputRaw) { + if (printComma) { + str += ", "; + } + printComma = true; + } + + if (condition.GetElement().type() == typeid(std::shared_ptr)) { + str += condition.ToString>(operation); + } else { + str += condition.ToString>(operation); + } + } + + return str; + } + }; + + // Collect the expression in the return + // + class ConditionPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + ConditionData data; + + std::unique_ptr exprPolicy; + std::unique_ptr declPolicy; + + public: + ConditionPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeConditionPolicyHandlers(); + } + + ~ConditionPolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + if (typeid(ExpressionPolicy) == typeid(*policy)) { + if(data.conditions.size() && ctx.diffStack.back().isReplace && data.conditions.back().GetElement().type() == typeid(std::shared_ptr)) { + data.conditions.back().Update(ctx.diffStack.back().operation, policy->Data()); + } else { + data.conditions.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } + } else if (typeid(DeclPolicy) == typeid(*policy)) { + // not sure how safe GetElement is here + std::shared_ptr decl = policy->Data(); + if (data.conditions.size() && decl->type->types.empty() + && data.conditions.back().GetElement().type() == typeid(std::shared_ptr)) { + decl->type = std::any_cast>(data.conditions.back().GetElement())->type; + decl->isStatic = std::any_cast>(data.conditions.back().GetElement())->isStatic; + } + srcDispatch::DiffOperation operation = ctx.diffStack.back().operation; + data.conditions.emplace_back(operation, decl); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeConditionPolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if (!depth) { + depth = ctx.depth; + data = ConditionData{}; + CollectExpressionHandlers(); + CollectDeclPolicyHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if (!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeConditionPolicyHandlers(); + }; + } + + void CollectExpressionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if (!depth) return; + + if (!exprPolicy) { + exprPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); + }; + } + + void CollectDeclPolicyHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { + if (!depth) return; + + if (!declPolicy) { + declPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(declPolicy.get()); + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffConditionalPolicy.hpp b/src/policy_classes/srcDiffConditionalPolicy.hpp new file mode 100644 index 0000000..365c6b1 --- /dev/null +++ b/src/policy_classes/srcDiffConditionalPolicy.hpp @@ -0,0 +1,115 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffConditionalPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_CONDITIONAL_POLICY_HPP +#define INCLUDED_SRCDIFF_CONDITIONAL_POLICY_HPP + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + template + class ConditionalPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + protected: + ConditionalData data; + + std::unique_ptr conditionPolicy; + std::unique_ptr blockPolicy; + + public: + ConditionalPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeConditionalPolicyHandlers(); + } + + ~ConditionalPolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + if (typeid(ConditionPolicy) == typeid(*policy)) { + data.condition = DeltaElement(ctx.diffStack.back().operation, policy->Data()); + } else if (typeid(BlockPolicy) == typeid(*policy)) { + data.block = DeltaElement(ctx.diffStack.back().operation, policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + void InitializeConditionalPolicyHandlers() { + + using namespace srcDispatch; + + openEventMap[DispatchEvent] = [this](srcSAXEventContext& ctx) { + if (!depth) { + depth = ctx.depth; + data = ConditionalData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectConditionHandlers(); + CollectBlockHandlers(); + } + }; + + // end of policy + closeEventMap[DispatchEvent] = [this](srcSAXEventContext& ctx) { + if (!depth || depth != ctx.depth) return ; + + depth = 0; + NotifyAll(ctx); + InitializeConditionalPolicyHandlers(); + }; + } + + void CollectConditionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if (!conditionPolicy) { + conditionPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(conditionPolicy.get()); + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if (!blockPolicy) { + blockPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffControlPolicy.hpp b/src/policy_classes/srcDiffControlPolicy.hpp new file mode 100644 index 0000000..b6a5dd5 --- /dev/null +++ b/src/policy_classes/srcDiffControlPolicy.hpp @@ -0,0 +1,166 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffControlPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_CONTROL_POLICY_HPP +#define INCLUDED_SRCDIFF_CONTROL_POLICY_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct ControlData { + + unsigned int lineNumber; + + DeltaElement> init; + DeltaElement> condition; + DeltaElement> incr; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + + std::string str = init.ToString(operation); + + if (condition) { + if(condition.IsOfOperation(operation)) { + str += "; "; + } + + str += condition.ToString(operation); + if(condition.IsOfOperation(operation)) { + str += "; "; + } + } + + str += incr.ToString(operation); + + return str; + } + }; + + // Collect the expression in the return + // + class ControlPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + ControlData data; + + std::unique_ptr declPolicy; + std::unique_ptr initPolicy; + std::unique_ptr conditionPolicy; + std::unique_ptr incrPolicy; + + public: + ControlPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeControlPolicyHandlers(); + } + + ~ControlPolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + using namespace srcDispatch; + if (typeid(InitPolicy) == typeid(*policy)) { + data.init.Update(ctx.diffStack.back().operation, policy->Data()); + } else if (typeid(ConditionPolicy) == typeid(*policy)) { + data.condition = DeltaElement(ctx.diffStack.back().operation, policy->Data()); + } else if (typeid(IncrPolicy) == typeid(*policy)) { + data.incr.Update(ctx.diffStack.back().operation, policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeControlPolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { + if (!depth) { + depth = ctx.depth; + data = ControlData{}; + CollectInitHandlers(); + CollectConditionHandlers(); + CollectIncrHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { + if (!depth || depth != ctx.depth) + + depth = 0; + NotifyAll(ctx); + InitializeControlPolicyHandlers(); + }; + } + + void CollectInitHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { + if (!depth) return; + + if (!initPolicy) { + initPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(initPolicy.get()); + }; + } + + void CollectConditionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { + if (!depth) return; + + if (!conditionPolicy) { + conditionPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(conditionPolicy.get()); + }; + } + + void CollectIncrHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { + if (!depth) return; + + if (!incrPolicy) { + incrPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(incrPolicy.get()); + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffDeclPolicy.hpp b/src/policy_classes/srcDiffDeclPolicy.hpp new file mode 100644 index 0000000..b52868b --- /dev/null +++ b/src/policy_classes/srcDiffDeclPolicy.hpp @@ -0,0 +1,312 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffDeclPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_DECL_POLICY_HPP +#define INCLUDED_SRCDIFF_DECL_POLICY_HPP + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +namespace srcDiffDispatch { + + struct DeclData { + + unsigned int lineNumber; + + std::vector>> generics; + DeltaElement accessSpecifier; + DeltaElement> type; + DeltaElement> name; + DeltaElement> init; + std::vector>> arguments; + DeltaElement> range; + + DeltaElement isStatic; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + + std::string str; + if(type) { + str += type.ToString(operation); + } + + if(name) { + if(name.IsOfOperation(operation)) { + str += ' '; + } + str += name.ToString(operation); + } + + if(init) { + if(init.IsOfOperation(operation)) { + str += " = "; + } + str += init.ToString(operation); + } + + if(!arguments.empty()) { + + bool isArgument = false; + for(const DeltaElement>& argument : arguments) { + + bool outputRaw = argument.IsOfOperation(operation); + if(outputRaw) { + if(!isArgument) { + str += '('; + } else { + str += ", "; + } + isArgument = true; + } + str += argument.ToString(operation); + } + + if(isArgument) { + str += ')'; + } + } + + if(range) { + if(range.IsOfOperation(operation)) { + str += " : "; + } + str += range.ToString(operation); + } + + return str; + } + }; + + class DeclPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + DeclData data; + + std::unique_ptr genericPolicy; + std::unique_ptr typePolicy; + std::unique_ptr namePolicy; + std::unique_ptr exprPolicy; + + public: + DeclPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeDeclPolicyHandlers(); + } + + ~DeclPolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + using namespace srcDispatch; + if(typeid(GenericPolicy) == typeid(*policy)) { + data.generics.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(TypePolicy) == typeid(*policy)) { + data.type = DeltaElement(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(NamePolicy) == typeid(*policy)) { + data.name = DeltaElement(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(ExpressionPolicy) == typeid(*policy)) { + if(ctx.IsOpen(ParserState::range)) { + data.range.Update(ctx.diffStack.back().operation, policy->Data()); + } else if(ctx.IsOpen(ParserState::init)) { + data.init.Update(ctx.diffStack.back().operation, policy->Data()); + } else if(ctx.IsOpen(ParserState::argumentlist)) { + data.arguments.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else { + throw std::string("Unhandled ExpressionPolicy condition"); + } + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeDeclPolicyHandlers() { + using namespace srcDispatch; + + // start of policy + std::function startDecl = [this](srcSAXEventContext &ctx) { + if(depth) { + return; + } + + depth = ctx.depth; + data = DeclData{}; + data.lineNumber = ctx.startLineNumber; + + CollectGenericHandlers(); + CollectSpecifiersHandlers(); + CollectTypeHandlers(); + CollectNameHandlers(); + CollectInitHandlers(); + CollectArgumentList(); + CollectRangeHandlers(); + }; + + openEventMap[ParserState::decl] = startDecl; + // For generic template parameter + openEventMap[ParserState::parameter] = startDecl; + + // close policy + std::function endDecl = [this](srcSAXEventContext &ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + data = DeclData{}; + InitializeDeclPolicyHandlers(); + }; + + closeEventMap[ParserState::decl] = endDecl; + closeEventMap[ParserState::parameter] = endDecl; + + } + + void CollectGenericHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::templates] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!genericPolicy) { + genericPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(genericPolicy.get()); + }; + } + + void CollectSpecifiersHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::specifier] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext &ctx) { + if(ctx.currentToken == "static") { + data.isStatic.Update(ctx.diffStack.back().operation, true); + } + }; + }; + + closeEventMap[ParserState::specifier] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + NopCloseEvents({ParserState::tokenstring}); + }; + } + + void CollectTypeHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::type] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + if(!typePolicy) { + typePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(typePolicy.get()); + }; + } + + void CollectNameHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::name] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + if(!namePolicy) { + namePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); + }; + } + + void CollectInitHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::init] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + openEventMap[ParserState::expr] = [this](srcSAXEventContext &ctx) { + if(!exprPolicy) { + exprPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); + }; + }; + + closeEventMap[ParserState::init] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + NopOpenEvents({ParserState::expr}); + }; + + } + + void CollectArgumentList() { + using namespace srcDispatch; + openEventMap[ParserState::argumentlist] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + openEventMap[ParserState::argument] = [this](srcSAXEventContext &ctx) { + if(!exprPolicy) { + exprPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); + }; + + closeEventMap[ParserState::argument] = [this](srcSAXEventContext &ctx) { + NopOpenEvents({ParserState::expr}); + }; + + }; + + closeEventMap[ParserState::argumentlist] = [this](srcSAXEventContext &ctx) { + NopOpenEvents({ParserState::argument}); + }; + } + + void CollectRangeHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::range] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + openEventMap[ParserState::expr] = [this](srcSAXEventContext &ctx) { + if(!exprPolicy) { + exprPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); + }; + }; + + closeEventMap[ParserState::range] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + NopOpenEvents({ParserState::expr}); + }; + } + }; +} + +#endif diff --git a/src/policy_classes/srcDiffDeclStmtPolicy.hpp b/src/policy_classes/srcDiffDeclStmtPolicy.hpp new file mode 100644 index 0000000..83ff9c9 --- /dev/null +++ b/src/policy_classes/srcDiffDeclStmtPolicy.hpp @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffDeclStmtPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_DECL_TYPE_POLICY_HPP +#define INCLUDED_SRCDIFF_DECL_TYPE_POLICY_HPP + +#include +#include +#include + +#include +#include + +namespace srcDiffDispatch { + + struct DeclStmtData { + + unsigned int lineNumber; + + std::vector>> decls; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + std::string str; + for(const DeltaElement>& decl : decls) { + str += decl.ToString(operation); + } + return str; + } + }; + + class DeclStmtPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + DeclStmtData data; + + std::unique_ptr declPolicy; + + public: + DeclStmtPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeDeclStmtPolicyHandlers(); + } + + ~DeclStmtPolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + if (typeid(DeclPolicy) == typeid(*policy)) { + // not sure how safe GetElement is here + srcDispatch::DiffOperation operation = ctx.diffStack.back().operation; + DeltaElement> decl(operation, policy->Data()); + if (data.decls.size() && decl.GetElement()->type->types.empty()) { + decl.GetElement()->type = data.decls.back().GetElement()->type; + decl.GetElement()->isStatic = data.decls.back().GetElement()->isStatic; + } + data.decls.push_back(decl); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeDeclStmtPolicyHandlers() { + using namespace srcDispatch; + + // start of policy + openEventMap[ParserState::declstmt] = [this](srcSAXEventContext &ctx) { + if (!depth) { + depth = ctx.depth; + data = DeclStmtData{}; + CollectDeclHandlers(ctx); + } + }; + + // end of policy + closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext &ctx) { + if (!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + data = DeclStmtData{}; + InitializeDeclStmtPolicyHandlers(); + }; + } + + void CollectDeclHandlers(srcDispatch::srcSAXEventContext& ctx) { + using namespace srcDispatch; + + openEventMap[ParserState::decl] = [this](srcSAXEventContext &ctx) { + if (!depth) return; + + if (!declPolicy) { + declPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(declPolicy.get()); + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffDoPolicy.hpp b/src/policy_classes/srcDiffDoPolicy.hpp new file mode 100644 index 0000000..5b1ab66 --- /dev/null +++ b/src/policy_classes/srcDiffDoPolicy.hpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffDoPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_DO_POLICY_HPP +#define INCLUDED_SRCDIFF_DO_POLICY_HPP + +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct DoData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + DeltaElement> condition; + DeltaElement> block; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return condition.ToString(operation); + } + }; + + class DoPolicy : public ConditionalPolicy { + public: + DoPolicy(std::initializer_list listeners) + : ConditionalPolicy(listeners) {} + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffElseIfPolicy.hpp b/src/policy_classes/srcDiffElseIfPolicy.hpp new file mode 100644 index 0000000..7cc5711 --- /dev/null +++ b/src/policy_classes/srcDiffElseIfPolicy.hpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffElseIfPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_ELSEIF_POLICY_HPP +#define INCLUDED_SRCDIFF_ELSEIF_POLICY_HPP + +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct ElseIfData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + DeltaElement> condition; + DeltaElement> block; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return condition.ToString(operation); + } + }; + + class ElseIfPolicy : public ConditionalPolicy { + public: + ElseIfPolicy(std::initializer_list listeners) + : ConditionalPolicy(listeners) {} + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffElsePolicy.hpp b/src/policy_classes/srcDiffElsePolicy.hpp new file mode 100644 index 0000000..100c57d --- /dev/null +++ b/src/policy_classes/srcDiffElsePolicy.hpp @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffElsePolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_ELSE_POLICY_HPP +#define INCLUDED_SRCDIFF_ELSE_POLICY_HPP + +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct ElseData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + DeltaElement> condition; + DeltaElement> block; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + assert(!condition); + return ""; + } + }; + + class ElsePolicy : public ConditionalPolicy { + public: + ElsePolicy(std::initializer_list listeners) + : ConditionalPolicy(listeners) {} + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffExprStmtPolicy.hpp b/src/policy_classes/srcDiffExprStmtPolicy.hpp new file mode 100644 index 0000000..fe6aed3 --- /dev/null +++ b/src/policy_classes/srcDiffExprStmtPolicy.hpp @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffExprStmtPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_EXPR_STMT_POLICY_HPP +#define INCLUDED_SRCDIFF_EXPR_STMT_POLICY_HPP + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct ExprStmtData { + DeltaElement> expr; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return expr.ToString(operation); + } + }; + + class ExprStmtPolicy : public ExprTypePolicy { + public: + ExprStmtPolicy(std::initializer_list listeners) + : ExprTypePolicy(listeners) { + } + + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffExprTypePolicy.hpp b/src/policy_classes/srcDiffExprTypePolicy.hpp new file mode 100644 index 0000000..6bdefa4 --- /dev/null +++ b/src/policy_classes/srcDiffExprTypePolicy.hpp @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffExprTypePolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_EXPR_TYPE_POLICY_HPP +#define INCLUDED_SRCDIFF_EXPR_TYPE_POLICY_HPP + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + template + class ExprTypePolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + ExprTypeData data; + + std::unique_ptr exprPolicy; + + public: + ExprTypePolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeExprTypePolicyHandlers(); + } + + ~ExprTypePolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + if(typeid(ExpressionPolicy) == typeid(*policy)) { + data.expr.Update(ctx.diffStack.back().operation, policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeExprTypePolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[DispatchEvent] = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = ExprTypeData{}; + CollectExpressionHandlers(); + } + }; + + // end of policy + closeEventMap[DispatchEvent] = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeExprTypePolicyHandlers(); + }; + } + + void CollectExpressionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!exprPolicy) + exprPolicy = make_unique_policy({this}); + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffExpressionPolicy.cpp b/src/policy_classes/srcDiffExpressionPolicy.cpp new file mode 100644 index 0000000..a301c10 --- /dev/null +++ b/src/policy_classes/srcDiffExpressionPolicy.cpp @@ -0,0 +1,162 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffExpressionPolicy.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#include +#include + +namespace srcDiffDispatch { + + std::string ExpressionData::ToString(srcDispatch::DiffOperation operation) const { + + std::string str = ""; + bool outputSpace = false; + for (const DeltaElement& item : expr) { + + bool outputRaw = item.IsOfOperation(operation); + if(outputRaw) { + if(outputSpace) { + str += ' '; + } + outputSpace = true; + } + + const std::type_info& type = item.HasOriginal()? item.GetOriginal().type() : item.GetModified().type(); + if(type == typeid(std::shared_ptr)) { + str += item.ToString>(operation); + } else if(type == typeid(std::shared_ptr)) { + str += item.ToString>(operation); + } else if(type == typeid(std::shared_ptr)) { + str += item.ToString>(operation); + } else if(type == typeid(std::shared_ptr)) { + str += item.ToString>(operation); + } + } + + return str; + } + + std::shared_ptr ExpressionData::copyAs(srcDispatch::DiffOperation operation) const { + std::shared_ptr data = std::make_shared(); + data->lineNumber = lineNumber; + + for (const DeltaElement& item : expr) { + DeltaElement exprAny; + if(item.GetElement().type() == typeid(std::shared_ptr)) { + exprAny = DeltaElement(operation, std::any_cast>(item)->copyAs(operation)); + } else if(item.GetElement().type() == typeid(std::shared_ptr)) { + exprAny = DeltaElement(operation, std::any_cast>(item)->copyAs(operation)); + } else if(item.GetElement().type() == typeid(std::shared_ptr)) { + exprAny = DeltaElement(operation, std::any_cast>(item)->copyAs(operation)); + } else { + exprAny = DeltaElement(operation, std::any_cast>(item)->copyAs(operation)); + } + + data->expr.emplace_back(exprAny); + } + + return data; + } + + ExpressionPolicy::~ExpressionPolicy() {} + + void ExpressionPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if(typeid(NamePolicy) == typeid(*policy)) { + data.expr.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(OperatorPolicy) == typeid(*policy)) { + data.expr.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(LiteralPolicy) == typeid(*policy)) { + data.expr.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(CallPolicy) == typeid(*policy)) { + data.expr.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + // Operators are added in CollectOtherHandlers() + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } + + void ExpressionPolicy::InitializeExpressionPolicyHandlers() + { + using namespace srcDispatch; + // start of policy + std::function expressionStart = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = ExpressionData{}; + data.lineNumber = ctx.startLineNumber; + CollectNameHandlers(); + CollectCallHandlers(); + CollectOperatorHandlers(); + CollectLiteralHandlers(); + } + }; + + // end of policy + std::function expressionEnd = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeExpressionPolicyHandlers(); + }; + + openEventMap[ParserState::expr] = expressionStart; + closeEventMap[ParserState::expr] = expressionEnd; + } + + void ExpressionPolicy::CollectNameHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!namePolicy) { + namePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); + }; + } + + void ExpressionPolicy::CollectCallHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!callPolicy) { + callPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(callPolicy.get()); + }; + } + + void ExpressionPolicy::CollectOperatorHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!operatorPolicy) { + operatorPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(operatorPolicy.get()); + }; + } + + void ExpressionPolicy::CollectLiteralHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!literalPolicy) { + literalPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(literalPolicy.get()); + }; + } + +} diff --git a/src/policy_classes/srcDiffExpressionPolicy.hpp b/src/policy_classes/srcDiffExpressionPolicy.hpp new file mode 100644 index 0000000..6458dbf --- /dev/null +++ b/src/policy_classes/srcDiffExpressionPolicy.hpp @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffExpressionPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_EXPRESSION_POLICY_HPP +#define INCLUDED_SRCDIFF_EXPRESSION_POLICY_HPP + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace srcDiffDispatch { + + struct CallData; + class CallPolicy; + + struct NameData; + class NamePolicy; + + // A vector of elements in the expression. + // Names, operators, calls in the correct order. + // Need for determining variable use, variable modification, calls + + struct ExpressionData { + + unsigned int lineNumber; + std::vector> expr; + + std::shared_ptr copyAs(srcDispatch::DiffOperation operation) const; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const; + }; + + class ExpressionPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + ExpressionData data; + + std::unique_ptr namePolicy; + std::unique_ptr operatorPolicy; + std::unique_ptr literalPolicy; + std::unique_ptr callPolicy; + + public: + ExpressionPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeExpressionPolicyHandlers(); + } + + ~ExpressionPolicy(); + + protected: + std::any DataInner() const override { return std::make_shared(data); } + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeExpressionPolicyHandlers(); + void CollectCallHandlers(); + void CollectNameHandlers(); + void CollectOperatorHandlers(); + void CollectLiteralHandlers(); + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffForPolicy.hpp b/src/policy_classes/srcDiffForPolicy.hpp new file mode 100644 index 0000000..968534d --- /dev/null +++ b/src/policy_classes/srcDiffForPolicy.hpp @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffForPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_FOR_POLICY_HPP +#define INCLUDED_SRCDIFF_FOR_POLICY_HPP + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + class BlockPolicy; + struct BlockData; + + struct ForData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + DeltaElement> control; + DeltaElement> block; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return control.ToString(operation); + } + }; + + class ForPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + ForData data; + + std::unique_ptr controlPolicy; + std::unique_ptr blockPolicy; + + public: + ForPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeForPolicyHandlers(); + } + + ~ForPolicy() {} + + protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if(typeid(ControlPolicy) == typeid(*policy)) { + data.control = DeltaElement(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(BlockPolicy) == typeid(*policy)) { + data.block = DeltaElement(ctx.diffStack.back().operation, policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} // doesn't use other parsers + + private: + void InitializeForPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = ForData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectControlHandlers(); + CollectBlockHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeForPolicyHandlers(); + }; + } + + void CollectControlHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!controlPolicy) { + controlPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(controlPolicy.get()); + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!blockPolicy) { + blockPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffFunctionPolicy.hpp b/src/policy_classes/srcDiffFunctionPolicy.hpp new file mode 100644 index 0000000..454da1b --- /dev/null +++ b/src/policy_classes/srcDiffFunctionPolicy.hpp @@ -0,0 +1,352 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffFunctionPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_FUNCTION_POLICY_HPP +#define INCLUDED_SRCDIFF_FUNCTION_POLICY_HPP + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace srcDiffDispatch { + + struct FunctionData { + + enum FunctionType { CONSTRUCTOR, DESTRUCTOR, OPERATOR, FUNCTION }; + + /*** @todo fix */ + // std::vector> namespaces; + std::vector namespaces; + + unsigned int lineNumber; + std::string language; + std::string filename; + + std::vector>> generics; + DeltaElement type; + DeltaElement accessSpecifier; + + std::vector>> leadingSpecifiers; + std::vector>> trailingSpecifiers; + + DeltaElement isDecl; + DeltaElement isPureVirtual; + DeltaElement isDelete; + + /*** @todo implement */ + std::set stereotypes; + + DeltaElement> returnType; + DeltaElement> name; + std::vector>> parameters; + std::vector>> memberInitList; + DeltaElement> block; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + + std::string signature; + + for(DeltaElement> specifier : leadingSpecifiers) { + if(specifier.IsOfOperation(operation)) { + signature += *specifier.GetOfOperation(operation) + ' '; + } + } + + signature += returnType.ToString(operation); + + if(returnType.IsOfOperation(operation)) { + signature += ' '; + } + + signature += name.ToString(operation); + + if(name.IsOfOperation(operation)) { + signature += '('; + } + + bool outputComma = false; + for (const DeltaElement>& parameter : parameters) { + bool outputRaw = parameter.IsOfOperation(operation); + if(outputRaw) { + if(outputComma) { + signature += ", "; + } + outputComma = true; + } + signature += parameter.ToString(operation); + } + + if(name.IsOfOperation(operation)) { + signature += ')'; + } + + for(DeltaElement> specifier : trailingSpecifiers) { + if(specifier.IsOfOperation(operation)) { + signature += ' ' + *specifier.GetOfOperation(operation); + } + } + + + if(isPureVirtual.IsOfOperation(operation) && isPureVirtual.GetOfOperation(operation)) { + signature += " = 0"; + } + + if(isDelete.IsOfOperation(operation) && isDelete.GetOfOperation(operation)) { + signature += " = delete"; + } + + if(isDecl.IsOfOperation(operation)) { + if(isDecl.GetOfOperation(operation)) { + signature += ';'; + } else { + signature += " {}"; + } + } + + return signature; + } + }; + + class FunctionPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + FunctionData data; + + bool beforeParameters; + + std::unique_ptr genericPolicy; + std::unique_ptr typePolicy; + std::unique_ptr namePolicy; + std::unique_ptr declPolicy; + std::unique_ptr callPolicy; + std::unique_ptr blockPolicy; + + public: + FunctionPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{}, beforeParameters(true) { + InitializeFunctionPolicyHandlers(); + } + + ~FunctionPolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + if(typeid(GenericPolicy) == typeid(*policy)) { + data.generics.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(TypePolicy) == typeid(*policy)) { + data.returnType = DeltaElement(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(NamePolicy) == typeid(*policy)) { + data.name = DeltaElement(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(DeclPolicy) == typeid(*policy)) { + data.parameters.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(CallPolicy) == typeid(*policy)) { + data.memberInitList.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(BlockPolicy) == typeid(*policy)) { + data.block.Update(ctx.diffStack.back().operation, policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeFunctionPolicyHandlers() { + using namespace srcDispatch; + // start of policy + std::function startFunction = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = FunctionData{}; + data.namespaces = ctx.currentNamespaces; + data.lineNumber = ctx.startLineNumber; + data.language = ctx.currentFileLanguage; + data.filename = ctx.currentFilePath; + std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); + if(stereotype_attr_itr != ctx.attributes.end()) { + std::istringstream stereostring(stereotype_attr_itr->second); + data.stereotypes = std::set(std::istream_iterator(stereostring), std::istream_iterator()); + } + if(ctx.currentTag == "function" || ctx.currentTag == "function_decl") { + if(ctx.isOperator) { + data.type.Update(ctx.diffStack.back().operation, FunctionData::OPERATOR); + } else { + data.type.Update(ctx.diffStack.back().operation, FunctionData::FUNCTION); + } + } else if(ctx.currentTag == "constructor" || ctx.currentTag == "constructor_decl") { + data.type.Update(ctx.diffStack.back().operation, FunctionData::CONSTRUCTOR); + } else if(ctx.currentTag == "destructor" || ctx.currentTag == "destructor_decl") { + data.type.Update(ctx.diffStack.back().operation, FunctionData::DESTRUCTOR); + } + + data.isDecl.Update(ctx.diffStack.back().operation, ctx.currentTag == "function_decl" || ctx.currentTag == "constructor_decl" || ctx.currentTag == "destructor_decl"); + + CollectXMLAttributeHandlers(); + CollectGenericHandlers(); + CollectTypeHandlers(); + CollectNameHandlers(); + CollectParameterHandlers(); + CollectCallHandlers(); + CollectOtherHandlers(); + CollectBlockHandlers(); + } + }; + + // end of policy + std::function endFunction = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeFunctionPolicyHandlers(); + }; + + openEventMap[ParserState::function] = startFunction; + openEventMap[ParserState::functiondecl] = startFunction; + openEventMap[ParserState::constructor] = startFunction; + openEventMap[ParserState::constructordecl] = startFunction; + openEventMap[ParserState::destructor] = startFunction; + openEventMap[ParserState::destructordecl] = startFunction; + + closeEventMap[ParserState::function] = endFunction; + closeEventMap[ParserState::functiondecl] = endFunction; + closeEventMap[ParserState::constructor] = endFunction; + closeEventMap[ParserState::constructordecl] = endFunction; + closeEventMap[ParserState::destructor] = endFunction; + closeEventMap[ParserState::destructordecl] = endFunction; + } + + void CollectXMLAttributeHandlers() {} + + void CollectGenericHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::templates] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!genericPolicy) { + genericPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(genericPolicy.get()); + }; + } + + void CollectTypeHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!typePolicy) { + typePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(typePolicy.get()); + }; + } + + void CollectNameHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!namePolicy) { + namePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); + }; + } + + void CollectParameterHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { + if(!declPolicy) { + declPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(declPolicy.get()); + }; + }; + + closeEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + beforeParameters = false; + NopOpenEvents({ParserState::parameter}); + }; + } + + void CollectCallHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!callPolicy) { + callPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(callPolicy.get()); + }; + } + + void CollectOtherHandlers() { + using namespace srcDispatch; + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(ctx.And({ParserState::specifier})) { + if(ctx.currentToken == "delete") { + data.isDelete.Update(ctx.diffStack.back().operation, true); + } else if(beforeParameters) { + data.leadingSpecifiers.emplace_back(ctx.diffStack.back().operation, std::make_shared(ctx.currentToken)); + } else { + data.trailingSpecifiers.emplace_back(ctx.diffStack.back().operation, std::make_shared(ctx.currentToken)); + } + } else if(ctx.And({ParserState::literal})) { + data.isPureVirtual.Update(ctx.diffStack.back().operation, true); + } + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!blockPolicy) { + blockPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffGenericArgumentsPolicy.cpp b/src/policy_classes/srcDiffGenericArgumentsPolicy.cpp new file mode 100644 index 0000000..bba4975 --- /dev/null +++ b/src/policy_classes/srcDiffGenericArgumentsPolicy.cpp @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffGenericArgumentsPolicy.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#include +#include +#include + +#include + +namespace srcDiffDispatch { + + std::string GenericArgumentsData::ToString(srcDispatch::DiffOperation operation) const { + + std::string str; + + bool hasArgument = false; + bool printComma = false; + for (const DeltaElement>& argument : arguments) { + + bool outputRaw = argument.IsOfOperation(operation); + if(outputRaw) { + if(printComma) { + str += ", "; + } + if(!hasArgument) { + str += "<"; + hasArgument = true; + } + printComma = true; + } + + str += argument.ToString(operation); + } + + if(hasArgument) { + str += '>'; + } + + return str; + } + + std::shared_ptr GenericArgumentsData::copyAs(srcDispatch::DiffOperation operation) const { + std::shared_ptr data = std::make_shared(); + data->lineNumber = lineNumber; + + for (const DeltaElement>& argument : arguments) { + data->arguments.emplace_back(DeltaElement(operation, argument.GetElement()->copyAs(operation))); + } + + return data; + } + + GenericArgumentsPolicy::GenericArgumentsPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeGenericArgumentsPolicyHandlers(); + } + + GenericArgumentsPolicy::~GenericArgumentsPolicy() {} + + void GenericArgumentsPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if(typeid(NamePolicy) == typeid(*policy)) { + //data.arguments.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(ExpressionPolicy) == typeid(*policy)) { + data.arguments.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + ctx.dispatcher->RemoveListener(nullptr); + } + + std::any GenericArgumentsPolicy::DataInner() const { + return std::make_shared(data); + } + + void GenericArgumentsPolicy::InitializeGenericArgumentsPolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext &ctx) { + if(!depth) { + depth = ctx.depth; + data = GenericArgumentsData{}; + data.lineNumber = ctx.startLineNumber; + CollectArgumentHandler(); + } + }; + + // end of policy + closeEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext &ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeGenericArgumentsPolicyHandlers(); + }; + } + + void GenericArgumentsPolicy::CollectArgumentHandler() { + using namespace srcDispatch; + + openEventMap[ParserState::argument] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + openEventMap[ParserState::expr] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + if(!expressionPolicy) { + expressionPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(expressionPolicy.get()); + }; + }; + + closeEventMap[ParserState::argument] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + NopOpenEvents({ParserState::expr}); + }; + } + +} diff --git a/src/policy_classes/srcDiffGenericArgumentsPolicy.hpp b/src/policy_classes/srcDiffGenericArgumentsPolicy.hpp new file mode 100644 index 0000000..fd9587a --- /dev/null +++ b/src/policy_classes/srcDiffGenericArgumentsPolicy.hpp @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffGenericArgumentsPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_GENERIC_ARGUMENTS_POLICY_HPP +#define INCLUDED_SRCDIFF_GENERIC_ARGUMENTS_POLICY_HPP + +#include +#include +#include + +namespace srcDiffDispatch { + + class NamePolicy; + class ExpressionPolicy; + struct ExpressionData; + + struct GenericArgumentsData { + + unsigned int lineNumber; + std::vector>> arguments; + + std::shared_ptr copyAs(srcDispatch::DiffOperation operation) const; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const; + }; + + class GenericArgumentsPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + + private: + GenericArgumentsData data; + + std::unique_ptr expressionPolicy; + + public: + GenericArgumentsPolicy(std::initializer_list listeners); + ~GenericArgumentsPolicy(); + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + protected: + virtual std::any DataInner() const override; + + private: + void InitializeGenericArgumentsPolicyHandlers(); + void CollectArgumentHandler(); + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffGenericPolicy.cpp b/src/policy_classes/srcDiffGenericPolicy.cpp new file mode 100644 index 0000000..e05ee30 --- /dev/null +++ b/src/policy_classes/srcDiffGenericPolicy.cpp @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffGenericPolicy.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#include +#include + +#include +#include + +#include + +namespace srcDiffDispatch { + + std::string GenericData::ToString(srcDispatch::DiffOperation operation) const { + + std::string str; + + bool hasParameter = false; + bool printComma = false; + for (const DeltaElement>& parameter : parameters) { + + bool outputRaw = parameter.IsOfOperation(operation); + if(outputRaw) { + if(printComma) { + str += ", "; + } + if(!hasParameter) { + str += "template<"; + hasParameter = true; + } + printComma = true; + } + + str += parameter.ToString(operation); + } + + if(hasParameter) { + str += '>'; + } + + return str; + } + + GenericPolicy::GenericPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeGenericPolicyHandlers(); + } + + GenericPolicy::~GenericPolicy() {} + + void GenericPolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if(typeid(DeclPolicy) == typeid(*policy)) { + data.parameters.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + ctx.dispatcher->RemoveListener(nullptr); + } + + std::any GenericPolicy::DataInner() const { + return std::make_shared(data); + } + + void GenericPolicy::InitializeGenericPolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[ParserState::templates] = [this](srcSAXEventContext &ctx) { + if(!depth) { + depth = ctx.depth; + data = GenericData{}; + data.lineNumber = ctx.startLineNumber; + CollectParameterHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::templates] = [this](srcSAXEventContext &ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeGenericPolicyHandlers(); + }; + } + + void GenericPolicy::CollectParameterHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { + if(!declPolicy) { + declPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(declPolicy.get()); + }; + }; + + closeEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + NopOpenEvents({ParserState::parameter}); + }; + } +} diff --git a/src/policy_classes/srcDiffGenericPolicy.hpp b/src/policy_classes/srcDiffGenericPolicy.hpp new file mode 100644 index 0000000..fd7a10d --- /dev/null +++ b/src/policy_classes/srcDiffGenericPolicy.hpp @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffGenericPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_GENERIC_POLICY_HPP +#define INCLUDED_SRCDIFF_GENERIC_POLICY_HPP + +#include + +#include + + +namespace srcDiffDispatch { + + class DeclPolicy; + struct DeclData; + + class NamePolicy; + + class ExpressionPolicy; + struct ExpressionData; + + struct GenericData { + + unsigned int lineNumber; + std::vector>> parameters; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const; + }; + + class GenericPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + GenericData data; + + std::unique_ptr declPolicy; + + public: + GenericPolicy(std::initializer_list listeners); + ~GenericPolicy(); + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + protected: + virtual std::any DataInner() const override; + + private: + void InitializeGenericPolicyHandlers(); + void CollectParameterHandlers(); + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffGotoPolicy.hpp b/src/policy_classes/srcDiffGotoPolicy.hpp new file mode 100644 index 0000000..9c8f7ce --- /dev/null +++ b/src/policy_classes/srcDiffGotoPolicy.hpp @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffGotoPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_GOTO_POLICY_HPP +#define INCLUDED_SRCDIFF_GOTO_POLICY_HPP + +#include +#include +#include +#include + +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct GotoData { + enum GotoType { GOTO, BREAK, CONTINUE }; + + unsigned int lineNumber; + + DeltaElement type; + DeltaElement> label; + }; + + // Collect the expression in the return + class GotoPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + private: + GotoData data; + + std::unique_ptr namePolicy; + + public: + GotoPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeGotoPolicyHandlers(); + } + + ~GotoPolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + if(typeid(NamePolicy) == typeid(*policy)) { + data.label.Update(ctx.diffStack.back().operation, policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeGotoPolicyHandlers() { + using namespace srcDispatch; + // start of policy + std::function startGoto = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = GotoData{}; + data.lineNumber = ctx.startLineNumber; + + if(ctx.currentTag == "break") { + data.type.Update(ctx.diffStack.back().operation, GotoData::BREAK); + } else if(ctx.currentTag == "continue") { + data.type.Update(ctx.diffStack.back().operation, GotoData::CONTINUE); + } else { + data.type.Update(ctx.diffStack.back().operation, GotoData::GOTO); + } + + CollectLabelHandlers(); + } + }; + + // end of policy + std::function endGoto = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + depth = 0; + NotifyAll(ctx); + InitializeGotoPolicyHandlers(); + }; + + openEventMap[ParserState::gotostmt] = startGoto; + openEventMap[ParserState::breakstmt] = startGoto; + openEventMap[ParserState::continuestmt] = startGoto; + + closeEventMap[ParserState::gotostmt] = endGoto; + closeEventMap[ParserState::breakstmt] = endGoto; + closeEventMap[ParserState::continuestmt] = endGoto; + } + + void CollectLabelHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!namePolicy) { + namePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); + }; + } + + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffIfPolicy.hpp b/src/policy_classes/srcDiffIfPolicy.hpp new file mode 100644 index 0000000..ca67a1b --- /dev/null +++ b/src/policy_classes/srcDiffIfPolicy.hpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffIfPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_IF_POLICY_HPP +#define INCLUDED_SRCDIFF_IF_POLICY_HPP + +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct IfData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + DeltaElement> condition; + DeltaElement> block; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return condition.ToString(operation); + } + }; + + class IfPolicy : public ConditionalPolicy { + public: + IfPolicy(std::initializer_list listeners) + : ConditionalPolicy(listeners) {} + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffIfStmtPolicy.hpp b/src/policy_classes/srcDiffIfStmtPolicy.hpp new file mode 100644 index 0000000..82b12ad --- /dev/null +++ b/src/policy_classes/srcDiffIfStmtPolicy.hpp @@ -0,0 +1,154 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffIfStmtPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_IF_STMT_POLICY_HPP +#define INCLUDED_SRCDIFF_IF_STMT_POLICY_HPP + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct IfStmtData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + std::vector> clauses; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + if(clauses.empty()) return ""; + + // Not sure how safe using GetElement is here + if(clauses.front().GetElement().type() != typeid(std::shared_ptr)) return ""; + + return clauses.front().ToString>(operation); + } + }; + + class IfStmtPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + IfStmtData data; + + std::unique_ptr ifPolicy; + std::unique_ptr elseIfPolicy; + std::unique_ptr elsePolicy; + + public: + IfStmtPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeIfStmtPolicyHandlers(); + } + + ~IfStmtPolicy() {} + + protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if(typeid(IfPolicy) == typeid(*policy)) { + data.clauses.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(ElseIfPolicy) == typeid(*policy)) { + data.clauses.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(ElsePolicy) == typeid(*policy)) { + data.clauses.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} // doesn't use other parsers + + private: + void InitializeIfStmtPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::ifgroup] = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = IfStmtData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectIfHandlers(); + CollectElseIfHandlers(); + CollectElseHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::ifgroup] = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeIfStmtPolicyHandlers(); + }; + } + + void CollectIfHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!ifPolicy) { + ifPolicy = make_unique_policy({this}); + } + + ctx.dispatcher->AddListenerDispatch(ifPolicy.get()); + }; + } + + void CollectElseIfHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::elseif] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!elseIfPolicy) { + elseIfPolicy = make_unique_policy({this}); + } + + ctx.dispatcher->AddListenerDispatch(elseIfPolicy.get()); + }; + } + + void CollectElseHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::elsestmt] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!elsePolicy) { + elsePolicy = make_unique_policy({this}); + } + + ctx.dispatcher->AddListenerDispatch(elsePolicy.get()); + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffIncrPolicy.hpp b/src/policy_classes/srcDiffIncrPolicy.hpp new file mode 100644 index 0000000..f3db2e1 --- /dev/null +++ b/src/policy_classes/srcDiffIncrPolicy.hpp @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffIncrPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_INCR_POLICY_HPP +#define INCLUDED_SRCDIFF_INCR_POLICY_HPP + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct IncrData { + + unsigned int startLineNumber; + std::vector>> exprs; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + if(exprs.empty()) return ""; + + std::string str; + bool printComma = false; + for(const DeltaElement>& expr : exprs) { + + bool outputRaw = expr.IsOfOperation(operation); + if(outputRaw) { + if(printComma) { + str += ", "; + } + printComma = true; + } + + str += expr.ToString(operation); + } + + return str; + } + }; + + class IncrPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + IncrData data; + + std::unique_ptr exprPolicy; + + public: + IncrPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeIncrPolicyHandlers(); + } + + ~IncrPolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + if(typeid(ExpressionPolicy) == typeid(*policy)) { + data.exprs.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeIncrPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = IncrData{}; + data.startLineNumber = ctx.startLineNumber; + CollectExpressionHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeIncrPolicyHandlers(); + }; + } + + void CollectExpressionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!exprPolicy) { + exprPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffInitPolicy.hpp b/src/policy_classes/srcDiffInitPolicy.hpp new file mode 100644 index 0000000..1a02ffb --- /dev/null +++ b/src/policy_classes/srcDiffInitPolicy.hpp @@ -0,0 +1,154 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffInitPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_INIT_POLICY_HPP +#define INCLUDED_SRCDIFF_INIT_POLICY_HPP + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct InitData { + + unsigned int startLineNumber; + std::vector> inits; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + if(inits.empty()) return ""; + + std::string str; + bool printComma = false; + for (const DeltaElement& init : inits) { + + bool outputRaw = init.IsOfOperation(operation); + if(outputRaw) { + if(printComma) { + str += ", "; + } + printComma = true; + } + + if(init.GetElement().type() == typeid(std::shared_ptr)) { + str += init.ToString>(operation); + } else { + str += init.ToString>(operation); + } + } + + return str; + } + }; + + class InitPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + InitData data; + + std::unique_ptr declPolicy; + std::unique_ptr exprPolicy; + + public: + InitPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeInitPolicyHandlers(); + } + + ~InitPolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + if(typeid(ExpressionPolicy) == typeid(*policy)) { + if(data.inits.size() && ctx.diffStack.back().isReplace && data.inits.back().GetElement().type() == typeid(std::shared_ptr)) { + data.inits.back().Update(ctx.diffStack.back().operation, policy->Data()); + } else { + data.inits.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } + } else if(typeid(DeclPolicy) == typeid(*policy)) { + // not sure how safe GetElement is here + srcDispatch::DiffOperation operation = ctx.diffStack.back().operation; + std::shared_ptr decl = policy->Data(); + if(data.inits.size() && data.inits.back().GetElement().type() == typeid(std::shared_ptr)) { + DeltaElement> typeData(operation, std::any_cast>(data.inits.back().GetElement())->type.GetElement()->copyAs(operation)); + decl->type = typeData; + decl->isStatic = std::any_cast>(data.inits.back().GetElement())->isStatic; + } + data.inits.emplace_back(operation, decl); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeInitPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = InitData{}; + data.startLineNumber = ctx.startLineNumber; + CollectExpressionHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeInitPolicyHandlers(); + }; + } + + void CollectExpressionHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!declPolicy) { + declPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(declPolicy.get()); + }; + + openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!exprPolicy) { + exprPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffLabelPolicy.hpp b/src/policy_classes/srcDiffLabelPolicy.hpp new file mode 100644 index 0000000..bfa48f2 --- /dev/null +++ b/src/policy_classes/srcDiffLabelPolicy.hpp @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffLabelPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_LABEL_POLICY_HPP +#define INCLUDED_SRCDIFF_LABEL_POLICY_HPP + +#include +#include +#include +#include + +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct LabelData { + DeltaElement> name; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return name.ToString(operation); + } + }; + + class LabelPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + LabelData data; + + std::unique_ptr namePolicy; + + public: + LabelPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeLabelPolicyHandlers(); + } + + ~LabelPolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { + if(typeid(NamePolicy) == typeid(*policy)) { + data.name.Update(ctx.diffStack.back().operation, policy->Data()); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeLabelPolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[ParserState::label] = [this](srcSAXEventContext &ctx) { + if(!depth) { + depth = ctx.depth; + data = LabelData{}; + CollectNameHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::label] = [this](srcSAXEventContext &ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeLabelPolicyHandlers(); + }; + } + + void CollectNameHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::name] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + if(!namePolicy) { + namePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffLiteralPolicy.hpp b/src/policy_classes/srcDiffLiteralPolicy.hpp new file mode 100644 index 0000000..8bcaa82 --- /dev/null +++ b/src/policy_classes/srcDiffLiteralPolicy.hpp @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffLiteralPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_LITERAL_POLICY_HPP +#define INCLUDED_SRCDIFF_LITERAL_POLICY_HPP + +#include +#include +#include +#include + +#include +#include + +namespace srcDiffDispatch { + + struct LiteralData { + + unsigned int startLineNumber; + DeltaElement literal; + + std::shared_ptr copyAs(srcDispatch::DiffOperation operation) const { + std::shared_ptr data = std::make_shared(); + data->literal = DeltaElement(operation, literal.GetElement()); + return data; + } + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return literal.ToString(operation); + } + }; + + class LiteralPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + LiteralData data; + + public: + LiteralPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeLiteralPolicyHandlers(); + } + + ~LiteralPolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override {} + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeLiteralPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = LiteralData{}; + data.startLineNumber = ctx.startLineNumber; + CollectTokenHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeLiteralPolicyHandlers(); + }; + } + + void CollectTokenHandlers() { + using namespace srcDispatch; + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { + if(data.literal.GetOperation() == srcDispatch::NONE) { + bool isChange = (ctx.depth + 1) == ctx.diffStack.back().depth && ctx.diffStack.back().isReplace; + srcDispatch::DiffOperation operation = isChange? CHANGE : ctx.diffStack.back().operation; + data.literal = DeltaElement(operation); + } + + if( ctx.diffStack.back().operation == srcDispatch::COMMON + || ctx.diffStack.back().operation == srcDispatch::DELETE) { + data.literal.GetOriginal() += ctx.currentToken; + } else if(ctx.diffStack.back().operation == srcDispatch::INSERT) { + data.literal.GetModified() += ctx.currentToken; + } + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffNamePolicy.cpp b/src/policy_classes/srcDiffNamePolicy.cpp new file mode 100644 index 0000000..50a4ebf --- /dev/null +++ b/src/policy_classes/srcDiffNamePolicy.cpp @@ -0,0 +1,189 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffNamePolicy.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#include +#include +#include + +#include + +namespace srcDiffDispatch { + + std::string NameData::SimpleName() const { + if(name) return name.ToString(); + + // Not sure how safe GetElement use is + assert(names.back().GetElement().type() == typeid(std::shared_ptr)); + return names.back().ToString>(); + } + + std::string NameData::ToString(srcDispatch::DiffOperation operation) const { + + std::string str = name.ToString(operation); + for (const DeltaElement& name_element : names) { + if(name_element.GetElement().type() == typeid(std::shared_ptr)) { + str += name_element.ToString>(operation); + } else { + str += name_element.ToString>(operation); + } + } + if(templateArgumentList) { + str += templateArgumentList.ToString(operation); + } + for (const DeltaElement>& index : indices) { + + bool outputRaw = index.IsOfOperation(operation); + if(outputRaw) { + str += '['; + } + + str += index.ToString(operation); + + if(outputRaw) { + str += ']'; + } + + } + + return str; + } + + std::shared_ptr NameData::copyAs(srcDispatch::DiffOperation operation) const { + std::shared_ptr data = std::make_shared(); + data->lineNumber = lineNumber; + if(name) { + data->name = DeltaElement(operation, name.GetElement()); + } + + for (const DeltaElement& name_element : names) { + DeltaElement nameAny; + if(name_element.GetElement().type() == typeid(std::shared_ptr)) { + nameAny = DeltaElement(operation, std::any_cast>(name_element)->copyAs(operation)); + } else { + nameAny = DeltaElement(operation, std::any_cast>(name_element)->copyAs(operation)); + } + data->names.emplace_back(nameAny); + } + + if(templateArgumentList) { + data->templateArgumentList = DeltaElement(operation, templateArgumentList.GetElement()->copyAs(operation)); + } + + for (const DeltaElement>& index : indices) { + data->indices.emplace_back(DeltaElement(operation, index.GetElement()->copyAs(operation))); + } + + return data; + } + + NamePolicy::~NamePolicy() {} + + void NamePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + + if(typeid(NamePolicy) == typeid(*policy)) { + data.names.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(OperatorPolicy) == typeid(*policy)) { + data.names.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else if(typeid(GenericArgumentsPolicy) == typeid(*policy)) { + data.templateArgumentList = DeltaElement(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(ExpressionPolicy) == typeid(*policy)) { + data.indices.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + ctx.dispatcher->RemoveListener(nullptr); + } + + void NamePolicy::InitializeNamePolicyHandlers() { + using namespace srcDispatch; + + // start of policy + openEventMap[ParserState::name] = [this](srcSAXEventContext &ctx) { + if(!depth) { + depth = ctx.depth; + data = NameData{}; + data.lineNumber = ctx.startLineNumber; + CollectOperatorsHandlers(); + CollectGenericArgumentsHandlers(); + CollectArrayIndicesHandlers(); + } else { + NopCloseEvents({ParserState::tokenstring}); + if(!namePolicy) { + namePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); + } + }; + + // end of policy + closeEventMap[ParserState::name] = [this](srcSAXEventContext &ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeNamePolicyHandlers(); + }; + + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + if(data.name.GetOperation() == srcDispatch::NONE) { + bool isChange = (ctx.depth + 1) == ctx.diffStack.back().depth && ctx.diffStack.back().isReplace; + srcDispatch::DiffOperation operation = isChange? CHANGE : ctx.diffStack.back().operation; + data.name = DeltaElement(operation); + } + + if( ctx.diffStack.back().operation == srcDispatch::COMMON + || ctx.diffStack.back().operation == srcDispatch::DELETE) { + data.name.GetOriginal() += ctx.currentToken; + } else if(ctx.diffStack.back().operation == srcDispatch::INSERT) { + data.name.GetModified() += ctx.currentToken; + } + }; + } + + void NamePolicy::CollectOperatorsHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::op] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + if(!operatorPolicy) { + operatorPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(operatorPolicy.get()); + }; + } + + void NamePolicy::CollectGenericArgumentsHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + if(!templateArgumentListPolicy) { + templateArgumentListPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(templateArgumentListPolicy.get()); + }; + } + + void NamePolicy::CollectArrayIndicesHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::index] = [this](srcSAXEventContext &ctx) { + if(!depth) return; + + openEventMap[ParserState::expr] = [this](srcSAXEventContext &ctx) { + if(!expressionPolicy) { + expressionPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(expressionPolicy.get()); + }; + }; + } + +} diff --git a/src/policy_classes/srcDiffNamePolicy.hpp b/src/policy_classes/srcDiffNamePolicy.hpp new file mode 100644 index 0000000..9979335 --- /dev/null +++ b/src/policy_classes/srcDiffNamePolicy.hpp @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffNamePolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_NAME_POLICY_HPP +#define INCLUDED_SRCDIFF_NAME_POLICY_HPP + +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + class ExpressionPolicy; + struct ExpressionData; + + class GenericArgumentsPolicy; + struct GenericArgumentsData; + + struct NameData { + + unsigned int lineNumber; + DeltaElement name; + std::vector> names; + DeltaElement> templateArgumentList; + std::vector>> indices; + + std::string SimpleName() const; + std::shared_ptr copyAs(srcDispatch::DiffOperation operation) const; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const; + }; + + class NamePolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + NameData data; + + std::unique_ptr namePolicy; + std::unique_ptr operatorPolicy; + std::unique_ptr templateArgumentListPolicy; + std::unique_ptr expressionPolicy; + + public: + NamePolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeNamePolicyHandlers(); + } + + ~NamePolicy(); + + protected: + std::any DataInner() const override { return std::make_shared(data); } + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeNamePolicyHandlers(); + void CollectOperatorsHandlers(); + void CollectGenericArgumentsHandlers(); + void CollectArrayIndicesHandlers(); + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffOperatorPolicy.hpp b/src/policy_classes/srcDiffOperatorPolicy.hpp new file mode 100644 index 0000000..6344865 --- /dev/null +++ b/src/policy_classes/srcDiffOperatorPolicy.hpp @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffOperatorPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_OPERATOR_POLICY_HPP +#define INCLUDED_SRCDIFF_OPERATOR_POLICY_HPP + +#include +#include +#include +#include + +#include +#include + +namespace srcDiffDispatch { + + struct OperatorData { + + unsigned int startLineNumber; + DeltaElement op; + + std::shared_ptr copyAs(srcDispatch::DiffOperation operation) const { + std::shared_ptr data = std::make_shared(); + data->op = DeltaElement(operation, op.GetElement()); + return data; + } + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return op.ToString(operation); + } + }; + + class OperatorPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + OperatorData data; + + public: + OperatorPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeOperatorPolicyHandlers(); + } + + ~OperatorPolicy() {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override {} + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + private: + void InitializeOperatorPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = OperatorData{}; + data.startLineNumber = ctx.startLineNumber; + CollectTokenHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeOperatorPolicyHandlers(); + }; + } + + void CollectTokenHandlers() { + using namespace srcDispatch; + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { + if(data.op.GetOperation() == srcDispatch::NONE) { + bool isChange = (ctx.depth + 1) == ctx.diffStack.back().depth && ctx.diffStack.back().isReplace; + srcDispatch::DiffOperation operation = isChange? CHANGE : ctx.diffStack.back().operation; + data.op = DeltaElement(operation); + } + + if( ctx.diffStack.back().operation == srcDispatch::COMMON + || ctx.diffStack.back().operation == srcDispatch::DELETE) { + data.op.GetOriginal() += ctx.currentToken; + } else if(ctx.diffStack.back().operation == srcDispatch::INSERT) { + data.op.GetModified() += ctx.currentToken; + } + }; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffReturnPolicy.hpp b/src/policy_classes/srcDiffReturnPolicy.hpp new file mode 100644 index 0000000..c2f6181 --- /dev/null +++ b/src/policy_classes/srcDiffReturnPolicy.hpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffReturnPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_RETURN_POLICY_HPP +#define INCLUDED_SRCDIFF_RETURN_POLICY_HPP + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct ReturnData { + DeltaElement> expr; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return expr.ToString(operation); + } + }; + + // Collect the expression in the return + class ReturnPolicy : public ExprTypePolicy { + public: + ReturnPolicy(std::initializer_list listeners) + : ExprTypePolicy(listeners) { + } + + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffSwitchPolicy.hpp b/src/policy_classes/srcDiffSwitchPolicy.hpp new file mode 100644 index 0000000..2692021 --- /dev/null +++ b/src/policy_classes/srcDiffSwitchPolicy.hpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffSwitchPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_SWITCH_POLICY_HPP +#define INCLUDED_SRCDIFF_SWITCH_POLICY_HPP + +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct SwitchData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + DeltaElement> condition; + DeltaElement> block; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return condition.ToString(operation); + } + }; + + class SwitchPolicy : public ConditionalPolicy { + public: + SwitchPolicy(std::initializer_list listeners) + : ConditionalPolicy(listeners) {} + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffThrowPolicy.hpp b/src/policy_classes/srcDiffThrowPolicy.hpp new file mode 100644 index 0000000..954c38f --- /dev/null +++ b/src/policy_classes/srcDiffThrowPolicy.hpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffThrowPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_THROW_POLICY_HPP +#define INCLUDED_SRCDIFF_THROW_POLICY_HPP + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct ThrowData { + DeltaElement> expr; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return expr.ToString(operation); + } + }; + + // Collect the expression in the return + class ThrowPolicy : public ExprTypePolicy { + public: + ThrowPolicy(std::initializer_list listeners) + : ExprTypePolicy(listeners) { + } + + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffTryPolicy.hpp b/src/policy_classes/srcDiffTryPolicy.hpp new file mode 100644 index 0000000..5daf023 --- /dev/null +++ b/src/policy_classes/srcDiffTryPolicy.hpp @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffTryPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_TRY_POLICY_HPP +#define INCLUDED_SRCDIFF_TRY_POLICY_HPP + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct TryData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + DeltaElement> block; + std::vector> clauses; + }; + + class TryPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + TryData data; + + std::unique_ptr blockPolicy; + std::unique_ptr catchPolicy; + + public: + TryPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeTryPolicyHandlers(); + } + + ~TryPolicy() {} + + protected: + std::any DataInner() const { return std::make_shared(data); } + + void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + if (typeid(BlockPolicy) == typeid(*policy)) { + data.block.Update(ctx.diffStack.back().operation, policy->Data()); + } else if (typeid(CatchPolicy) == typeid(*policy)) { + data.clauses.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); + } else { + throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); + } + + ctx.dispatcher->RemoveListener(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy, srcDispatch::srcSAXEventContext& ctx) {} // doesn't use other parsers + + private: + void InitializeTryPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::trystmt] = [this](srcSAXEventContext &ctx) { + if (!depth) { + depth = ctx.depth; + data = TryData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectBlockHandlers(); + CollectCatchHandlers(); + } + }; + + // end of policy + closeEventMap[ParserState::trystmt] = [this](srcSAXEventContext &ctx) { + if (!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeTryPolicyHandlers(); + }; + } + + void CollectBlockHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::block] = [this](srcSAXEventContext &ctx) { + if (!depth) return; + + if (!blockPolicy) { + blockPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); + }; + } + + void CollectCatchHandlers() { + using namespace srcDispatch; + openEventMap[ParserState::catchstmt] = [this](srcSAXEventContext &ctx) { + if (!depth) return; + + if (!catchPolicy) { + catchPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(catchPolicy.get()); + }; + } + + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffTypePolicy.cpp b/src/policy_classes/srcDiffTypePolicy.cpp new file mode 100644 index 0000000..306af2e --- /dev/null +++ b/src/policy_classes/srcDiffTypePolicy.cpp @@ -0,0 +1,161 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffTypePolicy.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#include +#include +#include +#include + +namespace srcDiffDispatch { + + std::string TypeData::ToString(srcDispatch::DiffOperation operation) const { + std::string str; + bool printSpace = false; + for (const std::pair, DeltaElement>& type : types) { + + bool outputRaw = type.second.IsOfOperation(operation); + if(outputRaw) { + if(printSpace) { + str += ' '; + } + printSpace = true; + } + + TypeData::TypeType outputsType = ((operation == srcDispatch::DELETE && type.second.HasOriginal()) || !type.second.HasModified())? type.second.GetOriginal() : type.second.GetModified(); + if(outputRaw && outputsType == TypeData::POINTER) { + str += '*'; + } else if(outputRaw && outputsType == TypeData::REFERENCE) { + str += '&'; + } else if(outputRaw && outputsType == TypeData::RVALUE) { + str += "&&"; + } else if(outputsType == TypeData::SPECIFIER) { + str += type.first.ToString>(operation); + } else if(outputsType == TypeData::TYPENAME) { + str += type.first.ToString>(operation); + } + + } + return str; + } + + std::shared_ptr TypeData::copyAs(srcDispatch::DiffOperation operation) const { + std::shared_ptr data = std::make_shared(); + data->lineNumber = lineNumber; + for(const std::pair, DeltaElement>& type : types) { + DeltaElement typeAny; + if(type.second.GetElement() == TypeData::SPECIFIER) { + typeAny = DeltaElement(operation, std::any_cast>(type.first)); + } else if(type.second.GetElement() == TypeData::TYPENAME) { + typeAny = DeltaElement(operation, std::any_cast>(type.first.GetElement())->copyAs(operation)); + } + data->types.emplace_back(typeAny, DeltaElement(operation, type.second.GetElement())); + } + return data; + } + + + TypePolicy::TypePolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), data{} { + InitializeTypePolicyHandlers(); + } + + TypePolicy::~TypePolicy() {} + + void TypePolicy::Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { + data.types.push_back(std::make_pair(DeltaElement(ctx.diffStack.back().operation, policy->Data()), DeltaElement(ctx.diffStack.back().operation, TypeData::TYPENAME))); + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } + + std::any TypePolicy::DataInner() const { + return std::make_shared(data); + } + + void TypePolicy::InitializeTypePolicyHandlers() { + using namespace srcDispatch; + // start of policy + openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { + if(!depth) { + depth = ctx.depth; + data = TypeData{}; + data.lineNumber = ctx.startLineNumber; + CollectNamesHandler(); + CollectModifersHandler(); + CollectSpecifiersHandler(); + } + }; + + // end of policy + closeEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { + if(!depth || depth != ctx.depth) return; + + depth = 0; + NotifyAll(ctx); + InitializeTypePolicyHandlers(); + }; + } + + void TypePolicy::CollectNamesHandler() { + using namespace srcDispatch; + openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + if(!namePolicy) { + namePolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(namePolicy.get()); + }; + } + + void TypePolicy::CollectModifersHandler() { + using namespace srcDispatch; + openEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) + { + if(!depth) return; + + data.types.push_back(std::make_pair(DeltaElement(), DeltaElement(ctx.diffStack.back().operation, TypeData::NONE))); + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { + TypeData::TypeType modifier = TypeData::NONE; + if(ctx.currentToken == "*") { + modifier = TypeData::POINTER; + } else if(ctx.currentToken == "&") { + modifier = TypeData::REFERENCE; + } else if(ctx.currentToken == "&&") { + modifier = TypeData::RVALUE; + } + + data.types.back().second.Update(ctx.diffStack.back().operation, modifier); + }; + }; + + closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + NopCloseEvents({ParserState::tokenstring}); + }; + } + + void TypePolicy::CollectSpecifiersHandler() { + using namespace srcDispatch; + openEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + data.types.push_back(std::make_pair(DeltaElement(ctx.diffStack.back().operation, std::make_shared("")), DeltaElement(ctx.diffStack.back().operation, TypeData::SPECIFIER))); + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { + data.types.back().first.Append>(ctx.diffStack.back().operation, ctx.currentToken); + }; + }; + + closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { + if(!depth) return; + + NopCloseEvents({ParserState::tokenstring}); + }; + } + +} diff --git a/src/policy_classes/srcDiffTypePolicy.hpp b/src/policy_classes/srcDiffTypePolicy.hpp new file mode 100644 index 0000000..d58b06e --- /dev/null +++ b/src/policy_classes/srcDiffTypePolicy.hpp @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffTypePolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_TYPE_POLICY_HPP +#define INCLUDED_SRCDIFF_TYPE_POLICY_HPP + +#include +#include +#include + +#include + +namespace srcDiffDispatch { + + class NamePolicy; + + struct TypeData { + enum TypeType { TYPENAME, POINTER, REFERENCE, RVALUE, SPECIFIER, NONE }; + + unsigned int lineNumber; + std::vector, DeltaElement>> types; + + std::shared_ptr copyAs(srcDispatch::DiffOperation operation) const; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const; + }; + + class TypePolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + private: + TypeData data; + + std::unique_ptr namePolicy; + + public: + TypePolicy(std::initializer_list listeners); + ~TypePolicy(); + virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override; + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + protected: + virtual std::any DataInner() const override; + + private: + void InitializeTypePolicyHandlers(); + void CollectNamesHandler(); + void CollectModifersHandler(); + void CollectSpecifiersHandler(); + }; +} + +#endif diff --git a/src/policy_classes/srcDiffUnitPolicy.hpp b/src/policy_classes/srcDiffUnitPolicy.hpp new file mode 100644 index 0000000..d9c7a60 --- /dev/null +++ b/src/policy_classes/srcDiffUnitPolicy.hpp @@ -0,0 +1,161 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffUnitPolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + * + * Policy for srcDispatch + * Listens for both classes and functions + * Calls the ClassPolicy for class + * Calls the FunctionPolicy for function + * + */ +#ifndef INCLUDED_SRCDIFF_UNIT_POLICY_HPP +#define INCLUDED_SRCDIFF_UNIT_POLICY_HPP + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace srcDiffDispatch { + + struct UnitData { + std::vector>> classInfo; + std::vector>> functionInfo; + std::vector>> declStmtInfo; + }; + + class UnitPolicy : + public srcDispatch::EventListener, + public srcDispatch::PolicyDispatcher, + public srcDispatch::PolicyListener { + + public: + static const std::size_t MAX_DEPTH = (std::size_t)-1; + + UnitData data; + std::size_t unitDepth; + + std::unique_ptr declStmtPolicy; + std::unique_ptr functionPolicy; + std::unique_ptr classPolicy; + + public: + UnitPolicy(std::initializer_list listeners) + : srcDispatch::PolicyDispatcher(listeners), unitDepth(MAX_DEPTH) { + InitializeUnitPolicyHandlers(); + } + + ~UnitPolicy() {} + + void Notify(const srcDispatch::PolicyDispatcher* policy, + const srcDispatch::srcSAXEventContext& ctx) override { + // Save class and function information + if(typeid(ClassPolicy) == typeid(*policy)) { + srcDispatch::DiffOperation operation = ctx.diffStack.back().isConvert? srcDispatch::COMMON : ctx.diffStack.back().operation; + data.classInfo.emplace_back(operation, policy->Data()); + } else if(typeid(FunctionPolicy) == typeid(*policy)) { + data.functionInfo.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } else if(typeid(DeclStmtPolicy) == typeid(*policy)) { + data.declStmtInfo.emplace_back(ctx.diffStack.back().operation, policy->Data()); + } + ctx.dispatcher->RemoveListenerDispatch(nullptr); + } + + void NotifyWrite(const PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + protected: + std::any DataInner() const override { return std::make_shared(data); } + + private: + void InitializeUnitPolicyHandlers() { + using namespace srcDispatch; + + openEventMap[ParserState::unit] = [this](srcSAXEventContext& ctx) { + if (unitDepth == MAX_DEPTH && (!ctx.isArchive || ctx.depth > 0)) { + unitDepth = ctx.depth; + data = UnitData{}; + } + }; + + closeEventMap[ParserState::unit] = [this](srcSAXEventContext& ctx) { + if (unitDepth != ctx.depth) return; + + unitDepth = MAX_DEPTH; + NotifyAll(ctx); + }; + + // start of policy + std::function startClassPolicy = [this](srcSAXEventContext& ctx) { + if(depth == MAX_DEPTH) return; + + if (!classPolicy) { + classPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(classPolicy.get()); + }; + + openEventMap[ParserState::classn] = startClassPolicy; + openEventMap[ParserState::structn] = startClassPolicy; + + // end of policy + std::function endClassPolicy = [](srcSAXEventContext& ctx) {}; + + closeEventMap[ParserState::classn] = endClassPolicy; + closeEventMap[ParserState::structn] = endClassPolicy; + + // start function of policy + std::function startFunction = [this](srcSAXEventContext& ctx) { + if(depth == MAX_DEPTH) return; + + if (!functionPolicy) { + functionPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(functionPolicy.get()); + }; + + openEventMap[ParserState::function] = startFunction; + openEventMap[ParserState::functiondecl] = startFunction; + openEventMap[ParserState::constructor] = startFunction; + openEventMap[ParserState::constructordecl] = startFunction; + openEventMap[ParserState::destructor] = startFunction; + openEventMap[ParserState::destructordecl] = startFunction; + + // end of policy + std::function endFunction = [](srcSAXEventContext& ctx) {}; + + closeEventMap[ParserState::function] = endFunction; + closeEventMap[ParserState::functiondecl] = endFunction; + closeEventMap[ParserState::constructor] = endFunction; + closeEventMap[ParserState::constructordecl] = endFunction; + closeEventMap[ParserState::destructor] = endFunction; + closeEventMap[ParserState::destructordecl] = endFunction; + + openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { + if(depth == MAX_DEPTH) return; + + if (!declStmtPolicy) { + declStmtPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(declStmtPolicy.get()); + }; + + closeEventMap[ParserState::declstmt] = [](srcSAXEventContext& ctx) {}; + } + }; + +} + +#endif diff --git a/src/policy_classes/srcDiffWhilePolicy.hpp b/src/policy_classes/srcDiffWhilePolicy.hpp new file mode 100644 index 0000000..19b2815 --- /dev/null +++ b/src/policy_classes/srcDiffWhilePolicy.hpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffWhilePolicy.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_SRCDIFF_WHILE_POLICY_HPP +#define INCLUDED_SRCDIFF_SRCDIFF_WHILE_POLICY_HPP + +#include +#include +#include + +#include +#include +#include + +namespace srcDiffDispatch { + + struct WhileData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + + DeltaElement> condition; + DeltaElement> block; + + template + friend class DeltaElement; + private: + std::string ToString(srcDispatch::DiffOperation operation) const { + return condition.ToString(operation); + } + }; + + class WhilePolicy : public ConditionalPolicy { + public: + WhilePolicy(std::initializer_list listeners) + : ConditionalPolicy(listeners) {} + }; + +} + +#endif From b11618b49bc9f46ac10cb29e3a3ceaee47421b07 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 09:03:30 +0900 Subject: [PATCH 123/149] Rename files --- .../{srcDiffBlockPolicy.cpp => BlockPolicy.cpp} | 16 ++++++++-------- .../{srcDiffBlockPolicy.hpp => BlockPolicy.hpp} | 14 +++++++------- .../{srcDiffCallPolicy.cpp => CallPolicy.cpp} | 2 +- .../{srcDiffCallPolicy.hpp => CallPolicy.hpp} | 4 ++-- .../{srcDiffCasePolicy.hpp => CasePolicy.hpp} | 2 +- .../{srcDiffCatchPolicy.hpp => CatchPolicy.hpp} | 4 ++-- .../{srcDiffClassPolicy.cpp => ClassPolicy.cpp} | 2 +- .../{srcDiffClassPolicy.hpp => ClassPolicy.hpp} | 8 ++++---- ...ffConditionPolicy.hpp => ConditionPolicy.hpp} | 4 ++-- ...nditionalPolicy.hpp => ConditionalPolicy.hpp} | 4 ++-- ...rcDiffControlPolicy.hpp => ControlPolicy.hpp} | 8 ++++---- src/policy_classes/ConvertPlexerPolicy.hpp | 12 ++++++------ .../{srcDiffDeclPolicy.hpp => DeclPolicy.hpp} | 8 ++++---- ...DiffDeclStmtPolicy.hpp => DeclStmtPolicy.hpp} | 2 +- .../{srcDiffDoPolicy.hpp => DoPolicy.hpp} | 2 +- ...{srcDiffElseIfPolicy.hpp => ElseIfPolicy.hpp} | 2 +- .../{srcDiffElsePolicy.hpp => ElsePolicy.hpp} | 2 +- ...DiffExprStmtPolicy.hpp => ExprStmtPolicy.hpp} | 2 +- ...DiffExprTypePolicy.hpp => ExprTypePolicy.hpp} | 2 +- ...ExpressionPolicy.cpp => ExpressionPolicy.cpp} | 2 +- ...ExpressionPolicy.hpp => ExpressionPolicy.hpp} | 8 ++++---- .../{srcDiffForPolicy.hpp => ForPolicy.hpp} | 4 ++-- ...DiffFunctionPolicy.hpp => FunctionPolicy.hpp} | 10 +++++----- ...entsPolicy.cpp => GenericArgumentsPolicy.cpp} | 4 ++-- ...entsPolicy.hpp => GenericArgumentsPolicy.hpp} | 2 +- ...rcDiffGenericPolicy.cpp => GenericPolicy.cpp} | 6 +++--- ...rcDiffGenericPolicy.hpp => GenericPolicy.hpp} | 0 .../{srcDiffGotoPolicy.hpp => GotoPolicy.hpp} | 2 +- .../{srcDiffIfPolicy.hpp => IfPolicy.hpp} | 2 +- ...{srcDiffIfStmtPolicy.hpp => IfStmtPolicy.hpp} | 6 +++--- .../{srcDiffIncrPolicy.hpp => IncrPolicy.hpp} | 4 ++-- .../{srcDiffInitPolicy.hpp => InitPolicy.hpp} | 4 ++-- .../{srcDiffLabelPolicy.hpp => LabelPolicy.hpp} | 2 +- ...rcDiffLiteralPolicy.hpp => LiteralPolicy.hpp} | 0 .../{srcDiffNamePolicy.cpp => NamePolicy.cpp} | 4 ++-- .../{srcDiffNamePolicy.hpp => NamePolicy.hpp} | 4 ++-- ...DiffOperatorPolicy.hpp => OperatorPolicy.hpp} | 0 ...{srcDiffReturnPolicy.hpp => ReturnPolicy.hpp} | 2 +- ...{srcDiffSwitchPolicy.hpp => SwitchPolicy.hpp} | 2 +- .../{srcDiffThrowPolicy.hpp => ThrowPolicy.hpp} | 2 +- .../{srcDiffTryPolicy.hpp => TryPolicy.hpp} | 4 ++-- .../{srcDiffTypePolicy.cpp => TypePolicy.cpp} | 4 ++-- .../{srcDiffTypePolicy.hpp => TypePolicy.hpp} | 2 +- .../{srcDiffUnitPolicy.hpp => UnitPolicy.hpp} | 6 +++--- .../{srcDiffWhilePolicy.hpp => WhilePolicy.hpp} | 2 +- src/policy_classes/dispatcher | 0 46 files changed, 94 insertions(+), 94 deletions(-) rename src/policy_classes/{srcDiffBlockPolicy.cpp => BlockPolicy.cpp} (98%) rename src/policy_classes/{srcDiffBlockPolicy.hpp => BlockPolicy.hpp} (93%) rename src/policy_classes/{srcDiffCallPolicy.cpp => CallPolicy.cpp} (99%) rename src/policy_classes/{srcDiffCallPolicy.hpp => CallPolicy.hpp} (96%) rename src/policy_classes/{srcDiffCasePolicy.hpp => CasePolicy.hpp} (96%) rename src/policy_classes/{srcDiffCatchPolicy.hpp => CatchPolicy.hpp} (98%) rename src/policy_classes/{srcDiffClassPolicy.cpp => ClassPolicy.cpp} (93%) rename src/policy_classes/{srcDiffClassPolicy.hpp => ClassPolicy.hpp} (99%) rename src/policy_classes/{srcDiffConditionPolicy.hpp => ConditionPolicy.hpp} (98%) rename src/policy_classes/{srcDiffConditionalPolicy.hpp => ConditionalPolicy.hpp} (98%) rename src/policy_classes/{srcDiffControlPolicy.hpp => ControlPolicy.hpp} (97%) rename src/policy_classes/{srcDiffDeclPolicy.hpp => DeclPolicy.hpp} (98%) rename src/policy_classes/{srcDiffDeclStmtPolicy.hpp => DeclStmtPolicy.hpp} (99%) rename src/policy_classes/{srcDiffDoPolicy.hpp => DoPolicy.hpp} (96%) rename src/policy_classes/{srcDiffElseIfPolicy.hpp => ElseIfPolicy.hpp} (96%) rename src/policy_classes/{srcDiffElsePolicy.hpp => ElsePolicy.hpp} (96%) rename src/policy_classes/{srcDiffExprStmtPolicy.hpp => ExprStmtPolicy.hpp} (96%) rename src/policy_classes/{srcDiffExprTypePolicy.hpp => ExprTypePolicy.hpp} (98%) rename src/policy_classes/{srcDiffExpressionPolicy.cpp => ExpressionPolicy.cpp} (99%) rename src/policy_classes/{srcDiffExpressionPolicy.hpp => ExpressionPolicy.hpp} (94%) rename src/policy_classes/{srcDiffForPolicy.hpp => ForPolicy.hpp} (98%) rename src/policy_classes/{srcDiffFunctionPolicy.hpp => FunctionPolicy.hpp} (98%) rename src/policy_classes/{srcDiffGenericArgumentsPolicy.cpp => GenericArgumentsPolicy.cpp} (98%) rename src/policy_classes/{srcDiffGenericArgumentsPolicy.hpp => GenericArgumentsPolicy.hpp} (98%) rename src/policy_classes/{srcDiffGenericPolicy.cpp => GenericPolicy.cpp} (96%) rename src/policy_classes/{srcDiffGenericPolicy.hpp => GenericPolicy.hpp} (100%) rename src/policy_classes/{srcDiffGotoPolicy.hpp => GotoPolicy.hpp} (99%) rename src/policy_classes/{srcDiffIfPolicy.hpp => IfPolicy.hpp} (96%) rename src/policy_classes/{srcDiffIfStmtPolicy.hpp => IfStmtPolicy.hpp} (98%) rename src/policy_classes/{srcDiffIncrPolicy.hpp => IncrPolicy.hpp} (98%) rename src/policy_classes/{srcDiffInitPolicy.hpp => InitPolicy.hpp} (98%) rename src/policy_classes/{srcDiffLabelPolicy.hpp => LabelPolicy.hpp} (98%) rename src/policy_classes/{srcDiffLiteralPolicy.hpp => LiteralPolicy.hpp} (100%) rename src/policy_classes/{srcDiffNamePolicy.cpp => NamePolicy.cpp} (99%) rename src/policy_classes/{srcDiffNamePolicy.hpp => NamePolicy.hpp} (96%) rename src/policy_classes/{srcDiffOperatorPolicy.hpp => OperatorPolicy.hpp} (100%) rename src/policy_classes/{srcDiffReturnPolicy.hpp => ReturnPolicy.hpp} (96%) rename src/policy_classes/{srcDiffSwitchPolicy.hpp => SwitchPolicy.hpp} (96%) rename src/policy_classes/{srcDiffThrowPolicy.hpp => ThrowPolicy.hpp} (96%) rename src/policy_classes/{srcDiffTryPolicy.hpp => TryPolicy.hpp} (98%) rename src/policy_classes/{srcDiffTypePolicy.cpp => TypePolicy.cpp} (98%) rename src/policy_classes/{srcDiffTypePolicy.hpp => TypePolicy.hpp} (98%) rename src/policy_classes/{srcDiffUnitPolicy.hpp => UnitPolicy.hpp} (98%) rename src/policy_classes/{srcDiffWhilePolicy.hpp => WhilePolicy.hpp} (96%) delete mode 100644 src/policy_classes/dispatcher diff --git a/src/policy_classes/srcDiffBlockPolicy.cpp b/src/policy_classes/BlockPolicy.cpp similarity index 98% rename from src/policy_classes/srcDiffBlockPolicy.cpp rename to src/policy_classes/BlockPolicy.cpp index ac3b15d..d181dcb 100644 --- a/src/policy_classes/srcDiffBlockPolicy.cpp +++ b/src/policy_classes/BlockPolicy.cpp @@ -7,20 +7,20 @@ * This file is part of the srcDiffDispatch Infrastructure. */ -#include +#include #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace srcDiffDispatch { diff --git a/src/policy_classes/srcDiffBlockPolicy.hpp b/src/policy_classes/BlockPolicy.hpp similarity index 93% rename from src/policy_classes/srcDiffBlockPolicy.hpp rename to src/policy_classes/BlockPolicy.hpp index 74e5a72..30b7217 100644 --- a/src/policy_classes/srcDiffBlockPolicy.hpp +++ b/src/policy_classes/BlockPolicy.hpp @@ -13,13 +13,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffCallPolicy.cpp b/src/policy_classes/CallPolicy.cpp similarity index 99% rename from src/policy_classes/srcDiffCallPolicy.cpp rename to src/policy_classes/CallPolicy.cpp index 9ce66cd..2532b65 100644 --- a/src/policy_classes/srcDiffCallPolicy.cpp +++ b/src/policy_classes/CallPolicy.cpp @@ -7,7 +7,7 @@ * This file is part of the srcDiffDispatch Infrastructure. */ -#include +#include #include namespace srcDiffDispatch { diff --git a/src/policy_classes/srcDiffCallPolicy.hpp b/src/policy_classes/CallPolicy.hpp similarity index 96% rename from src/policy_classes/srcDiffCallPolicy.hpp rename to src/policy_classes/CallPolicy.hpp index e41405c..2700faf 100644 --- a/src/policy_classes/srcDiffCallPolicy.hpp +++ b/src/policy_classes/CallPolicy.hpp @@ -12,8 +12,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffCasePolicy.hpp b/src/policy_classes/CasePolicy.hpp similarity index 96% rename from src/policy_classes/srcDiffCasePolicy.hpp rename to src/policy_classes/CasePolicy.hpp index 30acc6c..6c4361a 100644 --- a/src/policy_classes/srcDiffCasePolicy.hpp +++ b/src/policy_classes/CasePolicy.hpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffCatchPolicy.hpp b/src/policy_classes/CatchPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffCatchPolicy.hpp rename to src/policy_classes/CatchPolicy.hpp index ef5deda..f5c8736 100644 --- a/src/policy_classes/srcDiffCatchPolicy.hpp +++ b/src/policy_classes/CatchPolicy.hpp @@ -15,8 +15,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffClassPolicy.cpp b/src/policy_classes/ClassPolicy.cpp similarity index 93% rename from src/policy_classes/srcDiffClassPolicy.cpp rename to src/policy_classes/ClassPolicy.cpp index 642b07c..a3f83ec 100644 --- a/src/policy_classes/srcDiffClassPolicy.cpp +++ b/src/policy_classes/ClassPolicy.cpp @@ -7,7 +7,7 @@ * This file is part of the srcDiffDispatch Infrastructure. */ -#include +#include namespace srcDiffDispatch { diff --git a/src/policy_classes/srcDiffClassPolicy.hpp b/src/policy_classes/ClassPolicy.hpp similarity index 99% rename from src/policy_classes/srcDiffClassPolicy.hpp rename to src/policy_classes/ClassPolicy.hpp index 10e7017..ce3dcd3 100644 --- a/src/policy_classes/srcDiffClassPolicy.hpp +++ b/src/policy_classes/ClassPolicy.hpp @@ -14,10 +14,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffConditionPolicy.hpp b/src/policy_classes/ConditionPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffConditionPolicy.hpp rename to src/policy_classes/ConditionPolicy.hpp index 19fcfee..0eefaf8 100644 --- a/src/policy_classes/srcDiffConditionPolicy.hpp +++ b/src/policy_classes/ConditionPolicy.hpp @@ -14,8 +14,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffConditionalPolicy.hpp b/src/policy_classes/ConditionalPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffConditionalPolicy.hpp rename to src/policy_classes/ConditionalPolicy.hpp index 365c6b1..63d4e17 100644 --- a/src/policy_classes/srcDiffConditionalPolicy.hpp +++ b/src/policy_classes/ConditionalPolicy.hpp @@ -14,8 +14,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffControlPolicy.hpp b/src/policy_classes/ControlPolicy.hpp similarity index 97% rename from src/policy_classes/srcDiffControlPolicy.hpp rename to src/policy_classes/ControlPolicy.hpp index b6a5dd5..6e28a73 100644 --- a/src/policy_classes/srcDiffControlPolicy.hpp +++ b/src/policy_classes/ControlPolicy.hpp @@ -14,10 +14,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/src/policy_classes/ConvertPlexerPolicy.hpp b/src/policy_classes/ConvertPlexerPolicy.hpp index d7af739..a747f5f 100644 --- a/src/policy_classes/ConvertPlexerPolicy.hpp +++ b/src/policy_classes/ConvertPlexerPolicy.hpp @@ -16,13 +16,13 @@ #include -#include -#include -#include +#include +#include +#include -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffDeclPolicy.hpp b/src/policy_classes/DeclPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffDeclPolicy.hpp rename to src/policy_classes/DeclPolicy.hpp index b52868b..9071e3a 100644 --- a/src/policy_classes/srcDiffDeclPolicy.hpp +++ b/src/policy_classes/DeclPolicy.hpp @@ -14,10 +14,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffDeclStmtPolicy.hpp b/src/policy_classes/DeclStmtPolicy.hpp similarity index 99% rename from src/policy_classes/srcDiffDeclStmtPolicy.hpp rename to src/policy_classes/DeclStmtPolicy.hpp index 83ff9c9..a316ae8 100644 --- a/src/policy_classes/srcDiffDeclStmtPolicy.hpp +++ b/src/policy_classes/DeclStmtPolicy.hpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffDoPolicy.hpp b/src/policy_classes/DoPolicy.hpp similarity index 96% rename from src/policy_classes/srcDiffDoPolicy.hpp rename to src/policy_classes/DoPolicy.hpp index 5b1ab66..8c0f99f 100644 --- a/src/policy_classes/srcDiffDoPolicy.hpp +++ b/src/policy_classes/DoPolicy.hpp @@ -11,7 +11,7 @@ #define INCLUDED_SRCDIFF_DO_POLICY_HPP #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffElseIfPolicy.hpp b/src/policy_classes/ElseIfPolicy.hpp similarity index 96% rename from src/policy_classes/srcDiffElseIfPolicy.hpp rename to src/policy_classes/ElseIfPolicy.hpp index 7cc5711..48f5311 100644 --- a/src/policy_classes/srcDiffElseIfPolicy.hpp +++ b/src/policy_classes/ElseIfPolicy.hpp @@ -11,7 +11,7 @@ #define INCLUDED_SRCDIFF_ELSEIF_POLICY_HPP #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffElsePolicy.hpp b/src/policy_classes/ElsePolicy.hpp similarity index 96% rename from src/policy_classes/srcDiffElsePolicy.hpp rename to src/policy_classes/ElsePolicy.hpp index 100c57d..a2a425f 100644 --- a/src/policy_classes/srcDiffElsePolicy.hpp +++ b/src/policy_classes/ElsePolicy.hpp @@ -11,7 +11,7 @@ #define INCLUDED_SRCDIFF_ELSE_POLICY_HPP #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffExprStmtPolicy.hpp b/src/policy_classes/ExprStmtPolicy.hpp similarity index 96% rename from src/policy_classes/srcDiffExprStmtPolicy.hpp rename to src/policy_classes/ExprStmtPolicy.hpp index fe6aed3..6d7a5fa 100644 --- a/src/policy_classes/srcDiffExprStmtPolicy.hpp +++ b/src/policy_classes/ExprStmtPolicy.hpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffExprTypePolicy.hpp b/src/policy_classes/ExprTypePolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffExprTypePolicy.hpp rename to src/policy_classes/ExprTypePolicy.hpp index 6bdefa4..a256e2e 100644 --- a/src/policy_classes/srcDiffExprTypePolicy.hpp +++ b/src/policy_classes/ExprTypePolicy.hpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffExpressionPolicy.cpp b/src/policy_classes/ExpressionPolicy.cpp similarity index 99% rename from src/policy_classes/srcDiffExpressionPolicy.cpp rename to src/policy_classes/ExpressionPolicy.cpp index a301c10..de05b10 100644 --- a/src/policy_classes/srcDiffExpressionPolicy.cpp +++ b/src/policy_classes/ExpressionPolicy.cpp @@ -7,7 +7,7 @@ * This file is part of the srcDiffDispatch Infrastructure. */ -#include +#include #include namespace srcDiffDispatch { diff --git a/src/policy_classes/srcDiffExpressionPolicy.hpp b/src/policy_classes/ExpressionPolicy.hpp similarity index 94% rename from src/policy_classes/srcDiffExpressionPolicy.hpp rename to src/policy_classes/ExpressionPolicy.hpp index 6458dbf..e655044 100644 --- a/src/policy_classes/srcDiffExpressionPolicy.hpp +++ b/src/policy_classes/ExpressionPolicy.hpp @@ -12,10 +12,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffForPolicy.hpp b/src/policy_classes/ForPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffForPolicy.hpp rename to src/policy_classes/ForPolicy.hpp index 968534d..04dd39b 100644 --- a/src/policy_classes/srcDiffForPolicy.hpp +++ b/src/policy_classes/ForPolicy.hpp @@ -14,8 +14,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffFunctionPolicy.hpp b/src/policy_classes/FunctionPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffFunctionPolicy.hpp rename to src/policy_classes/FunctionPolicy.hpp index 454da1b..3a5fd0a 100644 --- a/src/policy_classes/srcDiffFunctionPolicy.hpp +++ b/src/policy_classes/FunctionPolicy.hpp @@ -14,11 +14,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffGenericArgumentsPolicy.cpp b/src/policy_classes/GenericArgumentsPolicy.cpp similarity index 98% rename from src/policy_classes/srcDiffGenericArgumentsPolicy.cpp rename to src/policy_classes/GenericArgumentsPolicy.cpp index bba4975..ad7ef53 100644 --- a/src/policy_classes/srcDiffGenericArgumentsPolicy.cpp +++ b/src/policy_classes/GenericArgumentsPolicy.cpp @@ -7,9 +7,9 @@ * This file is part of the srcDiffDispatch Infrastructure. */ -#include +#include #include -#include +#include #include diff --git a/src/policy_classes/srcDiffGenericArgumentsPolicy.hpp b/src/policy_classes/GenericArgumentsPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffGenericArgumentsPolicy.hpp rename to src/policy_classes/GenericArgumentsPolicy.hpp index fd9587a..5f83c9d 100644 --- a/src/policy_classes/srcDiffGenericArgumentsPolicy.hpp +++ b/src/policy_classes/GenericArgumentsPolicy.hpp @@ -11,7 +11,7 @@ #define INCLUDED_SRCDIFF_GENERIC_ARGUMENTS_POLICY_HPP #include -#include +#include #include namespace srcDiffDispatch { diff --git a/src/policy_classes/srcDiffGenericPolicy.cpp b/src/policy_classes/GenericPolicy.cpp similarity index 96% rename from src/policy_classes/srcDiffGenericPolicy.cpp rename to src/policy_classes/GenericPolicy.cpp index e05ee30..31103e9 100644 --- a/src/policy_classes/srcDiffGenericPolicy.cpp +++ b/src/policy_classes/GenericPolicy.cpp @@ -7,11 +7,11 @@ * This file is part of the srcDiffDispatch Infrastructure. */ -#include +#include #include -#include -#include +#include +#include #include diff --git a/src/policy_classes/srcDiffGenericPolicy.hpp b/src/policy_classes/GenericPolicy.hpp similarity index 100% rename from src/policy_classes/srcDiffGenericPolicy.hpp rename to src/policy_classes/GenericPolicy.hpp diff --git a/src/policy_classes/srcDiffGotoPolicy.hpp b/src/policy_classes/GotoPolicy.hpp similarity index 99% rename from src/policy_classes/srcDiffGotoPolicy.hpp rename to src/policy_classes/GotoPolicy.hpp index 9c8f7ce..7b16e17 100644 --- a/src/policy_classes/srcDiffGotoPolicy.hpp +++ b/src/policy_classes/GotoPolicy.hpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffIfPolicy.hpp b/src/policy_classes/IfPolicy.hpp similarity index 96% rename from src/policy_classes/srcDiffIfPolicy.hpp rename to src/policy_classes/IfPolicy.hpp index ca67a1b..1869283 100644 --- a/src/policy_classes/srcDiffIfPolicy.hpp +++ b/src/policy_classes/IfPolicy.hpp @@ -11,7 +11,7 @@ #define INCLUDED_SRCDIFF_IF_POLICY_HPP #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffIfStmtPolicy.hpp b/src/policy_classes/IfStmtPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffIfStmtPolicy.hpp rename to src/policy_classes/IfStmtPolicy.hpp index 82b12ad..8d6d93c 100644 --- a/src/policy_classes/srcDiffIfStmtPolicy.hpp +++ b/src/policy_classes/IfStmtPolicy.hpp @@ -14,9 +14,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffIncrPolicy.hpp b/src/policy_classes/IncrPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffIncrPolicy.hpp rename to src/policy_classes/IncrPolicy.hpp index f3db2e1..de9af60 100644 --- a/src/policy_classes/srcDiffIncrPolicy.hpp +++ b/src/policy_classes/IncrPolicy.hpp @@ -14,8 +14,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffInitPolicy.hpp b/src/policy_classes/InitPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffInitPolicy.hpp rename to src/policy_classes/InitPolicy.hpp index 1a02ffb..4bf9bbc 100644 --- a/src/policy_classes/srcDiffInitPolicy.hpp +++ b/src/policy_classes/InitPolicy.hpp @@ -14,8 +14,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffLabelPolicy.hpp b/src/policy_classes/LabelPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffLabelPolicy.hpp rename to src/policy_classes/LabelPolicy.hpp index bfa48f2..b8b7dd8 100644 --- a/src/policy_classes/srcDiffLabelPolicy.hpp +++ b/src/policy_classes/LabelPolicy.hpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffLiteralPolicy.hpp b/src/policy_classes/LiteralPolicy.hpp similarity index 100% rename from src/policy_classes/srcDiffLiteralPolicy.hpp rename to src/policy_classes/LiteralPolicy.hpp diff --git a/src/policy_classes/srcDiffNamePolicy.cpp b/src/policy_classes/NamePolicy.cpp similarity index 99% rename from src/policy_classes/srcDiffNamePolicy.cpp rename to src/policy_classes/NamePolicy.cpp index 50a4ebf..d1c55df 100644 --- a/src/policy_classes/srcDiffNamePolicy.cpp +++ b/src/policy_classes/NamePolicy.cpp @@ -7,9 +7,9 @@ * This file is part of the srcDiffDispatch Infrastructure. */ -#include +#include #include -#include +#include #include diff --git a/src/policy_classes/srcDiffNamePolicy.hpp b/src/policy_classes/NamePolicy.hpp similarity index 96% rename from src/policy_classes/srcDiffNamePolicy.hpp rename to src/policy_classes/NamePolicy.hpp index 9979335..baeb014 100644 --- a/src/policy_classes/srcDiffNamePolicy.hpp +++ b/src/policy_classes/NamePolicy.hpp @@ -12,8 +12,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffOperatorPolicy.hpp b/src/policy_classes/OperatorPolicy.hpp similarity index 100% rename from src/policy_classes/srcDiffOperatorPolicy.hpp rename to src/policy_classes/OperatorPolicy.hpp diff --git a/src/policy_classes/srcDiffReturnPolicy.hpp b/src/policy_classes/ReturnPolicy.hpp similarity index 96% rename from src/policy_classes/srcDiffReturnPolicy.hpp rename to src/policy_classes/ReturnPolicy.hpp index c2f6181..aada20b 100644 --- a/src/policy_classes/srcDiffReturnPolicy.hpp +++ b/src/policy_classes/ReturnPolicy.hpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffSwitchPolicy.hpp b/src/policy_classes/SwitchPolicy.hpp similarity index 96% rename from src/policy_classes/srcDiffSwitchPolicy.hpp rename to src/policy_classes/SwitchPolicy.hpp index 2692021..e2ea1c7 100644 --- a/src/policy_classes/srcDiffSwitchPolicy.hpp +++ b/src/policy_classes/SwitchPolicy.hpp @@ -11,7 +11,7 @@ #define INCLUDED_SRCDIFF_SWITCH_POLICY_HPP #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffThrowPolicy.hpp b/src/policy_classes/ThrowPolicy.hpp similarity index 96% rename from src/policy_classes/srcDiffThrowPolicy.hpp rename to src/policy_classes/ThrowPolicy.hpp index 954c38f..2bdd076 100644 --- a/src/policy_classes/srcDiffThrowPolicy.hpp +++ b/src/policy_classes/ThrowPolicy.hpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffTryPolicy.hpp b/src/policy_classes/TryPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffTryPolicy.hpp rename to src/policy_classes/TryPolicy.hpp index 5daf023..40b140b 100644 --- a/src/policy_classes/srcDiffTryPolicy.hpp +++ b/src/policy_classes/TryPolicy.hpp @@ -15,8 +15,8 @@ #include #include -#include -#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffTypePolicy.cpp b/src/policy_classes/TypePolicy.cpp similarity index 98% rename from src/policy_classes/srcDiffTypePolicy.cpp rename to src/policy_classes/TypePolicy.cpp index 306af2e..6381899 100644 --- a/src/policy_classes/srcDiffTypePolicy.cpp +++ b/src/policy_classes/TypePolicy.cpp @@ -7,8 +7,8 @@ * This file is part of the srcDiffDispatch Infrastructure. */ -#include -#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffTypePolicy.hpp b/src/policy_classes/TypePolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffTypePolicy.hpp rename to src/policy_classes/TypePolicy.hpp index d58b06e..e3bf040 100644 --- a/src/policy_classes/srcDiffTypePolicy.hpp +++ b/src/policy_classes/TypePolicy.hpp @@ -11,7 +11,7 @@ #define INCLUDED_SRCDIFF_TYPE_POLICY_HPP #include -#include +#include #include #include diff --git a/src/policy_classes/srcDiffUnitPolicy.hpp b/src/policy_classes/UnitPolicy.hpp similarity index 98% rename from src/policy_classes/srcDiffUnitPolicy.hpp rename to src/policy_classes/UnitPolicy.hpp index d9c7a60..84c49c8 100644 --- a/src/policy_classes/srcDiffUnitPolicy.hpp +++ b/src/policy_classes/UnitPolicy.hpp @@ -16,9 +16,9 @@ #define INCLUDED_SRCDIFF_UNIT_POLICY_HPP #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/policy_classes/srcDiffWhilePolicy.hpp b/src/policy_classes/WhilePolicy.hpp similarity index 96% rename from src/policy_classes/srcDiffWhilePolicy.hpp rename to src/policy_classes/WhilePolicy.hpp index 19b2815..d57389e 100644 --- a/src/policy_classes/srcDiffWhilePolicy.hpp +++ b/src/policy_classes/WhilePolicy.hpp @@ -11,7 +11,7 @@ #define INCLUDED_SRCDIFF_SRCDIFF_WHILE_POLICY_HPP #include -#include +#include #include #include diff --git a/src/policy_classes/dispatcher b/src/policy_classes/dispatcher deleted file mode 100644 index e69de29..0000000 From 362a5827b799c2ee9fa5220c0cae38e7da5236e2 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 09:06:19 +0900 Subject: [PATCH 124/149] Add in testing --- test/.DS_Store | Bin 0 -> 6148 bytes test/CMakeLists.txt | 40 + test/suite/CMakeLists.txt | 26 + test/suite/testCall.cpp | 389 +++ test/suite/testCase.cpp | 190 ++ test/suite/testClass.cpp | 3124 +++++++++++++++++++++++++ test/suite/testClassConvert.cpp | 88 + test/suite/testCondition.cpp | 194 ++ test/suite/testConditionalConvert.cpp | 363 +++ test/suite/testControl.cpp | 1427 +++++++++++ test/suite/testDecl.cpp | 1241 ++++++++++ test/suite/testDeclStmt.cpp | 112 + test/suite/testDo.cpp | 161 ++ test/suite/testExprConvert.cpp | 268 +++ test/suite/testExprStmt.cpp | 185 ++ test/suite/testFor.cpp | 124 + test/suite/testFunction.cpp | 1194 ++++++++++ test/suite/testGoto.cpp | 323 +++ test/suite/testIfStmt.cpp | 478 ++++ test/suite/testLabel.cpp | 121 + test/suite/testReturn.cpp | 214 ++ test/suite/testSwitch.cpp | 164 ++ test/suite/testTemplate.cpp | 335 +++ test/suite/testThrow.cpp | 138 ++ test/suite/testTry.cpp | 509 ++++ test/suite/testWhile.cpp | 225 ++ test/util/srcDiffDispatchRunner.hpp | 95 + tests/CMakeLists.txt | 35 - tests/TestCallPolicy.cpp | 69 - tests/TestClassPolicy.cpp | 83 - tests/TestDecleTypePolicy.cpp | 150 -- tests/TestExpr.cpp | 65 - tests/TestFnSignaturePolicy.cpp | 140 -- tests/TestParamTypePolicy.cpp | 148 -- tests/TestSNLPolicy.cpp | 75 - tests/TestSrcSlicePolicy.cpp | 109 - 36 files changed, 11728 insertions(+), 874 deletions(-) create mode 100644 test/.DS_Store create mode 100644 test/CMakeLists.txt create mode 100644 test/suite/CMakeLists.txt create mode 100644 test/suite/testCall.cpp create mode 100644 test/suite/testCase.cpp create mode 100644 test/suite/testClass.cpp create mode 100644 test/suite/testClassConvert.cpp create mode 100644 test/suite/testCondition.cpp create mode 100644 test/suite/testConditionalConvert.cpp create mode 100644 test/suite/testControl.cpp create mode 100644 test/suite/testDecl.cpp create mode 100644 test/suite/testDeclStmt.cpp create mode 100644 test/suite/testDo.cpp create mode 100644 test/suite/testExprConvert.cpp create mode 100644 test/suite/testExprStmt.cpp create mode 100644 test/suite/testFor.cpp create mode 100644 test/suite/testFunction.cpp create mode 100644 test/suite/testGoto.cpp create mode 100644 test/suite/testIfStmt.cpp create mode 100644 test/suite/testLabel.cpp create mode 100644 test/suite/testReturn.cpp create mode 100644 test/suite/testSwitch.cpp create mode 100644 test/suite/testTemplate.cpp create mode 100644 test/suite/testThrow.cpp create mode 100644 test/suite/testTry.cpp create mode 100644 test/suite/testWhile.cpp create mode 100644 test/util/srcDiffDispatchRunner.hpp delete mode 100644 tests/CMakeLists.txt delete mode 100644 tests/TestCallPolicy.cpp delete mode 100644 tests/TestClassPolicy.cpp delete mode 100644 tests/TestDecleTypePolicy.cpp delete mode 100644 tests/TestExpr.cpp delete mode 100644 tests/TestFnSignaturePolicy.cpp delete mode 100644 tests/TestParamTypePolicy.cpp delete mode 100644 tests/TestSNLPolicy.cpp delete mode 100644 tests/TestSrcSlicePolicy.cpp diff --git a/test/.DS_Store b/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1cbbab5036fbdccef0e581189e2f4cb89f109a30 GIT binary patch literal 6148 zcmeHKK}#D!6n+zf--54PR_T2s$ zul*(cJMH&oCX#49Dk$&4oA1q=_hy)HmU%lwq`JfY7EzOkJSbzWf#yHL_IpG8i7T$h?5@T z%u7mcMPA<@8IOt!H|Ov8B1?<1-TtF$3-!gNWpCMA@s7eXJqpXH92VVZ@Qr()wa((H z9mQYLWYlZE+}C*-rFk+i328q;$oH>l-q)k99_IbRN0^8(APfit56FPK+q{(rTtlW7284m9$pGIEK9n(VSXnez2O9GP z0M_9)0-JvmImdSxIIJvU1fpyz(55Q)#85UJe&59f4l9c`os@fgD7Uh5FBD}~$Natt zCly$fRu~Wl<{4P9-6q%n!~5U=^GVVZ284lU#ek|Gga=)0$<@|7o8wyRLyw^>99LPq kNr7QXF=DwCuS1Q%@3R36999 $ $ LibXml2::LibXml2 Boost::boost ${ARGN}) + add_test(NAME ${TEST_NAME} COMMAND $) + set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +endmacro() + +add_subdirectory(suite) diff --git a/test/suite/CMakeLists.txt b/test/suite/CMakeLists.txt new file mode 100644 index 0000000..b44c6dc --- /dev/null +++ b/test/suite/CMakeLists.txt @@ -0,0 +1,26 @@ +## +# CMakeLists.txt +# +# Copyright (C) 2025-2025 srcML, LLC. (www.srcDiff.org) +# +# This file is part of the srcDiffDispatch. +# +# The srcDiffDispatch is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# The srcDiffDispatch is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with the srcDiffDispatch; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +file(GLOB TESTS *.cpp) + +foreach(TEST IN ITEMS ${TESTS}) + add_unit_test(${TEST}) +endforeach() diff --git a/test/suite/testCall.cpp b/test/suite/testCall.cpp new file mode 100644 index 0000000..74b463d --- /dev/null +++ b/test/suite/testCall.cpp @@ -0,0 +1,389 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testCall.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE call tests +#include + +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(call_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { f(); }", "void foo() { f(); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(stmt.expr.IsCommon()); + BOOST_TEST(stmt.expr->expr.size() == 1); + BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); + + const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + BOOST_TEST(call.name.ToString() == "f"); + BOOST_TEST(call.arguments.size() == 0); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f()"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f()"); + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(call_insert_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { f(); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(stmt.expr.IsInsert()); + BOOST_TEST(stmt.expr->expr.size() == 1); + BOOST_TEST(stmt.expr->expr.at(0).IsInsert()); + + const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + BOOST_TEST(call.name.ToString() == "|f"); + BOOST_TEST(call.arguments.size() == 0); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "|f()"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|f()"); + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(call_delete_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { f(); }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(stmt.expr.IsDelete()); + BOOST_TEST(stmt.expr->expr.size() == 1); + BOOST_TEST(stmt.expr->expr.at(0).IsDelete()); + + const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + BOOST_TEST(call.name.ToString() == "f|"); + BOOST_TEST(call.arguments.size() == 0); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f()|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f()|"); + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(call_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { a = b; }", "void foo() { a = b + f(); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(stmt.expr.IsCommon()); + BOOST_TEST(stmt.expr->expr.size() == 5); + BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); + BOOST_TEST(stmt.expr->expr.at(1).IsCommon()); + BOOST_TEST(stmt.expr->expr.at(2).IsCommon()); + BOOST_TEST(stmt.expr->expr.at(3).IsInsert()); + BOOST_TEST(stmt.expr->expr.at(4).IsInsert()); + + const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(4).GetElement()); + BOOST_TEST(call.name.ToString() == "|f"); + BOOST_TEST(call.arguments.size() == 0); + BOOST_TEST(stmt.expr->expr.at(4).ToString>() == "|f()"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a = b|a = b + f()"); + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(call_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { a = b + f(); }", "void foo() { a = b; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(stmt.expr.IsCommon()); + BOOST_TEST(stmt.expr->expr.size() == 5); + BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); + BOOST_TEST(stmt.expr->expr.at(1).IsCommon()); + BOOST_TEST(stmt.expr->expr.at(2).IsCommon()); + BOOST_TEST(stmt.expr->expr.at(3).IsDelete()); + BOOST_TEST(stmt.expr->expr.at(4).IsDelete()); + + const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(4).GetElement()); + BOOST_TEST(call.name.ToString() == "f|"); + BOOST_TEST(call.arguments.size() == 0); + BOOST_TEST(stmt.expr->expr.at(4).ToString>() == "f()|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a = b + f()|a = b"); + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +// args +BOOST_AUTO_TEST_CASE(call_arg_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { f(a); }", "void foo() { f(a); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(stmt.expr.IsCommon()); + BOOST_TEST(stmt.expr->expr.size() == 1); + BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); + + const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + BOOST_TEST(call.name.ToString() == "f"); + BOOST_TEST(call.arguments.size() == 1); + BOOST_TEST(call.arguments.at(0).IsCommon()); + BOOST_TEST(call.arguments.at(0).ToString() == "a"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a)"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a)"); + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(call_arg_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { f(); }", "void foo() { f(a); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(stmt.expr.IsCommon()); + BOOST_TEST(stmt.expr->expr.size() == 1); + BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); + + const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + BOOST_TEST(call.name.ToString() == "f"); + BOOST_TEST(call.arguments.size() == 1); + BOOST_TEST(call.arguments.at(0).IsInsert()); + BOOST_TEST(call.arguments.at(0).ToString() == "|a"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f()|f(a)"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f()|f(a)"); + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(call_arg_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { f(a); }", "void foo() { f(); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(stmt.expr.IsCommon()); + BOOST_TEST(stmt.expr->expr.size() == 1); + BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); + + const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + BOOST_TEST(call.name.ToString() == "f"); + BOOST_TEST(call.arguments.size() == 1); + BOOST_TEST(call.arguments.at(0).IsDelete()); + BOOST_TEST(call.arguments.at(0).ToString() == "a|"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a)|f()"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a)|f()"); + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(call_arg_insert_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { f(a); }", "void foo() { f(0, a); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(stmt.expr.IsCommon()); + BOOST_TEST(stmt.expr->expr.size() == 1); + BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); + + const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + BOOST_TEST(call.name.ToString() == "f"); + BOOST_TEST(call.arguments.size() == 2); + BOOST_TEST(call.arguments.at(0).IsInsert()); + BOOST_TEST(call.arguments.at(0).ToString() == "|0"); + BOOST_TEST(call.arguments.at(1).IsCommon()); + BOOST_TEST(call.arguments.at(1).ToString() == "a"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a)|f(0, a)"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a)|f(0, a)"); + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(call_arg_insert_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { f(a); }", "void foo() { f(a, b + 1); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(stmt.expr.IsCommon()); + BOOST_TEST(stmt.expr->expr.size() == 1); + BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); + + const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + BOOST_TEST(call.name.ToString() == "f"); + BOOST_TEST(call.arguments.size() == 2); + BOOST_TEST(call.arguments.at(0).IsCommon()); + BOOST_TEST(call.arguments.at(0).ToString() == "a"); + BOOST_TEST(call.arguments.at(1).IsInsert()); + BOOST_TEST(call.arguments.at(1).ToString() == "|b + 1"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a)|f(a, b + 1)"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a)|f(a, b + 1)"); + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + + + +BOOST_AUTO_TEST_CASE(call_arg_delete_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { f(0, a); }", "void foo() { f(a); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(stmt.expr.IsCommon()); + BOOST_TEST(stmt.expr->expr.size() == 1); + BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); + + const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + BOOST_TEST(call.name.ToString() == "f"); + BOOST_TEST(call.arguments.size() == 2); + BOOST_TEST(call.arguments.at(0).IsDelete()); + BOOST_TEST(call.arguments.at(0).ToString() == "0|"); + BOOST_TEST(call.arguments.at(1).IsCommon()); + BOOST_TEST(call.arguments.at(1).ToString() == "a"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(0, a)|f(a)"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(0, a)|f(a)"); + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(call_arg_delete_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { f(a, b + 1); }", "void foo() { f(a); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(stmt.expr.IsCommon()); + BOOST_TEST(stmt.expr->expr.size() == 1); + BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); + + const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + BOOST_TEST(call.name.ToString() == "f"); + BOOST_TEST(call.arguments.size() == 2); + BOOST_TEST(call.arguments.at(0).IsCommon()); + BOOST_TEST(call.arguments.at(0).ToString() == "a"); + BOOST_TEST(call.arguments.at(1).IsDelete()); + BOOST_TEST(call.arguments.at(1).ToString() == "b + 1|"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a, b + 1)|f(a)"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a, b + 1)|f(a)"); + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testCase.cpp b/test/suite/testCase.cpp new file mode 100644 index 0000000..4f8fbbd --- /dev/null +++ b/test/suite/testCase.cpp @@ -0,0 +1,190 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testCase.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE case_expr tests +#include + +#include + +#include +#include +#include + +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(block_common_case) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { switch(1) { case foo; } }", "void foo() { switch(1) { case foo: }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + + const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(switchData.block.IsCommon()); + BOOST_TEST(switchData.block->statements.size() == 0); + + BOOST_TEST(switchData.block->cases.size() == 1); + BOOST_TEST(switchData.block->cases.at(0).IsCommon()); + BOOST_TEST(switchData.block->cases.at(0)->expr.IsCommon()); + BOOST_TEST(switchData.block->cases.at(0)->expr->expr.size() == 1); + BOOST_TEST(switchData.block->cases.at(0)->expr->expr.at(0).IsCommon()); + BOOST_TEST(switchData.block->cases.at(0).ToString() == "foo"); + + BOOST_TEST(switchData.block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_case) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { switch(1) {} }", "void foo() { switch(1) { case foo: }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + + const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(switchData.block.IsCommon()); + BOOST_TEST(switchData.block->statements.size() == 0); + + BOOST_TEST(switchData.block->cases.size() == 1); + BOOST_TEST(switchData.block->cases.at(0).IsInsert()); + BOOST_TEST(switchData.block->cases.at(0)->expr.IsInsert()); + BOOST_TEST(switchData.block->cases.at(0)->expr->expr.size() == 1); + BOOST_TEST(switchData.block->cases.at(0)->expr->expr.at(0).IsInsert()); + BOOST_TEST(switchData.block->cases.at(0).ToString() == "|foo"); + + BOOST_TEST(switchData.block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_case) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { switch(1) { case foo: } }", "void foo() { switch(1) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + + const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(switchData.block.IsCommon()); + BOOST_TEST(switchData.block->statements.size() == 0); + + BOOST_TEST(switchData.block->cases.size() == 1); + BOOST_TEST(switchData.block->cases.at(0).IsDelete()); + BOOST_TEST(switchData.block->cases.at(0)->expr.IsDelete()); + BOOST_TEST(switchData.block->cases.at(0)->expr->expr.size() == 1); + BOOST_TEST(switchData.block->cases.at(0)->expr->expr.at(0).IsDelete()); + BOOST_TEST(switchData.block->cases.at(0).ToString() == "foo|"); + + BOOST_TEST(switchData.block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_case_rename) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { switch(1) { case foo: } }", "void foo() { switch(1) { case bar: } }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + + const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(switchData.block.IsCommon()); + BOOST_TEST(switchData.block->statements.size() == 0); + + BOOST_TEST(switchData.block->cases.size() == 1); + BOOST_TEST(switchData.block->cases.at(0).IsCommon()); + BOOST_TEST(switchData.block->cases.at(0)->expr.IsCommon()); + BOOST_TEST(switchData.block->cases.at(0)->expr->expr.size() == 1); + BOOST_TEST(switchData.block->cases.at(0)->expr->expr.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(switchData.block->cases.at(0)->expr->expr.at(0).GetElement())->name.IsChange()); + BOOST_TEST(switchData.block->cases.at(0).ToString() == "foo|bar"); + + BOOST_TEST(switchData.block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_case_expr_replace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { switch(1) { case 0: } }", "void foo() { switch(1) { case foo: } }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + + const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(switchData.block.IsCommon()); + BOOST_TEST(switchData.block->statements.size() == 0); + + BOOST_TEST(switchData.block->cases.size() == 1); + BOOST_TEST(switchData.block->cases.at(0).IsCommon()); + BOOST_TEST(switchData.block->cases.at(0)->expr.IsChange()); + BOOST_TEST(switchData.block->cases.at(0)->expr.GetOriginal()->expr.size() == 1); + BOOST_TEST(switchData.block->cases.at(0)->expr.GetOriginal()->expr.at(0).IsDelete()); + BOOST_TEST(switchData.block->cases.at(0)->expr.GetModified()->expr.size() == 1); + BOOST_TEST(switchData.block->cases.at(0)->expr.GetModified()->expr.at(0).IsInsert()); + BOOST_TEST(switchData.block->cases.at(0).ToString() == "0|foo"); + + BOOST_TEST(switchData.block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testClass.cpp b/test/suite/testClass.cpp new file mode 100644 index 0000000..9a8fb88 --- /dev/null +++ b/test/suite/testClass.cpp @@ -0,0 +1,3124 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testClass.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE class_and_struct tests +#include + +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +// Do I need to collect class decl? + +BOOST_AUTO_TEST_CASE(class_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo {};", "class foo {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(struct_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("struct foo {};", "struct bar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::STRUCT); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo|bar"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("", "class foo {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsInsert()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsInsert()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsInsert()); + BOOST_TEST(classData->name.ToString() == "|foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo {};", ""); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsDelete()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsDelete()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsDelete()); + BOOST_TEST(classData->name.ToString() == "foo|"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_rename) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo {};", "class bar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo|bar"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +// parents +BOOST_AUTO_TEST_CASE(class_parent_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo : bar {};", "class foo : bar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.size() == 1); + BOOST_TEST(classData->parents.at(0). IsCommon()); + BOOST_TEST(classData->parents.at(0)->name); + BOOST_TEST(classData->parents.at(0)->name.IsCommon()); + BOOST_TEST(classData->parents.at(0)->name.ToString() == "bar"); + BOOST_TEST(!classData->parents.at(0)->isVirtual); + BOOST_TEST(!classData->parents.at(0)->accessSpecifier); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_parent_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo {};", "class foo : bar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.size() == 1); + BOOST_TEST(classData->parents.at(0).IsInsert()); + BOOST_TEST(classData->parents.at(0)->name); + BOOST_TEST(classData->parents.at(0)->name.IsInsert()); + BOOST_TEST(classData->parents.at(0)->name.ToString() == "|bar"); + BOOST_TEST(!classData->parents.at(0)->isVirtual); + BOOST_TEST(!classData->parents.at(0)->accessSpecifier); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_parent_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo : bar {};", "class foo {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.size() == 1); + BOOST_TEST(classData->parents.at(0).IsDelete()); + BOOST_TEST(classData->parents.at(0)->name); + BOOST_TEST(classData->parents.at(0)->name.IsDelete()); + BOOST_TEST(classData->parents.at(0)->name.ToString() == "bar|"); + BOOST_TEST(!classData->parents.at(0)->isVirtual); + BOOST_TEST(!classData->parents.at(0)->accessSpecifier); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_parent_rename) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo : public bar {};", "class foo : public foobar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.size() == 1); + BOOST_TEST(classData->parents.at(0).IsCommon()); + BOOST_TEST(classData->parents.at(0)->name); + BOOST_TEST(classData->parents.at(0)->name.IsCommon()); + BOOST_TEST(classData->parents.at(0)->name.ToString() == "bar|foobar"); + BOOST_TEST(!classData->parents.at(0)->isVirtual); + BOOST_TEST(bool(classData->parents.at(0)->accessSpecifier)); + BOOST_TEST(classData->parents.at(0)->accessSpecifier.IsCommon()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_parent_common_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo : public bar {};", "class foo : public bar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.size() == 1); + BOOST_TEST(classData->parents.at(0).IsCommon()); + BOOST_TEST(classData->parents.at(0)->name); + BOOST_TEST(classData->parents.at(0)->name.IsCommon()); + BOOST_TEST(classData->parents.at(0)->name.ToString() == "bar"); + BOOST_TEST(!classData->parents.at(0)->isVirtual); + BOOST_TEST(bool(classData->parents.at(0)->accessSpecifier)); + BOOST_TEST(classData->parents.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->parents.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_parent_insert_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo : bar {};", "class foo : public bar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.size() == 1); + BOOST_TEST(classData->parents.at(0).IsCommon()); + BOOST_TEST(classData->parents.at(0)->name); + BOOST_TEST(classData->parents.at(0)->name.IsCommon()); + BOOST_TEST(classData->parents.at(0)->name.ToString() == "bar"); + BOOST_TEST(!classData->parents.at(0)->isVirtual); + BOOST_TEST(bool(classData->parents.at(0)->accessSpecifier)); + BOOST_TEST(classData->parents.at(0)->accessSpecifier.IsInsert()); + BOOST_TEST(classData->parents.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_parent_delete_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo : public bar {};", "class foo : bar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.size() == 1); + BOOST_TEST(classData->parents.at(0).IsCommon()); + BOOST_TEST(classData->parents.at(0)->name); + BOOST_TEST(classData->parents.at(0)->name.IsCommon()); + BOOST_TEST(classData->parents.at(0)->name.ToString() == "bar"); + BOOST_TEST(!classData->parents.at(0)->isVirtual); + BOOST_TEST(bool(classData->parents.at(0)->accessSpecifier)); + BOOST_TEST(classData->parents.at(0)->accessSpecifier.IsDelete()); + BOOST_TEST(classData->parents.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_parent_change_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo : public bar {};", "class foo : private bar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.size() == 1); + BOOST_TEST(classData->parents.at(0).IsCommon()); + BOOST_TEST(classData->parents.at(0)->name); + BOOST_TEST(classData->parents.at(0)->name.IsCommon()); + BOOST_TEST(classData->parents.at(0)->name.ToString() == "bar"); + BOOST_TEST(!classData->parents.at(0)->isVirtual); + BOOST_TEST(bool(classData->parents.at(0)->accessSpecifier)); + BOOST_TEST(classData->parents.at(0)->accessSpecifier.IsChange()); + BOOST_TEST(classData->parents.at(0)->accessSpecifier.GetOriginal() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->parents.at(0)->accessSpecifier.GetModified() == AccessSpecifier::PRIVATE); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_parent_common_virtual) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo : virtual bar {};", "class foo : virtual bar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.size() == 1); + BOOST_TEST(classData->parents.at(0).IsCommon()); + BOOST_TEST(classData->parents.at(0)->name); + BOOST_TEST(classData->parents.at(0)->name.IsCommon()); + BOOST_TEST(classData->parents.at(0)->name.ToString() == "bar"); + BOOST_TEST(bool(classData->parents.at(0)->isVirtual)); + BOOST_TEST(classData->parents.at(0)->isVirtual.IsCommon()); + BOOST_TEST(!classData->parents.at(0)->accessSpecifier); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_parent_insert_virtual) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo : bar {};", "class foo : virtual bar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.size() == 1); + BOOST_TEST(classData->parents.at(0).IsCommon()); + BOOST_TEST(classData->parents.at(0)->name); + BOOST_TEST(classData->parents.at(0)->name.IsCommon()); + BOOST_TEST(classData->parents.at(0)->name.ToString() == "bar"); + BOOST_TEST(bool(classData->parents.at(0)->isVirtual)); + BOOST_TEST(classData->parents.at(0)->isVirtual.IsInsert()); + BOOST_TEST(!classData->parents.at(0)->accessSpecifier); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_parent_delete_virtual) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo : virtual bar {};", "class foo : bar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.size() == 1); + BOOST_TEST(classData->parents.at(0).IsCommon()); + BOOST_TEST(classData->parents.at(0)->name); + BOOST_TEST(classData->parents.at(0)->name.IsCommon()); + BOOST_TEST(classData->parents.at(0)->name.ToString() == "bar"); + BOOST_TEST(bool(classData->parents.at(0)->isVirtual)); + BOOST_TEST(classData->parents.at(0)->isVirtual.IsDelete()); + BOOST_TEST(!classData->parents.at(0)->accessSpecifier); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_parent_replace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo : bar {};", "class foo : foobar {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.size() == 2); + + BOOST_TEST(classData->parents.at(0).IsDelete()); + BOOST_TEST(classData->parents.at(0)->name); + BOOST_TEST(classData->parents.at(0)->name.IsDelete()); + BOOST_TEST(classData->parents.at(0)->name.ToString() == "bar|"); + BOOST_TEST(!classData->parents.at(0)->isVirtual); + BOOST_TEST(!classData->parents.at(0)->accessSpecifier); + + BOOST_TEST(classData->parents.at(1).IsInsert()); + BOOST_TEST(classData->parents.at(1)->name); + BOOST_TEST(classData->parents.at(1)->name.IsInsert()); + BOOST_TEST(classData->parents.at(1)->name.ToString() == "|foobar"); + BOOST_TEST(!classData->parents.at(1)->isVirtual); + BOOST_TEST(!classData->parents.at(1)->accessSpecifier); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +// fields +BOOST_AUTO_TEST_CASE(class_fields_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { int i; };", "class foo { int i; };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.size() == 1); + BOOST_TEST(classData->fields.at(0).IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.size() == 1); + BOOST_TEST(classData->fields.at(0)->decls.at(0).IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->fields.at(0).ToString() == "int i"); + + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_fields_private) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: int i; };", "class foo { private: int i; };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.size() == 1); + BOOST_TEST(classData->fields.at(0).IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.size() == 1); + BOOST_TEST(classData->fields.at(0)->decls.at(0).IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->fields.at(0).ToString() == "int i"); + + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_fields_private_default) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { int i; };", "class foo { private: int i; };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.size() == 1); + BOOST_TEST(classData->fields.at(0).IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.size() == 1); + BOOST_TEST(classData->fields.at(0)->decls.at(0).IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->fields.at(0).ToString() == "int i"); + + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_fields_public) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: int i; };", "class foo { public: int i; };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.size() == 1); + BOOST_TEST(classData->fields.at(0).IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.size() == 1); + BOOST_TEST(classData->fields.at(0)->decls.at(0).IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->fields.at(0).ToString() == "int i"); + + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_fields_protected) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { protected: int i; };", "class foo { protected: int i; };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.size() == 1); + BOOST_TEST(classData->fields.at(0).IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.size() == 1); + BOOST_TEST(classData->fields.at(0)->decls.at(0).IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PROTECTED); + BOOST_TEST(classData->fields.at(0).ToString() == "int i"); + + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_fields_access_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: int i; };", "class foo { protected: int i; };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.size() == 1); + BOOST_TEST(classData->fields.at(0).IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.size() == 1); + BOOST_TEST(classData->fields.at(0)->decls.at(0).IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.IsChange()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetOriginal() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetModified() == AccessSpecifier::PROTECTED); + BOOST_TEST(classData->fields.at(0).ToString() == "int i"); + + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_fields_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: };", "class foo { private: int i; };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.size() == 1); + BOOST_TEST(classData->fields.at(0).IsInsert()); + BOOST_TEST(classData->fields.at(0)->decls.size() == 1); + BOOST_TEST(classData->fields.at(0)->decls.at(0).IsInsert()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->fields.at(0).ToString() == "|int i"); + + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_fields_insert_with_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: };", "class foo { private: int i; };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.size() == 1); + BOOST_TEST(classData->fields.at(0).IsInsert()); + BOOST_TEST(classData->fields.at(0)->decls.size() == 1); + BOOST_TEST(classData->fields.at(0)->decls.at(0).IsInsert()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.IsInsert()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->fields.at(0).ToString() == "|int i"); + + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_fields_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: int i; };", "class foo { private: };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.size() == 1); + BOOST_TEST(classData->fields.at(0).IsDelete()); + BOOST_TEST(classData->fields.at(0)->decls.size() == 1); + BOOST_TEST(classData->fields.at(0)->decls.at(0).IsDelete()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->fields.at(0).ToString() == "int i|"); + + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_fields_delete_with_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: int i; };", "class foo { private: };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.size() == 1); + BOOST_TEST(classData->fields.at(0).IsDelete()); + BOOST_TEST(classData->fields.at(0)->decls.size() == 1); + BOOST_TEST(classData->fields.at(0)->decls.at(0).IsDelete()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.IsDelete()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->fields.at(0).ToString() == "int i|"); + + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_fields_replace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: int i; };", "class foo { private: double d; };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.size() == 2); + BOOST_TEST(classData->fields.at(0).IsDelete()); + BOOST_TEST(classData->fields.at(0)->decls.size() == 1); + BOOST_TEST(classData->fields.at(0)->decls.at(0).IsDelete()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->fields.at(0).ToString() == "int i|"); + + BOOST_TEST(classData->fields.at(1).IsInsert()); + BOOST_TEST(classData->fields.at(1)->decls.size() == 1); + BOOST_TEST(classData->fields.at(1)->decls.at(0).IsInsert()); + BOOST_TEST(classData->fields.at(1)->decls.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->fields.at(1)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->fields.at(1).ToString() == "|double d"); + + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_fields_replace_with_namespace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: int i; };", "class foo { private: double d; };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.size() == 2); + BOOST_TEST(classData->fields.at(0).IsDelete()); + BOOST_TEST(classData->fields.at(0)->decls.size() == 1); + BOOST_TEST(classData->fields.at(0)->decls.at(0).IsDelete()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.IsDelete()); + BOOST_TEST(classData->fields.at(0)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->fields.at(0).ToString() == "int i|"); + + BOOST_TEST(classData->fields.at(1).IsInsert()); + BOOST_TEST(classData->fields.at(1)->decls.size() == 1); + BOOST_TEST(classData->fields.at(1)->decls.at(0).IsInsert()); + BOOST_TEST(classData->fields.at(1)->decls.at(0)->accessSpecifier.IsInsert()); + BOOST_TEST(classData->fields.at(1)->decls.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->fields.at(1).ToString() == "|double d"); + + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +// constructor +BOOST_AUTO_TEST_CASE(class_constructors_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { foo() {} };", "class foo { foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->constructors.size() == 1); + BOOST_TEST(classData->constructors.at(0).IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->constructors.at(0).ToString() == "foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_constructors_private) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: foo() {} };", "class foo { private: foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->constructors.size() == 1); + BOOST_TEST(classData->constructors.at(0).IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->constructors.at(0).ToString() == "foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_constructors_private_default) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { foo() {} };", "class foo { private: foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->constructors.size() == 1); + BOOST_TEST(classData->constructors.at(0).IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->constructors.at(0).ToString() == "foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_constructors_public) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: foo() {} };", "class foo { public: foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->constructors.size() == 1); + BOOST_TEST(classData->constructors.at(0).IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->constructors.at(0).ToString() == "foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_constructors_protected) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { protected: foo() {} };", "class foo { protected: foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->constructors.size() == 1); + BOOST_TEST(classData->constructors.at(0).IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PROTECTED); + BOOST_TEST(classData->constructors.at(0).ToString() == "foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_constructors_access_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: foo() {} };", "class foo { protected: foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->constructors.size() == 1); + BOOST_TEST(classData->constructors.at(0).IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.IsChange()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetOriginal() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetModified() == AccessSpecifier::PROTECTED); + BOOST_TEST(classData->constructors.at(0).ToString() == "foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_constructors_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: };", "class foo { private: foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->constructors.size() == 1); + BOOST_TEST(classData->constructors.at(0).IsInsert()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->constructors.at(0).ToString() == "|foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_constructors_insert_with_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: };", "class foo { private: foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->constructors.size() == 1); + BOOST_TEST(classData->constructors.at(0).IsInsert()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.IsInsert()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->constructors.at(0).ToString() == "|foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_constructors_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: foo() {} };", "class foo { private: };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->constructors.size() == 1); + BOOST_TEST(classData->constructors.at(0).IsDelete()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->constructors.at(0).ToString() == "foo() {}|"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_constructors_delete_with_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: foo() {} };", "class foo { private: };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->constructors.size() == 1); + BOOST_TEST(classData->constructors.at(0).IsDelete()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.IsDelete()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->constructors.at(0).ToString() == "foo() {}|"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_constructors_replace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: foo() { ab; } public: void f() { c; d; } };", "class bar { private: bar() { b; } public: void f() { c; d; } };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo|bar"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->constructors.size() == 2); + BOOST_TEST(classData->constructors.at(0).IsDelete()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->constructors.at(0).ToString() == "foo() {}|"); + + BOOST_TEST(classData->constructors.at(1).IsInsert()); + BOOST_TEST(classData->constructors.at(1)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->constructors.at(1)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->constructors.at(1).ToString() == "|bar() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_constructors_replace_with_namespace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: foo() { a; } public: void f() { c + d + e + f; } };", "class bar { private: bar() { a; } public: void f() { c + d + e + f; } };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo|bar"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->constructors.size() == 2); + BOOST_TEST(classData->constructors.at(0).IsDelete()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.IsDelete()); + BOOST_TEST(classData->constructors.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->constructors.at(0).ToString() == "foo() {}|"); + + BOOST_TEST(classData->constructors.at(1).IsInsert()); + BOOST_TEST(classData->constructors.at(1)->accessSpecifier.IsInsert()); + BOOST_TEST(classData->constructors.at(1)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->constructors.at(1).ToString() == "|bar() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +// destructor +BOOST_AUTO_TEST_CASE(class_destructors_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { ~foo() {} };", "class foo { ~foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->destructor.ToString() == "~foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_destructors_private) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: ~foo() {} };", "class foo { private: ~foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->destructor.ToString() == "~foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_destructors_private_default) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { ~foo() {} };", "class foo { private: ~foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->destructor.ToString() == "~foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_destructors_public) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: ~foo() {} };", "class foo { public: ~foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->destructor.ToString() == "~foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_destructors_protected) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { protected: ~foo() {} };", "class foo { protected: ~foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.GetElement() == AccessSpecifier::PROTECTED); + BOOST_TEST(classData->destructor.ToString() == "~foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_destructors_access_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: ~foo() {} };", "class foo { protected: ~foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.IsChange()); + BOOST_TEST(classData->destructor->accessSpecifier.GetOriginal() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->destructor->accessSpecifier.GetModified() == AccessSpecifier::PROTECTED); + BOOST_TEST(classData->destructor.ToString() == "~foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_destructors_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: };", "class foo { private: ~foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsInsert()); + BOOST_TEST(classData->destructor->accessSpecifier.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->destructor.ToString() == "|~foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_destructors_insert_with_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: };", "class foo { private: ~foo() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsInsert()); + BOOST_TEST(classData->destructor->accessSpecifier.IsInsert()); + BOOST_TEST(classData->destructor->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->destructor.ToString() == "|~foo() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_destructors_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: ~foo() {} };", "class foo { private: };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsDelete()); + BOOST_TEST(classData->destructor->accessSpecifier.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->destructor.ToString() == "~foo() {}|"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_destructors_delete_with_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: ~foo() {} };", "class foo { private: };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsDelete()); + BOOST_TEST(classData->destructor->accessSpecifier.IsDelete()); + BOOST_TEST(classData->destructor->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->destructor.ToString() == "~foo() {}|"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_destructors_replace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: ~foo() { ab; } public: void f() { c; d; } };", "class bar { private: ~bar() { b; } public: void f() { c; d; } };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo|bar"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsChange()); + BOOST_TEST(classData->destructor->accessSpecifier.IsCommon()); + BOOST_TEST(classData->destructor->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->destructor.ToString() == "~foo() {}|~bar() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_destructors_replace_with_namespace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: ~foo() { a; } public: void f() { c + d + e + f; } };", "class bar { private: ~bar() { a; } public: void f() { c + d + e + f; } };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo|bar"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsChange()); + BOOST_TEST(classData->destructor.GetOriginal()->accessSpecifier.GetOriginal() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->destructor.GetModified()->accessSpecifier.GetModified() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->destructor.ToString() == "~foo() {}|~bar() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_destructors_replace_with_convert_namespace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: ~foo() {} void f(int c, double d, long e, float f) { c + d + e + f; } };", "class bar { private: ~bar() { delete a; } void f(int c, double d, long e, float f) { c + d + e + f; } };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo|bar"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->destructor); + BOOST_TEST(classData->destructor.IsChange()); + BOOST_TEST(classData->destructor->accessSpecifier.IsChange()); + BOOST_TEST(classData->destructor->accessSpecifier.GetOriginal() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->destructor->accessSpecifier.GetModified() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->destructor.ToString() == "~foo() {}|~bar() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +// operators +BOOST_AUTO_TEST_CASE(class_operators_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { bool operator==() {} };", "class foo { bool operator==() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->operators.size() == 1); + BOOST_TEST(classData->operators.at(0).IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->operators.at(0).ToString() == "bool operator==() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_operators_private) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: bool operator==() {} };", "class foo { private: bool operator==() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->operators.size() == 1); + BOOST_TEST(classData->operators.at(0).IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->operators.at(0).ToString() == "bool operator==() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_operators_private_default) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { bool operator==() {} };", "class foo { private: bool operator==() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->operators.size() == 1); + BOOST_TEST(classData->operators.at(0).IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->operators.at(0).ToString() == "bool operator==() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_operators_public) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: bool operator==() {} };", "class foo { public: bool operator==() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->operators.size() == 1); + BOOST_TEST(classData->operators.at(0).IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->operators.at(0).ToString() == "bool operator==() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_operators_protected) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { protected: bool operator==() {} };", "class foo { protected: bool operator==() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->operators.size() == 1); + BOOST_TEST(classData->operators.at(0).IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PROTECTED); + BOOST_TEST(classData->operators.at(0).ToString() == "bool operator==() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_operators_access_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: bool operator==() {} };", "class foo { protected: bool operator==() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->operators.size() == 1); + BOOST_TEST(classData->operators.at(0).IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.IsChange()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetOriginal() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetModified() == AccessSpecifier::PROTECTED); + BOOST_TEST(classData->operators.at(0).ToString() == "bool operator==() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_operators_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: };", "class foo { private: bool operator==() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->operators.size() == 1); + BOOST_TEST(classData->operators.at(0).IsInsert()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->operators.at(0).ToString() == "|bool operator==() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_operators_insert_with_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: };", "class foo { private: bool operator==() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->operators.size() == 1); + BOOST_TEST(classData->operators.at(0).IsInsert()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.IsInsert()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->operators.at(0).ToString() == "|bool operator==() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_operators_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: bool operator==() {} };", "class foo { private: };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->operators.size() == 1); + BOOST_TEST(classData->operators.at(0).IsDelete()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->operators.at(0).ToString() == "bool operator==() {}|"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_operators_delete_with_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: bool operator==() {} };", "class foo { private: };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->operators.size() == 1); + BOOST_TEST(classData->operators.at(0).IsDelete()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.IsDelete()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->operators.at(0).ToString() == "bool operator==() {}|"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_operators_replace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: bool operator==(int b) { return std::max(b - a, 0); } };", "class foo { private: bool operator!=(const object& that) { return *this != that; } };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->operators.size() == 2); + BOOST_TEST(classData->operators.at(0).IsDelete()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->operators.at(0).ToString() == "bool operator==(int b) {}|"); + + BOOST_TEST(classData->operators.at(1).IsInsert()); + BOOST_TEST(classData->operators.at(1)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->operators.at(1)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->operators.at(1).ToString() == "|bool operator!=(const object & that) {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_operators_replace_with_namespace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: bool operator==(int b) { return std::max(b - a, 0); } };", "class foo { private: bool operator!=(const object& that) { return *this != that; } };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->operators.size() == 2); + BOOST_TEST(classData->operators.at(0).IsDelete()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.IsDelete()); + BOOST_TEST(classData->operators.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->operators.at(0).ToString() == "bool operator==(int b) {}|"); + + BOOST_TEST(classData->operators.at(1).IsInsert()); + BOOST_TEST(classData->operators.at(1)->accessSpecifier.IsInsert()); + BOOST_TEST(classData->operators.at(1)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->operators.at(1).ToString() == "|bool operator!=(const object & that) {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +// methods +BOOST_AUTO_TEST_CASE(class_methods_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { void f() {} };", "class foo { void f() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->methods.at(0).IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->methods.at(0).ToString() == "void f() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_methods_private) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: void f() {} };", "class foo { private: void f() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->methods.at(0).IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->methods.at(0).ToString() == "void f() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_methods_private_default) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { void f() {} };", "class foo { private: void f() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->methods.at(0).IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->methods.at(0).ToString() == "void f() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_methods_public) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: void f() {} };", "class foo { public: void f() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->methods.at(0).IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->methods.at(0).ToString() == "void f() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_methods_protected) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { protected: void f() {} };", "class foo { protected: void f() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->methods.at(0).IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PROTECTED); + BOOST_TEST(classData->methods.at(0).ToString() == "void f() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_methods_access_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: void f() {} };", "class foo { protected: void f() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->methods.at(0).IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.IsChange()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetOriginal() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetModified() == AccessSpecifier::PROTECTED); + BOOST_TEST(classData->methods.at(0).ToString() == "void f() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_methods_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: };", "class foo { private: void f() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->methods.at(0).IsInsert()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->methods.at(0).ToString() == "|void f() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_methods_insert_with_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: };", "class foo { private: void f() {} };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->methods.at(0).IsInsert()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.IsInsert()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->methods.at(0).ToString() == "|void f() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_methods_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: void f() {} };", "class foo { private: };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->methods.at(0).IsDelete()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->methods.at(0).ToString() == "void f() {}|"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_methods_delete_with_access) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: void f() {} };", "class foo { private: };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->methods.at(0).IsDelete()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.IsDelete()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->methods.at(0).ToString() == "void f() {}|"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_methods_replace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { private: void f() { a; } };", "class foo { private: int g() { b; } };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->methods.size() == 2); + BOOST_TEST(classData->methods.at(0).IsDelete()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->methods.at(0).ToString() == "void f() {}|"); + + BOOST_TEST(classData->methods.at(1).IsInsert()); + BOOST_TEST(classData->methods.at(1)->accessSpecifier.IsCommon()); + BOOST_TEST(classData->methods.at(1)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->methods.at(1).ToString() == "|int g() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_methods_replace_with_namespace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { public: void f() { a; } };", "class foo { private: int g() { b; } };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->methods.size() == 2); + BOOST_TEST(classData->methods.at(0).IsDelete()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.IsDelete()); + BOOST_TEST(classData->methods.at(0)->accessSpecifier.GetElement() == AccessSpecifier::PUBLIC); + BOOST_TEST(classData->methods.at(0).ToString() == "void f() {}|"); + + BOOST_TEST(classData->methods.at(1).IsInsert()); + BOOST_TEST(classData->methods.at(1)->accessSpecifier.IsInsert()); + BOOST_TEST(classData->methods.at(1)->accessSpecifier.GetElement() == AccessSpecifier::PRIVATE); + BOOST_TEST(classData->methods.at(1).ToString() == "|int g() {}"); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +// abstract +BOOST_AUTO_TEST_CASE(class_is_abstract) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { virtual void f() = 0; };", "class foo { virtual void f() = 0; };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(classData->isAbstract); + BOOST_TEST(classData->isAbstract.IsCommon()); + BOOST_TEST(classData->isAbstract.GetElement()); +} + +BOOST_AUTO_TEST_CASE(class_becomes_abstract) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { };", "class foo { virtual void f() = 0; };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(classData->isAbstract); + BOOST_TEST(classData->isAbstract.IsInsert()); + BOOST_TEST(classData->isAbstract.GetElement()); +} + +BOOST_AUTO_TEST_CASE(class_was_abstract) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo { virtual void f() = 0; };", "class foo { };"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.size() == 1); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(classData->isAbstract); + BOOST_TEST(classData->isAbstract.IsDelete()); + BOOST_TEST(classData->isAbstract.GetElement()); +} + +// generic +BOOST_AUTO_TEST_CASE(class_is_generic) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template class foo {};", "template class foo {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.size() == 1); + BOOST_TEST(classData->generics.at(0).IsCommon()); + BOOST_TEST(classData->generics.at(0).ToString() == "template"); + + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_becomes_generic) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo {};", "template class foo {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.size() == 1); + BOOST_TEST(classData->generics.at(0).IsInsert()); + BOOST_TEST(classData->generics.at(0).ToString() == "|template"); + + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(class_was_generic) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template class foo {};", "class foo {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.size() == 1); + BOOST_TEST(classData->generics.at(0).IsDelete()); + BOOST_TEST(classData->generics.at(0).ToString() == "template|"); + + BOOST_TEST(classData->type.IsCommon()); + BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); + +} + +// Inner Classes diff --git a/test/suite/testClassConvert.cpp b/test/suite/testClassConvert.cpp new file mode 100644 index 0000000..b8f65d8 --- /dev/null +++ b/test/suite/testClassConvert.cpp @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testClassConvert.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE class type convert tests +#include + +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +// Do I need to collect class decl? + +BOOST_AUTO_TEST_CASE(class_to_struct) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("class foo {};", "struct foo {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsChange()); + BOOST_TEST(classData->type.GetOriginal() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetModified() == srcDiffDispatch::ClassData::STRUCT); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +BOOST_AUTO_TEST_CASE(struct_to_class) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("struct foo {};", "class foo {};"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + BOOST_TEST(classData.IsCommon()); + + BOOST_TEST(classData->generics.empty()); + BOOST_TEST(classData->type.IsChange()); + BOOST_TEST(classData->type.GetOriginal() == srcDiffDispatch::ClassData::STRUCT); + BOOST_TEST(classData->type.GetModified() == srcDiffDispatch::ClassData::CLASS); + + BOOST_TEST(classData->name.IsCommon()); + BOOST_TEST(classData->name.ToString() == "foo"); + + BOOST_TEST(classData->parents.empty()); + + BOOST_TEST(classData->fields.empty()); + BOOST_TEST(classData->constructors.empty()); + BOOST_TEST(!classData->destructor); + BOOST_TEST(classData->operators.empty()); + BOOST_TEST(classData->methods.empty()); + BOOST_TEST(classData->innerClasses.empty()); + + BOOST_TEST(!classData->isAbstract); +} + +// inner/local class convert diff --git a/test/suite/testCondition.cpp b/test/suite/testCondition.cpp new file mode 100644 index 0000000..db58418 --- /dev/null +++ b/test/suite/testCondition.cpp @@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testCondition.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE condition tests +#include + +#include + +#include +#include +#include + +#include + +// Define test data +namespace data = boost::unit_test; + +// condition decl +BOOST_AUTO_TEST_CASE(decl_condition_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { while(int i = 1) {} }", "void foo() { while(int i = 1) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(whileData.condition); + BOOST_TEST(whileData.condition.IsCommon()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); + + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "int i = 1"); + BOOST_TEST(whileData.condition.ToString() == "int i = 1"); + + BOOST_TEST(whileData.block.IsCommon()); + BOOST_TEST(whileData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(decl_condition_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { while(int i = 1) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(whileData.condition); + BOOST_TEST(whileData.condition.IsInsert()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsInsert()); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "|int i = 1"); + BOOST_TEST(whileData.condition.ToString() == "|int i = 1"); + + BOOST_TEST(whileData.block.IsInsert()); + BOOST_TEST(whileData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|int i = 1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(decl_condition_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { while(int i = 1) {} }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(whileData.condition); + BOOST_TEST(whileData.condition.IsDelete()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsDelete()); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "int i = 1|"); + BOOST_TEST(whileData.condition.ToString() == "int i = 1|"); + + BOOST_TEST(whileData.block.IsDelete()); + BOOST_TEST(whileData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 1|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(decl_condition_replace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { while(int i = 1) {} }", "void foo() { while(double d = 1.0) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(whileData.condition); + BOOST_TEST(whileData.condition.IsCommon()); + BOOST_TEST(whileData.condition->conditions.size() == 2); + BOOST_TEST(whileData.condition->conditions.at(0).IsDelete()); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "int i = 1|"); + BOOST_TEST(whileData.condition->conditions.at(1).IsInsert()); + BOOST_TEST(whileData.condition->conditions.at(1).ToString>() == "|double d = 1.0"); + BOOST_TEST(whileData.condition.ToString() == "int i = 1|double d = 1.0"); + + BOOST_TEST(whileData.block.IsCommon()); + BOOST_TEST(whileData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 1|double d = 1.0"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(decl_condition_modify) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { while(int i = 1) {} }", "void foo() { while(int i = 2) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(whileData.condition); + BOOST_TEST(whileData.condition.IsCommon()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "int i = 1|int i = 2"); + BOOST_TEST(whileData.condition.ToString() == "int i = 1|int i = 2"); + + BOOST_TEST(whileData.block.IsCommon()); + BOOST_TEST(whileData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 1|int i = 2"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testConditionalConvert.cpp b/test/suite/testConditionalConvert.cpp new file mode 100644 index 0000000..11d3b3c --- /dev/null +++ b/test/suite/testConditionalConvert.cpp @@ -0,0 +1,363 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testConditionalConvert.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE conditional convert tests +#include + +#include + +#include +#include +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(if_to_while) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { while(1) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(ifData.clauses.size() == 1); + + const srcDiffDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); + BOOST_TEST(ifData.clauses.at(0).IsDelete()); + BOOST_TEST(ifClause.condition.IsCommon()); + BOOST_TEST(ifClause.condition->conditions.size() == 1); + BOOST_TEST(ifClause.condition->conditions.at(0).IsCommon()); + BOOST_TEST(ifClause.condition.ToString() == "1"); + BOOST_TEST(ifClause.block.IsCommon()); + BOOST_TEST(ifClause.block->statements.size() == 0); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(whileData.condition); + BOOST_TEST(whileData.condition.IsCommon()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); + BOOST_TEST(whileData.condition.ToString() == "1"); + BOOST_TEST(whileData.block.IsCommon()); + BOOST_TEST(whileData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(while_to_if) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { while(1) {} }", "void foo() { if(1) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(whileData.condition); + BOOST_TEST(whileData.condition.IsCommon()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); + BOOST_TEST(whileData.condition.ToString() == "1"); + BOOST_TEST(whileData.block.IsCommon()); + BOOST_TEST(whileData.block->statements.size() == 0); + + const srcDiffDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(ifData.clauses.size() == 1); + + const srcDiffDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); + BOOST_TEST(ifData.clauses.at(0).IsInsert()); + BOOST_TEST(ifClause.condition.IsCommon()); + BOOST_TEST(ifClause.condition->conditions.size() == 1); + BOOST_TEST(ifClause.condition->conditions.at(0).IsCommon()); + BOOST_TEST(ifClause.condition.ToString() == "1"); + BOOST_TEST(ifClause.block.IsCommon()); + BOOST_TEST(ifClause.block->statements.size() == 0); + + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(while_to_if_with_convert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { while(1) { while(2) {} } }", "void foo() { if(1) { if(2) {} } }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(whileData.condition); + BOOST_TEST(whileData.condition.IsCommon()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); + BOOST_TEST(whileData.condition.ToString() == "1"); + + const srcDiffDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(ifData.clauses.size() == 1); + + const srcDiffDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); + BOOST_TEST(ifData.clauses.at(0).IsInsert()); + BOOST_TEST(ifClause.condition.IsCommon()); + BOOST_TEST(ifClause.condition->conditions.size() == 1); + BOOST_TEST(ifClause.condition->conditions.at(0).IsCommon()); + BOOST_TEST(ifClause.condition.ToString() == "1"); + BOOST_TEST(ifClause.block.IsCommon()); + BOOST_TEST(ifClause.block->statements.size() == 1); + + BOOST_TEST(whileData.block.IsCommon()); + BOOST_TEST(whileData.block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(if_to_for) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { if(i < 10) { sum += i; } }", "void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(ifData.clauses.size() == 1); + + const srcDiffDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); + BOOST_TEST(ifData.clauses.at(0).IsDelete()); + BOOST_TEST(ifClause.condition.IsCommon()); + BOOST_TEST(ifClause.condition->conditions.size() == 1); + BOOST_TEST(ifClause.condition->conditions.at(0).IsCommon()); + BOOST_TEST(ifClause.condition.ToString() == "i < 10"); + BOOST_TEST(ifClause.block.IsCommon()); + BOOST_TEST(ifClause.block->statements.size() == 1); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(forData.control); + BOOST_TEST(forData.control.IsInsert()); + + BOOST_TEST(forData.control->init.IsInsert()); + BOOST_TEST(forData.control->init.ToString() == "|int i = 0"); + + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 10"); + + BOOST_TEST(forData.control->incr.IsInsert()); + BOOST_TEST(forData.control->incr.ToString() == "|++ i"); + + BOOST_TEST(forData.control.ToString(srcDispatch::INSERT) == "int i = 0; i < 10; ++ i"); + + BOOST_TEST(forData.block.IsCommon()); + BOOST_TEST(forData.block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(for_to_if) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }", "void foo() { if(i < 10) { sum += i; } }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(forData.control); + BOOST_TEST(forData.control.IsDelete()); + + BOOST_TEST(forData.control->init.IsDelete()); + BOOST_TEST(forData.control->init.ToString() == "int i = 0|"); + + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 10"); + + BOOST_TEST(forData.control->incr.IsDelete()); + BOOST_TEST(forData.control->incr.ToString() == "++ i|"); + + BOOST_TEST(forData.control.ToString(srcDispatch::DELETE) == "int i = 0; i < 10; ++ i"); + + BOOST_TEST(forData.block.IsCommon()); + BOOST_TEST(forData.block->statements.size() == 1); + + const srcDiffDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(ifData.clauses.size() == 1); + + const srcDiffDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); + BOOST_TEST(ifData.clauses.at(0).IsInsert()); + BOOST_TEST(ifClause.condition.IsCommon()); + BOOST_TEST(ifClause.condition->conditions.size() == 1); + BOOST_TEST(ifClause.condition->conditions.at(0).IsCommon()); + BOOST_TEST(ifClause.condition.ToString() == "i < 10"); + BOOST_TEST(ifClause.block.IsCommon()); + BOOST_TEST(ifClause.block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(while_to_for) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { while(i < 10) { sum += i; } }", "void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(whileData.condition.IsCommon()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); + BOOST_TEST(whileData.condition.ToString() == "i < 10"); + BOOST_TEST(whileData.block.IsCommon()); + BOOST_TEST(whileData.block->statements.size() == 1); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(forData.control); + BOOST_TEST(forData.control.IsInsert()); + + BOOST_TEST(forData.control->init.IsInsert()); + BOOST_TEST(forData.control->init.ToString() == "|int i = 0"); + + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 10"); + + BOOST_TEST(forData.control->incr.IsInsert()); + BOOST_TEST(forData.control->incr.ToString() == "|++ i"); + + BOOST_TEST(forData.control.ToString(srcDispatch::INSERT) == "int i = 0; i < 10; ++ i"); + + BOOST_TEST(forData.block.IsCommon()); + BOOST_TEST(forData.block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(for_to_while) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }", "void foo() { while(i < 10) { sum += i; } }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(forData.control); + BOOST_TEST(forData.control.IsDelete()); + + BOOST_TEST(forData.control->init.IsDelete()); + BOOST_TEST(forData.control->init.ToString() == "int i = 0|"); + + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 10"); + + BOOST_TEST(forData.control->incr.IsDelete()); + BOOST_TEST(forData.control->incr.ToString() == "++ i|"); + + BOOST_TEST(forData.control.ToString(srcDispatch::DELETE) == "int i = 0; i < 10; ++ i"); + + BOOST_TEST(forData.block.IsCommon()); + BOOST_TEST(forData.block->statements.size() == 1); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(whileData.condition.IsCommon()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); + BOOST_TEST(whileData.condition.ToString() == "i < 10"); + BOOST_TEST(whileData.block.IsCommon()); + BOOST_TEST(whileData.block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testControl.cpp b/test/suite/testControl.cpp new file mode 100644 index 0000000..c394164 --- /dev/null +++ b/test/suite/testControl.cpp @@ -0,0 +1,1427 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testControl.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE control tests +#include + +#include + +#include +#include +#include + +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(block_common_control) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; 1; ++i) {} }", "void foo() { for(int i = 0; 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_control) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 1; i < 2; ++j) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0|int i = 1"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1|i < 2"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i|++ j"); + BOOST_TEST(forData.control->incr.ToString() == "++ i|++ j"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|int i = 1; i < 2; ++ j"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_expr_init_control_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_expr_init_control_minor_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(i = 1; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|i = 1"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|i = 1; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_expr_init_control_replace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(j = 1; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsChange()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|j = 1"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|j = 1; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_expr_init_control_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsInsert()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "|i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "; i < 1; ++ i|i = 0; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_expr_init_control_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsDelete()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_decl_init_control_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsInsert()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "|int i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "; i < 1; ++ i|int i = 0; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_decl_init_control_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsDelete()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0|"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_decl_to_expr) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 2); + BOOST_TEST(forData.control->init->inits.at(0).IsDelete()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0|"); + BOOST_TEST(forData.control->init->inits.at(1).IsInsert()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|i = 0; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_expr_to_decl) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 2); + BOOST_TEST(forData.control->init->inits.at(0).IsDelete()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|"); + BOOST_TEST(forData.control->init->inits.at(1).IsInsert()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|int i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|int i = 0; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_multi_decl) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 2); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int j = 1; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int j = 1; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 2); + BOOST_TEST(forData.control->init->inits.at(0).IsInsert()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "|int i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int j = 1; i < 1; ++ i|int i = 0, int j = 1; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 2); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).IsInsert()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|int j = 1"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|int i = 0, int j = 1; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_middle) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0, k = 2; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1, k = 2; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 3); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).IsInsert()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|int j = 1"); + BOOST_TEST(forData.control->init->inits.at(2).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(2).ToString>() == "int k = 2"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int k = 2; i < 1; ++ i|int i = 0, int j = 1, int k = 2; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(int j = 1; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 2); + BOOST_TEST(forData.control->init->inits.at(0).IsDelete()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0|"); + BOOST_TEST(forData.control->init->inits.at(1).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int j = 1; i < 1; ++ i|int j = 1; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 2); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).IsDelete()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1|"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int j = 1; i < 1; ++ i|int i = 0; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +// multi decl +BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_middle) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0, j = 1, k = 2; i < 1; ++i) {} }", "void foo() { for(int i = 0, k = 2; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 3); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).IsDelete()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1|"); + BOOST_TEST(forData.control->init->inits.at(2).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(2).ToString>() == "int k = 2"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int j = 1, int k = 2; i < 1; ++ i|int i = 0, int k = 2; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +// multi expr +BOOST_AUTO_TEST_CASE(block_init_control_multi_expr) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 2); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, j = 1; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(j = 1; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 2); + BOOST_TEST(forData.control->init->inits.at(0).IsInsert()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "|i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "j = 1; i < 1; ++ i|i = 0, j = 1; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 2); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).IsInsert()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|j = 1"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|i = 0, j = 1; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_middle) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(i = 0, k = 2; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1, k = 2; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 3); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).IsInsert()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|j = 1"); + BOOST_TEST(forData.control->init->inits.at(2).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(2).ToString>() == "k = 2"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, k = 2; i < 1; ++ i|i = 0, j = 1, k = 2; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(j = 1; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 2); + BOOST_TEST(forData.control->init->inits.at(0).IsDelete()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|"); + BOOST_TEST(forData.control->init->inits.at(1).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, j = 1; i < 1; ++ i|j = 1; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 2); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).IsDelete()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1|"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, j = 1; i < 1; ++ i|i = 0; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_middle) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(i = 0, j = 1, k = 2; i < 1; ++i) {} }", "void foo() { for(i = 0, k = 2; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 3); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).IsDelete()); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1|"); + BOOST_TEST(forData.control->init->inits.at(2).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(2).ToString>() == "k = 2"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 1); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr.ToString() == "++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, j = 1, k = 2; i < 1; ++ i|i = 0, k = 2; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +// multi incr +BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, --j) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 2); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr->exprs.at(1).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(1).ToString() == "-- j"); + BOOST_TEST(forData.control->incr.ToString() == "++ i, -- j"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, -- j"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 1; --j) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 2); + BOOST_TEST(forData.control->incr->exprs.at(0).IsInsert()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "|++ i"); + BOOST_TEST(forData.control->incr->exprs.at(1).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(1).ToString() == "-- j"); + BOOST_TEST(forData.control->incr.ToString() == "-- j|++ i, -- j"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; -- j|int i = 0; i < 1; ++ i, -- j"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 2); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr->exprs.at(1).IsInsert()); + BOOST_TEST(forData.control->incr->exprs.at(1).ToString() == "|-- j"); + BOOST_TEST(forData.control->incr.ToString() == "++ i|++ i, -- j"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|int i = 0; i < 1; ++ i, -- j"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_middle) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, k /= 2) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j, k /= 2) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 3); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr->exprs.at(1).IsInsert()); + BOOST_TEST(forData.control->incr->exprs.at(1).ToString() == "|-- j"); + BOOST_TEST(forData.control->incr->exprs.at(2).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(2).ToString() == "k /= 2"); + BOOST_TEST(forData.control->incr.ToString() == "++ i, k /= 2|++ i, -- j, k /= 2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, k /= 2|int i = 0; i < 1; ++ i, -- j, k /= 2"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, --j) {} }", "void foo() { for(int i = 0; i < 1; --j) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 2); + BOOST_TEST(forData.control->incr->exprs.at(0).IsDelete()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i|"); + BOOST_TEST(forData.control->incr->exprs.at(1).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(1).ToString() == "-- j"); + BOOST_TEST(forData.control->incr.ToString() == "++ i, -- j|-- j"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, -- j|int i = 0; i < 1; -- j"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, --j) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 2); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr->exprs.at(1).IsDelete()); + BOOST_TEST(forData.control->incr->exprs.at(1).ToString() == "-- j|"); + BOOST_TEST(forData.control->incr.ToString() == "++ i, -- j|++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, -- j|int i = 0; i < 1; ++ i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_middle) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, --j, k /= 2) {} }", "void foo() { for(int i = 0; i < 1; ++i, k /= 2) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 1); + BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition->conditions.size() == 1); + BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "i < 1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 3); + BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); + BOOST_TEST(forData.control->incr->exprs.at(1).IsDelete()); + BOOST_TEST(forData.control->incr->exprs.at(1).ToString() == "-- j|"); + BOOST_TEST(forData.control->incr->exprs.at(2).IsCommon()); + BOOST_TEST(forData.control->incr->exprs.at(2).ToString() == "k /= 2"); + BOOST_TEST(forData.control->incr.ToString() == "++ i, -- j, k /= 2|++ i, k /= 2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, -- j, k /= 2|int i = 0; i < 1; ++ i, k /= 2"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testDecl.cpp b/test/suite/testDecl.cpp new file mode 100644 index 0000000..c2fcc9f --- /dev/null +++ b/test/suite/testDecl.cpp @@ -0,0 +1,1241 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testDecl.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE decl tests +#include + +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +// templated (not arg but def) + +BOOST_AUTO_TEST_CASE(decl_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a = 0;", "type a = 0;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.ToString() == "0"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a = 0"); +} + +BOOST_AUTO_TEST_CASE(decl_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("", "type a = 0;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "|type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "|a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "|a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.ToString() == "|0"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "|type a = 0"); +} + +BOOST_AUTO_TEST_CASE(decl_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a = 0;", ""); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a|"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a|"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.ToString() == "0|"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a = 0|"); +} + +BOOST_AUTO_TEST_CASE(name_rename) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a = 0;", "type b = 0;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsChange()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a|b"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.GetOriginal() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.GetModified() == "b"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.ToString() == "0"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a = 0|type b = 0"); +} + +BOOST_AUTO_TEST_CASE(type_rename) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("foo a;", "bar a;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name.IsChange()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "foo|bar"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "foo a|bar a"); +} + +BOOST_AUTO_TEST_CASE(type_rename_two) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("foo a;", "foo* a;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 2); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name.IsCommon()); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDiffDispatch::TypeData::TypeType::POINTER); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "foo|foo *"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "foo a|foo * a"); +} + +BOOST_AUTO_TEST_CASE(decl_init_literal_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a = 0;", "type a = 1;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsChange()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetOriginal()->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetModified()->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetOriginal()->expr.at(0).IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetModified()->expr.at(0).IsInsert()); + + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetOriginal()->expr.at(0).GetOriginal())->literal.IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetModified()->expr.at(0).GetModified())->literal.IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetOriginal()->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetModified()->expr.at(0).GetModified())->literal.ToString() == "|1"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a = 0|type a = 1"); +} + +BOOST_AUTO_TEST_CASE(init_literal_change_2) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a(0);", "type a = 1;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0).IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.ToString() == "|1"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a(0)|type a = 1"); +} + +BOOST_AUTO_TEST_CASE(init_literal_change_3) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a{0};", "type a = 1;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0).IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.ToString() == "|1"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a(0)|type a = 1"); +} + +BOOST_AUTO_TEST_CASE(name_only_match) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type* a(0);", "typePtr a = 1;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 2); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name.IsChange()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "type|typePtr"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDiffDispatch::TypeData::TypeType::POINTER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type *|typePtr"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0).IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.ToString() == "|1"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type * a(0)|typePtr a = 1"); +} + +BOOST_AUTO_TEST_CASE(comma_separated_decl) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a = 0, b = 1, c = 2;", "type a = 0, c = 2, d = 3;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 4); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.ToString() == "0"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1).IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->generics.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type.ToString() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->name.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->name->name.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->name.ToString() == "b|"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->name->name.ToString() == "b|"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->init.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->init.ToString() == "1|"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->generics.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type.ToString() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->name.ToString() == "c"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->name->name.ToString() == "c"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->init.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->init.ToString() == "2"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3).IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type.ToString() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->name.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->name->name.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->name.ToString() == "|d"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->name->name.ToString() == "|d"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->init.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->init.ToString() == "|3"); + + // a little weird as type is shared, so always in common + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).ToString() == "type a = 0"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1).ToString() == "type b = 1|type"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2).ToString() == "type c = 2"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3).ToString() == "type|type d = 3"); +} + +// compound name +BOOST_AUTO_TEST_CASE(decl_compound_name_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("std::string str = \"\";", "std::string str = \"\";"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 3); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first).IsCommon()); + + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0)).IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->names.size() == 0); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->name.IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->name.ToString() == "std"); + + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1)).IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1).GetElement())->op.IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1).GetElement())->op.ToString() == "::"); + + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2)).IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->names.size() == 0); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->name.IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->name.ToString() == "string"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "std::string"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "std::string"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "str"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "str"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.ToString() == "\"\""); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "std::string str = \"\""); +} + +BOOST_AUTO_TEST_CASE(decl_compound_name_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("std::string str = \"\";", "std::wstring str = \"\";"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 3); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first).IsCommon()); + + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0)).IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->names.size() == 0); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->name.IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->name.ToString() == "std"); + + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1)).IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1).GetElement())->op.IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1).GetElement())->op.ToString() == "::"); + + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2)).IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->names.size() == 0); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->name.IsChange()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->name.ToString() == "string|wstring"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "std::string|std::wstring"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "std::string|std::wstring"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "str"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "str"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.ToString() == "\"\""); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "std::string str = \"\"|std::wstring str = \"\""); +} + +BOOST_AUTO_TEST_CASE(decl_simple_to_complex_name) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("string str = \"\";", "std::string str = \"\";"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsInsert()); + + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 3); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first).IsInsert()); + + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0)).IsInsert()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->names.size() == 0); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->name.ToString() == "|std"); + + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1)).IsInsert()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1).GetElement())->op.IsInsert()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1).GetElement())->op.ToString() == "|::"); + + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2)).IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->names.size() == 0); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->name.IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->name.ToString() == "string"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "string|std::string"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "string|std::string"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "str"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "str"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.ToString() == "\"\""); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "string str = \"\"|std::string str = \"\""); +} + +// specifier test +BOOST_AUTO_TEST_CASE(decl_add_specifier) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a = 0;", "const type a = 0;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 2); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::SPECIFIER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "|const"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.ToString>() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|const type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.ToString() == "0"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a = 0|const type a = 0"); +} + +// specifier test +BOOST_AUTO_TEST_CASE(decl_remove_specifier) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("const type a = 0;", "type a = 0;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 2); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::SPECIFIER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "const|"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.ToString>() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "const type|type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.ToString() == "0"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "const type a = 0|type a = 0"); +} + +// specifier test +BOOST_AUTO_TEST_CASE(decl_change_specifier) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("static type a = 0;", "const type a = 0;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 3); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::SPECIFIER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "static|"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDiffDispatch::TypeData::TypeType::SPECIFIER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.ToString>() == "|const"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(2).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(2).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(2).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(2).first.ToString>() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "static type|const type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.ToString() == "0"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "static type a = 0|const type a = 0"); +} + +// modifier change test +BOOST_AUTO_TEST_CASE(decl_modifier_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type* a;", "type& a;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 2); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "type"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.IsChange()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetOriginal() == srcDiffDispatch::TypeData::TypeType::POINTER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetModified() == srcDiffDispatch::TypeData::TypeType::REFERENCE); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type *|type &"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type * a|type & a"); +} + +// templated name +BOOST_AUTO_TEST_CASE(decl_template_argument_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a;", "type a;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + )->name.IsCommon() + ); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + )->name.ToString() == "type" + ); + + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 1); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "arg"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a"); +} + +BOOST_AUTO_TEST_CASE(decl_template_argument_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a;", "type a;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsInsert()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsInsert()); + + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + )->name.IsCommon() + ); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + )->name.ToString() == "type" + ); + + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 1); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "|arg"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a|type a"); +} + +BOOST_AUTO_TEST_CASE(decl_template_argument_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a;", "type a;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsDelete()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsDelete()); + + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + )->name.IsCommon() + ); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + )->name.ToString() == "type" + ); + + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 1); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "arg|"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a|type a"); +} + +BOOST_AUTO_TEST_CASE(decl_template_argument_insert_arg) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a;", "type a;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + )->name.IsCommon() + ); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + )->name.ToString() == "type" + ); + + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 2); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "foo"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(1).IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(1).ToString() == "|bar"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a|type a"); +} + +BOOST_AUTO_TEST_CASE(decl_template_argument_delete_arg) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a;", "type a;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + )->name.IsCommon() + ); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + )->name.ToString() == "type" + ); + + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 2); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "foo|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(1).IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(1).ToString() == "bar"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a|type a"); +} + +BOOST_AUTO_TEST_CASE(decl_template_argument_change_arg) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("type a;", "type a;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 0); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + )->name.IsCommon() + ); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + )->name.ToString() == "type" + ); + + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 1); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.size() == 1); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.at(0).IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.at(0).GetElement() + )->names.size() == 0 + ); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.at(0).GetElement() + )->name.IsChange() + ); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.at(0).GetElement() + )->name.GetOriginal() == "foo" + ); + BOOST_TEST(std::any_cast>( + std::any_cast>( + runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.at(0).GetElement() + )->name.GetModified() == "bar" + ); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "foo|bar"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a|type a"); +} + +// templated +BOOST_AUTO_TEST_CASE(decl_template_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template type a = 0;", "template type a = 0;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->generics.at(0).ToString() == "template"); + BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->accessSpecifier); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.ToString() == "a"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name->name.ToString() == "a"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.ToString() == "0"); + + BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a = 0"); +} diff --git a/test/suite/testDeclStmt.cpp b/test/suite/testDeclStmt.cpp new file mode 100644 index 0000000..88c3995 --- /dev/null +++ b/test/suite/testDeclStmt.cpp @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testDeclStmt.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE decl_stmt tests +#include + +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(block_common_decl_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { int i; }", "void foo() { int i; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_decl_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { foo bar; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|foo bar"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_decl_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { foo bar; }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "foo bar|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_replace_decl_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { foo f; }", "void foo() { bar b; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 2); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "foo f|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|bar b"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testDo.cpp b/test/suite/testDo.cpp new file mode 100644 index 0000000..88f4027 --- /dev/null +++ b/test/suite/testDo.cpp @@ -0,0 +1,161 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testDo.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE do_stmt tests +#include + +#include + +#include +#include +#include + +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(block_change_common_do) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { do {} while(1); }", "void foo() { do {} while(1); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_do) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { do {} while(1);"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::DoData& doData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(doData.condition); + BOOST_TEST(doData.condition.IsInsert()); + BOOST_TEST(doData.condition->conditions.size() == 1); + BOOST_TEST(doData.condition->conditions.at(0).IsInsert()); + + const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(doData.condition->conditions.at(0).GetElement()); + BOOST_TEST(expr.expr.size() == 1); + BOOST_TEST(expr.expr.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "|1"); + BOOST_TEST(expr.expr.at(0).ToString>() == "|1"); + BOOST_TEST(doData.condition->conditions.at(0).ToString>() == "|1"); + BOOST_TEST(doData.condition.ToString() == "|1"); + + BOOST_TEST(doData.block.IsInsert()); + BOOST_TEST(doData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_do) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { do {} while(1);", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::DoData& doData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(doData.condition); + BOOST_TEST(doData.condition.IsDelete()); + BOOST_TEST(doData.condition->conditions.size() == 1); + BOOST_TEST(doData.condition->conditions.at(0).IsDelete()); + + const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(doData.condition->conditions.at(0).GetElement()); + BOOST_TEST(expr.expr.size() == 1); + BOOST_TEST(expr.expr.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "1|"); + BOOST_TEST(expr.expr.at(0).ToString>() == "1|"); + BOOST_TEST(doData.condition->conditions.at(0).ToString>() == "1|"); + BOOST_TEST(doData.condition.ToString() == "1|"); + + BOOST_TEST(doData.block.IsDelete()); + BOOST_TEST(doData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_replace_do) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { do { a; } while(1); }", "void foo() { do { b; } while(2); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 2); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::DoData& deletedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(deletedData.condition.IsDelete()); + BOOST_TEST(deletedData.block.IsDelete()); + BOOST_TEST(deletedData.block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).IsInsert()); + + const srcDiffDispatch::DoData& insertedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(1).GetElement()); + BOOST_TEST(insertedData.condition.IsInsert()); + BOOST_TEST(insertedData.block.IsInsert()); + BOOST_TEST(insertedData.block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|2"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testExprConvert.cpp b/test/suite/testExprConvert.cpp new file mode 100644 index 0000000..168c654 --- /dev/null +++ b/test/suite/testExprConvert.cpp @@ -0,0 +1,268 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testExprConvert.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE expr convert tests +#include + +#include + +#include +#include +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(decl_to_expr) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { int i = 0; }", "void foo() { 0; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::DeclStmtData& declStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(declStmtData.decls.size() == 1); + BOOST_TEST(declStmtData.decls.at(0).IsDelete()); + BOOST_TEST(declStmtData.decls.at(0)->type.IsDelete()); + BOOST_TEST(declStmtData.decls.at(0)->type.ToString() == "int|"); + BOOST_TEST(declStmtData.decls.at(0)->name.IsDelete()); + BOOST_TEST(declStmtData.decls.at(0)->name.ToString() == "i|"); + BOOST_TEST(declStmtData.decls.at(0)->init.IsCommon()); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.size() == 1); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).IsCommon()); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).ToString>() == "0"); + BOOST_TEST(declStmtData.decls.at(0)->init.ToString() == "0"); + BOOST_TEST(declStmtData.decls.at(0).ToString(srcDispatch::DELETE) == "int i = 0"); + + const srcDiffDispatch::ExprStmtData& exprStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(exprStmtData.expr.IsCommon()); + BOOST_TEST(exprStmtData.expr->expr.size() == 1); + BOOST_TEST(exprStmtData.expr->expr.at(0).IsCommon()); + BOOST_TEST(exprStmtData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(exprStmtData.expr.ToString() == "0"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(expr_to_decl) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { 0; }", "void foo() { int i = 0; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::ExprStmtData& exprStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(exprStmtData.expr.IsCommon()); + BOOST_TEST(exprStmtData.expr->expr.size() == 1); + BOOST_TEST(exprStmtData.expr->expr.at(0).IsCommon()); + BOOST_TEST(exprStmtData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(exprStmtData.expr.ToString() == "0"); + + const srcDiffDispatch::DeclStmtData& declStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(declStmtData.decls.size() == 1); + BOOST_TEST(declStmtData.decls.at(0).IsInsert()); + BOOST_TEST(declStmtData.decls.at(0)->type.IsInsert()); + BOOST_TEST(declStmtData.decls.at(0)->type.ToString() == "|int"); + BOOST_TEST(declStmtData.decls.at(0)->name.IsInsert()); + BOOST_TEST(declStmtData.decls.at(0)->name.ToString() == "|i"); + BOOST_TEST(declStmtData.decls.at(0)->init.IsCommon()); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.size() == 1); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).IsCommon()); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).ToString>() == "0"); + BOOST_TEST(declStmtData.decls.at(0)->init.ToString() == "0"); + BOOST_TEST(declStmtData.decls.at(0).ToString(srcDispatch::INSERT) == "int i = 0"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(expr_to_return) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { 0; }", "void foo() { return 0; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::ExprStmtData& exprStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(exprStmtData.expr.IsCommon()); + BOOST_TEST(exprStmtData.expr->expr.size() == 1); + BOOST_TEST(exprStmtData.expr->expr.at(0).IsCommon()); + BOOST_TEST(exprStmtData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(exprStmtData.expr.ToString() == "0"); + + const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(returnData.expr.IsCommon()); + BOOST_TEST(returnData.expr->expr.size() == 1); + BOOST_TEST(returnData.expr->expr.at(0).IsCommon()); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(returnData.expr.ToString() == "0"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(return_to_expr) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { return 0; }", "void foo() { 0; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(returnData.expr.IsCommon()); + BOOST_TEST(returnData.expr->expr.size() == 1); + BOOST_TEST(returnData.expr->expr.at(0).IsCommon()); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(returnData.expr.ToString() == "0"); + + const srcDiffDispatch::ExprStmtData& exprStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(exprStmtData.expr.IsCommon()); + BOOST_TEST(exprStmtData.expr->expr.size() == 1); + BOOST_TEST(exprStmtData.expr->expr.at(0).IsCommon()); + BOOST_TEST(exprStmtData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(exprStmtData.expr.ToString() == "0"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(decl_to_return) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { int i = 0; }", "void foo() { return 0; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::DeclStmtData& declStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(declStmtData.decls.size() == 1); + BOOST_TEST(declStmtData.decls.at(0).IsDelete()); + BOOST_TEST(declStmtData.decls.at(0)->type.IsDelete()); + BOOST_TEST(declStmtData.decls.at(0)->type.ToString() == "int|"); + BOOST_TEST(declStmtData.decls.at(0)->name.IsDelete()); + BOOST_TEST(declStmtData.decls.at(0)->name.ToString() == "i|"); + BOOST_TEST(declStmtData.decls.at(0)->init.IsCommon()); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.size() == 1); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).IsCommon()); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).ToString>() == "0"); + BOOST_TEST(declStmtData.decls.at(0)->init.ToString() == "0"); + BOOST_TEST(declStmtData.decls.at(0).ToString(srcDispatch::DELETE) == "int i = 0"); + + const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(returnData.expr.IsCommon()); + BOOST_TEST(returnData.expr->expr.size() == 1); + BOOST_TEST(returnData.expr->expr.at(0).IsCommon()); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(returnData.expr.ToString() == "0"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(return_to_decl) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { return 0; }", "void foo() { int i = 0; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); + + const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + BOOST_TEST(returnData.expr.IsCommon()); + BOOST_TEST(returnData.expr->expr.size() == 1); + BOOST_TEST(returnData.expr->expr.at(0).IsCommon()); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(returnData.expr.ToString() == "0"); + + const srcDiffDispatch::DeclStmtData& declStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + BOOST_TEST(declStmtData.decls.size() == 1); + BOOST_TEST(declStmtData.decls.at(0).IsInsert()); + BOOST_TEST(declStmtData.decls.at(0)->type.IsInsert()); + BOOST_TEST(declStmtData.decls.at(0)->type.ToString() == "|int"); + BOOST_TEST(declStmtData.decls.at(0)->name.IsInsert()); + BOOST_TEST(declStmtData.decls.at(0)->name.ToString() == "|i"); + BOOST_TEST(declStmtData.decls.at(0)->init.IsCommon()); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.size() == 1); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).IsCommon()); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).ToString>() == "0"); + BOOST_TEST(declStmtData.decls.at(0)->init.ToString() == "0"); + BOOST_TEST(declStmtData.decls.at(0).ToString(srcDispatch::INSERT) == "int i = 0"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testExprStmt.cpp b/test/suite/testExprStmt.cpp new file mode 100644 index 0000000..a22cd4a --- /dev/null +++ b/test/suite/testExprStmt.cpp @@ -0,0 +1,185 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testExprStmt.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE expr_stmt tests +#include + +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(block_change_common_expr_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { a; }", "void foo() { a; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_expr_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { a; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::ExprStmtData& expr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(expr.expr); + BOOST_TEST(expr.expr.IsInsert()); + BOOST_TEST(expr.expr->expr.size() == 1); + BOOST_TEST(expr.expr->expr.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(expr.expr->expr.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(expr.expr->expr.at(0).ToString>() == "|a"); + BOOST_TEST(expr.expr.ToString() == "|a"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|a"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_expr_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { a; }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::ExprStmtData& expr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(expr.expr); + BOOST_TEST(expr.expr.IsDelete()); + BOOST_TEST(expr.expr->expr.size() == 1); + BOOST_TEST(expr.expr->expr.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(expr.expr->expr.at(0).GetElement())->name.IsDelete()); + BOOST_TEST(expr.expr->expr.at(0).ToString>() == "a|"); + BOOST_TEST(expr.expr.ToString() == "a|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_expr_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { a - b; }", "void foo() { a + b; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ExprStmtData& expr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(expr.expr); + BOOST_TEST(expr.expr.IsCommon()); + BOOST_TEST(expr.expr->expr.size() == 3); + BOOST_TEST(expr.expr->expr.at(0).IsCommon()); + BOOST_TEST(expr.expr->expr.at(0).ToString>() == "a"); + BOOST_TEST(expr.expr->expr.at(1).IsCommon()); + BOOST_TEST(std::any_cast>(expr.expr->expr.at(1).GetElement())->op.IsChange()); + BOOST_TEST(std::any_cast>(expr.expr->expr.at(1).GetElement())->op.ToString() == "-|+"); + BOOST_TEST(expr.expr->expr.at(1).ToString>() == "-|+"); + BOOST_TEST(expr.expr->expr.at(2).IsCommon()); + BOOST_TEST(expr.expr->expr.at(2).ToString>() == "b"); + BOOST_TEST(expr.expr.ToString() == "a - b|a + b"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a - b|a + b"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_replace_expr_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { a; }", "void foo() { b; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 2); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::ExprStmtData& deletedExpr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(deletedExpr.expr); + BOOST_TEST(deletedExpr.expr.IsDelete()); + BOOST_TEST(deletedExpr.expr->expr.size() == 1); + BOOST_TEST(deletedExpr.expr->expr.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(deletedExpr.expr->expr.at(0).GetElement())->name.IsDelete()); + BOOST_TEST(deletedExpr.expr->expr.at(0).ToString>() == "a|"); + BOOST_TEST(deletedExpr.expr.ToString() == "a|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a|"); + + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).IsInsert()); + + const srcDiffDispatch::ExprStmtData& insertedExpr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(1).GetElement()); + BOOST_TEST(insertedExpr.expr); + BOOST_TEST(insertedExpr.expr.IsInsert()); + BOOST_TEST(insertedExpr.expr->expr.size() == 1); + BOOST_TEST(insertedExpr.expr->expr.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(insertedExpr.expr->expr.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(insertedExpr.expr->expr.at(0).ToString>() == "|b"); + BOOST_TEST(insertedExpr.expr.ToString() == "|b"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|b"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testFor.cpp b/test/suite/testFor.cpp new file mode 100644 index 0000000..afd9982 --- /dev/null +++ b/test/suite/testFor.cpp @@ -0,0 +1,124 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testFor.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE for_stmt tests +#include + +#include + +#include +#include +#include + +#include + +// Define test data +namespace data = boost::unit_test; + +// // for and control +BOOST_AUTO_TEST_CASE(block_common_for) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(; 1; ) {} }", "void foo() { for(; 1; ) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsCommon()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsCommon()); + BOOST_TEST(forData.control->init->inits.size() == 0); + BOOST_TEST(forData.control->condition.IsCommon()); + BOOST_TEST(forData.control->condition.ToString() == "1"); + BOOST_TEST(forData.control->incr.IsCommon()); + BOOST_TEST(forData.control->incr->exprs.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "; 1; "); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_for) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { for(; 1; ) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsInsert()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsInsert()); + BOOST_TEST(forData.control->init->inits.size() == 0); + BOOST_TEST(forData.control->condition.IsInsert()); + BOOST_TEST(forData.control->condition.ToString() == "|1"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsInsert()); + BOOST_TEST(forData.control->incr->exprs.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|; 1; "); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_for) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { for(; 1; ) {} }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(forData.control.IsDelete()); + BOOST_TEST(forData.control->init); + BOOST_TEST(forData.control->init.IsDelete()); + BOOST_TEST(forData.control->init->inits.size() == 0); + BOOST_TEST(forData.control->condition.IsDelete()); + BOOST_TEST(forData.control->condition.ToString() == "1|"); + BOOST_TEST(forData.control->incr); + BOOST_TEST(forData.control->incr.IsDelete()); + BOOST_TEST(forData.control->incr->exprs.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "; 1; |"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testFunction.cpp b/test/suite/testFunction.cpp new file mode 100644 index 0000000..d478974 --- /dev/null +++ b/test/suite/testFunction.cpp @@ -0,0 +1,1194 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testFunction.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE function tests +#include + +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(function_foo) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("#include \n#include \n\nclass Person {\nprivate:\n std::string name_;\n int age_;\n\npublic:\n // Constructor\n Person(const std::string& NAME, int AGE): name_(NAME), age_(AGE) {}\n\n // Getter\n std::string getName() const {\n return name_;\n }\n\n // Setter\n void setName(const std::string& newName) {\n name_ = newName;\n }\n\n // Method\n void sayHello() const {\n std::cout << \"Hi, my name is \" << name_ << \" and I am \" << age_ << \" years old.\n\";\n }\n", "#include \n#include \n\nclass Person {\nprivate:\n std::string name_;\n int age_;\n\npublic:\n // Constructor\n Person(const std::string& NAME, int AGE): name_(NAME), age_(AGE) {}\n\n // Getter\n std::string getName() const {\n return name_;\n }\n\n // Setter\n void setName(const std::string& newName) {\n name_ = newName;\n }\n\n // Method\n void sayHello() const {\n std::cout << \"Hi, my name is \" << name_ << \" and I am \" << age_ << \" years old.\n\";\n }\n"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 0); + BOOST_TEST(runner.GetClassInfo().size() == 1); + + std::cerr << "HERE: " << __FILE__ << ' ' << __FUNCTION__ << ' ' << __LINE__ << ' ' << runner.GetClassInfo().at(0)->constructors.at(0) << '\n'; +} + +BOOST_AUTO_TEST_CASE(function_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(function_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "|void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "|foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "|foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "|void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(function_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", ""); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}|"); +} + +BOOST_AUTO_TEST_CASE(function_name_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void bar() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsChange()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo|bar"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.GetOriginal() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.GetModified() == "bar"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}|void bar() {}"); +} + +BOOST_AUTO_TEST_CASE(function_return_type_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "int foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.GetElement())->name.IsChange()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void|int"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}|int foo() {}"); +} + +BOOST_AUTO_TEST_CASE(function_add_parameter) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo(int i) {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).first.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.ToString() == "|int"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.ToString() == "|i"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}|void foo(int i) {}"); +} + +BOOST_AUTO_TEST_CASE(function_remove_parameter) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo(double d) {}", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).first.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.ToString() == "double|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.ToString() == "d|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo(double d) {}|void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(function_parameter_type_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo(double d) {}", "void foo(int d) {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).first.GetElement())->name.IsChange()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.ToString() == "double|int"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.ToString() == "d"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo(double d) {}|void foo(int d) {}"); +} + +BOOST_AUTO_TEST_CASE(function_parameter_name_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo(double d) {}", "void foo(double num) {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.ToString() == "double"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name->name.IsChange()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.ToString() == "d|num"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo(double d) {}|void foo(double num) {}"); +} + +BOOST_AUTO_TEST_CASE(function_parameter_multi_change) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo(int i, double d) {}", "void foo(double d, long l) {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 3); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).first.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.ToString() == "int|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.ToString() == "i|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(1).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(1)->type.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(1)->type->types.at(0).first.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->parameters.at(1)->type->types.at(0).first.GetElement())->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(1)->type.ToString() == "double"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(1)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(1)->name.ToString() == "d"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type->types.at(0).second.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type->types.at(0).first.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type.ToString() == "|long"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->name.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->name.ToString() == "|l"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo(int i, double d) {}|void foo(double d, long l) {}"); +} + +// decl to def +BOOST_AUTO_TEST_CASE(function_decl_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo();", "void foo();"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->block); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo();"); +} + +// specifiers +BOOST_AUTO_TEST_CASE(function_specifier_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo();", "void foo() const;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.at(0).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.at(0).ToString() == "|const"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->block); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo();|void foo() const;"); +} + +BOOST_AUTO_TEST_CASE(function_specifier_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() const;", "void foo();"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.at(0).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.at(0).ToString() == "const|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->block); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() const;|void foo();"); +} + +BOOST_AUTO_TEST_CASE(function_pure_virtual_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo();", "void foo() = 0;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(runner.GetFunctionInfo().at(0)->isPureVirtual.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->isPureVirtual.GetElement()); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->block); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo();|void foo() = 0;"); +} + +BOOST_AUTO_TEST_CASE(function_pure_virtual_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() = 0;", "void foo();"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(runner.GetFunctionInfo().at(0)->isPureVirtual.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->isPureVirtual.GetElement()); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->block); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() = 0;|void foo();"); +} + +BOOST_AUTO_TEST_CASE(function_pure_delete_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo();", "void foo() = delete;"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->isDelete); + BOOST_TEST(runner.GetFunctionInfo().at(0)->isDelete.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->isDelete.GetElement()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->block); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo();|void foo() = delete;"); +} + +BOOST_AUTO_TEST_CASE(function_pure_delete_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() = delete;", "void foo();"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(runner.GetFunctionInfo().at(0)->isDelete); + BOOST_TEST(runner.GetFunctionInfo().at(0)->isDelete.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->isDelete.GetElement()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->block); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() = delete;|void foo();"); +} + +// block +BOOST_AUTO_TEST_CASE(function_block_insert_expr_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { a; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::ExprStmtData& expr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(expr.expr); + BOOST_TEST(expr.expr.IsInsert()); + BOOST_TEST(expr.expr->expr.size() == 1); + BOOST_TEST(expr.expr->expr.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(expr.expr->expr.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(expr.expr->expr.at(0).ToString>() == "|a"); + BOOST_TEST(expr.expr.ToString() == "|a"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|a"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +// operator +BOOST_AUTO_TEST_CASE(function_operator_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("bool operator==() {}", "bool operator==() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::OPERATOR); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "bool"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "operator=="); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "operator"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "bool operator==() {}"); +} + +BOOST_AUTO_TEST_CASE(function_operator_common_decl) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("bool operator==();", "bool operator==();"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::OPERATOR); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "bool"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "operator=="); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "operator"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->block); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "bool operator==();"); +} + +BOOST_AUTO_TEST_CASE(function_operator_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("", "bool operator==() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::OPERATOR); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "|bool"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "|operator=="); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "|operator"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "|bool operator==() {}"); +} + +BOOST_AUTO_TEST_CASE(function_operator_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("bool operator==() {}", ""); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::OPERATOR); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "bool|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "operator==|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "operator|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "bool operator==() {}|"); +} + +BOOST_AUTO_TEST_CASE(function_operator_type) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("operator bool() {}", "operator bool() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::OPERATOR); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->returnType); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "operator bool"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "operator "); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "operator bool() {}"); +} + +// template function +BOOST_AUTO_TEST_CASE(function_template_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(function_template_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "template void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "|template"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(function_template_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void foo() {}", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); + BOOST_TEST(!runner.GetFunctionInfo().at(0)->isDelete); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->leadingSpecifiers.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->trailingSpecifiers.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->names.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name.ToString() == "foo"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->name->name.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +// decl to defn (add to srcDiff first) diff --git a/test/suite/testGoto.cpp b/test/suite/testGoto.cpp new file mode 100644 index 0000000..cd26db9 --- /dev/null +++ b/test/suite/testGoto.cpp @@ -0,0 +1,323 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testGoto.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE goto_stmts tests +#include + +#include + +#include +#include +#include + +#include + +// Define test data +namespace data = boost::unit_test; + +// goto/break/continue +BOOST_AUTO_TEST_CASE(block_change_common_break) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { break; }", "void foo() { break; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(gotoData.type.IsCommon()); + BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::BREAK); + BOOST_TEST(!gotoData.label); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_insert_break) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { break; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(gotoData.type.IsInsert()); + BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::BREAK); + BOOST_TEST(!gotoData.label); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_delete_break) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { break; }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(gotoData.type.IsDelete()); + BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::BREAK); + BOOST_TEST(!gotoData.label); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_common_continue) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { continue; }", "void foo() { continue; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(gotoData.type.IsCommon()); + BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::CONTINUE); + BOOST_TEST(!gotoData.label); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_insert_continue) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { continue; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(gotoData.type.IsInsert()); + BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::CONTINUE); + BOOST_TEST(!gotoData.label); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_delete_continue) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { continue; }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(gotoData.type.IsDelete()); + BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::CONTINUE); + BOOST_TEST(!gotoData.label); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_common_goto) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { goto; }", "void foo() { goto; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(gotoData.type.IsCommon()); + BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::GOTO); + BOOST_TEST(!gotoData.label); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_insert_goto) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { goto; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(gotoData.type.IsInsert()); + BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::GOTO); + BOOST_TEST(!gotoData.label); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_delete_goto) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { goto; }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(gotoData.type.IsDelete()); + BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::GOTO); + BOOST_TEST(!gotoData.label); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_common_label_goto) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { goto foo; }", "void foo() { goto foo; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(gotoData.type.IsCommon()); + BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::GOTO); + BOOST_TEST(gotoData.label.IsCommon()); + BOOST_TEST(gotoData.label.ToString() == "foo"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_rename_label_goto) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { goto foo; }", "void foo() { goto bar; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + + BOOST_TEST(gotoData.type.IsCommon()); + BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::GOTO); + BOOST_TEST(gotoData.label.IsCommon()); + BOOST_TEST(gotoData.label->name.IsChange()); + BOOST_TEST(gotoData.label.ToString() == "foo|bar"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testIfStmt.cpp b/test/suite/testIfStmt.cpp new file mode 100644 index 0000000..3084aff --- /dev/null +++ b/test/suite/testIfStmt.cpp @@ -0,0 +1,478 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testIfStmt.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE if_stmt tests +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(block_change_common_if_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { if(1) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_if_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { if(1) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 1); + BOOST_TEST(ifStmt.clauses.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "|1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "|1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_if_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { if(1) {} }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 1); + BOOST_TEST(ifStmt.clauses.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1|"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_condition_if_stmt) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { if(2) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 1); + BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1|2"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1|2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|2"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_common_elseif) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { if(1) {} else if(2) {} }", "void foo() { if(1) {} else if(2) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 2); + + BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); + + BOOST_TEST(ifStmt.clauses.at(1).IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "2"); + BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_elseif_whole) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { if(1) {} else if(2) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 2); + + BOOST_TEST(ifStmt.clauses.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "|1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "|1"); + + BOOST_TEST(ifStmt.clauses.at(1).IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "|2"); + BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "|2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_elseif_whole) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {if(1) {} else if(2) {} }", "void foo() { }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 2); + + BOOST_TEST(ifStmt.clauses.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1|"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1|"); + + BOOST_TEST(ifStmt.clauses.at(1).IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "2|"); + BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "2|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_elseif) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { if(1) {} else if(2) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 2); + + BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); + + BOOST_TEST(ifStmt.clauses.at(1).IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "|2"); + BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "|2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_elseif) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { if(1) {} else if(2) {} }", "void foo() { if(1) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 2); + + BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); + + BOOST_TEST(ifStmt.clauses.at(1).IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "2|"); + BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "2|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_common_else) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { if(1) {} else {} }", "void foo() { if(1) {} else {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 2); + + BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); + + BOOST_TEST(ifStmt.clauses.at(1).IsCommon()); + BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_else_whole) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { if(1) {} else {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 2); + + BOOST_TEST(ifStmt.clauses.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "|1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "|1"); + + BOOST_TEST(ifStmt.clauses.at(1).IsInsert()); + BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_else_whole) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {if(1) {} else {} }", "void foo() { }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 2); + + BOOST_TEST(ifStmt.clauses.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1|"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + + BOOST_TEST(ifStmt.clauses.at(1).IsDelete()); + BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_else) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { if(1) {} else {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 2); + + BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + + BOOST_TEST(ifStmt.clauses.at(1).IsInsert()); + BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_else) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { if(1) {} else {} }", "void foo() { if(1) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(ifStmt.clauses.size() == 2); + + BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + + BOOST_TEST(ifStmt.clauses.at(1).IsDelete()); + BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testLabel.cpp b/test/suite/testLabel.cpp new file mode 100644 index 0000000..b51f719 --- /dev/null +++ b/test/suite/testLabel.cpp @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testLabel.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE label tests +#include + +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(block_common_label) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { label: }", "void foo() { label: }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(0)->name.ToString() == "label"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_label) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { label: }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(0).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(0)->name.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(0)->name.ToString() == "|label"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_label) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { label: }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(0).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(0)->name.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(0)->name.ToString() == "label|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_replace_label) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { foo: }", "void foo() { bar: }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 2); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(0).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(0)->name.IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(0)->name.ToString() == "foo|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(1).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(1)->name.IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.at(1)->name.ToString() == "|bar"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testReturn.cpp b/test/suite/testReturn.cpp new file mode 100644 index 0000000..4eaa81d --- /dev/null +++ b/test/suite/testReturn.cpp @@ -0,0 +1,214 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testReturn.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE return_stmt tests +#include + +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(block_change_common_return) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { return 0; }", "void foo() { return 0; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "0"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_return) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { return a; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(returnData.expr); + BOOST_TEST(returnData.expr.IsInsert()); + BOOST_TEST(returnData.expr->expr.size() == 1); + BOOST_TEST(returnData.expr->expr.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(returnData.expr->expr.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "|a"); + BOOST_TEST(returnData.expr.ToString() == "|a"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|a"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_return) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { return a; }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(returnData.expr); + BOOST_TEST(returnData.expr.IsDelete()); + BOOST_TEST(returnData.expr->expr.size() == 1); + BOOST_TEST(returnData.expr->expr.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(returnData.expr->expr.at(0).GetElement())->name.IsDelete()); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "a|"); + BOOST_TEST(returnData.expr.ToString() == "a|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_return) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { return a - b; }", "void foo() { return a + b; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(returnData.expr); + BOOST_TEST(returnData.expr.IsCommon()); + BOOST_TEST(returnData.expr->expr.size() == 3); + BOOST_TEST(returnData.expr->expr.at(0).IsCommon()); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "a"); + BOOST_TEST(returnData.expr->expr.at(1).IsCommon()); + BOOST_TEST(std::any_cast>(returnData.expr->expr.at(1).GetElement())->op.IsChange()); + BOOST_TEST(std::any_cast>(returnData.expr->expr.at(1).GetElement())->op.ToString() == "-|+"); + BOOST_TEST(returnData.expr->expr.at(1).ToString>() == "-|+"); + BOOST_TEST(returnData.expr->expr.at(2).IsCommon()); + BOOST_TEST(returnData.expr->expr.at(2).ToString>() == "b"); + BOOST_TEST(returnData.expr.ToString() == "a - b|a + b"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a - b|a + b"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_return_expr) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { return a; }", "void foo() { return b; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(returnData.expr); + BOOST_TEST(returnData.expr.IsCommon()); + BOOST_TEST(returnData.expr->expr.size() == 1); + BOOST_TEST(returnData.expr->expr.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(returnData.expr->expr.at(0).GetElement())->name.IsChange()); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "a|b"); + BOOST_TEST(returnData.expr.ToString() == "a|b"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a|b"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_whole_return) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { return 0; }", "void foo() { return a; }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(returnData.expr); + BOOST_TEST(returnData.expr.IsChange()); + + BOOST_TEST(returnData.expr.GetOriginal()->expr.size() == 1); + BOOST_TEST(returnData.expr.GetOriginal()->expr.at(0).IsDelete()); + BOOST_TEST(returnData.expr.GetOriginal()->expr.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(returnData.expr.GetOriginal()->expr.at(0).GetElement())->literal.IsDelete()); + BOOST_TEST(std::any_cast>(returnData.expr.GetOriginal()->expr.at(0).GetElement())->literal.ToString() == "0|"); + BOOST_TEST(returnData.expr.GetOriginal()->expr.at(0).ToString>() == "0|"); + + BOOST_TEST(returnData.expr.GetModified()->expr.size() == 1); + BOOST_TEST(returnData.expr.GetModified()->expr.at(0).IsInsert()); + BOOST_TEST(returnData.expr.GetModified()->expr.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(returnData.expr.GetModified()->expr.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(std::any_cast>(returnData.expr.GetModified()->expr.at(0).GetElement())->name.ToString() == "|a"); + BOOST_TEST(returnData.expr.GetModified()->expr.at(0).ToString>() == "|a"); + + BOOST_TEST(returnData.expr.ToString() == "0|a"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "0|a"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testSwitch.cpp b/test/suite/testSwitch.cpp new file mode 100644 index 0000000..a87a116 --- /dev/null +++ b/test/suite/testSwitch.cpp @@ -0,0 +1,164 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testSwitch.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE switch_stmt tests +#include + +#include + +#include +#include +#include + +#include + +// Define test data +namespace data = boost::unit_test; + +// switch +BOOST_AUTO_TEST_CASE(block_change_common_switch) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { switch(1) {} }", "void foo() { switch(1) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_switch) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { switch(1) {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(switchData.condition); + BOOST_TEST(switchData.condition.IsInsert()); + BOOST_TEST(switchData.condition->conditions.size() == 1); + BOOST_TEST(switchData.condition->conditions.at(0).IsInsert()); + + const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(switchData.condition->conditions.at(0).GetElement()); + BOOST_TEST(expr.expr.size() == 1); + BOOST_TEST(expr.expr.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "|1"); + BOOST_TEST(expr.expr.at(0).ToString>() == "|1"); + BOOST_TEST(switchData.condition->conditions.at(0).ToString>() == "|1"); + BOOST_TEST(switchData.condition.ToString() == "|1"); + + BOOST_TEST(switchData.block.IsInsert()); + BOOST_TEST(switchData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_switch) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { switch(1) {}", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(switchData.condition); + BOOST_TEST(switchData.condition.IsDelete()); + BOOST_TEST(switchData.condition->conditions.size() == 1); + BOOST_TEST(switchData.condition->conditions.at(0).IsDelete()); + + const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(switchData.condition->conditions.at(0).GetElement()); + BOOST_TEST(expr.expr.size() == 1); + BOOST_TEST(expr.expr.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "1|"); + BOOST_TEST(expr.expr.at(0).ToString>() == "1|"); + BOOST_TEST(switchData.condition->conditions.at(0).ToString>() == "1|"); + BOOST_TEST(switchData.condition.ToString() == "1|"); + + BOOST_TEST(switchData.block.IsDelete()); + BOOST_TEST(switchData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_replace_switch) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { switch(1) { default: a; } }", "void foo() { switch(2) { default: b; } }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 2); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::SwitchData& deletedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(deletedData.condition.IsDelete()); + BOOST_TEST(deletedData.block.IsDelete()); + BOOST_TEST(deletedData.block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).IsInsert()); + + const srcDiffDispatch::SwitchData& insertedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(1).GetElement()); + BOOST_TEST(insertedData.condition.IsInsert()); + BOOST_TEST(insertedData.block.IsInsert()); + BOOST_TEST(insertedData.block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|2"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testTemplate.cpp b/test/suite/testTemplate.cpp new file mode 100644 index 0000000..1400a74 --- /dev/null +++ b/test/suite/testTemplate.cpp @@ -0,0 +1,335 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testFunction.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE template tests +#include + +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(template_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(template_insert_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void func() {}", "template template void func() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 2); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "|template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).ToString() == "template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void func() {}"); +} + +BOOST_AUTO_TEST_CASE(template_insert_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void func() {}", "template template void func() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 2); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).ToString() == "|template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void func() {}"); +} + +BOOST_AUTO_TEST_CASE(template_delete_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template template void func() {}", "template void func() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 2); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).ToString() == "template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void func() {}"); +} + +BOOST_AUTO_TEST_CASE(template_delete_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template template void func() {}", "template void func() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 2); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).ToString() == "template|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void func() {}"); +} + +BOOST_AUTO_TEST_CASE(template_insert_parameter_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.size() == 2); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(1).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(template_insert_parameter_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.size() == 2); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(1).IsInsert()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(template_delete_parameter_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.size() == 2); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(1).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(template_delete_parameter_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.size() == 2); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(1).IsDelete()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(template_modify_parameter_type) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0)->type.ToString() == "typename|class"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0)->name.ToString() == "type"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).ToString() == "typename type|class type"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(template_modify_parameter_name) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0)->type.ToString() == "typename"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0)->name.ToString() == "type|T"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).ToString() == "typename type|typename T"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(template_modify_parameter_init) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0)->type.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0)->type.ToString() == "typename"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0)->name.IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0)->name.ToString() == "type"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).ToString() == "typename type|typename type = object"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(template_common_int) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(template_common_int_insert_init) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testThrow.cpp b/test/suite/testThrow.cpp new file mode 100644 index 0000000..117afb5 --- /dev/null +++ b/test/suite/testThrow.cpp @@ -0,0 +1,138 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testThrow.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE throw_stmt tests +#include + +#include + +#include +#include +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(block_change_common_throw) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { throw std::string(); }", "void foo() { throw std::string(); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "std::string()"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_throw) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { throw Exception(); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::ThrowData& throwData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(throwData.expr); + BOOST_TEST(throwData.expr.IsInsert()); + BOOST_TEST(throwData.expr->expr.size() == 1); + BOOST_TEST(throwData.expr->expr.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(throwData.expr->expr.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(throwData.expr->expr.at(0).ToString>() == "|Exception()"); + BOOST_TEST(throwData.expr.ToString() == "|Exception()"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|Exception()"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_throw) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { throw Exception(); }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::ThrowData& throwData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(throwData.expr); + BOOST_TEST(throwData.expr.IsDelete()); + BOOST_TEST(throwData.expr->expr.size() == 1); + BOOST_TEST(throwData.expr->expr.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(throwData.expr->expr.at(0).GetElement())->name.IsDelete()); + BOOST_TEST(throwData.expr->expr.at(0).ToString>() == "Exception()|"); + BOOST_TEST(throwData.expr.ToString() == "Exception()|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "Exception()|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_throw) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { throw std::string(); }", "void foo() { throw Exception(); }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::ThrowData& throwData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(throwData.expr); + BOOST_TEST(throwData.expr.IsChange()); + BOOST_TEST(throwData.expr.GetOriginal()->expr.size() == 1); + BOOST_TEST(throwData.expr.GetOriginal()->expr.at(0).IsDelete()); + BOOST_TEST(throwData.expr.GetOriginal()->expr.at(0).ToString>() == "std::string()|"); + BOOST_TEST(throwData.expr.GetModified()->expr.size() == 1); + BOOST_TEST(throwData.expr.GetModified()->expr.at(0).IsInsert()); + BOOST_TEST(throwData.expr.GetModified()->expr.at(0).ToString>() == "|Exception()"); + BOOST_TEST(throwData.expr.ToString() == "std::string()|Exception()"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "std::string()|Exception()"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} \ No newline at end of file diff --git a/test/suite/testTry.cpp b/test/suite/testTry.cpp new file mode 100644 index 0000000..dc01d3b --- /dev/null +++ b/test/suite/testTry.cpp @@ -0,0 +1,509 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testIfStmt.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE try_catch tests +#include + +#include + +#include +#include +#include + +#include +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(try_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} }", "void foo() { try {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block)); + BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block.IsCommon())); + BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->clauses.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(try_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { try {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ModifiedType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block)); + BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block.IsInsert())); + BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->clauses.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(try_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} }", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block)); + BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block.IsDelete())); + BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->clauses.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(catch_common) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} catch() {} }", "void foo() { try {} catch() {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + + const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(bool(tryData.block)); + BOOST_TEST(bool(tryData.block.IsCommon())); + + BOOST_TEST(tryData.clauses.size() == 1); + BOOST_TEST(tryData.clauses.at(0).IsCommon()); + + const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + BOOST_TEST(catchData.parameters.size() == 0); + BOOST_TEST(catchData.block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(catch_insert) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} }", "void foo() { try {} catch() {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + + const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(bool(tryData.block)); + BOOST_TEST(bool(tryData.block.IsCommon())); + + BOOST_TEST(tryData.clauses.size() == 1); + BOOST_TEST(tryData.clauses.at(0).IsInsert()); + + const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + BOOST_TEST(catchData.parameters.size() == 0); + BOOST_TEST(catchData.block.IsInsert()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(catch_delete) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} catch() {} }", "void foo() { try {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + + const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(bool(tryData.block)); + BOOST_TEST(bool(tryData.block.IsCommon())); + + BOOST_TEST(tryData.clauses.size() == 1); + BOOST_TEST(tryData.clauses.at(0).IsDelete()); + + const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + BOOST_TEST(catchData.parameters.size() == 0); + BOOST_TEST(catchData.block.IsDelete()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(catch_common_param) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch(Exception e) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + + const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(bool(tryData.block)); + BOOST_TEST(bool(tryData.block.IsCommon())); + + BOOST_TEST(tryData.clauses.size() == 1); + BOOST_TEST(tryData.clauses.at(0).IsCommon()); + + const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + BOOST_TEST(catchData.parameters.size() == 1); + BOOST_TEST(catchData.parameters.at(0).IsCommon()); + BOOST_TEST(catchData.parameters.at(0).ToString() == "Exception e"); + + BOOST_TEST(catchData.block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(catch_insert_param) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} catch() {} }", "void foo() { try {} catch(Exception e) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + + const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(bool(tryData.block)); + BOOST_TEST(bool(tryData.block.IsCommon())); + + BOOST_TEST(tryData.clauses.size() == 1); + BOOST_TEST(tryData.clauses.at(0).IsCommon()); + + const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + BOOST_TEST(catchData.parameters.size() == 1); + BOOST_TEST(catchData.parameters.at(0).IsInsert()); + BOOST_TEST(catchData.parameters.at(0).ToString() == "|Exception e"); + + BOOST_TEST(catchData.block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(catch_delete_param) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch() {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + + const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(bool(tryData.block)); + BOOST_TEST(bool(tryData.block.IsCommon())); + + BOOST_TEST(tryData.clauses.size() == 1); + BOOST_TEST(tryData.clauses.at(0).IsCommon()); + + const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + BOOST_TEST(catchData.parameters.size() == 1); + BOOST_TEST(catchData.parameters.at(0).IsDelete()); + BOOST_TEST(catchData.parameters.at(0).ToString() == "Exception e|"); + + BOOST_TEST(catchData.block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(catch_common_param_insert_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch(foo bar, Exception e) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + + const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(bool(tryData.block)); + BOOST_TEST(bool(tryData.block.IsCommon())); + + BOOST_TEST(tryData.clauses.size() == 1); + BOOST_TEST(tryData.clauses.at(0).IsCommon()); + + const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + BOOST_TEST(catchData.parameters.size() == 2); + BOOST_TEST(catchData.parameters.at(0).IsInsert()); + BOOST_TEST(catchData.parameters.at(0).ToString() == "|foo bar"); + BOOST_TEST(catchData.parameters.at(1).IsCommon()); + BOOST_TEST(catchData.parameters.at(1).ToString() == "Exception e"); + + BOOST_TEST(catchData.block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(catch_common_param_insert_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch(Exception e, foo bar) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + + const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(bool(tryData.block)); + BOOST_TEST(bool(tryData.block.IsCommon())); + + BOOST_TEST(tryData.clauses.size() == 1); + BOOST_TEST(tryData.clauses.at(0).IsCommon()); + + const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + BOOST_TEST(catchData.parameters.size() == 2); + BOOST_TEST(catchData.parameters.at(0).IsCommon()); + BOOST_TEST(catchData.parameters.at(0).ToString() == "Exception e"); + BOOST_TEST(catchData.parameters.at(1).IsInsert()); + BOOST_TEST(catchData.parameters.at(1).ToString() == "|foo bar"); + + BOOST_TEST(catchData.block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(catch_common_param_delete_front) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} catch(foo bar, Exception e) {} }", "void foo() { try {} catch(Exception e) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + + const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(bool(tryData.block)); + BOOST_TEST(bool(tryData.block.IsCommon())); + + BOOST_TEST(tryData.clauses.size() == 1); + BOOST_TEST(tryData.clauses.at(0).IsCommon()); + + const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + BOOST_TEST(catchData.parameters.size() == 2); + BOOST_TEST(catchData.parameters.at(0).IsDelete()); + BOOST_TEST(catchData.parameters.at(0).ToString() == "foo bar|"); + BOOST_TEST(catchData.parameters.at(1).IsCommon()); + BOOST_TEST(catchData.parameters.at(1).ToString() == "Exception e"); + + BOOST_TEST(catchData.block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(catch_common_param_delete_back) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} catch(Exception e, foo bar) {} }", "void foo() { try {} catch(Exception e) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + + const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(bool(tryData.block)); + BOOST_TEST(bool(tryData.block.IsCommon())); + + BOOST_TEST(tryData.clauses.size() == 1); + BOOST_TEST(tryData.clauses.at(0).IsCommon()); + + const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + BOOST_TEST(catchData.parameters.size() == 2); + BOOST_TEST(catchData.parameters.at(0).IsCommon()); + BOOST_TEST(catchData.parameters.at(0).ToString() == "Exception e"); + BOOST_TEST(catchData.parameters.at(1).IsDelete()); + BOOST_TEST(catchData.parameters.at(1).ToString() == "foo bar|"); + + BOOST_TEST(catchData.block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(catch_common_param_replace) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { try {} catch(std::string str) {} }", "void foo() { try {} catch(Exception e) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + + const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(bool(tryData.block)); + BOOST_TEST(bool(tryData.block.IsCommon())); + + BOOST_TEST(tryData.clauses.size() == 1); + BOOST_TEST(tryData.clauses.at(0).IsCommon()); + + const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + BOOST_TEST(catchData.parameters.size() == 2); + BOOST_TEST(catchData.parameters.at(0).IsDelete()); + BOOST_TEST(catchData.parameters.at(0).ToString() == "std::string str|"); + BOOST_TEST(catchData.parameters.at(1).IsInsert()); + BOOST_TEST(catchData.parameters.at(1).ToString() == "|Exception e"); + + BOOST_TEST(catchData.block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} diff --git a/test/suite/testWhile.cpp b/test/suite/testWhile.cpp new file mode 100644 index 0000000..9a5992b --- /dev/null +++ b/test/suite/testWhile.cpp @@ -0,0 +1,225 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file testWhile.cpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiff Infrastructure. + */ + +#define BOOST_TEST_MODULE while_stmt tests +#include + +#include + +#include +#include +#include + +#include + +// Define test data +namespace data = boost::unit_test; + +BOOST_AUTO_TEST_CASE(block_common_while) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { while(1) {} }", "void foo() { while(1) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(whileData.condition); + BOOST_TEST(whileData.condition.IsCommon()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); + + const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(whileData.condition->conditions.at(0).GetElement()); + BOOST_TEST(expr.expr.size() == 1); + BOOST_TEST(expr.expr.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "1"); + BOOST_TEST(expr.expr.at(0).ToString>() == "1"); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "1"); + BOOST_TEST(whileData.condition.ToString() == "1"); + + BOOST_TEST(whileData.block.IsCommon()); + BOOST_TEST(whileData.block->statements.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_insert_while) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() {}", "void foo() { while(1) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(whileData.condition); + BOOST_TEST(whileData.condition.IsInsert()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsInsert()); + + const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(whileData.condition->conditions.at(0).GetElement()); + BOOST_TEST(expr.expr.size() == 1); + BOOST_TEST(expr.expr.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "|1"); + BOOST_TEST(expr.expr.at(0).ToString>() == "|1"); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "|1"); + BOOST_TEST(whileData.condition.ToString() == "|1"); + + BOOST_TEST(whileData.block.IsInsert()); + BOOST_TEST(whileData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_delete_while) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { while(1) {}", "void foo() {}"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(whileData.condition); + BOOST_TEST(whileData.condition.IsDelete()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsDelete()); + + const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(whileData.condition->conditions.at(0).GetElement()); + BOOST_TEST(expr.expr.size() == 1); + BOOST_TEST(expr.expr.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "1|"); + BOOST_TEST(expr.expr.at(0).ToString>() == "1|"); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "1|"); + BOOST_TEST(whileData.condition.ToString() == "1|"); + + BOOST_TEST(whileData.block.IsDelete()); + BOOST_TEST(whileData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_change_condition_expr_while) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { while(1) {}", "void foo() { while(2) {} }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); + + const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(whileData.condition); + BOOST_TEST(whileData.condition.IsCommon()); + BOOST_TEST(whileData.condition->conditions.size() == 1); + BOOST_TEST(whileData.condition->conditions.at(0).IsChange()); + + const srcDiffDispatch::ExpressionData& originalExpr = *std::any_cast>(whileData.condition->conditions.at(0).GetOriginal()); + BOOST_TEST(originalExpr.expr.size() == 1); + BOOST_TEST(originalExpr.expr.at(0).IsDelete()); + BOOST_TEST(originalExpr.expr.at(0).IsDelete()); + BOOST_TEST(originalExpr.expr.at(0).ToString>() == "1|"); + + const srcDiffDispatch::ExpressionData& modifiedExpr = *std::any_cast>(whileData.condition->conditions.at(0).GetModified()); + BOOST_TEST(modifiedExpr.expr.size() == 1); + BOOST_TEST(modifiedExpr.expr.at(0).IsInsert()); + BOOST_TEST(modifiedExpr.expr.at(0).IsInsert()); + BOOST_TEST(modifiedExpr.expr.at(0).ToString>() == "|2"); + + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "1|2"); + BOOST_TEST(whileData.condition.ToString() == "1|2"); + + BOOST_TEST(whileData.block.IsCommon()); + BOOST_TEST(whileData.block->statements.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|2"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + +BOOST_AUTO_TEST_CASE(block_replace_while) { + + srcDiffDispatch::srcDiffDispatchRunner runner; + runner.RunDispatcher("void foo() { while(1) { a; }", "void foo() { while(2) { b; } }"); + + BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); + BOOST_TEST(runner.GetFunctionInfo().size() == 1); + BOOST_TEST(runner.GetClassInfo().size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block.IsCommon()); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 2); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); + + const srcDiffDispatch::WhileData& deletedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + BOOST_TEST(deletedData.condition.IsDelete()); + BOOST_TEST(deletedData.block.IsDelete()); + BOOST_TEST(deletedData.block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).IsInsert()); + + const srcDiffDispatch::WhileData& insertedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(1).GetElement()); + BOOST_TEST(insertedData.condition.IsInsert()); + BOOST_TEST(insertedData.block.IsInsert()); + BOOST_TEST(insertedData.block->statements.size() == 1); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|2"); + + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); + + BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); +} + diff --git a/test/util/srcDiffDispatchRunner.hpp b/test/util/srcDiffDispatchRunner.hpp new file mode 100644 index 0000000..612b5fc --- /dev/null +++ b/test/util/srcDiffDispatchRunner.hpp @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file srcDiffDispatchRunner.hpp + * + * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * + * This file is part of the srcDiffDispatch Infrastructure. + */ + +#ifndef INCLUDED_SRCDIFF_DISPATCH_RUNNER_HPP +#define INCLUDED_SRCDIFF_DISPATCH_RUNNER_HPP + + +#include +#include +#include + +#include +#include + +#include + +namespace srcDiffDispatch { + +class srcDiffDispatchRunner : public srcDispatch::PolicyListener { +private: + std::string srcDiff(const std::string& original, const std::string& modified) { + + std::ofstream originalFile("original.cpp"); + originalFile << original; + originalFile.close(); + + std::ofstream modifiedFile("modified.cpp"); + modifiedFile << modified; + modifiedFile.close(); + + std::system("srcdiff original.cpp modified.cpp -o srcdiff.xml"); + + std::ifstream srcDiffFile("srcdiff.xml", std::ios::ate); + std::size_t size = srcDiffFile.tellg(); + srcDiffFile.seekg(0); + + std::string srcDiffStr(size, '\0'); + srcDiffFile.read(&srcDiffStr[0], size); + + std::remove("original.cpp"); + std::remove("modified.cpp"); + std::remove("srcdiff.xml"); + + return srcDiffStr; + } + + std::shared_ptr unit; + +public: + srcDiffDispatchRunner() {} + + const std::vector>>& GetClassInfo() const { + return unit->classInfo; + } + + const std::vector>>& GetFunctionInfo() const { + return unit->functionInfo; + } + + const std::vector>>& GetDeclStmtInfo() const { + return unit->declStmtInfo; + } + + void Notify(const srcDispatch::PolicyDispatcher * policy, + const srcDispatch::srcSAXEventContext & ctx) override { + unit = policy->Data(); + } + + void NotifyWrite(const srcDispatch::PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} + + + void RunDispatcher(const std::string& original, const std::string& modified) { + + std::string srcDiffStr = srcDiff(original, modified); + try { + srcSAXController control(srcDiffStr); + srcDispatch::srcDispatcherSingleEvent dispatch(this); + control.parse(&dispatch); //Start parsing + } catch(SAXError error) { + std::cerr << error.message; + exit(1); + } + } + +}; + +} + +#endif \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index 93302b3..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -## -# CMakeLists.txt -# -# Copyright (C) 2016-2018 srcML, LLC. (www.srcML.org) -# -# This file is part of the srcSAXEventDispatch. -# -# The srcSAXEventDispatch is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# The srcSAXEventDispatch is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the srcSAXEventDispatch; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -file( GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test* ) -include_directories(${DISPATCH_INCLUDE_DIR}) -message(${SOURCES}) - -add_definitions("-std=c++11") - -find_package(LibXml2 REQUIRED) - -foreach( testsourcefile ${SOURCES} ) - string( REPLACE ".cpp" "" testname ${testsourcefile} ) - get_filename_component(file ${testsourcefile} NAME_WE) - add_executable( ${file} EXCLUDE_FROM_ALL ${testsourcefile} ) - target_link_libraries( ${file} srcsaxeventdispatch srcsax_static srcml ${DISPATCH_LIBRARIES} LibXml2::LibXml2) -endforeach( testsourcefile ${SOURCES} ) diff --git a/tests/TestCallPolicy.cpp b/tests/TestCallPolicy.cpp deleted file mode 100644 index 9c0bebe..0000000 --- a/tests/TestCallPolicy.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char *ch = new char[str.size()]; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - //TrimFromEnd(ch, size); - return std::string(ch); -} - -class TestCalls : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestCalls(){} - TestCalls(std::initializer_list listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners){} - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - calldata = *policy->Data(); - datatotest.push_back(calldata); - for(auto it : calldata.callargumentlist){ - std::cerr< datatotest; - -}; - -int main(int argc, char** filename){ - std::string codestr = "void foo(){foo(bar, baz, 2 + bin(dep, pep(1+blep)), beep);}"; - std::string srcmlstr = StringToSrcML(codestr); - - TestCalls calldata; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher handler{&calldata}; - control.parse(&handler); //Start parsing - calldata.RunTest(); -} diff --git a/tests/TestClassPolicy.cpp b/tests/TestClassPolicy.cpp deleted file mode 100644 index f1d2a36..0000000 --- a/tests/TestClassPolicy.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include -#include -#include -#include -#include -#include - -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char * ch; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - - std::string srcml; - srcml.append(ch, size); - - return srcml; -} - -class TestClassPolicy : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - - ~TestClassPolicy() { } - - TestClassPolicy(std::initializer_list listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners) { } - - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - datatotest = *policy->Data>(); - } - - void RunTest(){ - assert(datatotest[0].className == "foo_data"); - assert(datatotest[0].members[0].nameOfIdentifier == "z"); - assert(datatotest[0].members[1].nameOfIdentifier == "y"); - - assert(datatotest[1].className == "foo"); - assert(datatotest[1].members[0].nameOfIdentifier == "x"); - assert(datatotest[1].methods[0].name == "Print"); - } - protected: - - void * DataInner() const override { - return (void*)0; - } - - private: - - ClassPolicy classpolicy; - ClassPolicy::ClassData classdata; - std::vector datatotest; - -}; - -int main(int argc, char** filename){ - std::string codestr = "class foo { \n public: \n void Print() { }; \n int x; \n struct foo_data { \n int z; \n int y; \n }; \n };"; - std::string srcmlstr = StringToSrcML(codestr); - - try { - TestClassPolicy classdata; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher handler { &classdata }; - control.parse(&handler); //Start parsing - classdata.RunTest(); - } catch(SAXError e) { - std::cerr << e.message; - } -} diff --git a/tests/TestDecleTypePolicy.cpp b/tests/TestDecleTypePolicy.cpp deleted file mode 100644 index 09aef75..0000000 --- a/tests/TestDecleTypePolicy.cpp +++ /dev/null @@ -1,150 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char *ch = 0; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - - return std::string(ch); -} - -class TestDeclType : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestDeclType(){} - TestDeclType(std::initializer_list listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners){} - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - decltypedata = *policy->Data(); - datatotest.push_back(decltypedata); - } - void NotifyWrite(const PolicyDispatcher * policy, srcSAXEventDispatch::srcSAXEventContext & ctx) override {} - void RunTest(){ - assert(datatotest.size() == 6); - assert(datatotest[0].nameOfType == "int"); - assert(datatotest[0].nameOfIdentifier == "abc"); - assert(datatotest[0].lineNumber == 1); - assert(datatotest[0].isConstValue == false); - assert(datatotest[0].isConstAlias == false); - assert(datatotest[0].isReference == true); - assert(datatotest[0].isPointer == false); - assert(datatotest[0].isStatic == false); - assert(datatotest[0].namespaces.empty()); - assert(datatotest[0].isClassMember == true); - assert(datatotest[0].nameOfContainingClass == "testclass"); - assert(datatotest[0].nameOfContainingFunction == ""); - assert(datatotest[0].nameOfContainingFile == "testsrcType.cpp"); - - assert(datatotest[1].nameOfType == "Object"); - assert(datatotest[1].nameOfIdentifier == "onetwothree"); - assert(datatotest[1].lineNumber == 1); - assert(datatotest[1].isConstValue == false); - assert(datatotest[1].isConstAlias == false); - assert(datatotest[1].isReference == false); - assert(datatotest[1].isPointer == false); - assert(datatotest[1].isStatic == false); - assert(datatotest[1].namespaces.empty()); - assert(datatotest[1].nameOfContainingClass == "testclass"); - assert(datatotest[1].nameOfContainingFunction == ""); - assert(datatotest[1].nameOfContainingFile == "testsrcType.cpp"); - - assert(datatotest[2].nameOfType == "Object"); - assert(datatotest[2].nameOfIdentifier == "DoReiMe"); - assert(datatotest[2].lineNumber == 1); - assert(datatotest[2].isConstValue == false); - assert(datatotest[2].isConstAlias == false); - assert(datatotest[2].isReference == false); - assert(datatotest[2].isPointer == true); - assert(datatotest[2].isStatic == true); - assert(datatotest[2].namespaces.empty()); - assert(datatotest[2].nameOfContainingClass == ""); - assert(datatotest[2].nameOfContainingFunction == "foo"); - assert(datatotest[2].nameOfContainingFile == "testsrcType.cpp"); - - assert(datatotest[3].nameOfType == "Object"); - assert(datatotest[3].nameOfIdentifier == "aybeecee"); - assert(datatotest[3].lineNumber == 1); - assert(datatotest[3].isConstAlias == true); - assert(datatotest[3].isConstValue == true); - assert(datatotest[3].isReference == false); - assert(datatotest[3].isPointer == true); - assert(datatotest[3].isStatic == false); - assert(datatotest[3].namespaces.empty()); - assert(datatotest[3].nameOfContainingClass == ""); - assert(datatotest[3].nameOfContainingFunction == "foo"); - assert(datatotest[3].nameOfContainingFile == "testsrcType.cpp"); - - assert(datatotest[4].nameOfType == "vector"); - assert(datatotest[4].nameOfIdentifier == "spaces"); - assert(datatotest[4].lineNumber == 2); - assert(datatotest[4].isConstValue == false); - assert(datatotest[4].isConstAlias == false); - assert(datatotest[4].isReference == false); - assert(datatotest[4].isPointer == false); - assert(datatotest[4].isStatic == false); - assert(datatotest[4].namespaces.size() == 2); - assert(datatotest[4].nameOfContainingClass == ""); - assert(datatotest[4].nameOfContainingFunction == "foo"); - assert(datatotest[4].nameOfContainingFile == "testsrcType.cpp"); - - assert(datatotest[5].nameOfType == "int"); - assert(datatotest[5].nameOfIdentifier == "ab"); - assert(datatotest[5].lineNumber == 2); - assert(datatotest[5].isConstValue == false); - assert(datatotest[5].isConstAlias == true); - assert(datatotest[5].isReference == false); - assert(datatotest[5].isPointer == true); - assert(datatotest[5].isStatic == false); - assert(datatotest[5].namespaces.empty()); - assert(datatotest[5].isClassMember == false); - assert(datatotest[5].usesSubscript == true); - assert(datatotest[5].nameOfContainingClass == ""); - assert(datatotest[5].nameOfContainingFunction == ""); - assert(datatotest[5].nameOfContainingFile == "testsrcType.cpp"); - - //assert(datatotest[5].nameOfType == ""); - //std::cerr<<"Msg: "< datatotest; -}; - -int main(int argc, char** filename){ - std::string codestr = "class testclass {int& abc; Object onetwothree; void foo(){static Object* DoReiMe; const Object* const aybeecee;\n nlp::std::vector spaces;} testclass(int i){}}; int* const ab[5];"; - std::string srcmlstr = StringToSrcML(codestr); - - TestDeclType decltypedata; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher handler {&decltypedata}; - control.parse(&handler); //Start parsing - decltypedata.RunTest(); -} \ No newline at end of file diff --git a/tests/TestExpr.cpp b/tests/TestExpr.cpp deleted file mode 100644 index 97d7240..0000000 --- a/tests/TestExpr.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char *ch = 0; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - ch[size-1] = 0; - return std::string(ch); -} - -class TestExpr : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestExpr(){} - TestExpr(std::initializer_list listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners){} - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - exprdata = *policy->Data(); - datatotest.push_back(exprdata); - } - void NotifyWrite(const PolicyDispatcher * policy, srcSAXEventDispatch::srcSAXEventContext & ctx) override { - } - void RunTest(){ - - } - protected: - void * DataInner() const override { - return (void*)0; //To silence the warning - } - private: - ExprPolicy::ExprDataSet exprdata; - std::vector datatotest; -}; - -int main(int argc, char** filename){ - std::string codestr = "void foo(){j = 0; \nk = 1; \ndoreme = 5; \nabc = abc + 0;\n i = j + k;\n foo(abc+doreme);}"; - std::string srcmlstr = StringToSrcML(codestr); - std::cerr< handler {&exprdata}; - control.parse(&handler); //Start parsing - exprdata.RunTest(); -} \ No newline at end of file diff --git a/tests/TestFnSignaturePolicy.cpp b/tests/TestFnSignaturePolicy.cpp deleted file mode 100644 index 38565c8..0000000 --- a/tests/TestFnSignaturePolicy.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char *ch = 0; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - ch[size] = 0; - return std::string(ch); -} - -class TestFunctionSignature : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestFunctionSignature(){} - TestFunctionSignature(std::initializer_list listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners){} - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - signaturedata = *policy->Data(); - datatotest.push_back(signaturedata); - } - void NotifyWrite(const PolicyDispatcher * policy, srcSAXEventDispatch::srcSAXEventContext & ctx) override {} - void RunTest(){ - - assert(datatotest.size() == 5); - assert(datatotest[0].returnType == "void"); - assert(datatotest[0].name== "foo"); - assert(datatotest[0].returnTypeModifier == std::string()); - assert(datatotest[0].lineNumber == 1); - assert(datatotest[0].isConst == false); - assert(datatotest[0].isMethod == false); - assert(datatotest[0].isStatic == false); - assert(datatotest[0].parameters.size() == 4); - assert(datatotest[0].returnTypeNamespaces.size() == 0); - assert(datatotest[0].functionNamespaces.size() == 0); - assert(datatotest[0].pointerToConstReturn == false); - assert(datatotest[0].constPointerReturn == false); - assert(datatotest[0].hasAliasedReturn == false); - - assert(datatotest[1].returnType == "void"); - assert(datatotest[1].name== "bar"); - assert(datatotest[1].returnTypeModifier == std::string()); - assert(datatotest[1].lineNumber == 2); - assert(datatotest[1].isConst == false); - assert(datatotest[1].isMethod == false); - assert(datatotest[1].isStatic == true); - assert(datatotest[1].parameters.size() == 4); - assert(datatotest[1].returnTypeNamespaces.size() == 0); - assert(datatotest[1].functionNamespaces.size() == 0); - assert(datatotest[1].pointerToConstReturn == false); - assert(datatotest[1].constPointerReturn == false); - assert(datatotest[1].hasAliasedReturn == false); - - assert(datatotest[2].returnType == "int"); - assert(datatotest[2].name== "bloo"); - assert(datatotest[2].returnTypeModifier == "*"); - assert(datatotest[2].lineNumber == 3); - assert(datatotest[2].isConst == false); - assert(datatotest[2].isMethod == false); - assert(datatotest[2].isStatic == false); - assert(datatotest[2].parameters.size() == 4); - assert(datatotest[2].returnTypeNamespaces.size() == 0); - assert(datatotest[2].functionNamespaces.size() == 0); - assert(datatotest[2].pointerToConstReturn == false); - assert(datatotest[2].constPointerReturn == false); - assert(datatotest[2].hasAliasedReturn == true); - - assert(datatotest[3].returnType == "void"); - assert(datatotest[3].name== "bleep"); - assert(datatotest[3].returnTypeModifier == std::string()); - assert(datatotest[3].lineNumber == 4); - assert(datatotest[3].isConst == true); - assert(datatotest[3].isMethod == true); - assert(datatotest[3].isStatic == false); - assert(datatotest[3].parameters.size() == 4); - assert(datatotest[3].returnTypeNamespaces.size() == 0); - assert(datatotest[3].functionNamespaces.size() == 0); - assert(datatotest[3].pointerToConstReturn == false); - assert(datatotest[3].constPointerReturn == false); - assert(datatotest[3].hasAliasedReturn == false); - assert(datatotest[3].nameOfContainingClass == "testclass"); - - assert(datatotest[4].returnType == "object"); - assert(datatotest[4].name== "bloo"); - assert(datatotest[4].returnTypeModifier == "*"); - assert(datatotest[4].lineNumber == 5); - assert(datatotest[4].isConst == false); - assert(datatotest[4].isMethod == false); - assert(datatotest[4].isStatic == true); - assert(datatotest[4].parameters.size() == 3); - assert(datatotest[4].returnTypeNamespaces.size() == 2); - assert(datatotest[4].functionNamespaces.size() == 1); - assert(datatotest[4].pointerToConstReturn == true); - assert(datatotest[4].constPointerReturn == true); - assert(datatotest[4].hasAliasedReturn == true); - - } - protected: - void * DataInner() const override { - return (void*)0; //To silence the warning - } - private: - SignatureData signaturedata; - std::vector datatotest; -}; - -int main(int argc, char** filename){ - std::string codestr = "void foo(int abc, Object onetwothree, Object* DoReiMe, const Object* aybeecee){}\n" - "static void bar(int abc, Object onetwothree, Object* DoReiMe, const Object* aybeecee){}\n" - "int* bloo(int abc, Object onetwothree, Object* DoReiMe, const Object* aybeecee){}\n" - "class testclass{void bleep(int abc, Object onetwothree, Object* DoReiMe, const Object* aybeecee)const{}};\n" - "static const GameDes::std::object* const std::bloo(Object onetwothree, Object* DoReiMe, const Object* aybeecee){}"; - std::string srcmlstr = StringToSrcML(codestr); - - TestFunctionSignature sigData; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher handler {&sigData}; - control.parse(&handler); //Start parsing - sigData.RunTest(); -} \ No newline at end of file diff --git a/tests/TestParamTypePolicy.cpp b/tests/TestParamTypePolicy.cpp deleted file mode 100644 index 4972b26..0000000 --- a/tests/TestParamTypePolicy.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/** - * @file TestParamTypePolicy.cpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include -#include -#include -#include -#include -#include -#include -#include -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char *ch = 0; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - ch[size] = 0; - return std::string(ch); -} - -class TestParamType : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestParamType(){} - TestParamType(std::initializer_list listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners){} - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - paramdata = *policy->Data(); - datatotest.push_back(paramdata); - } - void NotifyWrite(const PolicyDispatcher * policy, srcSAXEventDispatch::srcSAXEventContext & ctx) override{ - - } - void RunTest(){ - assert(datatotest.size() == 6); - assert(datatotest[0].nameOfType == "int"); - assert(datatotest[0].nameOfIdentifier == "abc"); - assert(datatotest[0].lineNumber == 1); - assert(datatotest[0].isConstValue == false); - assert(datatotest[0].isConstAlias == false); - assert(datatotest[0].isReference == true); - assert(datatotest[0].isPointer == false); - assert(datatotest[0].isStatic == false); - assert(datatotest[0].namespaces.empty()); - - assert(datatotest[1].nameOfType == "Object"); - assert(datatotest[1].nameOfIdentifier == "onetwothree"); - assert(datatotest[1].lineNumber == 1); - assert(datatotest[1].isConstValue == false); - assert(datatotest[1].isConstAlias == false); - assert(datatotest[1].isReference == false); - assert(datatotest[1].isPointer == false); - assert(datatotest[1].isStatic == false); - assert(datatotest[1].namespaces.empty()); - - assert(datatotest[2].nameOfType == "Object"); - assert(datatotest[2].nameOfIdentifier == "DoReiMe"); - assert(datatotest[2].lineNumber == 1); - assert(datatotest[2].isConstValue == false); - assert(datatotest[2].isConstAlias == false); - assert(datatotest[2].isReference == false); - assert(datatotest[2].isPointer == true); - assert(datatotest[2].isStatic == true); - assert(datatotest[2].namespaces.empty()); - - assert(datatotest[3].nameOfType == "Object"); - assert(datatotest[3].nameOfIdentifier == "aybeecee"); - assert(datatotest[3].lineNumber == 1); - assert(datatotest[3].isConstValue == true); - assert(datatotest[3].isConstAlias == true); - assert(datatotest[3].isReference == false); - assert(datatotest[3].isPointer == true); - assert(datatotest[3].isStatic == false); - assert(datatotest[3].namespaces.empty()); - - assert(datatotest[4].nameOfType == "vector"); - assert(datatotest[4].nameOfIdentifier == "spaces"); - assert(datatotest[4].lineNumber == 1); - assert(datatotest[4].isConstValue == false); - assert(datatotest[4].isConstAlias == false); - assert(datatotest[4].isReference == false); - assert(datatotest[4].isPointer == false); - assert(datatotest[4].isStatic == false); - assert(datatotest[4].namespaces.size() == 1); - - assert(datatotest[5].nameOfType == "int"); - assert(datatotest[5].nameOfIdentifier == "ab"); - assert(datatotest[5].lineNumber == 1); - assert(datatotest[5].isConstValue == false); - assert(datatotest[5].isConstAlias == true); - assert(datatotest[5].isReference == false); - assert(datatotest[5].isPointer == true); - assert(datatotest[5].isStatic == false); - assert(datatotest[5].namespaces.empty()); - assert(datatotest[5].isClassMember == false); - assert(datatotest[5].usesSubscript == true); - } - protected: - void * DataInner() const override { - return (void*)0; //To silence the warning - } - private: - - ParamTypePolicy parampolicy; - DeclData paramdata; - std::vector datatotest; -}; - -int main(int argc, char** filename){ - std::string codestr = "void foo(int& abc, Object onetwothree, static Object* DoReiMe, const Object* const aybeecee, std::vector spaces, int* const ab[5]){}"; - std::string srcmlstr = StringToSrcML(codestr); - - TestParamType paramData; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher handler {¶mData}; - control.parse(&handler); //Start parsing - paramData.RunTest(); -} \ No newline at end of file diff --git a/tests/TestSNLPolicy.cpp b/tests/TestSNLPolicy.cpp deleted file mode 100644 index 57c9c7f..0000000 --- a/tests/TestSNLPolicy.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -std::string filetostring (const std::string file){ - std::ifstream t(file); - std::string str; - - t.seekg(0, std::ios::end); - str.reserve(t.tellg()); - t.seekg(0, std::ios::beg); - - str.assign((std::istreambuf_iterator(t)), - std::istreambuf_iterator()); - return str; -} -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char *ch = 0; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - ch[size] = 0; - return std::string(ch); -} - -class TestSNLPolicy : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestSNLPolicy(){} - TestSNLPolicy(std::initializer_list listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners){} - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - sourcenlpdata = *policy->Data(); - for(auto data : sourcenlpdata.nlsetmap){ - std::cerr< handler {&decltypedata}; - control.parse(&handler); //Start parsing -} \ No newline at end of file diff --git a/tests/TestSrcSlicePolicy.cpp b/tests/TestSrcSlicePolicy.cpp deleted file mode 100644 index 5ad21ba..0000000 --- a/tests/TestSrcSlicePolicy.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char *ch = 0; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - ch[size] = 0; - return std::string(ch); -} - -class TestSrcSlice : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestSrcSlice(){} - TestSrcSlice(std::initializer_list listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners){} - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - decltypedata = *policy->Data(); - datatotest.push_back(decltypedata); - } - void RunTest(){ - assert(datatotest.size() == 5); - assert(datatotest[0].nameoftype == "int"); - assert(datatotest[0].nameofidentifier == "abc"); - assert(datatotest[0].linenumber == 1); - assert(datatotest[0].isConst == false); - assert(datatotest[0].isReference == true); - assert(datatotest[0].isPointer == false); - assert(datatotest[0].isStatic == false); - assert(datatotest[0].namespaces.empty()); - - assert(datatotest[1].nameoftype == "Object"); - assert(datatotest[1].nameofidentifier == "onetwothree"); - assert(datatotest[1].linenumber == 1); - assert(datatotest[1].isConst == false); - assert(datatotest[1].isReference == false); - assert(datatotest[1].isPointer == false); - assert(datatotest[1].isStatic == false); - assert(datatotest[1].namespaces.empty()); - - assert(datatotest[2].nameoftype == "Object"); - assert(datatotest[2].nameofidentifier == "DoReiMe"); - assert(datatotest[2].linenumber == 1); - assert(datatotest[2].isConst == false); - assert(datatotest[2].isReference == false); - assert(datatotest[2].isPointer == true); - assert(datatotest[2].isStatic == true); - assert(datatotest[2].namespaces.empty()); - - assert(datatotest[3].nameoftype == "Object"); - assert(datatotest[3].nameofidentifier == "aybeecee"); - assert(datatotest[3].linenumber == 1); - assert(datatotest[3].isConst == true); - assert(datatotest[3].isReference == false); - assert(datatotest[3].isPointer == true); - assert(datatotest[3].isStatic == false); - assert(datatotest[3].namespaces.empty()); - - assert(datatotest[4].nameoftype == "vector"); - assert(datatotest[4].nameofidentifier == "spaces"); - assert(datatotest[4].linenumber == 2); - assert(datatotest[4].isConst == false); - assert(datatotest[4].isReference == false); - assert(datatotest[4].isPointer == false); - assert(datatotest[4].isStatic == false); - assert(datatotest[4].namespaces.size() == 2); - } - protected: - void * DataInner() const override { - return (void*)0; //To silence the warning - } - private: - - srcSlicePolicy declpolicy; - srcSlicePolicy::DeclTypeData decltypedata; - std::vector datatotest; -}; - -int main(int argc, char** filename){ - std::string codestr = "void foo(){int& abc; Object onetwothree; static Object* DoReiMe; const Object* aybeecee;\n nlp::std::vector spaces;}"; - std::string srcmlstr = StringToSrcML(codestr); - - TestSrcSlice decltypedata; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher handler {&decltypedata}; - control.parse(&handler); //Start parsing - decltypedata.RunTest(); -} \ No newline at end of file From bd1fd4486c88110f6a77b3632bf9a79db9858bbd Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 09:08:29 +0900 Subject: [PATCH 125/149] Cleanup build --- CMake/CMakeLists.txt | 28 - CMake/srcdispatch_build.cmake | 38 - CMake/srcdispatch_install.cmake | 25 - CMakeLists.txt | 36 +- dispatch.nlp.str.xml | 16540 ------------------------------ 5 files changed, 27 insertions(+), 16640 deletions(-) delete mode 100644 CMake/CMakeLists.txt delete mode 100644 CMake/srcdispatch_build.cmake delete mode 100644 CMake/srcdispatch_install.cmake delete mode 100644 dispatch.nlp.str.xml diff --git a/CMake/CMakeLists.txt b/CMake/CMakeLists.txt deleted file mode 100644 index d3f18b4..0000000 --- a/CMake/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -## -# CMakeLists.txt -# -# Copyright (C) 2016-2018 srcML, LLC. (www.srcML.org) -# -# This file is part of the srcSAXEventDispatch. -# -# The srcSAXEventDispatch is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# The srcSAXEventDispatch is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the srcSAXEventDispatch; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -# add this directory -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) - -include(srcdispatch_build) -if(CMAKE_PROJECT_NAME STREQUAL "srcSAXEventDispatch") - include(srcdispatch_install) -endif() diff --git a/CMake/srcdispatch_build.cmake b/CMake/srcdispatch_build.cmake deleted file mode 100644 index 1259926..0000000 --- a/CMake/srcdispatch_build.cmake +++ /dev/null @@ -1,38 +0,0 @@ -## -# srcsax_event_dispatch.cmake -# -# Copyright (C) 2016-2018 srcML, LLC. (www.srcML.org) -# -# This file is part of the srcSAXEventDispatch. -# -# The srcSAXEventDispatch is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# The srcSAXEventDispatch is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the srcSAXEventDispatch; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -get_filename_component(DISPATCH_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) -get_filename_component(DISPATCH_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} DIRECTORY) - -add_subdirectory(${DISPATCH_SOURCE_DIR}/srcSAX/CMake ${DISPATCH_BINARY_DIR}/srcSAX/CMake) - -set(DISPATCH_INCLUDE_DIR ${SRCSAX_INCLUDE_DIR} - ${DISPATCH_SOURCE_DIR}/src/dispatcher - ${DISPATCH_SOURCE_DIR}/src/policy_classes - CACHE INTERNAL "Include directories for srcSAXEventDispatch") - -set(DISPATCH_LIBRARIES ${SRCSAX_LIBRARIES} CACHE INTERNAL "Libraries for srcSAXEventDispatch") - -# include needed includes -include_directories(${DISPATCH_INCLUDE_DIR}) - -# Continue to build directory -add_subdirectory(${DISPATCH_SOURCE_DIR}/src ${DISPATCH_BINARY_DIR}/src) diff --git a/CMake/srcdispatch_install.cmake b/CMake/srcdispatch_install.cmake deleted file mode 100644 index 221b69b..0000000 --- a/CMake/srcdispatch_install.cmake +++ /dev/null @@ -1,25 +0,0 @@ -## -# srcsax_event_dispatch_install.cmake -# -# Copyright (C) 2016-2018 srcML, LLC. (www.srcML.org) -# -# This file is part of the srcSAXEventDispatch. -# -# The srcSAXEventDispatch is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# The srcSAXEventDispatch is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with the srcSAXEventDispatch; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -if(NOT WIN32) - set(CMAKE_INSTALL_PREFIX "/usr/local/") -endif() - diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f9b27e..1b8c1f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,36 +1,54 @@ ## # CMakeLists.txt # -# Copyright (C) 2016-2024 srcML, LLC. (www.srcML.org) +# Copyright (C) 2025-2025 srcML, LLC. (www.srcDiff.org) # -# This file is part of the srcSAXEventDispatch. +# This file is part of the srcDiffDispatch. # -# The srcSAXEventDispatch is free software; you can redistribute it and/or modify +# The srcDiffDispatch is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # -# The srcSAXEventDispatch is distributed in the hope that it will be useful, +# The srcDiffDispatch is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with the srcSAXEventDispatch; if not, write to the Free Software +# along with the srcDiffDispatch; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cmake_minimum_required(VERSION 3.14) -project(srcSAXEventDispatch) +project(srcDispatch) + +include(CTest) + +if(NOT WIN32) + set(CMAKE_INSTALL_PREFIX "/usr/local/") +endif() set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) - add_definitions("-Wall") +add_subdirectory(srcDispatch/CMake) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -add_subdirectory(CMake) -add_subdirectory(tests) +set(SRCDIFF_DISPATCH_INCLUDE_DIR ${SRCSAX_INCLUDE_DIR} + src/policy_classes + src/dispatcher + CACHE INTERNAL "Include directories for srcDispatch") + +set(SRCDIFF_DISPATCH_LIBRARIES ${SRCSAX_LIBRARIES} CACHE INTERNAL "Libraries for srcDiffDispatch") + +# include needed includes +include_directories(${SRCDIFF_DISPATCH_INCLUDE_DIR}) + +# Continue to src +add_subdirectory(src) +add_subdirectory(test) diff --git a/dispatch.nlp.str.xml b/dispatch.nlp.str.xml deleted file mode 100644 index 26b44e6..0000000 --- a/dispatch.nlp.str.xml +++ /dev/null @@ -1,16540 +0,0 @@ - - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <unordered_map> -#include <unordered_set> -#include <srcSAXHandler.hpp> -#include <FunctionCallPolicy.hpp> -#include <cassert> -#include <srcml.h> -std::string StringToSrcMLStringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char * ch = new char[str.size()]; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - //TrimFromEnd(ch, size); - return std::string(ch); -} - -class TestCalls : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestCalls(){} - TestCalls(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners ){} - /**command collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - calldata = *policy->Data<CallPolicy::CallData>(); - datatotest.push_back(calldata); - } - /**unclassified */ - void RunTest(){ - assert(datatotest[0].fnName == "bin"); //TODO: Fix, figure out way to test. - } - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return (void*)0; //To silence the warning - } - private: - CallPolicy callpolicy; - CallPolicy::CallData calldata; - std::vector<CallPolicy::CallData> datatotest; - -}; - -int main(int argc, char** filename){ - std::string codestr = "void foo(){foo(bar, baz, bin(), beep);}"; - std::string srcmlstr = StringToSrcML(codestr); - - TestCalls calldata; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher<CallPolicy> handler{&calldata}; - control.parseparse(&handler); //Start parsing - calldata.RunTestRunTest(); -} - - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <unordered_map> -#include <unordered_set> -#include <srcSAXHandler.hpp> -#include <ExprPolicy.hpp> -#include <cassert> -#include <srcml.h> -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char * ch = new char[str.size()]; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - //TrimFromEnd(ch, size); - return std::string(ch); -} - -class TestExpr : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestExpr(){} - TestExpr(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners ){} - /**command collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - exprdata = *policy->Data<ExprPolicy::ExprData>(); - datatotest.push_back(exprdata); - } - /**unclassified */ - void RunTest(){ - - } - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return (void*)0; //To silence the warning - } - private: - ExprPolicy::ExprData exprdata; - std::vector<ExprPolicy::ExprData> datatotest; -}; - -int main(int argc, char** filename){ - std::string codestr = "void foo(){j = 0; \nk = 1; \ndoreme = 5; \nabc = abc + 0;\n i = j + k;\n foo(abc+doreme);}"; - std::string srcmlstr = StringToSrcML(codestr); - std::cerr<<srcmlstr<<std::endl; - TestExpr exprdata; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher<ExprPolicy> handler {&exprdata}; - control.parseparse(&handler); //Start parsing - exprdata.RunTestRunTest(); -} - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <unordered_map> -#include <unordered_set> -#include <srcSAXHandler.hpp> -#include <DeclTypePolicy.hpp> -#include <cassert> -#include <srcml.h> -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char * ch = new char[str.size()]; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - //TrimFromEnd(ch, size); - return std::string(ch); -} - -class TestDeclType : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestDeclType(){} - TestDeclType(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners ){} - /**command collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - decltypedata = *policy->Data<DeclTypePolicy::DeclTypeData>(); - datatotest.push_back(decltypedata); - } - /**command */ - void RunTest(){ - assert(datatotest.size() == 5); - assert(datatotest[0].nameoftype == "int"); - assert(datatotest[0].nameofidentifier == "abc"); - assert(datatotest[0].linenumber == 1); - assert(datatotest[0].isConst == false); - assert(datatotest[0].isReference == true); - assert(datatotest[0].isPointer == false); - assert(datatotest[0].isStatic == false); - assert(datatotest[0].namespaces.empty()); - - assert(datatotest[1].nameoftype == "Object"); - assert(datatotest[1].nameofidentifier == "onetwothree"); - assert(datatotest[1].linenumber == 1); - assert(datatotest[1].isConst == false); - assert(datatotest[1].isReference == false); - assert(datatotest[1].isPointer == false); - assert(datatotest[1].isStatic == false); - assert(datatotest[1].namespaces.empty()); - - assert(datatotest[2].nameoftype == "Object"); - assert(datatotest[2].nameofidentifier == "DoReiMe"); - assert(datatotest[2].linenumber == 1); - assert(datatotest[2].isConst == false); - assert(datatotest[2].isReference == false); - assert(datatotest[2].isPointer == true); - assert(datatotest[2].isStatic == true); - assert(datatotest[2].namespaces.empty()); - - assert(datatotest[3].nameoftype == "Object"); - assert(datatotest[3].nameofidentifier == "aybeecee"); - assert(datatotest[3].linenumber == 1); - assert(datatotest[3].isConst == true); - assert(datatotest[3].isReference == false); - assert(datatotest[3].isPointer == true); - assert(datatotest[3].isStatic == false); - assert(datatotest[3].namespaces.empty()); - - assert(datatotest[4].nameoftype == "vector"); - assert(datatotest[4].nameofidentifier == "spaces"); - assert(datatotest[4].linenumber == 2); - assert(datatotest[4].isConst == false); - assert(datatotest[4].isReference == false); - assert(datatotest[4].isPointer == false); - assert(datatotest[4].isStatic == false); - assert(datatotest[4].namespaces.size() == 2); - } - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return (void*)0; //To silence the warning - } - private: - - DeclTypePolicy declpolicy; - DeclTypePolicy::DeclTypeData decltypedata; - std::vector<DeclTypePolicy::DeclTypeData> datatotest; -}; - -int main(int argc, char** filename){ - std::string codestr = "void foo(){int& abc; Object<int> onetwothree; static Object* DoReiMe; const Object* aybeecee;\n nlp::std::vector<std::string> spaces;}"; - std::string srcmlstr = StringToSrcML(codestr); - std::cerr<<"out"<<std::endl; - TestDeclType decltypedata; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher<DeclTypePolicy> handler {&decltypedata}; - control.parseparse(&handler); //Start parsing - decltypedata.RunTestRunTest(); -} - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <unordered_map> -#include <unordered_set> -#include <srcSAXHandler.hpp> -#include <CollectNLContext.hpp> -#include <cassert> -#include <srcml.h> -#include <string> -#include <fstream> -#include <streambuf> - -std::string filetostring (const std::string file){ - std::ifstream t(file); - std::string str; - - t.seekg(0, std::ios::end); - str.reserve(t.tellg()); - t.seekg(0, std::ios::beg); - - str.assign((std::istreambuf_iterator<char>(t)), - std::istreambuf_iterator<char>()); - return str; -} -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char * ch = new char[str.size()]; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - //TrimFromEnd(ch, size); - return std::string(ch); -} - -class TestSNLPolicy : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestSNLPolicy(){} - TestSNLPolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners ){} - /**set collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - sourcenlpdata = *policy->Data<NLContextPolicy::NLContextData>(); - std::cerr<<"Output: "<<sourcenlpdata.identifiername<<" "<<sourcenlpdata.category<<std::endl; - //datatotest.push_back(NLContextData); - } - /**unclassified */ - void RunTest(){ - } - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return (void*)0; //To silence the warning - } - private: - - NLContextPolicy::NLContextData sourcenlpdata; -}; - -int main(int argc, char** filename){ - std::string srcmlstr = filetostring(filename[1]); - - TestSNLPolicy decltypedata; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher<NLContextPolicy> handler {&decltypedata}; - control.parseparse(&handler); //Start parsing -} - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <unordered_map> -#include <unordered_set> -#include <srcSAXHandler.hpp> -#include <FunctionSignaturePolicy.hpp> -#include <cassert> -#include <srcml.h> -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char * ch = new char[str.size()]; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - //TrimFromEnd(ch, size); - return std::string(ch); -} - -class TestFunctionSignature : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestFunctionSignature(){} - TestFunctionSignature(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners ){} - /**command collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - signaturedata = *policy->Data<FunctionSignaturePolicy::SignatureData>(); - datatotest.push_back(signaturedata); - } - /**command */ - void RunTest(){ - - assert(datatotest.size() == 5); - assert(datatotest[0].returnType == "void"); - assert(datatotest[0].functionName == "foo"); - assert(datatotest[0].returnTypeModifier == std::string()); - assert(datatotest[0].linenumber == 1); - assert(datatotest[0].isConst == false); - assert(datatotest[0].isMethod == false); - assert(datatotest[0].isStatic == false); - assert(datatotest[0].parameters.size() == 4); - assert(datatotest[0].returnTypeNamespaces.size() == 0); - assert(datatotest[0].functionNamespaces.size() == 0); - assert(datatotest[0].pointerToConstReturn == false); - assert(datatotest[0].constPointerReturn == false); - assert(datatotest[0].hasAliasedReturn == false); - - assert(datatotest[1].returnType == "void"); - assert(datatotest[1].functionName == "bar"); - assert(datatotest[1].returnTypeModifier == std::string()); - assert(datatotest[1].linenumber == 2); - assert(datatotest[1].isConst == false); - assert(datatotest[1].isMethod == false); - assert(datatotest[1].isStatic == true); - assert(datatotest[1].parameters.size() == 4); - assert(datatotest[1].returnTypeNamespaces.size() == 0); - assert(datatotest[1].functionNamespaces.size() == 0); - assert(datatotest[1].pointerToConstReturn == false); - assert(datatotest[1].constPointerReturn == false); - assert(datatotest[1].hasAliasedReturn == false); - - assert(datatotest[2].returnType == "int"); - assert(datatotest[2].functionName == "bloo"); - assert(datatotest[2].returnTypeModifier == "*"); - assert(datatotest[2].linenumber == 3); - assert(datatotest[2].isConst == false); - assert(datatotest[2].isMethod == false); - assert(datatotest[2].isStatic == false); - assert(datatotest[2].parameters.size() == 4); - assert(datatotest[2].returnTypeNamespaces.size() == 0); - assert(datatotest[2].functionNamespaces.size() == 0); - assert(datatotest[2].pointerToConstReturn == false); - assert(datatotest[2].constPointerReturn == false); - assert(datatotest[2].hasAliasedReturn == true); - - assert(datatotest[3].returnType == "void"); - assert(datatotest[3].functionName == "bleep"); - assert(datatotest[3].returnTypeModifier == std::string()); - assert(datatotest[3].linenumber == 4); - assert(datatotest[3].isConst == true); - assert(datatotest[3].isMethod == true); - assert(datatotest[3].isStatic == false); - assert(datatotest[3].parameters.size() == 4); - assert(datatotest[3].returnTypeNamespaces.size() == 0); - assert(datatotest[3].functionNamespaces.size() == 0); - assert(datatotest[3].pointerToConstReturn == false); - assert(datatotest[3].constPointerReturn == false); - assert(datatotest[3].hasAliasedReturn == false); - - assert(datatotest[4].returnType == "object"); - assert(datatotest[4].functionName == "bloo"); - assert(datatotest[4].returnTypeModifier == "*"); - assert(datatotest[4].linenumber == 5); - assert(datatotest[4].isConst == false); - assert(datatotest[4].isMethod == false); - assert(datatotest[4].isStatic == true); - assert(datatotest[4].parameters.size() == 3); - assert(datatotest[4].returnTypeNamespaces.size() == 2); - assert(datatotest[4].functionNamespaces.size() == 1); - assert(datatotest[4].pointerToConstReturn == true); - assert(datatotest[4].constPointerReturn == true); - assert(datatotest[4].hasAliasedReturn == true); - - } - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return (void*)0; //To silence the warning - } - private: - FunctionSignaturePolicy::SignatureData signaturedata; - std::vector<FunctionSignaturePolicy::SignatureData> datatotest; -}; - -int main(int argc, char** filename){ - std::string codestr = "void foo(int abc, Object<int> onetwothree, Object* DoReiMe, const Object* aybeecee){}\n" - "static void bar(int abc, Object<int> onetwothree, Object* DoReiMe, const Object* aybeecee){}\n" - "int* bloo(int abc, Object<int> onetwothree, Object* DoReiMe, const Object* aybeecee){}\n" - "class{void bleep(int abc, Object<int> onetwothree, Object* DoReiMe, const Object* aybeecee)const{}};\n" - "static const GameDes::std::object* const std::bloo(Object<int> onetwothree, Object* DoReiMe, const Object* aybeecee){}"; - std::string srcmlstr = StringToSrcML(codestr); - - TestFunctionSignature sigData; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher<FunctionSignaturePolicy> handler {&sigData}; - control.parseparse(&handler); //Start parsing - sigData.RunTestRunTest(); -} - -#include <cassert> -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <unordered_map> -#include <unordered_set> -#include <srcSAXHandler.hpp> -#include <ParamTypePolicy.hpp> -#include <srcml.h> -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char * ch = new char[str.size()]; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - //TrimFromEnd(ch, size); - return std::string(ch); -} - -class TestParamType : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestParamType(){} - TestParamType(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners ){} - /**command collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - paramdata = *policy->Data<ParamTypePolicy::ParamData>(); - datatotest.push_back(paramdata); - } - /**command */ - void RunTest(){ - assert(datatotest.size() == 5); - assert(datatotest[0].nameoftype == "int"); - assert(datatotest[0].nameofidentifier == "abc"); - assert(datatotest[0].linenumber == 1); - assert(datatotest[0].isConst == false); - assert(datatotest[0].isReference == true); - assert(datatotest[0].isPointer == false); - assert(datatotest[0].isStatic == false); - assert(datatotest[0].namespaces.empty()); - - assert(datatotest[1].nameoftype == "Object"); - assert(datatotest[1].nameofidentifier == "onetwothree"); - assert(datatotest[1].linenumber == 1); - assert(datatotest[1].isConst == false); - assert(datatotest[1].isReference == false); - assert(datatotest[1].isPointer == false); - assert(datatotest[1].isStatic == false); - assert(datatotest[1].namespaces.empty()); - - assert(datatotest[2].nameoftype == "Object"); - assert(datatotest[2].nameofidentifier == "DoReiMe"); - assert(datatotest[2].linenumber == 1); - assert(datatotest[2].isConst == false); - assert(datatotest[2].isReference == false); - assert(datatotest[2].isPointer == true); - assert(datatotest[2].isStatic == true); - assert(datatotest[2].namespaces.empty()); - - assert(datatotest[3].nameoftype == "Object"); - assert(datatotest[3].nameofidentifier == "aybeecee"); - assert(datatotest[3].linenumber == 1); - assert(datatotest[3].isConst == true); - assert(datatotest[3].isReference == false); - assert(datatotest[3].isPointer == true); - assert(datatotest[3].isStatic == false); - assert(datatotest[3].namespaces.empty()); - - assert(datatotest[4].nameoftype == "vector"); - assert(datatotest[4].nameofidentifier == "spaces"); - assert(datatotest[4].linenumber == 1); - assert(datatotest[4].isConst == false); - assert(datatotest[4].isReference == false); - assert(datatotest[4].isPointer == false); - assert(datatotest[4].isStatic == false); - assert(datatotest[4].namespaces.size() == 1); - } - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return (void*)0; //To silence the warning - } - private: - - ParamTypePolicy parampolicy; - ParamTypePolicy::ParamData paramdata; - std::vector<ParamTypePolicy::ParamData> datatotest; -}; - -int main(int argc, char** filename){ - std::string codestr = "void foo(int& abc, Object<int> onetwothree, static Object* DoReiMe, const Object* aybeecee, std::vector<std::string> spaces){}"; - std::string srcmlstr = StringToSrcML(codestr); - - TestParamType paramData; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher<ParamTypePolicy> handler {&paramData}; - control.parseparse(&handler); //Start parsing - paramData.RunTestRunTest(); -} - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <unordered_map> -#include <unordered_set> -#include <srcSAXHandler.hpp> -#include <srcSlicePolicy.hpp> -#include <cassert> -#include <srcml.h> -std::string StringToSrcML(std::string str){ - struct srcml_archive* archive; - struct srcml_unit* unit; - size_t size = 0; - - char * ch = new char[str.size()]; - - archive = srcml_archive_create(); - srcml_archive_enable_option(archive, SRCML_OPTION_POSITION); - srcml_archive_write_open_memory(archive, &ch, &size); - - unit = srcml_unit_create(archive); - srcml_unit_set_language(unit, SRCML_LANGUAGE_CXX); - srcml_unit_set_filename(unit, "testsrcType.cpp"); - - srcml_unit_parse_memory(unit, str.c_str(), str.size()); - srcml_archive_write_unit(archive, unit); - - srcml_unit_free(unit); - srcml_archive_close(archive); - srcml_archive_free(archive); - //TrimFromEnd(ch, size); - return std::string(ch); -} - -class TestSrcSlice : public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - ~TestSrcSlice(){} - TestSrcSlice(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners ){} - /**command collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - decltypedata = *policy->Data<srcSlicePolicy::DeclTypeData>(); - datatotest.push_back(decltypedata); - } - /**command */ - void RunTest(){ - assert(datatotest.size() == 5); - assert(datatotest[0].nameoftype == "int"); - assert(datatotest[0].nameofidentifier == "abc"); - assert(datatotest[0].linenumber == 1); - assert(datatotest[0].isConst == false); - assert(datatotest[0].isReference == true); - assert(datatotest[0].isPointer == false); - assert(datatotest[0].isStatic == false); - assert(datatotest[0].namespaces.empty()); - - assert(datatotest[1].nameoftype == "Object"); - assert(datatotest[1].nameofidentifier == "onetwothree"); - assert(datatotest[1].linenumber == 1); - assert(datatotest[1].isConst == false); - assert(datatotest[1].isReference == false); - assert(datatotest[1].isPointer == false); - assert(datatotest[1].isStatic == false); - assert(datatotest[1].namespaces.empty()); - - assert(datatotest[2].nameoftype == "Object"); - assert(datatotest[2].nameofidentifier == "DoReiMe"); - assert(datatotest[2].linenumber == 1); - assert(datatotest[2].isConst == false); - assert(datatotest[2].isReference == false); - assert(datatotest[2].isPointer == true); - assert(datatotest[2].isStatic == true); - assert(datatotest[2].namespaces.empty()); - - assert(datatotest[3].nameoftype == "Object"); - assert(datatotest[3].nameofidentifier == "aybeecee"); - assert(datatotest[3].linenumber == 1); - assert(datatotest[3].isConst == true); - assert(datatotest[3].isReference == false); - assert(datatotest[3].isPointer == true); - assert(datatotest[3].isStatic == false); - assert(datatotest[3].namespaces.empty()); - - assert(datatotest[4].nameoftype == "vector"); - assert(datatotest[4].nameofidentifier == "spaces"); - assert(datatotest[4].linenumber == 2); - assert(datatotest[4].isConst == false); - assert(datatotest[4].isReference == false); - assert(datatotest[4].isPointer == false); - assert(datatotest[4].isStatic == false); - assert(datatotest[4].namespaces.size() == 2); - } - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return (void*)0; //To silence the warning - } - private: - - srcSlicePolicy declpolicy; - srcSlicePolicy::DeclTypeData decltypedata; - std::vector<srcSlicePolicy::DeclTypeData> datatotest; -}; - -int main(int argc, char** filename){ - std::string codestr = "void foo(){int& abc; Object<int> onetwothree; static Object* DoReiMe; const Object* aybeecee;\n nlp::std::vector<std::string> spaces;}"; - std::string srcmlstr = StringToSrcML(codestr); - - TestSrcSlice decltypedata; - srcSAXController control(srcmlstr); - srcSAXEventDispatch::srcSAXEventDispatcher<srcSlicePolicy> handler {&decltypedata}; - control.parseparse(&handler); //Start parsing - decltypedata.RunTestRunTest(); -} - -/** - * @file srcsax_handler_test.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef INCLUDED_SRCSAX_HANDLER_TEST_HPP -#define INCLUDED_SRCSAX_HANDLER_TEST_HPP - -#include <srcSAXHandler.hpp> - -#include <libxml/parser.h> - -#include <string.h> -#include <string> -#include <cassert> - -/** - * srcsax_handler_test - * - * Test class with callbacks for C API. - */ -class srcsax_handler_test { - -public : - - /** number which start_document callback was called */ - int start_document_call_number; - /** number which end_document callback was called */ - int end_document_call_number; - - /** number which start_root callback was called */ - int start_root_call_number; - /** number which start_unit callback was called */ - int start_unit_call_number; - /** number which start_element callback was called */ - int start_element_call_number; - - /** number which end_root callback was called */ - int end_root_call_number; - /** number which end_unit callback was called */ - int end_unit_call_number; - /** number which end_elemnt callback was called */ - int end_element_call_number; - - /** number which characters_root callback was called */ - int characters_root_call_number; - /** number which characters_unit callback was called */ - int characters_unit_call_number; - - /** number which meta_tag callback was called */ - int meta_tag_call_number; - /** number which comment callback was called */ - int comment_call_number; - /** number which cdata_block callback was called */ - int cdata_block_call_number; - /** number which processing_instruction callback was called */ - int processing_instruction_call_number; - - /** the number of calls made */ - int call_count; - - /** - * srcsax_handler_test - * - * Constructor. Initialize members for testing C API. - */ - srcsax_handler_test() - : start_document_call_number(0), end_document_call_number(0), start_root_call_number(0), start_unit_call_number(0), start_element_call_number(0), - end_root_call_number(0), end_unit_call_number(0), end_element_call_number(0), characters_root_call_number(0), characters_unit_call_number(0), - meta_tag_call_number(0), comment_call_number(0), cdata_block_call_number(0), processing_instruction_call_number(0), call_count(0) {} - - /** - * factory - * - * Factory method to generate the srcsax_handler containin this classes - * callbacks needed to test C API. - * - * @returns the generated srcsax_handler with the correct callbacks for C API. - */ - /**collaborator */ - static srcsax_handler factory() { - - srcsax_handler handler; - - handler.start_document = start_document; - handler.end_document = end_document; - handler.start_root = start_root; - handler.start_unit = start_unit; - handler.start_element = start_element; - handler.end_root = end_root; - handler.end_unit = end_unit; - handler.end_element = end_element; - handler.characters_root = characters_root; - handler.characters_unit = characters_unit; - handler.meta_tag = meta_tag; - handler.comment = comment; - handler.cdata_block = cdata_block; - handler.processing_instruction = processing_instruction; - - return handler; - - } - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" - - /** - * start_document - * @param context a srcSAX context - * - * SAX handler function for start of document. - * Overidden for testing. Count calls made and order. - */ - /**collaborational-command collaborator */ - static void start_documentstart_document(struct srcsax_context * context) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - assert(context->stack_size == 0); - assert(context->srcml_element_stack == 0); - - test_handler->start_document_call_number = ++test_handler->call_count; - - } - - /** - * end_document - * @param context a srcSAX context - * - * SAX handler function for end of document. - * Overidden for testing. Count calls made and order. - */ - /**collaborational-command collaborator */ - static void end_documentend_document(struct srcsax_context * context) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - assert(context->stack_size == 0); - assert(context->srcml_element_stack == 0); - - test_handler->end_document_call_number = ++test_handler->call_count; - - } - - /** - * start_root - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of the root element. - * Overidden for testing. Count calls made and order. - */ - /**command collaborator */ - static void start_rootstart_root(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI, - int nb_namespaces, const struct srcsax_namespace * namespaces, int nb_attributes, - const struct srcsax_attribute * attributes) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - assert(context->stack_size == 1); - assert(strcmp(context->srcml_element_stack[context->stack_size - 1], "unit") == 0); - - test_handler->start_root_call_number = ++test_handler->call_count; - - } - - /** - * start_unit - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of an unit. - * Overidden for testing. Count calls made and order. - */ - /**command collaborator */ - static void start_unit(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI, - int nb_namespaces, const struct srcsax_namespace * namespaces, int nb_attributes, - const struct srcsax_attribute * attributes) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - assert(strcmp(context->srcml_element_stack[context->stack_size - 1], "unit") == 0); - - test_handler->start_unit_call_number = ++test_handler->call_count; - - } - - /** - * start_element - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of an element. - * Overidden for testing. Count calls made and order. - */ - /**command collaborational-command collaborator */ - static void start_element(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI, - int nb_namespaces, const struct srcsax_namespace * namespaces, int nb_attributes, - const struct srcsax_attribute * attributes) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - std::string element = ""; - if(prefix) { - - element += prefix; - element += ':'; - - } - - element += localname; - - assert(std::string(context->srcml_element_stack[context->stack_size - 1]) == element); - - test_handler->start_element_call_number = ++test_handler->call_count; - - } - - /** - * end_root - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of the root element. - * Overidden for testing. Count calls made and order. - */ - /**collaborational-command collaborator */ - static void end_root(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - test_handler->end_root_call_number = ++test_handler->call_count; - - } - - /** - * end_unit - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of an unit. - * Overidden for testing. Count calls made and order. - */ - /**collaborational-command collaborator */ - static void end_unitend_unit(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - test_handler->end_unit_call_number = ++test_handler->call_count; - - } - - /** - * end_element - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of an element. - * Overidden for testing. Count calls made and order. - */ - /**collaborational-command collaborator */ - static void end_elementend_element(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - test_handler->end_element_call_number = ++test_handler->call_count; - - } - - /** - * characters_root - * @param context a srcSAX context - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling at the root level. - * Overidden for testing. Count calls made and order. - */ - /**collaborational-command collaborator */ - static void characters_rootcharacters_root(struct srcsax_context * context, const char * ch, int len) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - test_handler->characters_root_call_number = ++test_handler->call_count; - - } - - /** - * characters_unit - * @param context a srcSAX context - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling within a unit. - * Overidden for testing. Count calls made and order. - */ - /**collaborational-command collaborator */ - static void characters_unitcharacters_unit(struct srcsax_context * context, const char * ch, int len) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - test_handler->characters_unit_call_number = ++test_handler->call_count; - - } - - /** - * meta_tag - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for meta tags. - * Overidden for testing. Count calls made and order. - */ - /**command collaborator */ - static void meta_tagmeta_tag(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI, - int nb_namespaces, const struct srcsax_namespace * namespaces, int nb_attributes, - const struct srcsax_attribute * attributes) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - assert(strcmp(context->srcml_element_stack[context->stack_size - 1], localname) == 0); - - test_handler->meta_tag_call_number = ++test_handler->call_count; - - } - - - /** - * comment - * @param context a srcSAX context - * @param value the comment content - * - * A comment has been parsed. - * Overidden for testing. Count calls made and order. - */ - /**collaborational-command collaborator */ - static void comment(struct srcsax_context * context, const char * value) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - test_handler->comment_call_number = ++test_handler->call_count; - - } - - /** - * cdata_block - * @param context a srcSAX context - * @param value the pcdata content - * @param len the block length - * - * Called when a pcdata block has been parsed. - * Overidden for testing. Count calls made and order. - */ - /**collaborational-command collaborator */ - static void cdata_blockcdata_block(struct srcsax_context * context, const char * value, int len) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - test_handler->cdata_block_call_number = ++test_handler->call_count; - - } - - /** - * processing_instruction - * @param context a srcSAX context - * @param value the pcdata content - * @param len the block length - * - * Called when a pcdata block has been parsed. - * Overidden for testing. Count calls made and order. - */ - /**collaborational-command collaborator */ - static void processing_instructionprocessing_instruction(struct srcsax_context * context, const char * target, const char * data) { - - srcsax_handler_test * test_handler = (srcsax_handler_test *)context->data; - - test_handler->processing_instruction_call_number = ++test_handler->call_count; - - } - -#pragma GCC diagnostic pop - -}; - -#endif - - -/** - * @file test_srcsax.cpp - * - * @copyright Copyright (C) 2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <srcsax.h> -#include <srcsax_handler_test.hpp> - -#include <stdio.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> -#include <cassert> - -/** - * read_callback - * @param context the context to read from - * @param buffer the buffer to read into - * @param len the number of bytes to read - * - * FILE read callback for testing io. - * - * @returns the number of bytes read. - */ -int read_callback(void * context, char * buffer, int len) { - - return (int)fread(buffer, 1, len, (FILE *)context); - -} - -/** - * close_callback - * @param context the context to read from - * - * FILE close callback for testing io. - * - * @returns 0 on success EOF otherwise. - */ -int close_callback(void * context) { - - return fclose((FILE *)context); - -} - -/** - * main - * - * Test the srcsax functions. - * - * @returns 0 on success. - */ -int main() { - - /* - srcsax_create_context_filename - */ - { - - srcsax_context * context = srcsax_create_context_filename(__FILE__, "UTF-8"); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - - } - - { - - srcsax_context * context = srcsax_create_context_filename(__FILE__, "ISO-8859-1"); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - - } - - { - - srcsax_context * context = srcsax_create_context_filename(__FILE__, 0); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - - } - - { - - srcsax_context * context = srcsax_create_context_filename(0, "UTF-8"); - - assert(context == 0); - - } - - { - - srcsax_context * context = srcsax_create_context_filename("foobar", "UTF-8"); - - assert(context == 0); - - } - - /* - srcsax_create_context_memory - */ - { - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), "UTF-8"); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - - } - - { - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), "ISO-8859-1"); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - - } - - { - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), 0); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - - } - - { - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(0, strlen(srcml_buffer), "UTF-8"); - - assert(context == 0); - - } - - { - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, 0, "UTF-8"); - - assert(context == 0); - - } - - /* - srcsax_create_context_FILE - */ - { - - FILE * file = fopen(__FILE__, "r"); - srcsax_context * context = srcsax_create_context_FILE(file, "UTF-8"); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - fclose(file); - - } - - { - - FILE * file = fopen(__FILE__, "r"); - srcsax_context * context = srcsax_create_context_FILE(file, "ISO-8859-1"); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - fclose(file); - - } - - { - - FILE * file = fopen(__FILE__, "r"); - srcsax_context * context = srcsax_create_context_FILE(file, 0); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - fclose(file); - - } - - { - - srcsax_context * context = srcsax_create_context_FILE(0, "UTF-8"); - - assert(context == 0); - - } - - /* - srcsax_create_context_fd - */ - { - - int fd = open(__FILE__, O_RDONLY); - srcsax_context * context = srcsax_create_context_fd(fd, "UTF-8"); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - close(fd); - - } - - { - - int fd = open(__FILE__, O_RDONLY); - srcsax_context * context = srcsax_create_context_fd(fd, "ISO-8859-1"); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - close(fd); - - } - - { - - int fd = open(__FILE__, O_RDONLY); - srcsax_context * context = srcsax_create_context_fd(fd, 0); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - close(fd); - - } - - { - - srcsax_context * context = srcsax_create_context_fd(-1, "UTF-8"); - - assert(context == 0); - - } - - /* - srcsax_create_context_io - */ - { - - FILE * file = fopen(__FILE__, "r"); - srcsax_context * context = srcsax_create_context_io((void *)file, read_callback, close_callback, "UTF-8"); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - - } - - { - - FILE * file = fopen(__FILE__, "r"); - srcsax_context * context = srcsax_create_context_io((void *)file, read_callback, close_callback, "ISO-8859-1"); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - - } - - { - - FILE * file = fopen(__FILE__, "r"); - srcsax_context * context = srcsax_create_context_io((void *)file, read_callback, close_callback, 0); - - assert(context->data == 0); - assert(context->handler == 0); - assert(context->srcsax_error == 0); - assert(context->is_archive == 0); - assert(context->unit_count == 0); - assert(context->encoding == 0); - assert(context->input != 0); - assert(context->libxml2_context != 0); - - srcsax_free_context(context); - - } - - { - - FILE * file = fopen(__FILE__, "r"); - srcsax_context * context = srcsax_create_context_io((void *)file, 0, close_callback, "UTF-8"); - - assert(context == 0); - - } - - { - - srcsax_context * context = srcsax_create_context_io(0, read_callback, close_callback, "UTF-8"); - - assert(context == 0); - - } - - /* - srcsax_free_context - */ - - { - - srcsax_free_context(0); - - } - - /* - srcsax_parse - */ - { - - srcsax_handler_test data; - srcsax_handler handler = srcsax_handler_test::factory(); - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), "UTF-8"); - context->data = &data; - context->handler = &handler; - - assert(srcsax_parse(context) == 0); - - srcsax_free_context(context); - - } - - { - - srcsax_handler_test data; - srcsax_handler handler = srcsax_handler_test::factory(); - - const char * srcml_buffer = "<unit>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), "UTF-8"); - context->data = &data; - context->handler = &handler; - - assert(srcsax_parse(context) == -1); - - srcsax_free_context(context); - - } - - { - - srcsax_handler_test data; - srcsax_handler handler = srcsax_handler_test::factory(); - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), "UTF-8"); - context->data = &data; - context->handler = &handler; - - assert(srcsax_parse(0) == -1); - - srcsax_free_context(context); - - } - - { - - srcsax_handler_test data; - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), "UTF-8"); - context->data = &data; - - assert(srcsax_parse(context) == -1); - - srcsax_free_context(context); - - } - - { - - srcsax_handler_test data; - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), "UTF-8"); - context->data = &data; - context->handler = 0; - - assert(srcsax_parse(context) == -1); - - srcsax_free_context(context); - - } - - /* - srcsax_parse_handler - */ - { - - srcsax_handler_test data; - srcsax_handler handler = srcsax_handler_test::factory(); - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), "UTF-8"); - context->data = &data; - - assert(srcsax_parse_handler(context, &handler) == 0); - - srcsax_free_context(context); - - } - - { - - srcsax_handler_test data; - srcsax_handler handler = srcsax_handler_test::factory(); - - const char * srcml_buffer = "<unit>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), "UTF-8"); - context->data = &data; - - assert(srcsax_parse_handler(context, &handler) == -1); - - srcsax_free_context(context); - - } - - { - - srcsax_handler_test data; - srcsax_handler handler = srcsax_handler_test::factory(); - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), "UTF-8"); - context->data = &data; - - assert(srcsax_parse_handler(0, &handler) == -1); - - srcsax_free_context(context); - - } - - { - - srcsax_handler_test data; - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), "UTF-8"); - context->data = &data; - - assert(srcsax_parse_handler(context, 0) == -1); - - srcsax_free_context(context); - - } - - /* - srcsax_stop_parse - */ - { - - srcsax_handler_test data; - srcsax_handler handler = srcsax_handler_test::factory(); - - const char * srcml_buffer = "<unit/>"; - - srcsax_context * context = srcsax_create_context_memory(srcml_buffer, strlen(srcml_buffer), "UTF-8"); - context->data = &data; - context->handler = &handler; - - srcsax_stop_parser(context); - - srcsax_free_context(context); - - } - - return 0; - -} - - -/** - * @file test_srcsax_control_handler.cpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <sax2_srcsax_handler.hpp> -#include <srcsax_handler_test.hpp> -#include <cppCallbackAdapter.hpp> - -#include <srcsax.h> - -#include <stdio.h> -#include <string.h> -#include <cassert> - -/** default initialization used throughout for testing */ -sax2_srcsax_handler sax2_handler_init; - -/** default initialization used throughout for testing */ -xmlParserCtxt ctxt_init; - -/** - * main - * - * Test the srcsax functions. - * - * @returns 0 on success. - */ -int main() { - - - /** - srcml_element_stack - */ - { - - srcSAXHandler handler; - cppCallbackAdapter cpp_adapter(&handler); - srcsax_handler srcsax_sax = cppCallbackAdapter::factory(); - - srcsax_context context; - context.data = &cpp_adapter; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - - start_document(&ctxt); - assert(handler.get_stack().size() == 0); - - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(handler.get_stack().size() == 0); - - start_element_ns_first(&ctxt, (const xmlChar *)"expr_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(handler.get_stack().size() == 2); - assert(handler.get_stack().front() == "unit"); - assert(handler.get_stack().back() == "expr_stmt"); - - start_unit(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(handler.get_stack().size() == 3); - assert(handler.get_stack().back() == "unit"); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(handler.get_stack().size() == 2); - assert(handler.get_stack().back() == "expr_stmt"); - - start_unit(&ctxt, (const xmlChar *)"decl_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(handler.get_stack().size() == 3); - assert(handler.get_stack().back() == "decl_stmt"); - - start_unit(&ctxt, (const xmlChar *)"if", (const xmlChar *)"cpp", - (const xmlChar *)"http://www.sdml.info/srcML/cpp", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(handler.get_stack().size() == 4); - assert(handler.get_stack().back() == "cpp:if"); - - end_element_ns(&ctxt, (const xmlChar *)"if", (const xmlChar *)"cpp", - (const xmlChar *)"http://www.sdml.info/srcML/cpp"); - - assert(handler.get_stack().size() == 3); - assert(handler.get_stack().back() == "decl_stmt"); - - end_element_ns(&ctxt, (const xmlChar *)"decl_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(handler.get_stack().size() == 2); - assert(handler.get_stack().back() == "expr_stmt"); - - end_element_ns(&ctxt, (const xmlChar *)"expr_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(handler.get_stack().size() == 1); - assert(handler.get_stack().back() == "unit"); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(handler.get_stack().size() == 0); - - end_document(&ctxt); - - assert(handler.get_stack().size() == 0); - - } - - { - - srcSAXHandler handler; - cppCallbackAdapter cpp_adapter(&handler); - srcsax_handler srcsax_sax = cppCallbackAdapter::factory(); - - srcsax_context context; - context.data = &cpp_adapter; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - - start_document(&ctxt); - assert(handler.get_stack().size() == 0); - - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(handler.get_stack().size() == 0); - - start_element_ns_first(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(handler.get_stack().size() == 2); - assert(handler.get_stack().front() == "unit"); - assert(handler.get_stack().back() == "unit"); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(handler.get_stack().size() == 1); - assert(handler.get_stack().back() == "unit"); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(handler.get_stack().size() == 0); - - end_document(&ctxt); - - assert(handler.get_stack().size() == 0); - - } - - { - - srcSAXHandler handler; - cppCallbackAdapter cpp_adapter(&handler); - srcsax_handler srcsax_sax = cppCallbackAdapter::factory(); - - srcsax_context context; - context.data = &cpp_adapter; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - - start_document(&ctxt); - assert(handler.get_stack().size() == 0); - - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(handler.get_stack().size() == 0); - - start_element_ns_first(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(handler.get_stack().size() == 0); - - end_element_ns(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(handler.get_stack().size() == 0); - - start_element_ns_first(&ctxt, (const xmlChar *)"expr_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(handler.get_stack().size() == 2); - assert(handler.get_stack().front() == "unit"); - assert(handler.get_stack().back() == "expr_stmt"); - - end_element_ns(&ctxt, (const xmlChar *)"expr_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(handler.get_stack().size() == 1); - assert(handler.get_stack().back() == "unit"); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(handler.get_stack().size() == 0); - - end_document(&ctxt); - - assert(handler.get_stack().size() == 0); - - } - - { - - srcSAXHandler handler; - cppCallbackAdapter cpp_adapter(&handler); - srcsax_handler srcsax_sax = cppCallbackAdapter::factory(); - - srcsax_context context; - context.data = &cpp_adapter; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - - start_document(&ctxt); - assert(handler.get_stack().size() == 0); - - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(handler.get_stack().size() == 0); - - start_element_ns_first(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(handler.get_stack().size() == 0); - - end_element_ns(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(handler.get_stack().size() == 0); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(handler.get_stack().size() == 0); - - end_document(&ctxt); - - assert(handler.get_stack().size() == 0); - - } - - return 0; -} - - -/** - * @file windows_utils.cpp - * - * @copyright Copyright (C) 2013-2014 srcML, LLC. (www.srcML.org) - * - * srcSAX are free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * srcSAX are distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <windows_utils.hpp> - -#include <cstdlib> -#include <cstring> - -#ifdef _MSC_BUILD - -char * strndup(const char * source, size_t n) { - - if(source == 0) return 0; - - char * dup = (char *)malloc((n + 1) * sizeof(char)); - strncpy(dup, source, n); - dup[n] = 0; - - return dup; - -} - -#endif - - -/** - * @file windows_utils.hpp - * - * @copyright Copyright (C) 2014 srcML, LLC. (www.srcML.org) - * - * srcSAX are free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * srcSAX are distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef INCLUDED_SRCTOOLS_WINDOWS_HPP -#define INCLUDED_SRCTOOLS_WINDOWS_HPP - -#ifdef _MSC_BUILD - -#ifdef WIN32 -#include <cstdlib> -#endif - -char * strndup(const char * source, size_t n); - -#endif - -#endif - - -/** - * @file test_sax2_srcsax_handler.cpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <sax2_srcsax_handler.hpp> -#include <srcsax_handler_test.hpp> - -#include <srcsax.h> - -#include <stdio.h> -#include <string.h> -#include <cassert> - -/** default initialization used throughout for testing */ -sax2_srcsax_handler sax2_handler_init; - -/** default initialization used throughout for testing */ -xmlParserCtxt ctxt_init; - -/** - * main - * - * Test the sax2_srcsax_handler. - * - * @returns 0 on success. - */ -int main() { - - /* - start_document - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - start_document(&ctxt); - - } - - { - - start_document(NULL); - - } - - /* - end_document - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_document(&ctxt); - - } - - { - - end_document(NULL); - - } - - /* - start_root - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert((const char *)sax2_handler.root.localname == std::string("unit")); - assert((const char *)sax2_handler.root.prefix == 0); - assert((const char *)sax2_handler.root.URI == std::string("http://www.sdml.info/srcML/src")); - assert(sax2_handler.root.nb_namespaces == 2); - assert((const char *)sax2_handler.root.namespaces[0] == 0); - assert((const char *)sax2_handler.root.namespaces[1] == std::string("http://www.sdml.info/srcML/src")); - assert((const char *)sax2_handler.root.namespaces[2] == std::string("cpp")); - assert((const char *)sax2_handler.root.namespaces[3] == std::string("http://www.sdml.info/srcML/cpp")); - assert(sax2_handler.root.nb_attributes == 3); - assert(sax2_handler.root.nb_defaulted == 0); - assert((const char *)sax2_handler.root.attributes[0] == std::string("filename")); - assert((const char *)sax2_handler.root.attributes[1] == 0); - assert((const char *)sax2_handler.root.attributes[2] == std::string("http://www.sdml.info/srcML/src")); - assert(sax2_handler.root.attributes[4] - sax2_handler.root.attributes[3] == 1); - assert((char)sax2_handler.root.attributes[3][0] == 'a'); - assert((const char *)sax2_handler.root.attributes[5] == std::string("dir")); - assert((const char *)sax2_handler.root.attributes[6] == 0); - assert((const char *)sax2_handler.root.attributes[7] == std::string("http://www.sdml.info/srcML/src")); - assert(sax2_handler.root.attributes[9] - sax2_handler.root.attributes[8] == 1); - assert((char)sax2_handler.root.attributes[8][0] == 'b'); - assert((const char *)sax2_handler.root.attributes[10] == std::string("language")); - assert((const char *)sax2_handler.root.attributes[11] == 0); - assert((const char *)sax2_handler.root.attributes[12] == std::string("http://www.sdml.info/srcML/src")); - assert(sax2_handler.root.attributes[14] - sax2_handler.root.attributes[13] == 1); - assert((char)sax2_handler.root.attributes[13][0] == 'c'); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_element_ns_first); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_first); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - end_document(&ctxt); - - } - - { - - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(NULL, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - } - - /* - start_element_ns_first - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_element_ns); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_unit); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - - } - - { - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(NULL, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - start_element_ns_first(NULL, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - } - - /* - start_unit - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_unit(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_element_ns); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_unit); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - - } - - { - - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_unit(NULL, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - } - - /* - start_element_ns - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_root); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_first); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - - } - - { - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_element_ns(NULL, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - } - - /* - end_element_ns - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_unit); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_root); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - sax.startElementNs = &start_unit; - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_unit); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_first); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_element_ns(&ctxt, (const xmlChar *)"name", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_root); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_first); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - - } - - { - - end_element_ns(NULL, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - } - - /* - characters_first - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - characters_first(&ctxt, (const xmlChar *)"unit", 4); - assert(sax2_handler.characters == "unit"); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_root); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_first); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - - } - - { - - characters_first(NULL, (const xmlChar *)"unit", 4); - - } - - /* - characters_root - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - characters_root(&ctxt, (const xmlChar *)"unit", 4); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_root); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_first); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - } - - { - - characters_root(NULL, (const xmlChar *)"unit", 4); - - } - - /* - characters_unit - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - characters_unit(&ctxt, (const xmlChar *)"unit", 4); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_root); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_first); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - } - - { - - characters_unit(NULL, (const xmlChar *)"unit", 4); - - } - - /* - meta_tag - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - sax.startElementNs = start_element_ns_first; - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char ** namespaces = 0; - const char * values = "ab"; - const char * attributes[10] = { "token", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "type", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 0, (const xmlChar **)namespaces, 2, 0, - (const xmlChar **) attributes); - - start_element_ns_first(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 0, (const xmlChar **)namespaces, 2, 0, - (const xmlChar **) attributes); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_element_ns_first); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_first); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - - } - - /* - comment - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - comment(&ctxt, (const xmlChar *)"unit"); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_root); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_first); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - } - - { - - comment(NULL, (const xmlChar *)"unit"); - - } - - /* - cdata_block - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - cdata_block(&ctxt, (const xmlChar *)"unit", 4); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_root); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_first); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - } - - { - - cdata_block(NULL, (const xmlChar *)"unit", 4); - - } - - /* - processing_instruction - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - processing_instruction(&ctxt, (const xmlChar *)"target", (const xmlChar *)"data"); - assert(ctxt.sax->startDocument == start_document); - assert(ctxt.sax->endDocument == end_document); - assert(ctxt.sax->startElementNs == start_root); - assert(ctxt.sax->endElementNs == end_element_ns); - assert(ctxt.sax->characters == characters_first); - assert(ctxt.sax->comment == comment); - assert(ctxt.sax->cdataBlock == cdata_block); - assert(ctxt.sax->processingInstruction == processing_instruction); - } - - { - - processing_instruction(NULL, (const xmlChar *)"target", (const xmlChar *)"data"); - - } - - /** - srcml_element_stack - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - - start_document(&ctxt); - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - start_element_ns_first(&ctxt, (const xmlChar *)"expr_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 2); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "expr_stmt") == 0); - - start_unit(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 3); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 2); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "expr_stmt") == 0); - - start_element_ns(&ctxt, (const xmlChar *)"decl_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 3); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "decl_stmt") == 0); - - start_element_ns(&ctxt, (const xmlChar *)"if", (const xmlChar *)"cpp", - (const xmlChar *)"http://www.sdml.info/srcML/cpp", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 4); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "cpp:if") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"if", (const xmlChar *)"cpp", - (const xmlChar *)"http://www.sdml.info/srcML/cpp"); - - assert(context.stack_size == 3); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "decl_stmt") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"decl_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 2); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "expr_stmt") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"expr_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - end_document(&ctxt); - - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - - start_document(&ctxt); - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - start_element_ns_first(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 2); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - end_document(&ctxt); - - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - - start_document(&ctxt); - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - start_element_ns_first(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - - start_element_ns_first(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 2); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - end_document(&ctxt); - - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - - start_document(&ctxt); - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - start_element_ns_first(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - - start_element_ns_first(&ctxt, (const xmlChar *)"expr_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 2); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "expr_stmt") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"expr_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - end_document(&ctxt); - - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - - start_document(&ctxt); - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - start_element_ns_first(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 1); - assert(context.srcml_element_stack != 0); - assert(strcmp(context.srcml_element_stack[context.stack_size - 1], "unit") == 0); - - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - end_document(&ctxt); - - assert(context.stack_size == 0); - assert(context.srcml_element_stack == 0); - - } - - return 0; -} - - -/** - * @file sax2_srcsax_handler.hpp - * - * @copyright Copyright (C) 2013-2014 srcML, LLC. (www.srcML.org) - * - * This file is part of the srcML SAX2 Framework. - * - * The srcML SAX2 Framework is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML SAX2 Framework is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML SAX2 Framework; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef INCLUDED_SAX2_SRCSAX_HANDLER_HPP -#define INCLUDED_SAX2_SRCSAX_HANDLER_HPP - -#include <srcml_element.hpp> -#include <srcsax.h> - -#include <libxml/parser.h> - -#include <string> -#include <vector> - -/** - * srcMLMode - * - * Enum of srcML parsing modes. - */ -enum srcMLMode { - - START, - ROOT, - UNIT, - END_UNIT, - END_ROOT - -}; - -/** - * declaration - * - * Data structure to hold a declaration. - */ -struct declaration { - - /** default constructor */ - declaration() : type(), name(), mode(TYPE) {} - - /** declaration type */ - std::string type; - - /** declaration name */ - std::string name; - - /** declaration parsing modes */ - enum { TYPE, NAME, INIT } mode; - -}; - -/** - * function_prototype - * - * Data structure to hold a function prototype. - */ -struct function_prototype { - - /**constructor */ - function_prototype(bool is_decl = false) : name(), return_type(), parameter_list(), mode(RETURN_TYPE), is_decl(is_decl) {} - - /** function name */ - std::string name; - - /** function return type */ - std::string return_type; - - /** function parameter list */ - std::vector<declaration> parameter_list; - - /** function prototype parsing modes */ - enum { RETURN_TYPE, NAME, PARAMETER_LIST, PARAMETER } mode; - - /** bool to indicate if function_decl or function */ - bool is_decl; - -}; - -/** - * sax2_srcsax_handler - * - * Data structure to hold process during - * sax parsing. - */ -struct sax2_srcsax_handler { - - /** default constructor */ - sax2_srcsax_handler() : context(0), root(), meta_tags(), characters(), is_archive(false), mode(START), parse_function(false), in_function_header(false), current_function() {} - - /** hooks for processing */ - srcsax_context * context; - - /** temporary storage for root unit */ - srcml_element root; - - /** temporary storage of meta-tags */ - std::vector<srcml_element> meta_tags; - - /** temporary storate of root characters */ - std::string characters; - - /** used to detect root unit */ - bool is_archive; - - /** open srcMLElement stack */ - std::vector<const char *> srcml_element_stack; - - /** the current parsing mode */ - srcMLMode mode; - - /** bool to indicate if should do special function parsing */ - bool parse_function; - - /** bool to indicate if in funciton for special function parsing */ - bool in_function_header; - - /** store data for special function parsing */ - function_prototype current_function; - -}; - -/** - * srcsax_sax2_factory - * - * Create SAX handler. - */ -xmlSAXHandler srcsax_sax2_factory(); - -/** - * start_document - * @param ctx an xmlParserCtxtPtr - * - * SAX handler function for start of document. - * Immediately calls supplied handlers function. - */ -void start_document(void * ctx); - -/** - * end_document - * @param ctx an xmlParserCtxtPtr - * - * SAX handler function for end of document. - * Calls endRoot if needed then - * immediately calls supplied handlers function. - */ -void end_document(void * ctx); - -/** - * start_root - * @param ctx an xmlParserCtxtPtr - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param nb_defaulted the number of defaulted attributes - * @param attributes list of attribute name value pairs (localname/prefix/URI/value/end) - * - * SAX handler function for start of root element. - * Caches root info and immediately calls supplied handlers function. - */ -void start_root(void * ctx, const xmlChar * localname, const xmlChar * prefix, const xmlChar * URI, - int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, - const xmlChar ** attributes); - - -/** - * start_element_ns_first - * @param ctx an xmlParserCtxtPtr - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param nb_defaulted the number of defaulted attributes - * @param attributes list of attribute name value pairs (localname/prefix/URI/value/end) - * - * SAX handler function for start of first element after root - * Detects archive and acts accordingly. - */ -void start_element_ns_first(void * ctx, const xmlChar * localname, const xmlChar * prefix, const xmlChar * URI, - int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, - const xmlChar ** attributes); -/** - * start_unit - * @param ctx an xmlParserCtxtPtr - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param nb_defaulted the number of defaulted attributes - * @param attributes list of attribute name value pairs (localname/prefix/URI/value/end) - * - * SAX handler function for start of an unit. - * Immediately calls supplied handlers function. - */ -void start_unit(void * ctx, const xmlChar * localname, const xmlChar * prefix, const xmlChar * URI, - int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, - const xmlChar ** attributes); - -/** - * start_element_ns - * @param ctx an xmlParserCtxtPtr - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param nb_defaulted the number of defaulted attributes - * @param attributes list of attribute name value pairs (localname/prefix/URI/value/end) - * - * SAX handler function for start of an element. - * Immediately calls supplied handlers function. - */ -void start_element_ns(void * ctx, const xmlChar * localname, const xmlChar * prefix, const xmlChar * URI, - int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, - const xmlChar ** attributes); - -/** - * end_element_ns - * @param ctx an xmlParserCtxtPtr - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of an element. - * Detects end of unit and calls correct functions - * for either end_root end_unit or end_element_ns. - */ -void end_element_ns(void * ctx, const xmlChar * localname, const xmlChar * prefix, const xmlChar * URI); - -/** - * characters_first - * @param ctx an xmlParserCtxtPtr - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling before we - * know if we have an archive or not. - * Immediately calls supplied handlers function. - */ -void characters_first(void * ctx, const xmlChar * ch, int len); - -/** - * characters_root - * @param ctx an xmlParserCtxtPtr - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling at the root level. - * Immediately calls supplied handlers function. - */ -void characters_root(void * ctx, const xmlChar * ch, int len); - -/** - * characters_unit - * @param ctx an xmlParserCtxtPtr - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling within a unit. - * Immediately calls supplied handlers function. - */ -void characters_unit(void * ctx, const xmlChar * ch, int len); - -/** - * comment - * @param ctx an xmlParserCtxtPtr - * @param value the comment content - * - * A comment has been parsed. - * Immediately calls supplied handlers function. - */ -void comment(void * ctx, const xmlChar * value); - -/** - * cdata_block - * @param ctx an xmlParserCtxtPtr - * @param value the pcdata content - * @param len the block length - * - * Called when a pcdata block has been parsed. - * Immediately calls supplied handlers function. - */ -void cdata_block(void * ctx, const xmlChar * value, int len); - -/** - * processing_instruction - * @param ctx an xmlParserCtxtPtr - * @param target the processing instruction target. - * @param data the processing instruction data. - * - * Called when a processing instruction has been parsed. - * Immediately calls supplied handlers function. - */ -void processing_instruction(void * ctx, const xmlChar * target, const xmlChar * data); - -#endif - - -/** - * @file srcml_element.hpp - * - * @copyright Copyright (C) 2013-2014 srcML, LLC. (www.srcML.org) - * - * srcSAX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * srcSAX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef INCLUDED_SRCML_ELEMENT_HPP -#define INCLUDED_SRCML_ELEMENT_HPP - -#ifndef _MSC_BUILD -/** Macro to define the correct name of strdup on unix/windows */ -#define STRDUP strdup -#else -#define STRDUP _strdup -#endif - -#include <srcsax.h> - -#include <libxml/parser.h> - -#include <string.h> -#include <string> - -/** Check if a copy was actually allocated */ -#define CHECK_COPY(ORIGINAL , COPY ) if(ORIGINAL && !COPY) { fprintf(stderr, "ERROR allocating memory"); srcsax_stop_parser(context); return; } - -/** - * srcml_element - * - * Data structure to hold an element - * mainly root element - */ -struct srcml_element { - - /** Default constructor to Zero out srcml_element */ - srcml_element() : context(0), localname(0), prefix(0), URI(0), - nb_namespaces(0), namespaces(0), - nb_attributes(0), nb_defaulted(0), - attributes(0) - {} - - /** Constructor to initialize using start element items */ - srcml_element(srcsax_context * context, const xmlChar * localname, const xmlChar * prefix, const xmlChar * URI, - int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, - const xmlChar ** attributes) - : context(context), localname(0), prefix(0), URI(0), - nb_namespaces(0), namespaces(0), - nb_attributes(0), nb_defaulted(0), - attributes(0) { - - // save all the info in case this is not a srcML archive - this->localname = localname ? (xmlChar*) STRDUP((const char*) localname) : 0; - CHECK_COPY(localname, this->localname); - - this->prefix = prefix ? (xmlChar*) STRDUP((const char*) prefix) : 0; - CHECK_COPY(prefix, this->prefix); - - this->URI = URI ? (xmlChar*) STRDUP((const char*) URI) : 0; - CHECK_COPY(URI, this->URI); - - this->nb_namespaces = nb_namespaces; - int ns_length = nb_namespaces * 2; - this->namespaces = (const xmlChar**) malloc(ns_length * sizeof(namespaces[0])); - CHECK_COPY(namespaces, this->namespaces); - memset(this->namespaces, 0, ns_length * sizeof(namespaces[0])); - - for (int i = 0; i < ns_length; ++i) { - - if(prefix && namespaces[i] && strcmp((const char *)prefix, (const char *)namespaces[i]) == 0) - this->namespaces[i] = this->prefix; - else if(URI && namespaces[i] && strcmp((const char *)URI, (const char *)namespaces[i]) == 0) - this->namespaces[i] = this->URI; - else { - - this->namespaces[i] = namespaces[i] ? (xmlChar*) STRDUP((const char*) namespaces[i]) : 0; - CHECK_COPY(namespaces[i], this->namespaces[i]); - } - - } - - this->nb_attributes = nb_attributes; - this->nb_defaulted = nb_defaulted; - - int nb_length = nb_attributes * 5; - this->attributes = (const xmlChar**) malloc(nb_length * sizeof(attributes[0])); - CHECK_COPY(attributes, this->attributes); - - memset(this->attributes, 0, nb_length * sizeof(attributes[0])); - - for (int i = 0, index = 0; i < nb_attributes; ++i, index += 5) { - this->attributes[index] = attributes[index] ? (xmlChar*) STRDUP((const char*) attributes[index]) : 0; - CHECK_COPY(attributes[index], this->attributes[index]); - this->attributes[index + 1] = attributes[index + 1] ? (xmlChar*) STRDUP((const char*) attributes[index + 1]) : 0; - CHECK_COPY(attributes[index + 1], this->attributes[index + 1]); - this->attributes[index + 2] = attributes[index + 2] ? (xmlChar*) STRDUP((const char*) attributes[index + 2]) : 0; - CHECK_COPY(attributes[index + 2], this->attributes[index + 2]); - - int vallength = (int)(attributes[index + 4] - attributes[index + 3]); - this->attributes[index + 3] = (const xmlChar*) malloc(vallength + 1); - CHECK_COPY(attributes[index + 3], this->attributes[index + 3]); - - strncpy((char *) this->attributes[index + 3], (const char*) attributes[index + 3], vallength); - ((char *)this->attributes[index + 3])[vallength] = 0; - this->attributes[index + 4] = this->attributes[index + 3] + vallength; - - } - - } - - /** Copy constructor */ - srcml_element(const srcml_element & element) - : context(element.context), localname(0), prefix(0), URI(0), - nb_namespaces(0), namespaces(0), - nb_attributes(0), nb_defaulted(0), - attributes(0) { - - // save all the info in case this is not a srcML archive - this->localname = element.localname ? (xmlChar*) STRDUP((const char*) element.localname) : 0; - CHECK_COPY(element.localname, this->localname); - - this->prefix = element.prefix ? (xmlChar*) STRDUP((const char*) element.prefix) : 0; - CHECK_COPY(element.prefix, this->prefix); - - this->URI = element.URI ? (xmlChar*) STRDUP((const char*) element.URI) : 0; - CHECK_COPY(element.URI, this->URI); - - this->nb_namespaces = element.nb_namespaces; - int ns_length = element.nb_namespaces * 2; - this->namespaces = (const xmlChar**) malloc(ns_length * sizeof(element.namespaces[0])); - CHECK_COPY(element.namespaces, this->namespaces); - memset(this->namespaces, 0, ns_length * sizeof(element.namespaces[0])); - - for (int i = 0; i < ns_length; ++i) { - this->namespaces[i] = element.namespaces[i] ? (xmlChar*) STRDUP((const char*) element.namespaces[i]) : 0; - CHECK_COPY(element.namespaces[i], this->namespaces[i]); - } - - this->nb_attributes = element.nb_attributes; - this->nb_defaulted = element.nb_defaulted; - - int nb_length = element.nb_attributes * 5; - this->attributes = (const xmlChar**) malloc(nb_length * sizeof(element.attributes[0])); - CHECK_COPY(element.attributes, this->attributes); - - memset(this->attributes, 0, nb_length * sizeof(element.attributes[0])); - - for (int i = 0, index = 0; i < element.nb_attributes; ++i, index += 5) { - this->attributes[index] = element.attributes[index] ? (xmlChar*) STRDUP((const char*) element.attributes[index]) : 0; - CHECK_COPY(element.attributes[index], this->attributes[index]); - this->attributes[index + 1] = element.attributes[index + 1] ? (xmlChar*) STRDUP((const char*) element.attributes[index + 1]) : 0; - CHECK_COPY(element.attributes[index + 1], this->attributes[index + 1]); - this->attributes[index + 2] = element.attributes[index + 2] ? (xmlChar*) STRDUP((const char*) element.attributes[index + 2]) : 0; - CHECK_COPY(element.attributes[index + 2], this->attributes[index + 2]); - - int vallength = (int)(element.attributes[index + 4] - element.attributes[index + 3]); - this->attributes[index + 3] = (const xmlChar*) malloc(vallength + 1); - CHECK_COPY(element.attributes[index + 3], this->attributes[index + 3]); - - strncpy((char *) this->attributes[index + 3], (const char*) element.attributes[index + 3], vallength); - ((char *)this->attributes[index + 3])[vallength] = 0; - this->attributes[index + 4] = this->attributes[index + 3] + vallength; - - } - - } - - /** Overloaded assignment operator */ - /**non-void-command collaborator stateless */ - srcml_element & operator=operator=operator=(srcml_element element) { - - swap(element); - return *this; - - } - - /** swap operator */ - /**command collaborational-command collaborator */ - void swapswap(srcml_element & element) { - - std::swap(localname, element.localname); - std::swap(prefix, element.prefix); - std::swap(URI, element.URI); - std::swap(nb_namespaces, element.nb_namespaces); - std::swap(namespaces, element.namespaces); - std::swap(nb_attributes, element.nb_attributes); - std::swap(nb_defaulted, element.nb_defaulted); - std::swap(attributes, element.attributes); - - } - - /** destructor */ - ~srcml_element() { - - if(namespaces) { - - for(int i = 0; i < nb_namespaces * 2; ++i) - if(namespaces[i] && namespaces[i] != prefix && namespaces[i] != URI) - free((void *)namespaces[i]); - - free((void *)namespaces); - } - - if(localname) free((void *)localname); - if(prefix) free((void *)prefix); - if(URI) free((void *)URI); - - if(attributes) { - - for (int i = 0, index = 0; i < nb_attributes; ++i, index += 5) { - if(attributes[index]) - free((void *)attributes[index]); - if(attributes[index + 1]) - free((void *)attributes[index + 1]); - if(attributes[index + 2]) - free((void *)attributes[index + 2]); - free((void *)attributes[index + 3]); - } - - free((void *)attributes); - - } - - } - - /** parser context */ - srcsax_context * context; - - /** local name of an element*/ - const xmlChar* localname; - - /** prefix of an element*/ - const xmlChar* prefix; - - /** URI of an element*/ - const xmlChar* URI; - - /** number of namespaces on an element*/ - int nb_namespaces; - - /** namespaces on an element*/ - const xmlChar** namespaces; - - /** number of attributes on an element*/ - int nb_attributes; - - /** number of defaulted on an element*/ - int nb_defaulted; - - /** attributes of an element*/ - const xmlChar** attributes; - -}; - -#endif - - -/** - * @file sax2_srcsax_handler.cpp - * - * @copyright Copyright (C) 2013-2014 srcML, LLC. (www.srcML.org) - * - * This file is part of the srcML SAX2 Framework. - * - * The srcML SAX2 Framework is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML SAX2 Framework is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with the srcML SAX2 Framework; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <sax2_srcsax_handler.hpp> -#include <windows_utils.hpp> - -#include <cstring> - -/** Static sax handler for zero initializing in factory */ -xmlSAXHandler sax2_srcml_handler_init; - -/** - * factory - * - * Create SAX handler. - */ -xmlSAXHandler srcsax_sax2_factory() { - - xmlSAXHandler sax = sax2_srcml_handler_init; - - sax.initialized = XML_SAX2_MAGIC; - - sax.startDocumentstartDocumentstartDocument = &start_documentstart_document; - sax.endDocumentendDocumentendDocument = &end_documentend_document; - - sax.startElementNs = &start_rootstart_root; - sax.endElementNs = &end_element_nsend_element_ns; - - sax.characters = &characters_firstcharacters_first; - sax.ignorableWhitespace = &characters_firstcharacters_first; - - sax.commentcommentcomment = &commentcomment; - sax.cdataBlockcdataBlockcdataBlock = &cdata_blockcdata_block; - sax.processingInstructionprocessingInstructionprocessingInstruction = &processing_instructionprocessing_instruction; - - return sax; -} - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" - -/** - * libxml2_namespaces2srcsax_namespaces - * @param number_namespaces the number of namespaces - * @param libxml2_namespaces - * - * Helper function to convert the libxml2 namespaces to srcsax namespaces - * returning a dynamically allocated struct containing the namespaces. - * - * @returns the converted namespaces as srcsax_namespace. - */ -static inline srcsax_namespace * libxml2_namespaces2srcsax_namespaces(int number_namespaces, const xmlChar ** libxml2_namespaces) { - - struct srcsax_namespace * srcsax_namespaces = (srcsax_namespace *)calloc(number_namespaces, sizeof(srcsax_namespace)); - - for(int pos = 0, index = 0; pos < number_namespaces; ++pos, index += 2) { - - srcsax_namespaces[pos].prefix = (const char *)libxml2_namespaces[index]; - srcsax_namespaces[pos].uri = (const char *)libxml2_namespaces[index + 1]; - - } - - return srcsax_namespaces; -} - -/** - * free_srcsax_namespaces - * @param number_namespaces the number of namespaces (not currently used) - * @param libxml2_namespaces - * - * Helper function to free srcsax_namespace * struct allocated by libxml2_namespaces2srcsax_namespaces. - */ -static inline void free_srcsax_namespaces(int /*number_namespaces*/, srcsax_namespace * namespaces) { - - free((void *)namespaces); - -} - -/** - * libxml2_attributes2srcsax_attributes - * @param number_attributes the number of attributes - * @param libxml2_attributes - * - * Helper function to convert the libxml2 attributes to srcsax attributes - * returning a dynamically allocated struct containing the attributes. - * - * @returns the converted attributes as srcsax_attribute. - */ -static inline srcsax_attribute * libxml2_attributes2srcsax_attributes(int number_attributes, const xmlChar ** libxml2_attributes) { - - struct srcsax_attribute * srcsax_attributes = (srcsax_attribute *)calloc(number_attributes, sizeof(srcsax_attribute)); - - for(int pos = 0, index = 0; pos < number_attributes; ++pos, index += 5) { - - srcsax_attributes[pos].localname = (const char *)libxml2_attributes[index]; - srcsax_attributes[pos].prefix = (const char *)libxml2_attributes[index + 1]; - srcsax_attributes[pos].uri = (const char *)libxml2_attributes[index + 2]; - srcsax_attributes[pos].value = strndup((const char *)libxml2_attributes[index + 3], libxml2_attributes[index + 4] - libxml2_attributes[index + 3]); - - } - - return srcsax_attributes; -} - -/** - * free_srcsax_attributes - * @param number_attributes the number of attributes - * @param libxml2_attributes - * - * Helper function to free srcsax_attribute * struct allocated by libxml2_attributes2srcsax_attributes. - */ -static inline void free_srcsax_attributes(int number_attributes, srcsax_attribute * attributes) { - - for(int pos = 0; pos < number_attributes; ++pos) - free((void *)attributes[pos].value); - - free((void *)attributes); - -} - -/** - * srcml_element_stack_push - * @param context the srcsax_context - * @param srcml_element_stack the stack - * @param prefix the prefix of the element to push - * @param localname the name of the element to push - * - * Push the element on to the stack. - */ - void srcml_element_stack_push(srcsax_context * context, std::vector<const char *> & srcml_element_stack, const char * prefix, const char * localname) { - - size_t prefix_length = prefix ? strlen(prefix) : 0; - size_t name_length = strlen(localname); - size_t srcml_element_length = prefix ? prefix_length + name_length + 1 : name_length; - char * srcml_element_string = (char *)calloc(srcml_element_length + 1, sizeof(char)); - - size_t offset = 0; - if(prefix) { - - strncat(srcml_element_string, prefix, prefix_length); - srcml_element_string[prefix_length] = ':'; - offset = prefix_length + 1; - - } - - strncat(srcml_element_string + offset, localname, name_length); - - srcml_element_stack.push_back(srcml_element_string); - - context->stack_size = srcml_element_stack.size(); - context->srcml_element_stack = &srcml_element_stack.front(); - - } - -/** - * srcml_element_stack_pop - * @param context the srcsax_context - * @param srcml_element_stack the stack - * - * Pop an element off the stack. - */ - void srcml_element_stack_pop(srcsax_context * context, std::vector<const char *> & srcml_element_stack) { - - if(srcml_element_stack.size() == 0) return; - - const char * srcml_element = srcml_element_stack.back(); - - srcml_element_stack.pop_back(); - - free((void *)srcml_element); - - context->stack_size = srcml_element_stack.size(); - if(context->stack_size == 0) - context->srcml_element_stack = 0; - else - context->srcml_element_stack = &srcml_element_stack.front(); - - } - -/** - * start_document - * @param ctx an xmlParserCtxtPtr - * - * SAX handler function for start of document. - * Immediately calls supplied handlers function. - */ -void start_document(void * ctx) { - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - - if(ctx == NULL) return; - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - state->context->stack_size = 0; - state->context->srcml_element_stack = 0; - - state->context->encoding = "UTF-8"; - if(ctxt->encoding && ctxt->encoding[0]!= '\0') - state->context->encoding = (const char *)ctxt->encoding; - else if(ctxt->input) - state->context->encoding = (const char *)ctxt->input->encoding; - - if(state->context->terminate) return; - - if(state->context->handler->start_documentstart_documentstart_document) - state->context->handler->start_document(state->context); - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - -} - -/** - * end_document - * @param ctx an xmlParserCtxtPtr - * - * SAX handler function for end of document. - * Calls end_root if needed then - * immediately calls supplied handlers function. - */ -void end_document(void * ctx) { - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - - if(ctx == NULL) return; - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - state->context->stack_size = 0; - state->context->srcml_element_stack = 0; - - if(state->context->terminate) return; - - if(state->mode != END_ROOT && state->mode != START && state->context->handler->end_rootend_rootend_root) - state->context->handler->end_root(state->context, (const char *)state->root.localname, (const char *)state->root.prefix, (const char *)state->root.URI); - - if(state->context->terminate) return; - - if(state->context->handler->end_documentend_documentend_document) - state->context->handler->end_document(state->context); - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - -} - -/** - * start_root - * @param ctx an xmlParserCtxtPtr - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param nb_defaulted the number of defaulted attributes - * @param attributes list of attribute name value pairs (localname/prefix/URI/value/end) - * - * SAX handler function for start of root element. - * Caches root info and immediately calls supplied handlers function. - */ -void start_root(void * ctx, const xmlChar * localname, const xmlChar * prefix, const xmlChar * URI, - int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, - const xmlChar ** attributes) { - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, (const char *)localname); -#endif - - if(ctx == NULL) return; - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - srcml_element_stack_push(state->context, state->srcml_element_stack, (const char *)prefix, (const char *)localname); - - state->root = srcml_element(state->context, localname, prefix, URI, nb_namespaces, namespaces, nb_attributes, nb_defaulted, attributes); - - state->mode = ROOT; - - // handle nested units - ctxt->sax->startElementNs = &start_element_ns_firststart_element_ns_first; - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, (const char *)localname); -#endif - -} - -/** - * start_element_ns_first - * @param ctx an xmlParserCtxtPtr - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param nb_defaulted the number of defaulted attributes - * @param attributes list of attribute name value pairs (localname/prefix/URI/value/end) - * - * SAX handler function for start of first element after root - * Detects archive and acts accordingly. - */ -void start_element_ns_first(void * ctx, const xmlChar * localname, const xmlChar * prefix, const xmlChar * URI, - int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, - const xmlChar ** attributes) { - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, (const char *)localname); -#endif - - if(ctx == NULL) return; - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - int ns_length = state->root.nb_namespaces * 2; - for (int i = 0; i < ns_length; i += 2) - if(prefix && state->root.namespaces[i] && strcmp((const char *)state->root.namespaces[i], (const char *)prefix) == 0) - prefix = state->root.namespaces[i]; - - for (int i = 1; i < ns_length; i += 2) - if(URI && state->root.namespaces[i] && strcmp((const char *)state->root.namespaces[i], (const char *)URI) == 0) - URI = state->root.namespaces[i]; - - if(strcmp((const char *)localname, "macro-list") == 0) { - - if(state->context->handler->meta_tag) - state->meta_tags.push_back(srcml_element(state->context, localname, prefix, URI, nb_namespaces, namespaces, nb_attributes, nb_defaulted, attributes)); - - return; - - } - - srcsax_namespace * srcsax_namespaces = (srcsax_namespace *)libxml2_namespaces2srcsax_namespaceslibxml2_namespaces2srcsax_namespaces(nb_namespaceslibxml2_namespaces2srcsax_namespaces, namespaceslibxml2_namespaces2srcsax_namespaces); - srcsax_attribute * srcsax_attributes = (srcsax_attribute *)libxml2_attributes2srcsax_attributeslibxml2_attributes2srcsax_attributes(nb_attributeslibxml2_attributes2srcsax_attributes, attributeslibxml2_attributes2srcsax_attributes); - - state->is_archive = strcmp((const char *)localname, "unit") == 0; - state->context->is_archive = state->is_archive; - - if(state->context->terminate) return; - - if(state->context->handler->start_rootstart_rootstart_root) { - - srcsax_namespace * srcsax_namespaces_root = (srcsax_namespace *)libxml2_namespaces2srcsax_namespaces(state->root.nb_namespaces, state->root.namespaces); - srcsax_attribute * srcsax_attributes_root = (srcsax_attribute *)libxml2_attributes2srcsax_attributes(state->root.nb_attributes, state->root.attributes); - state->context->handler->start_root(state->context, (const char *)state->root.localname, (const char *)state->root.prefix, (const char *)state->root.URI, - state->root.nb_namespaces, srcsax_namespaces_root, state->root.nb_attributes, - srcsax_attributes_root); - - free_srcsax_namespaces(state->root.nb_namespaces, srcsax_namespaces_root); - free_srcsax_attributes(state->root.nb_attributes, srcsax_attributes_root); - - } - - if(state->context->terminate) return; - - if(state->context->handler->meta_tagmeta_tagmeta_tag && !state->meta_tags.empty()) { - - for(std::vector<srcml_element>::const_iterator citr = state->meta_tags.begin(); citr < state->meta_tags.end(); ++citr) { - - if(state->context->terminate) return; - - srcml_element_stack_push(state->context, state->srcml_element_stack, (const char *)citr->prefix, (const char *)citr->localname); - - srcsax_namespace * srcsax_namespaces_meta_tag = (srcsax_namespace *)libxml2_namespaces2srcsax_namespaces(citr->nb_namespaces, citr->namespaces); - srcsax_attribute * srcsax_attributes_meta_tag = (srcsax_attribute *)libxml2_attributes2srcsax_attributes(citr->nb_attributes, citr->attributes); - - state->context->handler->meta_tag(state->context, (const char *)citr->localname, (const char *)citr->prefix, (const char *)citr->URI, - citr->nb_namespaces, srcsax_namespaces_meta_tag, citr->nb_attributes, - srcsax_attributes_meta_tag); - - free_srcsax_namespaces(citr->nb_namespaces, srcsax_namespaces_meta_tag); - free_srcsax_attributes(citr->nb_attributes, srcsax_attributes_meta_tag); - - srcml_element_stack_pop(state->context, state->srcml_element_stack); - - } - - } - - if(state->context->terminate) return; - - if(!state->is_archive) { - - ++state->context->unit_count; - - if(state->context->terminate) return; - - state->mode = UNIT; - - if(state->context->handler->start_unit) { - - srcsax_namespace * srcsax_namespaces_root = (srcsax_namespace *)libxml2_namespaces2srcsax_namespaces(state->root.nb_namespaces, state->root.namespaces); - srcsax_attribute * srcsax_attributes_root = (srcsax_attribute *)libxml2_attributes2srcsax_attributes(state->root.nb_attributes, state->root.attributes); - state->context->handler->start_unit(state->context, (const char *)state->root.localname, (const char *)state->root.prefix, (const char *)state->root.URI, - state->root.nb_namespaces, srcsax_namespaces_root, state->root.nb_attributes, - srcsax_attributes_root); - - free_srcsax_namespaces(state->root.nb_namespaces, srcsax_namespaces_root); - free_srcsax_attributes(state->root.nb_attributes, srcsax_attributes_root); - - } - - if(state->context->terminate) return; - - if(state->characters.size() != 0 && state->context->handler->characters_unit) - state->context->handler->characters_unit(state->context, state->characters.c_str(), (int)state->characters.size()); - - if(state->context->terminate) return; - - srcml_element_stack_push(state->context, state->srcml_element_stack, (const char *)prefix, (const char *)localname); - - if(state->context->handler->start_element) - state->context->handler->start_element(state->context, (const char *)localname, (const char *)prefix, (const char *)URI, - nb_namespaces, srcsax_namespaces, nb_attributes, srcsax_attributes); - } else { - - if(state->context->terminate) return; - - if(state->context->handler->characters_root) - state->context->handler->characters_root(state->context, state->characters.c_str(), (int)state->characters.size()); - - ++state->context->unit_count; - - srcml_element_stack_push(state->context, state->srcml_element_stack, (const char *)prefix, (const char *)localname); - - if(state->context->terminate) return; - - state->mode = UNIT; - if(state->context->handler->start_unit) - state->context->handler->start_unit(state->context, (const char *)localname, (const char *)prefix, (const char *)URI, - nb_namespaces, srcsax_namespaces, nb_attributes, srcsax_attributes); - - - } - - if(state->context->terminate) return; - - if(ctxt->sax->startElementNs) ctxt->sax->startElementNs = &start_element_ns; - if(ctxt->sax->characters) { - - ctxt->sax->characters = &characters_unit; - ctxt->sax->ignorableWhitespace = &characters_unit; - - } - - free_srcsax_namespaces(nb_namespaces, srcsax_namespaces); - free_srcsax_attributes(nb_attributes, srcsax_attributes); - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, (const char *)localname); -#endif - -} - -/** - * start_unit - * @param ctx an xmlParserCtxtPtr - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param nb_defaulted the number of defaulted attributes - * @param attributes list of attribute name value pairs (localname/prefix/URI/value/end) - * - * SAX handler function for start of an unit. - * Immediately calls supplied handlers function. - */ -void start_unit(void * ctx, const xmlChar * localname, const xmlChar * prefix, const xmlChar * URI, - int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, - const xmlChar ** attributes) { - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, (const char *)localname); -#endif - - if(ctx == NULL) return; - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - if(state->context->terminate) return; - - srcsax_namespace * srcsax_namespaces = (srcsax_namespace *)libxml2_namespaces2srcsax_namespaceslibxml2_namespaces2srcsax_namespaces(nb_namespaceslibxml2_namespaces2srcsax_namespaces, namespaceslibxml2_namespaces2srcsax_namespaces); - srcsax_attribute * srcsax_attributes = (srcsax_attribute *)libxml2_attributes2srcsax_attributeslibxml2_attributes2srcsax_attributes(nb_attributeslibxml2_attributes2srcsax_attributes, attributeslibxml2_attributes2srcsax_attributes); - - srcml_element_stack_push(state->context, state->srcml_element_stack, (const char *)prefix, (const char *)localname); - - int ns_length = state->root.nb_namespaces * 2; - for (int i = 0; i < ns_length; i += 2) - if(prefix && state->root.namespaces[i] && strcmp((const char *)state->root.namespaces[i], (const char *)prefix) == 0) - prefix = state->root.namespaces[i]; - - for (int i = 1; i < ns_length; i += 2) - if(URI && state->root.namespaces[i] && strcmp((const char *)state->root.namespaces[i], (const char *)URI) == 0) - URI = state->root.namespaces[i]; - - ++state->context->unit_count; - - state->mode = UNIT; - - - - if(state->context->handler->start_unitstart_unitstart_unit) - state->context->handler->start_unit(state->context, (const char *)localname, (const char *)prefix, (const char *)URI, - nb_namespaces, srcsax_namespaces, nb_attributes, srcsax_attributes); - - if(ctxt->sax->startElementNs) ctxt->sax->startElementNs = &start_element_ns; - if(ctxt->sax->characters) { - - ctxt->sax->characters = &characters_unit; - ctxt->sax->ignorableWhitespace = &characters_unit; - - } - - free_srcsax_namespaces(nb_namespaces, srcsax_namespaces); - free_srcsax_attributes(nb_attributes, srcsax_attributes); - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, (const char *)localname); -#endif - -} - -/** - * start_element_ns - * @param ctx an xmlParserCtxtPtr - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param nb_defaulted the number of defaulted attributes - * @param attributes list of attribute name value pairs (localname/prefix/URI/value/end) - * - * SAX handler function for start of an element. - * Immediately calls supplied handlers function. - */ -void start_element_ns(void * ctx, const xmlChar * localname, const xmlChar * prefix, const xmlChar * URI, - int nb_namespaces, const xmlChar ** namespaces, int nb_attributes, int nb_defaulted, - const xmlChar ** attributes) { - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, (const char *)localname); -#endif - - if(ctx == NULL) return; - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - if(state->context->terminate) return; - - srcsax_namespace * srcsax_namespaces = (srcsax_namespace *)libxml2_namespaces2srcsax_namespaceslibxml2_namespaces2srcsax_namespaces(nb_namespaceslibxml2_namespaces2srcsax_namespaces, namespaceslibxml2_namespaces2srcsax_namespaces); - srcsax_attribute * srcsax_attributes = (srcsax_attribute *)libxml2_attributes2srcsax_attributeslibxml2_attributes2srcsax_attributes(nb_attributeslibxml2_attributes2srcsax_attributes, attributeslibxml2_attributes2srcsax_attributes); - - srcml_element_stack_push(state->context, state->srcml_element_stack, (const char *)prefix, (const char *)localname); - - int ns_length = state->root.nb_namespaces * 2; - for (int i = 0; i < ns_length; i += 2) - if(prefix && state->root.namespaces[i] && strcmp((const char *)state->root.namespaces[i], (const char *)prefix) == 0) - prefix = state->root.namespaces[i]; - - for (int i = 1; i < ns_length; i += 2) - if(URI && state->root.namespaces[i] && strcmp((const char *)state->root.namespaces[i], (const char *)URI) == 0) - URI = state->root.namespaces[i]; - - if(state->parse_function && (strcmp((const char *)localname, "function_decl") == 0 || strcmp((const char *)localname, "function") == 0)) { - - state->in_function_header = true; - state->current_function = function_prototype(strcmp((const char *)localname, "function_decl") == 0); - - } else if(!state->in_function_header) { - - if(state->context->handler->start_element) - state->context->handler->start_element(state->context, (const char *)localname, (const char *)prefix, (const char *)URI, - nb_namespaces, srcsax_namespaces, nb_attributes, srcsax_attributes); - - } else { - - if(state->current_function.mode == function_prototype::NAME && strcmp((const char *)localname, "parameter_list") == 0) { - - state->current_function.mode = function_prototype::PARAMETER_LIST; - - } else if(state->current_function.mode == function_prototype::PARAMETER_LIST && strcmp((const char *)localname, "param") == 0) { - - state->current_function.parameter_list.push_back(declaration()); - state->current_function.mode = function_prototype::PARAMETER; - - } else if(state->current_function.mode == function_prototype::PARAMETER && strcmp((const char *)localname, "init") == 0) { - - state->current_function.parameter_list.back().mode = declaration::INIT; - - state->current_function.mode = function_prototype::PARAMETER_LIST; - - } - - } - - free_srcsax_namespaces(nb_namespaces, srcsax_namespaces); - free_srcsax_attributes(nb_attributes, srcsax_attributes); - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, (const char *)localname); -#endif - -} - -/** - * end_element_ns - * @param ctx an xmlParserCtxtPtr - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of an element. - * Detects end of unit and calls correct functions - * for either end_root end_unit or end_element_ns. - */ -void end_element_ns(void * ctx, const xmlChar * localname, const xmlChar * prefix, const xmlChar * URI) { - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, (const char *)localname); -#endif - - if(ctx == NULL) return; - - if(strcmp((const char *)localname, "macro-list") == 0) { - - return; - - } - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - if(strcmp((const char *)localname, "unit") == 0) { - - if(state->mode == ROOT) { - - state->is_archive = false; - state->context->is_archive = state->is_archive; - - if(state->context->terminate) return; - - srcsax_namespace * srcsax_namespaces_root = (srcsax_namespace *)libxml2_namespaces2srcsax_namespaces(state->root.nb_namespaces, state->root.namespaces); - srcsax_attribute * srcsax_attributes_root = (srcsax_attribute *)libxml2_attributes2srcsax_attributes(state->root.nb_attributes, state->root.attributes); - - if(state->context->handler->start_root) - state->context->handler->start_root(state->context, (const char *)state->root.localname, (const char *)state->root.prefix, (const char *)state->root.URI, - state->root.nb_namespaces, srcsax_namespaces_root, state->root.nb_attributes, - srcsax_attributes_root); - - if(state->context->terminate) return; - - if(state->context->handler->meta_tag && !state->meta_tags.empty()) { - - for(std::vector<srcml_element>::const_iterator citr = state->meta_tags.begin(); citr < state->meta_tags.end(); ++citr) { - - srcml_element_stack_push(state->context, state->srcml_element_stack, (const char *)citr->prefix, (const char *)citr->localname); - - srcsax_namespace * srcsax_namespaces_meta_tag = (srcsax_namespace *)libxml2_namespaces2srcsax_namespaces(citr->nb_namespaces, citr->namespaces); - srcsax_attribute * srcsax_attributes_meta_tag = (srcsax_attribute *)libxml2_attributes2srcsax_attributes(citr->nb_attributes, citr->attributes); - - if(state->context->terminate) { - - free_srcsax_namespaces(state->root.nb_namespaces, srcsax_namespaces_root); - free_srcsax_attributes(state->root.nb_attributes, srcsax_attributes_root); - return; - - } - - state->context->handler->meta_tag(state->context, (const char *)citr->localname, (const char *)citr->prefix, (const char *)citr->URI, - citr->nb_namespaces, srcsax_namespaces_meta_tag, citr->nb_attributes, - srcsax_attributes_meta_tag); - - free_srcsax_namespaces(citr->nb_namespaces, srcsax_namespaces_meta_tag); - free_srcsax_attributes(citr->nb_attributes, srcsax_attributes_meta_tag); - - srcml_element_stack_pop(state->context, state->srcml_element_stack); - - } - - } - - if(state->context->terminate) { - - free_srcsax_namespaces(state->root.nb_namespaces, srcsax_namespaces_root); - free_srcsax_attributes(state->root.nb_attributes, srcsax_attributes_root); - return; - - } - - if(state->context->handler->start_unit) - state->context->handler->start_unit(state->context, (const char *)state->root.localname, (const char *)state->root.prefix, (const char *)state->root.URI, - state->root.nb_namespaces, srcsax_namespaces_root, state->root.nb_attributes, - srcsax_attributes_root); - - free_srcsax_namespaces(state->root.nb_namespaces, srcsax_namespaces_root); - free_srcsax_attributes(state->root.nb_attributes, srcsax_attributes_root); - - if(state->context->terminate) return; - - if(state->characters.size() != 0 && state->context->handler->characters_unit) - state->context->handler->characters_unit(state->context, state->characters.c_str(), (int)state->characters.size()); - - } - - srcml_element_stack_pop(state->context, state->srcml_element_stack); - - if(state->context->terminate) return; - - if(ctxt->sax->startElementNs == &start_unit) { - - state->mode = END_ROOT; - if(state->context->handler->end_root) - state->context->handler->end_root(state->context, (const char *)localname, (const char *)prefix, (const char *)URI); - - } else { - - state->mode = END_UNIT; - if(state->context->handler->end_unit) - state->context->handler->end_unit(state->context, (const char *)localname, (const char *)prefix, (const char *)URI); - if(ctxt->sax->startElementNs) ctxt->sax->startElementNs = &start_unit; - if(ctxt->sax->characters) { - - ctxt->sax->characters = &characters_root; - ctxt->sax->ignorableWhitespace = &characters_root; - - } - } - - if(state->context->terminate) return; - - } else { - - srcml_element_stack_pop(state->context, state->srcml_element_stack); - - if(state->in_function_header && (strcmp((const char *)localname, "function_decl") == 0 || strcmp((const char *)localname, "function") == 0)) { - - //state->context->handler->endFunction(); - - } else if(!state->in_function_header) { - - if(state->context->terminate) return; - - if(state->context->handler->end_element) - state->context->handler->end_element(state->context, (const char *)localname, (const char *)prefix, (const char *)URI); - - if(state->context->terminate) return; - - } else { - - if(state->current_function.mode == function_prototype::RETURN_TYPE && strcmp((const char *)localname, "type") == 0) { - - state->current_function.mode = function_prototype::NAME; - - } else if(state->current_function.mode == function_prototype::PARAMETER && state->current_function.parameter_list.back().mode == declaration::TYPE - && strcmp((const char *)localname, "type") == 0) { - - state->current_function.parameter_list.back().mode = declaration::NAME; - - } else if(state->current_function.mode == function_prototype::PARAMETER - && (strcmp((const char *)localname, "param") == 0 || strcmp((const char *)localname, "decl") == 0)) { - - state->current_function.mode = function_prototype::PARAMETER_LIST; - - } else if(state->current_function.mode == function_prototype::PARAMETER_LIST && strcmp((const char *)localname, "parameter_list") == 0) { - - state->in_function_header = false; - //state->context->handler->startFunction(state->current_function.name, state->current_function.return_type, state->current_function.parameter_list, state->current_function.is_decl); - - } - - } - - } - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, (const char *)localname); -#endif - -} - -/** - * characters_first - * @param ctx an xmlParserCtxtPtr - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling before we - * know if we have an archive or not. - * Immediately calls supplied handlers function. - */ -void characters_first(void * ctx, const xmlChar * ch, int len) { - -#ifdef SRCSAX_DEBUG - std::string chars; - chars.append((const char *)ch, len); - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, chars.c_str()); -#endif - - if(ctx == NULL) return; - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - state->characters.append((const char *)ch, len); - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, chars.c_str()); -#endif - -} - -/** - * characters_root - * @param ctx an xmlParserCtxtPtr - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling at the root level. - * Immediately calls supplied handlers function. - */ -void characters_root(void * ctx, const xmlChar * ch, int len) { - -#ifdef SRCSAX_DEBUG - std::string chars; - chars.append((const char *)ch, len); - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, chars.c_str()); -#endif - - if(ctx == NULL) return; - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - if(state->context->terminate) return; - - if(state->context->handler->characters_rootcharacters_rootcharacters_root) - state->context->handler->characters_root(state->context, (const char *)ch, len); - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, chars.c_str()); -#endif - -} - -/** - * characters_unit - * @param ctx an xmlParserCtxtPtr - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling within a unit. - * Immediately calls supplied handlers function. - */ -void characters_unit(void * ctx, const xmlChar * ch, int len) { - -#ifdef SRCSAX_DEBUG - std::string chars; - chars.append((const char *)ch, len); - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, chars.c_str()); -#endif - - if(ctx == NULL) return; - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - - if(!state->in_function_header) { - - if(state->context->terminate) return; - - if(state->context->handler->characters_unit) - state->context->handler->characters_unit(state->context, (const char *)ch, len); - - } else { - - if(state->current_function.mode == function_prototype::RETURN_TYPE) - state->current_function.return_type.append((const char *)ch, len); - else if(state->current_function.mode == function_prototype::NAME) - state->current_function.name.append((const char *)ch, len); - else if(state->current_function.mode == function_prototype::PARAMETER) { - - if(state->current_function.parameter_list.back().mode == declaration::TYPE) - state->current_function.parameter_list.back().type.append((const char *)ch, len); - else if(state->current_function.parameter_list.back().mode == declaration::NAME) - state->current_function.parameter_list.back().name.append((const char *)ch, len); - - } - - } - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d '%s'\n", __FILE__, __FUNCTION__, __LINE__, chars.c_str()); -#endif - -} - -/** - * comment - * @param ctx an xmlParserCtxtPtr - * @param value the comment content - * - * A comment has been parsed. - * Immediately calls supplied handlers function. - */ -void comment(void * ctx, const xmlChar * value) { - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - - if(ctx == NULL) return; - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - if(state->context->terminate) return; - - if(state->context->handler->commentcommentcomment) - state->context->handler->comment(state->context, (const char *)value); - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - -} - -/** - * cdata_block - * @param ctx an xmlParserCtxtPtr - * @param value the pcdata content - * @param len the block length - * - * Called when a pcdata block has been parsed. - * Immediately calls supplied handlers function. - */ -void cdata_block(void * ctx, const xmlChar * value, int len) { - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - - if(ctx == NULL) return; - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - if(state->context->terminate) return; - - if(state->context->handler->cdata_blockcdata_blockcdata_block) - state->context->handler->cdata_block(state->context, (const char *)value, len); - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - -} - -/** - * processing_instruction - * @param ctx an xmlParserCtxtPtr - * @param target the processing instruction target. - * @param data the processing instruction data. - * - * Called when a processing instruction has been parsed. - * Immediately calls supplied handlers function. - */ -void processing_instruction(void * ctx, const xmlChar * target, const xmlChar * data) { - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - - if(ctx == NULL) return; - - xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; - sax2_srcsax_handler * state = (sax2_srcsax_handler *) ctxt->_private; - - if(state->context->terminate) return; - - if(state->context->handler->processing_instructionprocessing_instructionprocessing_instruction) - state->context->handler->processing_instruction(state->context, (const char *)target, (const char *)data); - -#ifdef SRCSAX_DEBUG - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); -#endif - -} - -#pragma GCC diagnostic pop - - -/** - * @file srcsax.h - * - * @copyright Copyright (C) 2013-2014 srcML, LLC. (www.srcML.org) - * - * srcSAX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * srcSAX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef INCLUDED_SRCSAX_H -#define INCLUDED_SRCSAX_H - -#include <srcsax_handler.h> - -#include <libxml/parser.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * srcsax_context - * - * Context data structure passed between callbacks. - */ -struct srcsax_context { - - /** user provided data */ - void * data; - - /** srcSAX handler callbacks */ - struct srcsax_handler * handler; - - /** error callback need to figure this one out probably message and errorcode. or struct. Might not need, but might be nice to avoid libxml2 stuff */ - void (*srcsax_error)(const char * message, int error_code); - - /** is the document an archive */ - int is_archive; - - /** the current unit count */ - int unit_count; - - /** size of the srcml_element stack */ - size_t stack_size; - - /** stack of open srcML elements */ - const char ** srcml_element_stack; - - /** the xml documents encoding */ - const char * encoding; - - /* Internal context handling NOT FOR PUBLIC USE */ - - /** xml parser input buffer */ - xmlParserInputBufferPtr input; - - /** boolean to indicate need to free input buffer */ - int free_input; - - /** internally used libxml2 context */ - xmlParserCtxtPtr libxml2_context; - - /** indicate stop parser */ - int terminate; - -}; - -/* srcSAX context creation/open functions */ -struct srcsax_context * srcsax_create_context_filenamesrcsax_create_context_filename(const char * filename, const char * encoding); -struct srcsax_context * srcsax_create_context_memorysrcsax_create_context_memory(const char * buffer, size_t buffer_size, const char * encoding); -struct srcsax_context * srcsax_create_context_FILEsrcsax_create_context_FILE(FILE * srcml_file, const char * encoding); -struct srcsax_context * srcsax_create_context_fdsrcsax_create_context_fd(int srcml_fd, const char * encoding); -struct srcsax_context * srcsax_create_context_io(void * srcml_context, int (*read_callback)(void * context, char * buffer, int len), int (*close_callback)(void * context), const char * encoding); -struct srcsax_context * srcsax_create_context_parser_input_buffersrcsax_create_context_parser_input_buffer(xmlParserInputBufferPtr input); - -/* srcSAX free function */ -void srcsax_free_contextsrcsax_free_context(struct srcsax_context * context); - -/* srcSAX parse function */ -int srcsax_parse(struct srcsax_context * context); -int srcsax_parse_handlersrcsax_parse_handler(struct srcsax_context * context, struct srcsax_handler * handler); - -/* srcSAX terminate parse function */ -void srcsax_stop_parsersrcsax_stop_parser(struct srcsax_context * context); - -#ifdef __cplusplus -} -#endif - -#endif - - -/** - * @file srcsax_handler.h - * - * @copyright Copyright (C) 2013-2014 srcML, LLC. (www.srcML.org) - * - * srcSAX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * srcSAX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef INCLUDED_SRCSAX_HANDLER_H -#define INCLUDED_SRCSAX_HANDLER_H - -#include <libxml/parser.h> - -#ifdef __cplusplus -extern "C" { -#endif - -struct srcsax_context; - -/** - * srcsax_namespace - * - * Data structure for a srcML/xml namespace - */ -struct srcsax_namespace { - - /** a namespace prefix */ - const char * prefix; - - /** a namespace uri */ - const char * uri; - -}; - -/** - * srcsax_attribute - * - * Data structure for a srcML/xml attribute - */ - struct srcsax_attribute { - - /** attribute name */ - const char * localname; - - /** attribute namespace prefix */ - const char * prefix; - - /** attribute namespace uri */ - const char * uri; - - /** attribute value */ - const char * value; - -}; - -/** - * srcsax_handler - * - * Struct of srcSAX callback functions i.e. srcSAX handler. - */ -struct srcsax_handler { - -/** - * start_document - * @param context a srcSAX context - * - * Signature for srcSAX handler function for start of document. - */ -void (*start_document)(struct srcsax_context * context); - -/** - * end_document - * @param context a srcSAX context - * - * Signature for srcSAX handler function for end of document. - */ -void (*end_document)(struct srcsax_context * context); - -/** - * start_root - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * Signature for srcSAX handler function for start of the root element. - */ -void (*start_root)(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes); - -/** - * start_unit - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * Signature srcSAX handler function for start of an unit. - */ -void (*start_unit)(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes); - -/** - * start_function - * @param context a srcSAX context - * @param name the function's name - * @param return_type the function return type - * @param parameter_list a list of the function parameters in struct containing (declaration.type/declaration.name) - * @param is_decl indicates if the call is a function declaration (true) or definition (false) - * - * Signature for srcSAX handler function for start of function with prototype. - */ -//void (*start_function(struct srcsax_context * context, const char * name, const char * return_type, const struct declaration * parameter_list, _Bool is_decl); - -/** - * start_element - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * Signature for srcSAX handler function for start of an element. - */ -void (*start_element)(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes); - -/** - * end_root - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * Signature for srcSAX handler function for end of the root element. - */ -void (*end_root)(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI); - -/** - * end_unit - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * Signature for srcSAX handler function for end of an unit. - */ -void (*end_unit)(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI); - -/** - * end_function - * @param context a srcSAX context - * - * Signature for srcSAX handler function for end of a function. - */ -//void (*end_function(struct srcsax_context * context); - -/** - * end_element - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * Signature for srcSAX handler function for end of an element. - */ -void (*end_element)(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI); - -/** - * characters_root - * @param context a srcSAX context - * @param ch the characers - * @param len number of characters - * - * Signature for srcSAX handler function for character handling at the root level. - */ -void (*characters_root)(struct srcsax_context * context, const char * ch, int len); - -/** - * characters_unit - * @param ch the characers - * @param len number of characters - * - * Signature for srcSAX handler function for character handling within a unit. - */ -void (*characters_unit)(struct srcsax_context * context, const char * ch, int len); - -/** - * meta_tag - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * Signature for srcSAX handler function for meta tags. - */ -void (*meta_tag)(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes); - -/** - * comment - * @param context a srcSAX context - * @param value the comment content - * - * Signature for srcSAX handler function for a XML comment. - */ -void (*comment)(struct srcsax_context * context, const char * value); - -/** - * cdata_block - * @param context a srcSAX context - * @param value the pcdata content - * @param len the block length - * - * Signature for srcSAX handler function for pcdata block. - */ -void (*cdata_block)(struct srcsax_context * context, const char * value, int len); - -/** - * processing_instruction - * @param context a srcSAX context - * @param target the processing instruction target. - * @param data the processing instruction data. - * - * Signature for srcSAX handler function for processing instruction. - */ -void (*processing_instruction)(struct srcsax_context * context, const char * target, const char * data); - -}; - -#ifdef __cplusplus -} -#endif - -#endif - - -/** - * @file test_srcsax_test_handler.cpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <srcsax_handler_test.hpp> -#include <sax2_srcsax_handler.hpp> - -#include <stdio.h> -#include <string.h> -#include <cassert> - -/** default initialization used throughout for testing */ -sax2_srcsax_handler sax2_handler_init; - -/** default initialization used throughout for testing */ -xmlParserCtxt ctxt_init; - -/** - * main - * - * Test the sax2_srcsax_handler/srcsax_test_handler. - * - * @returns 0 on success. - */ - int main() { - - /* - start_document - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - start_document(&ctxt); - assert(test_handler.start_document_call_number == 1); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.start_document = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - start_document(&ctxt); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - /* - end_document - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_document(&ctxt); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 1); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.mode = END_UNIT; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_document(&ctxt); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 2); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 1); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.end_document = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_document(&ctxt); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.end_root = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.mode = END_UNIT; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_document(&ctxt); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 1); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.end_document = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.mode = END_UNIT; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_document(&ctxt); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 1); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - /* - start_root - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.start_document = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - start_document(&ctxt); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - /* - start_element_ns_first - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 1); - assert(test_handler.start_unit_call_number == 3); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 2); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"name", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 1); - assert(test_handler.start_unit_call_number == 2); - assert(test_handler.start_element_call_number == 4); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 3); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.start_root = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 2); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 1); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.start_unit = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 1); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 2); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.characters_root = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 1); - assert(test_handler.start_unit_call_number == 2); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.start_root = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"name", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 1); - assert(test_handler.start_element_call_number == 3); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 2); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.start_unit = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"name", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 1); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 3); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 2); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.characters_unit = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"name", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 1); - assert(test_handler.start_unit_call_number == 2); - assert(test_handler.start_element_call_number == 3); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.start_element = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"name", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 1); - assert(test_handler.start_unit_call_number == 2); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 3); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - /* - start_unit - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_unit(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 1); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.start_unit = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_unit(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - /* - start_element_ns - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 1); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.start_element = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char * namespaces[4] = { 0, "http://www.sdml.info/srcML/src", "cpp", "http://www.sdml.info/srcML/cpp" }; - const char * values = "abc"; - const char * attributes[15] = { "filename", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "dir", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2, - "language", 0, "http://www.sdml.info/srcML/src", values + 2, values + 3 }; - - start_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 2, (const xmlChar **)namespaces, 3, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - /* - end_element_ns - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - sax.startElementNs = &start_unit; - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 1); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 1); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_element_ns(&ctxt, (const xmlChar *)"name", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 1); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.end_root = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - sax.startElementNs = &start_unit; - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.end_unit = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_element_ns(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.end_element = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - end_element_ns(&ctxt, (const xmlChar *)"name", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src"); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - /* - characters_root - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - characters_root(&ctxt, (const xmlChar *)"unit", 4); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 1); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.characters_root = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - characters_root(&ctxt, (const xmlChar *)"unit", 4); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - /* - characters_unit - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - characters_unit(&ctxt, (const xmlChar *)"unit", 4); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 1); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.characters_unit = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - characters_unit(&ctxt, (const xmlChar *)"unit", 4); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - /* - meta_tag - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - sax.startElementNs = start_element_ns_first; - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char ** namespaces = 0; - const char * values = "ab"; - const char * attributes[10] = { "token", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "type", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 0, (const xmlChar **)namespaces, 2, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 0, (const xmlChar **)namespaces, 2, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"expr_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 0, (const xmlChar **)namespaces, 2, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 1); - assert(test_handler.start_unit_call_number == 3); - assert(test_handler.start_element_call_number == 5); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 4); - assert(test_handler.meta_tag_call_number == 2); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - sax.startElementNs = start_element_ns_first; - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char ** namespaces = 0; - const char * values = "ab"; - const char * attributes[10] = { "token", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "type", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 0, (const xmlChar **)namespaces, 2, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 0, (const xmlChar **)namespaces, 2, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 0, (const xmlChar **)namespaces, 2, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 1); - assert(test_handler.start_unit_call_number == 4); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 3); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 2); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.meta_tag = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - sax.startElementNs = start_element_ns_first; - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - const char ** namespaces = 0; - const char * values = "ab"; - const char * attributes[10] = { "token", 0, "http://www.sdml.info/srcML/src", values, values + 1, - "type", 0, "http://www.sdml.info/srcML/src", values + 1, values + 2 }; - - start_root(&ctxt, (const xmlChar *)"unit", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 0, (const xmlChar **)namespaces, 2, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"macro-list", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 0, (const xmlChar **)namespaces, 2, 0, - (const xmlChar **) attributes); - start_element_ns_first(&ctxt, (const xmlChar *)"expr_stmt", (const xmlChar *)0, - (const xmlChar *)"http://www.sdml.info/srcML/src", 0, (const xmlChar **)namespaces, 2, 0, - (const xmlChar **) attributes); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 1); - assert(test_handler.start_unit_call_number == 2); - assert(test_handler.start_element_call_number == 4); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 3); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - end_document(&ctxt); - - } - - /* - comment - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - comment(&ctxt, (const xmlChar *)"unit"); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 1); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.comment = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - comment(&ctxt, (const xmlChar *)"unit"); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - /* - cdata_block - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - cdata_block(&ctxt, (const xmlChar *)"unit", 4); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 1); - assert(test_handler.processing_instruction_call_number == 0); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.cdata_block = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - cdata_block(&ctxt, (const xmlChar *)"unit", 4); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - /* - processing_instruction - */ - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - processing_instruction(&ctxt, (const xmlChar *)"target", (const xmlChar *)"data"); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 1); - - } - - { - - srcsax_handler_test test_handler; - srcsax_handler srcsax_sax = srcsax_handler_test::factory(); - srcsax_sax.processing_instruction = 0; - - srcsax_context context; - context.data = &test_handler; - context.handler = &srcsax_sax; - - sax2_srcsax_handler sax2_handler = sax2_handler_init; - sax2_handler.context = &context; - - xmlParserCtxt ctxt = ctxt_init; - xmlSAXHandler sax = srcsax_sax2_factory(); - ctxt.sax = &sax; - ctxt._private = &sax2_handler; - processing_instruction(&ctxt, (const xmlChar *)"target", (const xmlChar *)"data"); - assert(test_handler.start_document_call_number == 0); - assert(test_handler.end_document_call_number == 0); - assert(test_handler.start_root_call_number == 0); - assert(test_handler.start_unit_call_number == 0); - assert(test_handler.start_element_call_number == 0); - assert(test_handler.end_root_call_number == 0); - assert(test_handler.end_unit_call_number == 0); - assert(test_handler.end_element_call_number == 0); - assert(test_handler.characters_root_call_number == 0); - assert(test_handler.characters_unit_call_number == 0); - assert(test_handler.meta_tag_call_number == 0); - assert(test_handler.comment_call_number == 0); - assert(test_handler.cdata_block_call_number == 0); - assert(test_handler.processing_instruction_call_number == 0); - - } - - return 0; - -} - - -/** - * @file srcsax_controller.cpp - * - * @copyright Copyright (C) 2013-2014 srcML, LLC. (www.srcML.org) - * - * srcSAX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * srcSAX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#include <srcsax.h> -#include <sax2_srcsax_handler.hpp> - -#include <libxml/parserInternals.h> - -#include <cstring> - -/** - * libxml_error - * - * Silence/catch/default libxml2 errors. - */ -static void libxml_error(void * /*ctx*/, const char * /*msg*/, ... ) {} - -/* srcsax_create_parser_context forward declaration */ -static xmlParserCtxtPtr srcsax_create_parser_context(xmlParserInputBufferPtr buffer_input); - -#ifdef LIBXML2_NEW_BUFFER -struct _xmlBuf { - xmlChar * content; /* The buffer content UTF8 */ - unsigned int compat_use; /* for binary compatibility */ - unsigned int compat_size; /* for binary compatibility */ - xmlBufferAllocationScheme alloc; /* The realloc method */ - xmlChar * contentIO; /* in IO mode we may have a different base */ - size_t use; /* The buffer size used */ - size_t size; /* The buffer size */ - xmlBufferPtr buffer; /* wrapper for an old buffer */ - int error; /* an error code if a failure occured */ -}; - -#define _CHECK_COMPAT(buf ) \ - if (buf->size != (size_t) buf->compat_size) \ - if (buf->compat_size < INT_MAX) \ - buf->size = buf->compat_size; \ - if (buf->use != (size_t) buf->compat_use) \ - if (buf->compat_use < INT_MAX) \ - buf->use = buf->compat_use; - -/** - * xmlBufResetInput - * @param buf XML buffer - * @param input XML parser input - * - * Function is taken from libxml2. - * - * @returns 0 on success and -1 on error. - */ -static int -_xmlBufResetInput(xmlBuf * buf, xmlParserInputPtr input) { - if ((input == NULL) || (buf == NULL) || (buf->error)) - return(-1); - _CHECK_COMPAT(buf) - input->base = input->cur = buf->content; - input->end = &buf->content[buf->use]; - return(0); - -} -#else -/** - * xmlBufResetInput - * @param buf XML buffer - * @param input XML parser input - * - * Function is taken fro libxml2. - * - * @returns 0 on success and -1 on error. - */ -static int -_xmlBufResetInput(xmlBuffer * buf, xmlParserInputPtr input) { - if ((input == NULL) || (buf == NULL)) - return -1; - input->base = input->buf->buffer->content; - input->cur = input->buf->buffer->content; - input->end = &input->buf->buffer->content[input->buf->buffer->use]; - return 0; -} - -#endif - -/** - * srcsax_controller_init - * - * Internal method to initialize the controller module. - */ -static void srcsax_controller_init() { - - static bool initialized = false; - - if(initialized) return; - - xmlGenericErrorFunc error_handler = (xmlGenericErrorFunc) libxml_errorlibxml_error; - initGenericErrorDefaultFunc(&error_handler); - initialized = true; - -} - -/** - * srcsax_create_context_inner - * @param input a libxml2 parser input buffer - * - * A helper function that creates the srcSAX context and does error handling. - * With a supplied xmlParserInputBufferPtr. - * - * @returns srcsax_context context to be used for srcML parsing. - */ -static struct srcsax_context * srcsax_create_context_inner(xmlParserInputBufferPtr input, int free_input) { - - if(input == 0) return 0; - - struct srcsax_context * context = (struct srcsax_context *)malloc(sizeof(struct srcsax_context)); - - if(context == 0) { - - xmlFreeParserInputBuffer(input); - return 0; - - } - - memset(context, 0, sizeof(struct srcsax_context)); - context->input = input; - context->free_input = free_input; - - xmlParserCtxtPtr libxml2_context = srcsax_create_parser_context(context->input); - - if(libxml2_context == NULL) { - - xmlFreeParserInputBuffer(input); - free(context); - return 0; - - } - - /** @todo this does not make sense */ - libxml2_context->_private = context; - - context->libxml2_context = libxml2_context; - - context->terminate = 0; - - return context; - -} - -/** - * srcsax_create_context_filename - * @param filename a filename - * @param encoding the files character encoding - * - * Open the filename with the specified encoding and return a srcSAX context for parsing. - * - * @returns srcsax_context context to be used for srcML parsing. - */ -struct srcsax_context * srcsax_create_context_filename(const char * filename, const char * encoding) { - - if(filename == 0) return 0; - - srcsax_controller_initsrcsax_controller_init(); - - xmlParserInputBufferPtr input = - xmlParserInputBufferCreateFilename(filename, encoding ? xmlParseCharEncoding(encoding) : XML_CHAR_ENCODING_NONE); - - return srcsax_create_context_inner(input, 1); - -} - -/** - * srcsax_create_context_memory - * @param buffer a buffer of memory - * @param buffer_size the size of the buffer/amount of buffer to use - * @param encoding the files character encoding - * - * Create a srcsSAX context from the supplied buffer using the provided amount and encoding. - * - * @returns srcsax_context context to be used for srcML parsing. - */ -struct srcsax_context * srcsax_create_context_memory(const char * buffer, size_t buffer_size, const char * encoding) { - - if(buffer == 0 || buffer_size == 0) return 0; - - srcsax_controller_initsrcsax_controller_init(); - - xmlParserInputBufferPtr input = - xmlParserInputBufferCreateMem(buffer, (int)buffer_size, encoding ? xmlParseCharEncoding(encoding) : XML_CHAR_ENCODING_NONE); - - return srcsax_create_context_inner(input, 1); - -} - -/** - * srcsax_create_context_FILE - * @param srcml_file an opened file containing srcML - * @param encoding the files character encoding - * - * Create a srcsSAX context from the supplied FILE using the provided encoding. - * - * @returns srcsax_context context to be used for srcML parsing. - */ -struct srcsax_context * srcsax_create_context_FILE(FILE * srcml_file, const char * encoding) { - - if(srcml_file == 0) return 0; - - srcsax_controller_initsrcsax_controller_init(); - - xmlParserInputBufferPtr input = - xmlParserInputBufferCreateFile(srcml_file, encoding ? xmlParseCharEncoding(encoding) : XML_CHAR_ENCODING_NONE); - - return srcsax_create_context_inner(input, 1); - -} - -/** - * srcsax_create_context_fd - * @param srcml_fd an opened file descriptor containing srcML - * @param encoding the files character encoding - * - * Create a srcsSAX context from the supplied file descriptor using the provided encoding. - * - * @returns srcsax_context context to be used for srcML parsing. - */ -struct srcsax_context * srcsax_create_context_fd(int srcml_fd, const char * encoding) { - - if(srcml_fd < 0) return 0; - - srcsax_controller_initsrcsax_controller_init(); - - xmlParserInputBufferPtr input = - xmlParserInputBufferCreateFd(srcml_fd, encoding ? xmlParseCharEncoding(encoding) : XML_CHAR_ENCODING_NONE); - - return srcsax_create_context_inner(input, 1); - -} - -/** - * srcsax_create_context_io - * @param srcml_context an opened context for opened srcML document - * @param read_callback a read callback function - * @close_callback a close callback function - * @param encoding the files character encoding - * - * Create a srcsSAX context from a general context and read/close callbacks with the specified encoding. - * - * @returns srcsax_context context to be used for srcML parsing. - */ -struct srcsax_context * srcsax_create_context_io(void * srcml_context, int (*read_callback)(void * context, char * buffer, int len), int (*close_callback)(void * context), const char * encoding) { - - if(srcml_context == 0 || read_callbackread_callback == 0) return 0; - - srcsax_controller_initsrcsax_controller_init(); - - xmlParserInputBufferPtr input = - xmlParserInputBufferCreateIO(read_callback, close_callback, srcml_context, encoding ? xmlParseCharEncoding(encoding) : XML_CHAR_ENCODING_NONE); - - return srcsax_create_context_inner(input, 1); - -} - -/** - * srcsax_create_context_parser_input_buffer - * @param srcml_context an opened context for opened srcML document - * @param read_callback a read callback function - * @close_callback a close callback function - * @param encoding the files character encoding - * - * Create a srcsSAX context from a general context and read/close callbacks with the specified encoding. - * - * @returns srcsax_context context to be used for srcML parsing. - */ -struct srcsax_context * srcsax_create_context_parser_input_buffer(xmlParserInputBufferPtr input) { - - if(input == 0) return 0; - - srcsax_controller_initsrcsax_controller_init(); - - return srcsax_create_context_inner(input, 0); - -} - -/** - * srcsax_free_context - * @param context a srcSAX context - * - * Free the resources associated with a srcsax_context as created - * by a previous srcsax_create_context_*. - */ -void srcsax_free_context(struct srcsax_context * context) { - - if(context == 0) return; - - xmlParserInputPtr stream = inputPop(context->libxml2_context); - stream->buf = 0; - xmlFreeInputStream(stream); - if(context->libxml2_context) xmlFreeParserCtxt(context->libxml2_context); - if(context->free_input) xmlFreeParserInputBuffer(context->input); - - free(context); - -} - -/** - * srcsax_parse - * @param context srcSAX context - * - * Parse the context using the provide sax handlers. - * On error calls the error callback function before returning. - * - * @returns 0 on success -1 on error. - */ -int srcsax_parse(struct srcsax_context * context) { - - if(context == 0 || context->handler == 0) return -1; - - xmlSAXHandlerPtr save_sax = context->libxml2_context->sax; - xmlSAXHandler sax = srcsax_sax2_factory(); - context->libxml2_context->sax = &sax; - - sax2_srcsax_handler state; - state.context = context; - context->libxml2_context->_private = &state; - - int status = 0; - try { - - status = xmlParseDocument(context->libxml2_context); - - } catch(... ) { - - return -1; - - } - - context->libxml2_context->sax = save_sax; - - if(status != 0) { - - xmlErrorPtr ep = xmlCtxtGetLastError(context->libxml2_context); - - size_t str_length = strlen(ep->message); - ep->message[str_length - 1] = '\0'; - - if(context->srcsax_error) - context->srcsax_error((const char *)ep->message, ep->code); - - } - - return status; - -} - -/** - * srcsax_parse - * @param context srcSAX context - * @param handler sax callback handlers - * - * Parse the context using the provide sax handlers. - * On error calls the error callback function before returning. - * - * @returns 0 on success -1 on error. - */ -int srcsax_parse_handler(struct srcsax_context * context, struct srcsax_handler * handler) { - - if(context == 0) return -1; - - context->handler = handler; - - return srcsax_parse(context); - -} - -/** - * srcsax_create_parser_context - * @param buffer_input a parser input buffer - * - * Create a ctxt from a parser input buffer. - * Modeled after function in libxml2. - * - * @returns xml parser ctxt - */ -xmlParserCtxtPtr -srcsax_create_parser_context(xmlParserInputBufferPtr buffer_input) { - xmlParserCtxtPtr ctxt; - xmlParserInputPtr input; - xmlParserInputBufferPtr buf; - - ctxt = xmlNewParserCtxt(); - if (ctxt == NULL) - return(NULL); - - xmlCtxtUseOptions(ctxt, XML_PARSE_COMPACT | XML_PARSE_HUGE | XML_PARSE_NODICT); - - buf = buffer_input; - if (buf == NULL) { - xmlFreeParserCtxt(ctxt); - return(NULL); - } - - input = xmlNewInputStream(ctxt); - if (input == NULL) { - xmlFreeParserCtxt(ctxt); - return(NULL); - } - - input->filename = NULL; - input->buf = buf; - _xmlBufResetInput(input->buf->buffer, input); - - inputPush(ctxt, input); - - return(ctxt); -} - -/** - * srcsax_stop_parser - * @param context a srcSAX context - * - * Stop srcSAX parser. - */ -void srcsax_stop_parser(struct srcsax_context * context) { - - context->terminate = 1; - - xmlParserCtxtPtr ctxt = context->libxml2_context; - - ctxt->sax->startDocumentstartDocumentstartDocument = 0; - ctxt->sax->endDocumentendDocumentendDocument = 0; - ctxt->sax->startElementNs = 0; - ctxt->sax->endElementNs = 0; - ctxt->sax->characters = 0; - ctxt->sax->cdataBlockcdataBlockcdataBlock = 0; - ctxt->sax->commentcommentcomment = 0; - ctxt->sax->ignorableWhitespace = 0; - - xmlStopParser(ctxt); - -} - - -/** - * @file srcSAXController.hpp - * - * @copyright Copyright (C) 2013-2014 srcML, LLC. (www.srcML.org) - * - * srcSAX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * srcSAX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef INCLUDED_SRCSAX_CONTROLLER_HPP -#define INCLUDED_SRCSAX_CONTROLLER_HPP - -class srcSAXHandler; -#include <srcsax.h> - -#include <libxml/parser.h> -#include <libxml/parserInternals.h> - -#include <string> - -/** - * SAXError - * - * Data struct to hold contents of an error. - */ -struct SAXError { - - /** error message */ - std::string message; - - /** error code */ - int error_code; - -}; - -/** - * srcSAXController - * - * Provides execution of sax with - * given hooks. - */ -class srcSAXController { - -private : - - // xmlParserCtxt - srcsax_context * context; - - // memory buffer storage - std::string srcml_buffer; - -public : - - /** - * srcSAXController - * @param filename name of a file - * @param encoding the xml encoding - * - * Constructor - */ - srcSAXController(const char * filename, const char * encoding = 0); - - /** - * srcSAXController - * @param srcml_buffer a string buffer - * - * Constructor - */ - srcSAXController(const std::string & srcml_buffer, const char * encoding = 0); - - /** - * srcSAXController - * @param srcml_file a FILE for a srcML document - * - * Constructor - */ - srcSAXController(FILE * srcml_file, const char * encoding = 0); - - /** - * srcSAXController - * @param srcml_fd a file descriptor for a srcML document - * - * Constructor - */ - srcSAXController(int srcml_fd, const char * encoding = 0); - - - /** - * srcSAXController - * @param srcml_context a general context for a srcML document - * @param read_callback a read callback function - * @param close_callback a close callback function - * - * Constructor - */ - srcSAXController(void * srcml_context, int (*read_callback)(void * context, char * buffer, int len), int (*close_callback)(void * context), const char * encoding = 0); - - /** - * srcSAXController - * @param input a parser input buffer - * - * Constructor - */ - srcSAXController(xmlParserInputBufferPtr input); - - /** - * getCtxt - * - * Return the used parser context. - */ - srcsax_context * getContextgetContext(); - - /** - * ~srcSAXController - * - * Destructor - */ - ~srcSAXController(); - - - /** - * enable_startDocument - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables startDocument parsing. - */ - void enable_startDocumentenable_startDocument(bool enable); - - /** - * enable_endDocument - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables endDocument parsing. - */ - void enable_endDocumentenable_endDocument(bool enable); - - /** - * enable_startRoot - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables startRoot parsing. - */ - void enable_startRootenable_startRoot(bool enable); - - /** - * enable_startUnit - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables startUnit parsing. - */ - void enable_startUnitenable_startUnit(bool enable); - - /** - * enable_startElement - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables startElement parsing. - */ - void enable_startElementenable_startElement(bool enable); - - /** - * enable_endRoot - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables endRoot parsing. - */ - void enable_endRootenable_endRoot(bool enable); - - /** - * enable_endUnit - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables endUnit parsing. - */ - void enable_endUnitenable_endUnit(bool enable); - - - /** - * enable_endElement - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables endElement parsing. - */ - void enable_endElementenable_endElement(bool enable); - - /** - * enable_charactersRoot - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables charactersRoot parsing. - */ - void enable_charactersRootenable_charactersRoot(bool enable); - - /** - * enable_charactersUnit - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables charactersUnit parsing. - */ - void enable_charactersUnitenable_charactersUnit(bool enable); - - /** - * enable_metaTag - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables metaTag parsing. - */ - void enable_metaTagenable_metaTag(bool enable); - - /** - * enable_comment - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables comment parsing. - */ - void enable_commentenable_comment(bool enable); - - /** - * enable_cdataBlock - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables cdataBlock parsing. - */ - void enable_cdataBlockenable_cdataBlock(bool enable); - - /** - * enable_processingInstruction - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables processingInstruction parsing. - */ - void enable_processingInstructionenable_processingInstruction(bool enable); - - /** - * enable_function - * @param enable bool indicate enable or disable special function parsing. - * - * Enables or disables special function parsing. - */ - void enable_functionenable_function(bool enable); - - /** - * parse - * @param handler srcMLHandler with hooks for sax parsing - * - * Parse the xml document with the supplied hooks. - */ - void parseparse(srcSAXHandler * handler); - - /** - * stop_parser - * - * Stop parsing. - */ - void stop_parserstop_parser(); - -}; - -#endif - - -/** - * @file cppCallbackAdapter.hpp - * - * @copyright Copyright (C) 2013-2014 srcML, LLC. (www.srcML.org) - * - * srcSAX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * srcSAX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/** - * cppCallbackAdapter - * - * Wrapper around C srcSAX api to provide for C++ interface. - * Simply, forward the callbacks to the provided srcSAXHandler. - */ -class cppCallbackAdapter { - -private: - - /** the srcSAXHandler to forward the callbacks */ - srcSAXHandler * handler; - -public: - - /** - * cppCallbackAdapter - * @param handler a srcSAXHandler whose callbacks will be called. - * - * Constructor. Initialize the handler - */ - cppCallbackAdapter(srcSAXHandler * handler) : handler(handler) {} - - /** - * factory - * - * Factory method to generate the srcsax_handler containin this classes - * callbacks needed to perform to use the C++ wrapper API. - * - * @returns the generated srcsax_handler with the correct callbacks for C API. - */ - /**collaborator */ - static srcsax_handler factory() { - - srcsax_handler handler; - - handler.start_document = start_document; - handler.end_document = end_document; - handler.start_root = start_root; - handler.start_unit = start_unit; - handler.start_element = start_element; - handler.end_root = end_root; - handler.end_unit = end_unit; - handler.end_element = end_element; - handler.characters_root = characters_root; - handler.characters_unit = characters_unit; - handler.meta_tag = meta_tag; - handler.comment = comment; - handler.cdata_block = cdata_block; - handler.processing_instruction = processing_instruction; - - return handler; - - } - - /** - * srcml_element_stack_push - * @param prefix the element to push prefix - * @param localname the elements name - * - * Push the element to the stack. - */ - /**command */ - void srcml_element_stack_pushsrcml_element_stack_push(const char * prefix, const char * localname) { - - std::string srcml_element_string = ""; - if(prefix) { - - srcml_element_string += prefix; - srcml_element_string += ':'; - - } - - srcml_element_string += localname; - - handler->get_stack().push_back(srcml_element_string); - - - } - - /** - * srcml_element_stack_pop - * - * Pop an element from the stack. Testing - * may try to pop with 0 items so simply return. - */ - /**command */ - void srcml_element_stack_popsrcml_element_stack_pop() { - - if(handler->get_stack().size() == 0) return; - - handler->get_stack().pop_back(); - - } - - /** - * start_document - * @param context a srcSAX context - * - * Callback. Forwards C API start_document to C++ API srcSAXHandler startDocument. - */ - /**command collaborator */ - static void start_documentstart_document(struct srcsax_context * context) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->handler->set_encoding(context->encoding); - - cpp_adapter->handler->startDocument(); - - } - - /** - * end_document - * @param context a srcSAX context - * - * Callback. Forwards C API end_document to C++ API srcSAXHandler endDocument. - */ - /**command collaborator */ - static void end_documentend_document(struct srcsax_context * context) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->handler->get_stack().clear(); - - cpp_adapter->handler->endDocument(); - - - } - - /** - * start_root - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * Callback. Forwards C API start_root to C++ API srcSAXHandler startRoot. - */ - /**command collaborator */ - static void start_rootstart_root(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->handler->set_is_archive(context->is_archive); - - if(context->is_archive) - cpp_adapter->srcml_element_stack_push((const char *)prefix, (const char *)localname); - - cpp_adapter->handler->startRoot(localname, prefix, URI, num_namespaces, namespaces, num_attributes, attributes); - - } - - /** - * start_unit - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * Signature srcSAX handler function for start of an unit. - * Callback. Forwards C API start_unit to C++ API srcSAXHandler startUnit. - */ - /**command collaborator */ - static void start_unitstart_unit(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->srcml_element_stack_push((const char *)prefix, (const char *)localname); - - cpp_adapter->handler->startUnit(localname, prefix, URI, num_namespaces, namespaces, num_attributes, attributes); - - - } -#if 0 - /** - * start_function - * @param context a srcSAX context - * @param name the function's name - * @param return_type the function return type - * @param parameter_list a list of the function parameters in struct containing (declaration.type/declaration.name) - * @param is_decl indicates if the call is a function declaration (true) or definition (false) - * - * Callback. Forwards C API start_function to C++ API srcSAXHandler startFunction. - */ - static void start_function(struct srcsax_context * context, const char * name, const char * return_type, const struct declaration * parameter_list, _Bool is_decl) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - - } -#endif - - /** - * start_element - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * Signature for srcSAX handler function for start of an element. - * Callback. Forwards C API start_element to C++ API srcSAXHandler startElement. - */ - /**command collaborator */ - static void start_elementstart_element(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->srcml_element_stack_push((const char *)prefix, (const char *)localname); - - cpp_adapter->handler->startElement(localname, prefix, URI, num_namespaces, namespaces, num_attributes, attributes); - - - } - - /** - * end_root - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * Callback. Forwards C API end_root to C++ API srcSAXHandler endRoot. - */ - /**command collaborator */ - static void end_rootend_root(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->srcml_element_stack_pop(); - - cpp_adapter->handler->endRoot(localname, prefix, URI); - - } - - /** - * end_unit - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * Callback. Forwards C API end_unit to C++ API srcSAXHandler endUnit. - */ - /**command collaborator */ - static void end_unitend_unit(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->srcml_element_stack_pop(); - - cpp_adapter->handler->endUnit(localname, prefix, URI); - - } -#if 0 - /** - * end_function - * @param context a srcSAX context - * - * Callback. Forwards C API end_function to C++ API srcSAXHandler endFunction. - */ - static void end_function(struct srcsax_context * context) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - - } -#endif - /** - * end_element - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * Callback. Forwards C API end_element to C++ API srcSAXHandler endElement. - */ - /**command collaborator */ - static void end_elementend_element(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->srcml_element_stack_pop(); - - cpp_adapter->handler->endElement(localname, prefix, URI); - - } - - /** - * characters_root - * @param context a srcSAX context - * @param ch the characers - * @param len number of characters - * - * Callback. Forwards C API characters_root to C++ API srcSAXHandler charactersRoot. - */ - /**command collaborator */ - static void characters_rootcharacters_root(struct srcsax_context * context, const char * ch, int len) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->handler->charactersRoot(ch, len); - - - } - - /** - * characters_unit - * @param context a srcSAX context - * @param ch the characers - * @param len number of characters - * - * Callback. Forwards C API characters_unit to C++ API srcSAXHandler charactersUnit. - */ - /**command collaborator */ - static void characters_unitcharacters_unit(struct srcsax_context * context, const char * ch, int len) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->handler->charactersUnit(ch, len); - - } - - /** - * meta_tag - * @param context a srcSAX context - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * Callback. Forwards C API meta_tag to C++ API srcSAXHandler metaTag. - */ - /**command collaborator */ - static void meta_tagmeta_tag(struct srcsax_context * context, const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->srcml_element_stack_push((const char *)prefix, (const char *)localname); - - cpp_adapter->handler->metaTag(localname, prefix, URI, num_namespaces, namespaces, num_attributes, attributes); - - cpp_adapter->srcml_element_stack_pop(); - - } - - /** - * comment - * @param context a srcSAX context - * @param value the comment content - * - * Callback. Forwards C API comment to C++ API srcSAXHandler comment. - */ - /**command collaborator */ - static void commentcomment(struct srcsax_context * context, const char * value) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->handler->comment(value); - - } - - /** - * cdata_block - * @param context a srcSAX context - * @param value the pcdata content - * @param len the block length - * - * Callback. Forwards C API cdata_block to C++ API srcSAXHandler cdata_block. - */ - /**command collaborator */ - static void cdata_blockcdata_block(struct srcsax_context * context, const char * value, int len) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->handler->cdataBlock(value, len); - - } - - /** - * processing_instruction - * @param context a srcSAX context - * @param target the processing instruction target. - * @param data the processing instruction data. - * - * Callback. Forwards C API processing_instruction to C++ API srcSAXHandler processingInstruction. - */ - /**command collaborator */ - static void processing_instructionprocessing_instruction(struct srcsax_context * context, const char * target, const char * data) { - - cppCallbackAdapter * cpp_adapter = (cppCallbackAdapter *)context->data; - - cpp_adapter->handler->processingInstruction(target, data); - - } - -}; - - -/** - * @file print_callbacks.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - /* - - Print each callback as it is called (callback trace). - - Input: input_file.xml - Useage: print_callbacks input_file.xml - - */ - -#include "print_callbacks_handler.hpp" -#include <srcSAXController.hpp> - -#include <iostream> - -/** - * main - * @param argc number of arguments - * @param argv the provided arguments (array of C strings) - * - * Invoke srcSAX handler to print out each callback as it is called. - */ -int main(int argc, char * argv[]) { - - if(argc < 2) { - - std::cerr << "Useage: print_callbacks input_file.xml\n"; - exit(1); - - } - - srcSAXController control(argv[1]); - //control.enable_function(true); - print_callbacks_handler handler; - control.parseparseparse(&handlerparse); - - return 0; -} - - -/** - * @file srcSAXController.cpp - * - * @copyright Copyright (C) 2013-2014 srcML, LLC. (www.srcML.org) - * - * srcSAX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * srcSAX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <srcSAXController.hpp> -#include <srcSAXHandler.hpp> -#include <cppCallbackAdapter.hpp> - -#include <sax2_srcsax_handler.hpp> - -#include <string> - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" - -/** - * srcSAXController - * @param filename name of a file - * - * Constructor - */ -srcSAXController::srcSAXController(const char * filename, const char * encoding) { - - context = srcsax_create_context_filename(filename, encoding); - - if(context == NULL) throw std::string("File does not exist"); - - -} - -/** - * srcSAXController - * @param srcml_buffer a string buffer - * - * Constructor - */ -srcSAXController::srcSAXController(const std::string & srcml_buffer, const char * encoding) : srcml_buffer(srcml_buffer) { - - context = srcsax_create_context_memory(this->srcml_buffer.c_str(), this->srcml_buffer.size(), encoding); - - if(context == NULL) throw std::string("File does not exist"); - -} - -/** - * srcSAXController - * @param srcml_file a FILE for a srcML document - * - * Constructor - */ -srcSAXController::srcSAXController(FILE * srcml_file, const char * encoding) { - - context = srcsax_create_context_FILE(srcml_file, encoding); - - if(context == NULL) throw std::string("File does not exist"); - -} - -/** - * srcSAXController - * @param srcml_fd a file descriptor for a srcML document - * - * Constructor - */ -srcSAXController::srcSAXController(int srcml_fd, const char * encoding) { - - context = srcsax_create_context_fd(srcml_fd, encoding); - - if(context == NULL) throw std::string("File does not exist"); - -} - -/** - * srcSAXController - * @param srcml_context a general context for a srcML document - * @param read_callback a read callback function - * @param close_callback a close callback function - * - * Constructor - */ -srcSAXController::srcSAXController(void * srcml_context, int (*read_callback)(void * context, char * buffer, int len), int (*close_callback)(void * context), const char * encoding) { - - context = srcsax_create_context_io(srcml_context, read_callback, close_callback, encoding); - - if(context == NULL) throw std::string("File does not exist"); - -} - - -/** - * srcSAXController - * @param input a parser input buffer - * - * Constructor - */ -srcSAXController::srcSAXController(xmlParserInputBufferPtr input) { - - context = srcsax_create_context_parser_input_buffer(input); - - if(context == NULL) throw std::string("File does not exist"); - -} - -/** - * ~srcSAXController - * - * Constructor - */ -srcSAXController::~srcSAXController() { - - if(context) srcsax_free_context(context); - -} - -/** - * getCtxt - * - * Return the used parser context. - */ -/**nonconstget collaborator */ -srcsax_context * srcSAXController::getContext() { - - return context; - -} - -/** - * enable_startDocument - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables startDocument parsing. - */ -/**unclassified */ -void srcSAXController::enable_startDocument(bool enable) { - - if(enable) context->handler->start_document = cppCallbackAdapter::start_document; - else context->handler->start_document = 0; - -} - -/** - * enable_endDocument - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables endDocument parsing. - */ -/**unclassified */ -void srcSAXController::enable_endDocument(bool enable) { - - if(enable) context->handler->end_document = cppCallbackAdapter::end_document; - else context->handler->end_document = 0; - -} - -/** - * enable_startRoot - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables startRoot parsing. - */ -/**unclassified */ -void srcSAXController::enable_startRoot(bool enable) { - - if(enable) context->handler->start_root = cppCallbackAdapter::start_root; - else context->handler->start_root = 0; - -} - -/** - * enable_startUnit - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables startUnit parsing. - */ -/**unclassified */ -void srcSAXController::enable_startUnit(bool enable) { - - if(enable) context->handler->start_unit = cppCallbackAdapter::start_unit; - else context->handler->start_unit = 0; - -} - -/** - * enable_startElement - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables startElement parsing. - */ -/**unclassified */ -void srcSAXController::enable_startElement(bool enable) { - - if(enable) context->handler->start_element = cppCallbackAdapter::start_element; - else context->handler->start_element = 0; - -} - -/** - * enable_endRoot - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables endRoot parsing. - */ -/**unclassified */ -void srcSAXController::enable_endRoot(bool enable) { - - if(enable) context->handler->end_root = cppCallbackAdapter::end_root; - else context->handler->end_root = 0; - -} - -/** - * enable_endUnit - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables endUnit parsing. - */ -/**unclassified */ -void srcSAXController::enable_endUnit(bool enable) { - - if(enable) context->handler->end_unit = cppCallbackAdapter::end_unit; - else context->handler->end_unit = 0; - -} - -/** - * enable_endElement - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables endElement parsing. - */ -/**unclassified */ -void srcSAXController::enable_endElement(bool enable) { - - if(enable) context->handler->end_element = cppCallbackAdapter::end_element; - else context->handler->end_element = 0; - -} - -/** - * enable_charactersRoot - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables charactersRoot parsing. - */ -/**unclassified */ -void srcSAXController::enable_charactersRoot(bool enable) { - - if(enable) { - - context->handler->characters_root = cppCallbackAdapter::characters_root; - - } else { - - context->handler->characters_root = 0; - - } - -} - -/** - * enable_charactersUnit - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables charactersUnit parsing. - */ -/**unclassified */ -void srcSAXController::enable_charactersUnit(bool enable) { - - if(enable) { - - context->handler->characters_unit = cppCallbackAdapter::characters_unit; - - } else { - - context->handler->characters_unit = 0; - - } - -} - -/** - * enable_metaTag - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables metaTag parsing. - */ -/**unclassified */ -void srcSAXController::enable_metaTag(bool enable) { - - if(enable) { - - context->handler->meta_tag = cppCallbackAdapter::meta_tag; - - } else { - - context->handler->meta_tag = 0; - - } - -} - -/** - * enable_comment - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables comment parsing. - */ -/**unclassified */ -void srcSAXController::enable_comment(bool enable) { - - if(enable) context->handler->comment = cppCallbackAdapter::comment; - else context->handler->comment = 0; - -} - -/** - * enable_cdataBlock - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables cdataBlock parsing. - */ -/**unclassified */ -void srcSAXController::enable_cdataBlock(bool enable) { - - if(enable) context->handler->cdata_block = cppCallbackAdapter::cdata_block; - else context->handler->cdata_block = 0; - -} - -/** - * enable_processingInstruction - * @param enable bool indicate enable or disable SAX parsing. - * - * Enables or disables processingInstruction parsing. - */ -/**unclassified */ -void srcSAXController::enable_processingInstruction(bool enable) { - - if(enable) context->handler->processing_instruction = cppCallbackAdapter::processing_instruction; - else context->handler->processing_instruction = 0; - -} - -/** -* enable_function -* @param enable bool indicate enable or disable special function parsing. -* -* Enables or disables special function parsing. -*/ -/**unclassified */ -void srcSAXController::enable_function(bool enable) { - - //sax2_handler.parse_function = enable; - -} - -/** - * parse - * @param handler srcMLHandler with hooks for sax parsing - * - * Parse the xml document with the supplied hooks. - */ -/**command collaborator */ -void srcSAXController::parse(srcSAXHandler * handler) { - - handler->set_controllerset_controllerset_controller(thisset_controller); - - cppCallbackAdapter adapter(handler); - context->data = &adapter; - srcsax_handler sax_handler = cppCallbackAdapter::factoryfactoryfactory(); - context->handler = &sax_handler; - - int status = srcsax_parse(context); - - context->data = 0; - - if(status != 0) { - - xmlErrorPtr ep = xmlCtxtGetLastError(context->libxml2_context); - - size_t str_length = strlen(ep->message); - ep->message[str_length - 1] = '\0'; - SAXError error = { std::string((const char *)ep->message), ep->code }; - - throw error; - } - -} - - - -/** - * @file identity_copy.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - /* - - Copy the srcML document. - - Input: input_file.xml - Input: output_file.xml - Useage: identity_copy input_file.xml output_file.xml - - */ - -#include "identity_copy_handler.hpp" -#include <srcSAXController.hpp> - -#include <iostream> - -/** - * main - * @param argc number of arguments - * @param argv the provided arguments (array of C strings) - * - * Invoke srcSAX handler to copy the supplied srcML document and into the given - * output file. - */ - int main(int argc, char * argv[]) { - - if(argc < 3) { - - std::cerr << "Useage: identify_copy input_file.xml output_file.xml\n"; - exit(1); - - } - - srcSAXController control(argv[1]); - identity_copy_handler handler(argv[2]); - control.parseparseparse(&handlerparse); - - return 0; -} - - -/** - * @file srcSAXHandler.hpp - * - * @copyright Copyright (C) 2013-2014 srcML, LLC. (www.srcML.org) - * - * srcSAX is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * srcSAX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef INCLUDED_SRCSAX_HANDLER_HPP -#define INCLUDED_SRCSAX_HANDLER_HPP - -#include <srcSAXController.hpp> - -#include <libxml/parser.h> - -#include <vector> - -/** - * srcSAXHandler - * - * Base class that provides hooks for SAX processing. - */ -class srcSAXHandler { - -private : - - /** Controller for parser */ - srcSAXController * controller; - -protected: - - /** is the document an archive */ - bool is_archive; - - /** the current unit count */ - int unit_count; - - /** open srcML element stack */ - std::vector<std::string> srcml_element_stack; - - /** the xml documents encoding */ - const char * encoding; - -public : - - /** - * srcSAXHandler - * - * Default constructor default values to everything - */ - srcSAXHandler() : controller(0), is_archive(false), unit_count(0), encoding(0) {} - - /** - * set_controller - * @param controller pointer to control class - * - * Used by srcSAXController to provide access to self - * for such things as disabeling sax parsing. - */ - /**collaborational-command collaborator */ - void set_controller(srcSAXController * controller) { - - this->controller = controller; - - } - - /** - * increment_unit_count - * - * Internally used to increment the count in SAX2srcSAXHandler. - */ - /**unclassified */ - void increment_unit_countincrement_unit_count() { - - ++unit_count; - - } - - /** - * get_stack - * - * Used internally to update the stack. - */ - /**nonconstget */ - std::vector<std::string> & get_stack() { - - return srcml_element_stack; - - } - - /** - * get_controller - * - * Get the control handler. - */ - /**collaborator */ - srcSAXController & get_controllerget_controller() { - - return *controller; - - } - - /** - * stop_parser - * - * Stop the srcML parser. - */ - /**command */ - void stop_parserstop_parser() { - - srcsax_stop_parser(controller->getContext()); - - } - - /** - * set_encoding - * @param encoding set the encoding - * - * Used by SAX2srcSAXHandler when determined - * encoding. Set the input encoding if any. - */ - /**collaborational-command */ - void set_encodingset_encoding(const char * encoding) { - - this->encoding = encoding; - } - - /** - * set_is_archive - * @param is_archive is the srcML document an archive - * - * Used by SAX2srcSAXHandler when determined - * if an archive. Sets if srcML document is an archive. - */ - /**collaborational-command */ - void set_is_archiveset_is_archive(bool is_archive) { - - this->is_archive = is_archive; - - } - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" - - /** - * startDocument - * - * SAX handler function for start of document. - * Overide for desired behaviour. - */ - /**unclassified */ - virtual void startDocumentstartDocument() {} - - /** - * endDocument - * - * SAX handler function for end of document. - * Overide for desired behaviour. - */ - /**unclassified */ - virtual void endDocumentendDocument() {} - - /** - * startRoot - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of the root element. - * Overide for desired behaviour. - */ - /**collaborator */ - virtual void startRootstartRoot(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) {} - - /** - * startUnit - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of an unit. - * Overide for desired behaviour. - */ - /**collaborator */ - virtual void startUnitstartUnit(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) {} -#if 0 - /** - * startFunction - * @param name the function's name - * @param return_type the function return type - * @param parameter_list a list of the function parameters in struct containing (declaration.type/declaration.name) - * @param is_decl indicates if the call is a function declaration (true) or definition (false) - * - * SAX handler function for start of function with prototype. - * Accessing references after callback termination is undefined. - * - * Overide for desired behaviour. - */ - virtual void startFunction(const std::string & name, const std::string & return_type, const std::vector<declaration> & parameter_list, bool is_decl) {} -#endif - /** - * startElement - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of an element. - * Overide for desired behaviour. - */ - /**collaborator */ - virtual void startElementstartElement(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) {} - - /** - * endRoot - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of the root element. - * Overide for desired behaviour. - */ - /**unclassified */ - virtual void endRootendRoot(const char * localname, const char * prefix, const char * URI) {} - - /** - * endUnit - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of an unit. - * Overide for desired behaviour. - */ - /**unclassified */ - virtual void endUnitendUnit(const char * localname, const char * prefix, const char * URI) {} -#if 0 - /** - * endFunction - * - * SAX handler function for end of a function. - * Overide for desired behaviour. - */ - virtual void endFunction() {} -#endif - /** - * endElement - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of an element. - * Overide for desired behaviour. - */ - /**unclassified */ - virtual void endElementendElement(const char * localname, const char * prefix, const char * URI) {} - - /** - * charactersRoot - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling at the root level. - * Overide for desired behaviour. - */ - /**unclassified */ - virtual void charactersRootcharactersRoot(const char * ch, int len) {} - - /** - * charactersUnit - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling within a unit. - * Overide for desired behaviour. - */ - /**unclassified */ - virtual void charactersUnitcharactersUnit(const char * ch, int len) {} - - /** - * metaTag - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes\ - * - * SAX handler function for a meta tags. - * Overide for desired behaviour. - */ - /**collaborator */ - virtual void metaTagmetaTag(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) {} - - /** - * comment - * @param value the comment content - * - * A comment has been parsed. - * Overide for desired behaviour. - */ - /**unclassified */ - virtual void commentcomment(const char * value) {} - - /** - * cdataBlock - * @param value the pcdata content - * @param len the block length - * - * Called when a pcdata block has been parsed. - * Overide for desired behaviour. - */ - /**unclassified */ - virtual void cdataBlockcdataBlock(const char * value, int len) {} - - /** - * processingInstruction - * @param target the processing instruction target. - * @param data the processing instruction data. - * - * Called when a processing instruction has been parsed. - * Overide for desired behaviour. - */ - /**unclassified */ - virtual void processingInstructionprocessingInstruction(const char * target, const char * data) {} - -#pragma GCC diagnostic pop - -}; - -#endif - - -/** - * @file element_count.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - /* - - Count each the occurrences of each srcML element. - - Input: input_file.xml - Useage: element_count input_file.xml - - */ - -#include "element_count_handler.hpp" -#include <srcSAXController.hpp> - -#include <map> -#include <iostream> - -/** - * main - * @param argc number of arguments - * @param argv the provided arguments (array of C strings) - * - * Invoke srcSAX handler to count element occurences and print out the resulting element counts. - */ -int main(int argc, char * argv[]) { - - if(argc < 2) { - - std::cerr << "Useage: element_count input_file.xml\n"; - exit(1); - - } - - srcSAXController control(argv[1]); - element_count_handler handler; - control.parseparseparse(&handlerparse); - - for(std::map<std::string, unsigned long long>::const_iterator citr = handler.get_countsget_counts().begin(); citr != handler.get_countsget_counts().end(); ++citr) { - - std::cout << citr->first << ": " << citr->second << '\n'; - - } - - return 0; -} - - -/** - * @file print_callbacks_handler.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef INCLUDED_PRINT_CALLBACKS_HANDLER_HPP -#define INCLUDED_PRINT_CALLBACKS_HANDLER_HPP - -#include <srcSAXHandler.hpp> - -class print_callbacks_handler : public srcSAXHandler { - -public : - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" - - /** - * startDocument - * - * SAX handler function for start of document. - * Print when callback is called. - * Overide for desired behaviour. - */ - /**command */ - virtual void startDocument() { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - /** - * endDocument - * - * SAX handler function for end of document. - * Print when callback is called. - * Overide for desired behaviour. - */ - /**command */ - virtual void endDocumentendDocument() { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - /** - * startRoot - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of the root element. - * Print when callback is called. - * Overide for desired behaviour. - */ - /**command collaborator */ - virtual void startRootstartRoot(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - - /** - * startUnit - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of an unit. - * Print when callback is called. - * Overide for desired behaviour. - */ - /**command collaborator */ - virtual void startUnitstartUnit(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - /** - * startFunction - * @param name the function's name - * @param return_type the function return type - * @param parameter_list a list of the function parameters in struct containing (declaration.type/declaration.name) - * @param is_decl indicates if the call is a function declaration (true) or definition (false) - * - * SAX handler function for start of function with prototype. - * Accessing references after callback termination is undefined. - * Print when callback is called. - * - * Overide for desired behaviour. - */ - /* - virtual void startFunction(const std::string & name, const std::string & return_type, const std::vector<declaration> & parameter_list, bool is_decl) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - */ - - /** - * startElement - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of an element. - * Print when callback is called. - * - * Overide for desired behaviour. - */ - /**command collaborator */ - virtual void startElementstartElement(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - /** - * endRoot - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of the root element. - * Print when callback is called. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void endRootendRoot(const char * localname, const char * prefix, const char * URI) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - /** - * endUnit - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of an unit. - * Print when callback is called. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void endUnitendUnit(const char * localname, const char * prefix, const char * URI) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - /** - * endFunction - * - * SAX handler function for end of a function. - * Print when callback is called. - * - * Overide for desired behaviour. - */ - /* - virtual void endFunction() { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - */ - - /** - * endElement - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of an element. - * Print when callback is called. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void endElementendElement(const char * localname, const char * prefix, const char * URI) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - /** - * charactersRoot - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling at the root level. - * Print when callback is called. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void charactersRootcharactersRoot(const char * ch, int len) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - /** - * charactersUnit - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling within a unit. - * Print when callback is called. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void charactersUnitcharactersUnit(const char * ch, int len) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - /** - * metaTag - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * @param meta_tags vector of elements composed of metage tags defined after root tag - * - * SAX handler function for meta tags. - * Print when callback is called. - * Overide for desired behaviour. - */ - /**command collaborator */ - virtual void metaTagmetaTag(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - /** - * comment - * @param value the comment content - * - * A comment has been parsed. - * Print when callback is called. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void commentcomment(const char * value) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - /** - * cdataBlock - * @param value the pcdata content - * @param len the block length - * - * Called when a pcdata block has been parsed. - * Print when callback is called. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void cdataBlockcdataBlock(const char * value, int len) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - - /** - * processingInstruction - * @param target the processing instruction target. - * @param data the processing instruction data. - * - * Called when a processing instruction has been parsed. - * Print when callback is called. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void processingInstructionprocessingInstruction(const char * target, const char * data) { - - fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); - - } - -#pragma GCC diagnostic pop - -}; - -#endif - - -/** - * @file element_count_handler.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef INCLUDED_ELEMENT_COUNT_HANDLER_HPP -#define INCLUDED_ELEMENT_COUNT_HANDLER_HPP - -#include <srcSAXHandler.hpp> -#include <map> - -/** - * element_count_handler - * - * Base class that provides hooks for SAX processing. - */ -class element_count_handler : public srcSAXHandler { - -private : - - /** map to count srcML elements */ - std::map<std::string, unsigned long long> element_counts; - -public : - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" - - /** - * get_counts - * - * Accessor method to get the element counts. - * - * @returns the element count map. - */ - /**get */ - const std::map<std::string, unsigned long long> & get_counts() const { - - return element_counts; - - } - - /** - * update_count - * @param prefix the element's prefix - * @param localname the element name - * - * Helper function to update the count of an element or add it if necessary. - * Need the full name (prefix + localname) of elemement to disambiguate between - * elements with the same name, but different prefix/namespaces (e.g. cpp:if, if). - * A more general find approach is used instead of relying on access using the - * operator[] to default non-existant items to 0. - */ - /**command */ - void update_countupdate_count(const char * prefix, const char * localname) { - - std::string element = ""; - if(prefix) { - - element += (const char *)prefix; - element += ":"; - - } - element += (const char *)localname; - - /* Note: in map could just use operator[], however, this a bit more general */ - std::map<std::string, unsigned long long>::iterator itr = element_counts.find(element); - if(itr == element_counts.end()) { - - element_counts.insert(std::pair<std::string, unsigned long long>(element, 1)); - - } else { - - ++itr->second; - - } - - } - - /* - virtual void startDocument() {} - virtual void endDocument() {} - */ - - /** - * startRoot - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of the root element. - * Counts the root unit (if an archive, to avoid double count with startUnit). - * Overide for desired behaviour. - */ - /**command collaborator */ - virtual void startRoot(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) { - - if(is_archive) - update_count(prefix, localname); - - } - - /** - * startUnit - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of an unit. - * Counts each unit tag (= filecount non-archive, = filecount + 1 if archive). - * Overide for desired behaviour. - */ - /**command collaborator stateless */ - virtual void startUnitstartUnit(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) { - - update_count(prefix, localname); - - } - - /** - * startElement - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param num_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of an element. - * Count each element. - * Overide for desired behaviour. - */ - /**command collaborator stateless */ - virtual void startElementstartElement(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) { - - update_count(prefix, localname); - - } - - /* - - // end elements may need to be used if you want to collect only on per file basis or some other granularity. - virtual void endRoot(const char * localname, const char * prefix, const char * URI) {} - virtual void endUnit(const char * localname, const char * prefix, const char * URI) {} - virtual void endElement(const char * localname, const char * prefix, const char * URI) {} - - // Contains information such as stuff used for parsing. So, probably do not need to count. - virtual void metaTag(const char* localname, const char* prefix, const char* URI, int num_namespaces, const char** namespaces, int num_attributes, const char** attributes) {} - - // Not typically in srcML documents - virtual void comment(const char * value) {} - virtual void cdataBlock(const char * value, int len) {} - virtual void processingInstruction(const char * target, const char * data) {} - */ - -#pragma GCC diagnostic pop - -}; - -#endif - - -/** - * @file identity_copy_handler.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef INCLUDED_IDENTITY_COPY_HANDLER_HPP -#define INCLUDED_IDENTITY_COPY_HANDLER_HPP - -#include <srcSAXHandler.hpp> -#include <iostream> -#include <string> - -#include <libxml/xmlwriter.h> - -/** - * identity_copy_handler - * - * Base class that provides hooks for SAX processing. - */ -class identity_copy_handler : public srcSAXHandler { - -private : - - xmlTextWriterPtr writer; - std::string content; - -public : - - /** - * identity_copy_handler - * - * Constructor. Open xmlwriter. - */ - identity_copy_handler(std::string output_filename) : writer(0) { - - if((writer = xmlNewTextWriterFilename(output_filename.c_str(), 0)) == 0) { - - std::cerr << "Problems opening output file: " << output_filename << '\n'; - exit(1); - - } - - } - - /** - * ~identity_copy_handler - * - * Destructor. Free writer resource. - */ - ~identity_copy_handler() { - - if(writer) - xmlFreeTextWriter(writer); - - } - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" - - /** - * startDocument - * - * SAX handler function for start of document. - * Write start of xml document. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void startDocumentstartDocument() { - - xmlTextWriterStartDocument(writer, "1.0", "UTF-8", "yes"); - - } - - /** - * endDocument - * - * SAX handler function for end of document. - * Write the end of xml document. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void endDocumentendDocument() { - - xmlTextWriterEndDocument(writer); - - } - - /** - * write_start_tag - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of the root element. - * Write out a start tag. - * - * Overide for desired behaviour. - */ - /**command collaborator */ - void write_start_tagwrite_start_tag(const char* localname, const char* prefix, const char* URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) { - - xmlTextWriterStartElementNS(writer, (const xmlChar *)prefix, (const xmlChar *)localname, 0); - - for(int pos = 0; pos < num_namespaces; ++pos) { - - std::string name = "xmlns"; - if(namespaces[pos].prefix) { - name += ":"; - - name += (const char *)namespaces[pos].prefix; - - } - - xmlTextWriterWriteAttribute(writer, (const xmlChar *)name.c_str(), (const xmlChar *)namespaces[pos].uri); - - } - - for(int pos = 0; pos < num_attributes; ++pos) { - - xmlTextWriterWriteAttributeNS(writer, (const xmlChar *)attributes[pos].prefix, (const xmlChar *)attributes[pos].localname, - (const xmlChar *)attributes[pos].uri, (const xmlChar *)attributes[pos].value); - - } - - } - - /** - * write_content - * @param text_content - * - * Write out the provided text content, escaping everything but ". - */ - /**command */ - void write_contentwrite_content(std::string & text_content) { - - if(text_content != "") { - - /* - Normal output of text is for the most part - identical to what libxml2 provides. However, - srcML does not escape " while libxml2 does escape - quotations. - */ - int ret = 0; - char * text = (char *)text_content.c_str(); - for(char * pos = text; *pos; ++pos) { - - if(*pos != '"') continue; - - *pos = 0; - ret = xmlTextWriterWriteString(writer, (const xmlChar *)text); - //if(ret == -1) return false; - - *pos = '\"'; - xmlTextWriterWriteRaw(writer, (const xmlChar *)"\""); - //if(ret == -1) return false; - - text = pos + 1; - - } - - ret = xmlTextWriterWriteString(writer, (const xmlChar *)text); - - text_content = ""; - - } - - } - - /** - * startRoot - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of the root element. - * Write out the root start tag (unless non-archive, startUnit will handle). - * - * Overide for desired behaviour. - */ - /**command collaborator */ - virtual void startRootstartRoot(const char* localname, const char* prefix, const char* URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int nb_attributes, - const struct srcsax_attribute * attributes) { - - if(is_archive) - write_start_tag(localname, prefix, URI, num_namespaces, namespaces, nb_attributes, attributes); - - } - - /** - * startUnit - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of an unit. - * Write out any saved text, then write out the unit tag. - * - * Overide for desired behaviour. - */ - /**command collaborator */ - virtual void startUnitstartUnit(const char* localname, const char* prefix, const char* URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int nb_attributes, - const struct srcsax_attribute * attributes) { - - // write out buffered root level characters - write_content(content); - - write_start_tag(localname, prefix, URI, num_namespaces, namespaces, nb_attributes, attributes); - - } - - /** - * startElement - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for start of an element. - * Write out any saved text, then write out the elementtag. - * - * Overide for desired behaviour. - */ - /**command collaborator */ - virtual void startElementstartElement(const char* localname, const char* prefix, const char* URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int nb_attributes, - const struct srcsax_attribute * attributes) { - - // write out buffered characters - write_content(content); - - write_start_tag(localname, prefix, URI, num_namespaces, namespaces, nb_attributes, attributes); - - } - - /** - * endRoot - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of the root element. - * Write out any saved content, then end the root tag. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void endRootendRoot(const char* localname, const char* prefix, const char* URI) { - - // write out buffered root level characters - if(is_archive) { - - write_content(content); - - xmlTextWriterEndElement(writer); - - } - - } - - /** - * endUnit - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of an unit. - * Write out any saved up content, then write out ending unit tag. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void endUnitendUnit(const char* localname, const char* prefix, const char* URI) { - - // write out any buffered characters - write_content(content); - - xmlTextWriterEndElement(writer); - - } - - /** - * endElement - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * - * SAX handler function for end of an element. - * Write out any saved content, then write out ending element tag. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void endElementendElement(const char* localname, const char* prefix, const char* URI) { - - // write out any buffered characters - write_content(content); - - xmlTextWriterEndElement(writer); - - } - - /** - * charactersRoot - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling at the root level. - * Collect/write root level charactes. - * - * Characters may be called multiple times in succession - * in some cases the text may need to be gathered all at once - * before output. Both methods are shown here although the delayed - * output is used. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void charactersRootcharactersRoot(const char* ch, int len) { - - - //std::string content = ""; - content.append((const char *)ch, len); - //write_content(content); - - } - - /** - * charactersUnit - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling within a unit. - * Collect/write unit level charactes. - * - * Characters may be called multiple times in succession - * in some cases the text may need to be gathered all at once - * before output. Both methods are shown here although the delayed - * output is used. - * - * Overide for desired behaviour. - */ - /**command */ - virtual void charactersUnitcharactersUnit(const char* ch, int len) { - - /* - Characters may be called multiple times in succession - in some cases the text may need to be gathered all at once - before output. Both methods are shown here although the delayed - output is used. - */ - - //std::string content = ""; - content.append((const char *)ch, len); - //write_content(content); - - } - - /** - * metaTag - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param num_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param attributes list of attributes - * - * SAX handler function for meta tag. - * Write out the meta tags. - * - * Overide for desired behaviour. - */ - /**command collaborator */ - virtual void metaTagmetaTag(const char* localname, const char* prefix, const char* URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int nb_attributes, - const struct srcsax_attribute * attributes) { - - // write out any buffered characters - write_content(content); - - write_start_tag(localname, prefix, URI, num_namespaces, namespaces, nb_attributes, attributes); - xmlTextWriterEndElement(writer); - - } - - /* - // Not typically in srcML documents - virtual void comment(const char* value) {} - virtual void cdataBlock(const char* value, int len) {} - virtual void processingInstruction(const char* target, const char* data) {} - */ - -#pragma GCC diagnostic pop - -}; - -#endif - - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <exception> -#include <SNLPolicy.hpp> -#include <stack> -class NLContextPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - public: - struct NLContextData{ - NLContextData(){} - /**command */ - void clear(){ - category.clear(); - identifiername.clear(); - } - std::string category; - std::string identifiername; - }; - NLContextData data; - ~NLContextPolicy(){} - NLContextPolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners ){ - sourcenlpolicy.AddListener(this); - InitializeEventHandlers(); - } - /**command collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - sourcenlpdata = policy->Data<SourceNLPolicy::SourceNLData>(); - std::string top; - if(!context.empty()){ - top = context.top(); - } - std::cerr<<"Output: "<<sourcenlpdata->identifiername<<" "<<sourcenlpdata->category<<" "<<top<<std::endl; - //datatotest.push_back(SourceNLData); - } - protected: - /**voidaccessor */ - void * DataInner() const override { - return new NLContextData(data); - } - private: - SourceNLPolicy sourcenlpolicy; - SourceNLPolicy::SourceNLData* sourcenlpdata; - std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; - std::stack<std::string> context; - /**command collaborator */ - void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; - openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - ctx.dispatcher->AddListener(&sourcenlpolicy); - }; - openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { - std::cerr<<"seen while"<<std::endl; - context.push("while"); - }; - openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { - std::cerr<<"seen for"<<std::endl; - context.push("for"); - }; - openEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx) { - std::cerr<<"seen if"<<std::endl; - context.push("if"); - }; - /* - openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { - context.push("else if"); - }; - openEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx) { - context.push("else"); - };*/ - closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx){ - ctx.dispatcher->RemoveListener(&sourcenlpolicy); - data.clear(); - }; - closeEventMap[ParserState::whilestmt] = [this](srcSAXEventContext& ctx){ - context.pop(); - }; - closeEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx){ - context.pop(); - }; - closeEventMap[ParserState::ifstmt] = [this](srcSAXEventContext& ctx){ - context.pop(); - }; - - } -}; - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <exception> - -class DeclTypePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - public: - struct DeclTypeData{ - DeclTypeData(): linenumber{0}, isConst{false}, isReference{false}, isPointer{false}, isStatic{false} {} - /**command */ - void clear(){ - nameoftype.clear(); - nameofidentifier.clear(); - namespaces.clear(); - linenumber = -1; - isConst = false; - isReference = false; - isPointer = false; - isStatic = false; - } - std::string nameoftype; - std::string nameofidentifier; - std::vector<std::string> namespaces; - int linenumber; - bool isConst; - bool isReference; - bool isPointer; - bool isStatic; - }; - DeclTypeData data; - ~DeclTypePolicy(){} - DeclTypePolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners ){ - InitializeEventHandlers(); - } - /**collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return new DeclTypeData(data); - } - private: - std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; - /**command collaborator */ - void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; - openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::type, ParserState::declstmt}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - data.namespaces.push_back(ctx.currentToken); - } - }; - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx){ - if(ctx.IsOpen(ParserState::declstmt)){ - if(currentModifier == "*"){ - data.isPointer = true; - } - if(currentModifier == "&"){ - data.isReference = true; - } - } - }; - - closeEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::declstmt})){ - data.linenumber = ctx.currentLineNumber; - data.nameofidentifier = currentDeclName; - } - }; - - closeEventMap[ParserState::type] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::declstmt})){ - data.nameoftype = currentTypeName; - } - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - //TODO: possibly, this if-statement is suppressing more than just unmarked whitespace. Investigate. - if(!(ctx.currentToken.empty() || ctx.currentToken[0] == ' ')){ - if(ctx.And({ParserState::name, ParserState::type, ParserState::decl, ParserState::declstmt}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - currentTypeName = ctx.currentToken; - } - if(ctx.And({ParserState::name, ParserState::decl, ParserState::declstmt}) && - ctx.Nor({ParserState::type, ParserState::index/*skip array portion*/, ParserState::argumentlist/*skip init list portion*/, ParserState::init, ParserState::specifier, ParserState::modifier})){ - currentDeclName = ctx.currentToken; - } - if(ctx.And({ParserState::specifier, ParserState::decl, ParserState::declstmt})){ - currentSpecifier = ctx.currentToken; - } - if(ctx.And({ParserState::modifier, ParserState::type, ParserState::declstmt})){ - currentModifier = ctx.currentToken; - } - } - }; - closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx){ - NotifyAll(ctx); - data.clear(); - }; - closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx){ - if(ctx.IsOpen(ParserState::declstmt)){ - if(currentSpecifier == "const"){ - data.isConst = true; - } - if(currentSpecifier == "static"){ - data.isStatic = true; - } - } - currentSpecifier.clear(); - }; - - } -}; - -#include <srcSAXEventDispatchUtilities.hpp> - -#include <TypePolicySingleEvent.hpp> -#include <NamePolicySingleEvent.hpp> - -#include <string> -#include <vector> - -#ifndef INCLUDED_DECL_TYPE_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_DECL_TYPE_POLICY_SINGLE_EVENT_HPP - -class DeclTypePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - -public: - - struct DeclTypeData { - - TypePolicy::TypeData * type; - NamePolicy::NameData * name; - bool isStatic; - - friend /**collaborator */ -friend std::ostream & operator<<(std::ostream & out, const DeclTypeData & declData) { - - out << *declData.type; - - if(declData.name) - out << ' ' << *declData.name; - - return out; - - } - - }; - -private: - - - DeclTypeData data; - std::size_t declDepth; - - TypePolicy * typePolicy; - NamePolicy * namePolicy; - -public: - - DeclTypePolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), - data{}, - declDepth(0), - typePolicy(nullptr), - namePolicy(nullptr) { - - InitializeDeclTypePolicyHandlers(); - - } - - ~DeclTypePolicy() { - - if(typePolicy) delete typePolicy; - if(namePolicy) delete namePolicy; - - } - -protected: - void * DataInner() const override { - - return new DeclTypeData(data); - - } - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - - if(typeid(TypePolicy) == typeid(*policy)) { - - data.type = policy->Data<TypePolicy::TypeData>(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - - } else if(typeid(NamePolicy) == typeid(*policy)) { - - data.name = policy->Data<NamePolicy::NameData>(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - - } - - } - -private: - - void InitializeDeclTypePolicyHandlers() { - using namespace srcSAXEventDispatch; - - // start of policy - openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - - if(!declDepth) { - - declDepth = ctx.depth; - data = DeclTypeData{}; - - CollectTypeHandlers(); - CollectNameHandlers(); - CollectSpecifiersHandlers(); - - } - - }; - - // end of policy - closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - - if(declDepth && declDepth == ctx.depth) { - - declDepth = 0; - - NotifyAll(ctx); - InitializeDeclTypePolicyHandlers(); - - } - - }; - - } - - void CollectTypeHandlers() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - - if(declDepth && (declDepth + 2) == ctx.depth) { - - if(!typePolicy) typePolicy = new TypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(typePolicy); - - } - - }; - - } - - void CollectNameHandlers() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - - if(declDepth && (declDepth + 2) == ctx.depth) { - - if(!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); - - } - - }; - - } - - - -void CollectSpecifiersHandlers() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { - - if(declDepth && (declDepth + 2) == ctx.depth) { - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - - if(ctx.currentToken == "static") - data.isStatic = true; - - }; - - } - - }; - - closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { - - if(declDepth && (declDepth + 1) == ctx.depth) { - - NopCloseEvents({ParserState::tokenstring}); - - } - - }; - -} - -}; - -#endif - - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <exception> -#include <stack> -#include <list> -/* - *Record current function being called - *Record argument names and positions - */ -class CallPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - /* - {CalledFunction1{arg1, line#}, {arg2, line#}, ..., {argn, line#}, - NestedCalledFunction1{arg1, line#},{arg2, line#}, ..., {argn, line#} - } - */ - public: - struct CallData{ - /**command */ - void clear(){ - fnName.clear(); - callargumentlist.clear(); - } - std::string fnName; - std::list<std::string> callargumentlist; - }; - ~CallPolicy(){} - CallPolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners ){ - InitializeEventHandlers(); - } - /**collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - - //data.name = policy->Data<NamePolicy::NameData>(); - - } - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return new CallData(data); - } - private: - CallData data; - std::string currentTypeName, currentCallName, currentModifier, currentSpecifier; - /**command collaborator */ - void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; - closeEventMap[ParserState::call] = [this](srcSAXEventContext& ctx){ - if(ctx.triggerField[ParserState::call] == 1){ //TODO: Fix - data.callargumentlist.push_back(")"); - NotifyAll(ctx); - data.callargumentlist.clear(); - data.fnName.clear(); - }else{ - data.callargumentlist.push_back(")"); - } - }; - - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx){ - if(currentModifier == "*"){} - else if(currentModifier == "&"){} - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - if(ctx.IsOpen(ParserState::name) && ctx.IsGreaterThan(ParserState::call,ParserState::argumentlist) && ctx.IsClosed(ParserState::genericargumentlist)){ - data.fnName = ctx.currentToken; - data.callargumentlist.push_back("("); - data.callargumentlist.push_back(ctx.currentToken); - } - //std::cerr<<ctx.IsOpen(ParserState::name)<<" "<<ctx.IsOpen(ParserState::argument)<<" "<<ctx.IsOpen(ParserState::argumentlist)<<" "<<ctx.IsOpen(ParserState::genericargumentlist)<<std::endl; - if(ctx.And({ParserState::name, ParserState::argument, ParserState::argumentlist}) && ctx.IsEqualTo(ParserState::call,ParserState::argumentlist) && ctx.IsClosed(ParserState::genericargumentlist)){ - data.callargumentlist.push_back(ctx.currentToken); - } - }; - } -}; - -#include <srcSAXEventDispatchUtilities.hpp> - -#include <NamePolicySingleEvent.hpp> -#include <DeclTypePolicySingleEvent.hpp> -#include <FunctionSignaturePolicySingleEvent.hpp> - -#include <string> -#include <vector> - -#ifndef INCLUDED_CLASS_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_CLASS_POLICY_SINGLE_EVENT_HPP - -class ClassPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - -public: - - enum ClassType : std::size_t { CLASS, STRUCT/*, UNION, ENUM*/ }; - enum AccessSpecifier { PUBLIC = 0, PRIVATE = 1, PROTECTED = 2 }; - struct ParentData { - - // should this be a NamePolicy::NameData? - std::string name; - bool isVirtual; - AccessSpecifier accessSpecifier; - - }; - - struct ClassData { - - ClassType type; - std::string stereotype; - - bool isGeneric; - NamePolicy::NameData * name; - - std::vector<ParentData> parents; - - std::vector<DeclTypePolicy::DeclTypeData *> fields[3]; - std::vector<FunctionSignaturePolicy::FunctionSignatureData *> constructors[3]; - bool hasDestructor; - std::vector<FunctionSignaturePolicy::FunctionSignatureData *> operators[3]; - std::vector<FunctionSignaturePolicy::FunctionSignatureData *> methods[3]; - - std::vector<ClassPolicy::ClassData *> innerClasses[3]; - - bool hasPureVirtual; - - }; - -private: - - ClassData data; - std::size_t classDepth; - AccessSpecifier currentRegion; - - NamePolicy * namePolicy; - DeclTypePolicy * declPolicy; - FunctionSignaturePolicy * functionPolicy; - ClassPolicy * classPolicy; - -public: - - ClassPolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), - data{}, - classDepth(0), - currentRegion(PUBLIC), - namePolicy(nullptr), - declPolicy(nullptr), - functionPolicy(nullptr), - classPolicy(nullptr) { - - InitializeClassPolicyHandlers(); - - } - - ~ClassPolicy() { - - if(namePolicy) delete namePolicy; - if(declPolicy) delete declPolicy; - if(functionPolicy) delete functionPolicy; - if(classPolicy) delete classPolicy; - - } - - void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - - if(typeid(NamePolicy) == typeid(*policy)) { - - data.name = policy->Data<NamePolicy::NameData>(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - - } else if(typeid(DeclTypePolicy) == typeid(*policy)) { - - data.fields[currentRegion].emplace_back(policy->Data<DeclTypePolicy::DeclTypeData>()); - ctx.dispatcher->RemoveListenerDispatchRemoveListenerDispatch(nullptr); - - } else if(typeid(FunctionSignaturePolicy) == typeid(*policy)) { - - FunctionSignaturePolicy::FunctionSignatureData * f_data = policy->Data<FunctionSignaturePolicy::FunctionSignatureData>Data(); - - if(f_data->isPureVirtual) - data.hasPureVirtual = true; - - if(f_data->type == FunctionSignaturePolicy::CONSTRUCTOR) - data.constructors[currentRegion].emplace_back(f_data); - else if(f_data->type == FunctionSignaturePolicy::OPERATOR) - data.operators[currentRegion].emplace_back(f_data); - else - data.methods[currentRegion].emplace_back(f_data); - ctx.dispatcher->RemoveListenerDispatchRemoveListenerDispatch(nullptr); - - } else if(typeid(ClassPolicy) == typeid(*policy)) { - - data.innerClasses[currentRegion].emplace_back(policy->Data<ClassPolicy::ClassData>()); - ctx.dispatcher->RemoveListenerRemoveListener(nullptr); - - } - - } - -protected: - void * DataInner() const override { - - return new ClassData(data); - - } - -private: - - void InitializeClassPolicyHandlers() { - using namespace srcSAXEventDispatch; - - // start of policy - std::function<void(srcSAXEventDispatch::srcSAXEventContext&)> startPolicy = [this](srcSAXEventContext& ctx) { - - if(!classDepth) { - - classDepth = ctx.depth; - - data = ClassData{}; - if(ctx.elementStack.back() == "class") - data.type = CLASS; - else if(ctx.elementStack.back() == "struct") - data.type = STRUCT; - - data.name = nullptr; - - CollectXMLAttributeHandlers(); - CollectNameHandlers(); - CollectGenericHandlers(); - CollectSuperHanders(); - CollectBlockHanders(); - - } else if((classDepth + 3) == ctx.depth) { - - if(!classPolicy) classPolicy = new ClassPolicy{this}; - ctx.dispatcher->AddListenerDispatch(classPolicy); - - } - - }; - - // end of policy - std::function<void(srcSAXEventDispatch::srcSAXEventContext&)> endPolicy = [this](srcSAXEventContext& ctx) { - - if(classDepth && classDepth == ctx.depth) { - - classDepth = 0; - NotifyAll(ctx); - InitializeClassPolicyHandlers(); - - } - - }; - - openEventMap[ParserState::classn] = startPolicy; - closeEventMap[ParserState::classn] = endPolicy; - openEventMap[ParserState::structn] = startPolicy; - closeEventMap[ParserState::structn] = endPolicy; - - } - - void CollectXMLAttributeHandlers() { - using namespace srcSAXEventDispatch; - - closeEventMap[ParserState::xmlattribute] = [this](srcSAXEventContext& ctx) { - - if(classDepth == ctx.depth && ctx.currentAttributeName == "stereotype") { - - data.stereotype = ctx.currentAttributeValue; - - } - - }; - - } - - void CollectNameHandlers() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - - if((classDepth + 1) == ctx.depth) { - - if(!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); - - } - - }; - - closeEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - - if((classDepth + 1) == ctx.depth) { - - NopOpenEvents({ParserState::name}); - NopCloseEvents({ParserState::name}); - - } - - }; - - } - - void CollectGenericHandlers() { - using namespace srcSAXEventDispatch; - - closeEventMap[ParserState::templates] = [this](srcSAXEventContext& ctx) { - - if((classDepth + 1) == ctx.depth) { - - data.isGeneric = true; - - } - - }; - - } - - void CollectSuperHanders() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::super_list] = [this](srcSAXEventContext& ctx) { - - if((classDepth + 1) == ctx.depth) { - - openEventMap[ParserState::super] = [this](srcSAXEventContext& ctx) { - - data.parents.emplace_back(ParentData{ "", false, PUBLIC }); - - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - - if(ctx.And({ ParserState::specifier })) { - - if(ctx.currentToken == "virtual") { - data.parents.back().isVirtual = true; - } else if(ctx.currentToken == "public") { - data.parents.back().accessSpecifier = PUBLIC; - } else if(ctx.currentToken == "private") { - data.parents.back().accessSpecifier = PRIVATE; - } else if(ctx.currentToken == "protected") { - data.parents.back().accessSpecifier = PROTECTED; - } - - } else if(ctx.And({ ParserState::name })) { - - data.parents.back().name += ctx.currentToken; - - } - - - }; - - } - - }; - - closeEventMap[ParserState::super_list] = [this](srcSAXEventContext& ctx) { - - if((classDepth + 1) == ctx.depth) { - - NopOpenEvents({ParserState::super_list, ParserState::super}); - NopCloseEvents({ParserState::super_list, ParserState::tokenstring}); - - } - - }; - - } - - void CollectBlockHanders() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - - if((classDepth + 1) == ctx.depth) { - - NopOpenEvents({ParserState::name, ParserState::super_list, ParserState::super}); - NopCloseEvents({ParserState::name, ParserState::super_list, ParserState::tokenstring}); - - // set up to listen to decl_stmt, member, and class policies - openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { - - if((classDepth + 3) == ctx.depth) { - - if(!declPolicy) declPolicy = new DeclTypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(declPolicy); - - } - - }; - std::function<void (srcSAXEventContext& ctx)> functionEvent = [this](srcSAXEventContext& ctx) { - - if((classDepth + 3) == ctx.depth) { - - if(!functionPolicy) functionPolicy = new FunctionSignaturePolicy{this}; - ctx.dispatcher->AddListenerDispatch(functionPolicy); - - } - - }; - openEventMap[ParserState::function] = functionEvent; - openEventMap[ParserState::functiondecl] = functionEvent; - openEventMap[ParserState::constructor] = functionEvent; - openEventMap[ParserState::constructordecl] = functionEvent; - - std::function<void (srcSAXEventContext& ctx)> destructorEvent = [this](srcSAXEventContext& ctx) { - - if((classDepth + 3) == ctx.depth) { - - data.hasDestructor = true; - - } - - }; - - openEventMap[ParserState::destructor] = destructorEvent; - openEventMap[ParserState::destructordecl] = destructorEvent; - - } - - }; - - - // should always be in a region once block starts, so should not have to close - openEventMap[ParserState::publicaccess] = [this](srcSAXEventContext& ctx) { - - if((classDepth + 2) == ctx.depth) { - - currentRegion = PUBLIC; - - } - - }; - - openEventMap[ParserState::protectedaccess] = [this](srcSAXEventContext& ctx) { - - if((classDepth + 2) == ctx.depth) { - - currentRegion = PROTECTED; - - } - - }; - - openEventMap[ParserState::privateaccess] = [this](srcSAXEventContext& ctx) { - - if((classDepth + 2) == ctx.depth) { - - currentRegion = PRIVATE; - - } - - }; - - closeEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { - - if((classDepth + 1) == ctx.depth) { - - NopOpenEvents({ParserState::block, ParserState::function, ParserState::functiondecl, - ParserState::constructor, ParserState::constructordecl, ParserState::destructor, ParserState::destructordecl, - ParserState::declstmt, - ParserState::publicaccess, ParserState::protectedaccess, ParserState::privateaccess}); - NopCloseEvents({ParserState::block}); - - } - - }; - - } - -}; - -#endif - - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <exception> -#include <set> -#include <vector> -class ExprPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - public: - struct ExprData{ - ExprData() {} - /**command */ - void clear(){ - def.clear(); - use.clear(); - } - std::string nameofidentifier; - std::set<unsigned int> def; - std::set<unsigned int> use; //could be used multiple times in same expr - }; - std::map<std::string, ExprData> dataset; - ~ExprPolicy(){} - ExprPolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners ){ - seenAssignment = false; - InitializeEventHandlers(); - } - /**collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return new ExprData(data); - } - private: - ExprData data; - std::string currentTypeName, currentExprName, currentModifier, currentSpecifier; - std::vector<unsigned int> currentLine; - bool seenAssignment; - /**command collaborator */ - void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; - closeEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ - if(ctx.currentToken == "="){ - auto it = dataset.find(currentExprName); - if(it != dataset.end()){ - it->second.use.erase(currentLine.back()); - it->second.def.insert(currentLine.back()); - }else{ - std::cerr<<"No such thing as: "<<currentExprName<<std::endl; - } - seenAssignment = true; - //std::cerr<<"Back: "<<currentLine.back()<<std::endl; - } - }; - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx){ - - }; - - closeEventMap[ParserState::name] = [this](srcSAXEventContext& ctx){ - if(currentLine.empty() || currentLine.back() != ctx.currentLineNumber){ - currentLine.push_back(ctx.currentLineNumber); - } - if(ctx.IsOpen({ParserState::exprstmt})){ - auto it = dataset.find(currentExprName); - if(it != dataset.end()){ - it->second.use.insert(currentLine.back()); //assume it's a use - }else{ - data.nameofidentifier = currentExprName; - data.use.insert(currentLine.back()); - dataset.insert(std::make_pair(currentExprName, data)); - } - } - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - //TODO: possibly, this if-statement is suppressing more than just unmarked whitespace. Investigate. - if(!(ctx.currentToken.empty() || ctx.currentToken == " ")){ - if(ctx.IsOpen(ParserState::exprstmt)){ - - } - if(ctx.And({ParserState::name, ParserState::expr, ParserState::exprstmt}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::op})){ - currentExprName = ctx.currentToken; - } - if(ctx.And({ParserState::specifier, ParserState::expr, ParserState::exprstmt})){ - currentSpecifier = ctx.currentToken; - } - if(ctx.And({ParserState::modifier, ParserState::exprstmt})){ - currentModifier = ctx.currentToken; - } - } - }; - closeEventMap[ParserState::exprstmt] = [this](srcSAXEventContext& ctx){ - NotifyAll(ctx); - for(auto deal : dataset){ - std::cerr<<deal.second.nameofidentifier<<std::endl; - std::cerr<<"def { "; - for(auto num : deal.second.def){ - std::cerr<<num<<","; - } - std::cerr<<"}"<<std::endl; - std::cerr<<"use { "; - for(auto num : deal.second.use){ - std::cerr<<num<<","; - } - std::cerr<<"}"<<std::endl; - } - currentLine.pop_back(); - seenAssignment = false; - currentLine.clear(); - data.clear(); - }; - - } -}; - -/** - * @file test_srcsax_control_handler.cpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <srcSAXController.hpp> -#include <srcSAXHandler.hpp> -#include <cppCallbackAdapter.hpp> - -#include <srcsax.h> - -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <iostream> -#include <string.h> -#include <cassert> - -/** - * read_callback - * @param context the context to read from - * @param buffer the buffer to read into - * @param len the number of bytes to read - * - * FILE read callback for testing io. - * - * @returns the number of bytes read. - */ -int read_callback(void * context, char * buffer, int len) { - - return (int)fread(buffer, 1, len, (FILE *)context); - -} - -/** - * close_callback - * @param context the context to read from - * - * FILE close callback for testing io. - * - * @returns 0 on success EOF otherwise. - */ -int close_callback(void * context) { - - return fclose((FILE *)context); - -} - -/** - * main - * - * Test the srcsax functions. - * - * @returns 0 on success. - */ -int main() { - - /* - srcSAXController - */ - { - try { - - srcSAXController control(__FILE__); - - } catch(... ) { assert(false); } - } - - { - try { - - srcSAXController control(__FILE__, "ISO-8859-1"); - - } catch(... ) { assert(false); } - } - - { - try { - - srcSAXController control(std::string("foobar")); - - } catch(... ) { assert(false); } - } - - { - try { - - srcSAXController control(std::string("foobar"), "ISO-8859-1"); - - } catch(... ) { assert(false); } - } - - { - try { - - srcSAXController control(__FILE__, "ISO-8859-1"); - - } catch(... ) { assert(false); } - } - - { - try { - - FILE * file = fopen(__FILE__, "r"); - srcSAXController control(file); - - } catch(... ) { assert(false); } - } - - { - try { - - FILE * file = fopen(__FILE__, "r"); - srcSAXController control(file, "ISO-8859-1"); - - } catch(... ) { assert(false); } - } - - { - try { - - int fd = open(__FILE__, O_RDONLY); - srcSAXController control(fd); - - } catch(... ) { assert(false); } - } - - { - try { - - int fd = open(__FILE__, O_RDONLY); - srcSAXController control(fd, "ISO-8859-1"); - - } catch(... ) { assert(false); } - } - - { - try { - - FILE * file = fopen(__FILE__, "r"); - srcSAXController control((void *)file, read_callback, close_callback); - - } catch(... ) { assert(false); } - } - - { - try { - - FILE * file = fopen(__FILE__, "r"); - srcSAXController control((void *)file, read_callback, close_callback, "ISO-8859-1"); - - } catch(... ) { assert(false); } - } - - /* - enable_startDocument - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_startDocument(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_startDocument(false); - assert(sax.start_document == 0); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_startDocument(false); - control.enable_startDocument(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_endDocument - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_endDocument(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_endDocument(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == 0); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_endDocument(false); - control.enable_endDocument(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_startRoot - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_startRoot(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_startRoot(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == 0); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_startRoot(false); - control.enable_startRoot(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_startUnit - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_startUnit(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_startUnit(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == 0); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_startUnit(false); - control.enable_startUnit(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_startElement - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_startElement(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_startElement(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == 0); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_startElement(false); - control.enable_startElement(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_endRoot - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_endRoot(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_endRoot(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == 0); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_endRoot(false); - control.enable_endRoot(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_endUnit - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_endUnit(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_endUnit(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == 0); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_endUnit(false); - control.enable_endUnit(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_endElement - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_endElement(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_endElement(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == 0); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_endElement(false); - control.enable_endElement(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_charactersRoot - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_charactersRoot(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_charactersRoot(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == 0); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_charactersRoot(false); - control.enable_charactersRoot(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_charactersUnit - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_charactersUnit(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_charactersUnit(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == 0); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_charactersUnit(false); - control.enable_charactersUnit(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_metaTag - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_metaTag(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_metaTag(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == 0); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_metaTag(false); - control.enable_metaTag(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_comment - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_comment(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_comment(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == 0); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_comment(false); - control.enable_comment(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_cdataBlock - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_cdataBlock(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_cdataBlock(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == 0); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_cdataBlock(false); - control.enable_cdataBlock(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - enable_processingInstruction - */ - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_processingInstruction(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_processingInstruction(false); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == 0); - } - - { - - srcSAXController control(__FILE__); - srcsax_handler sax = cppCallbackAdapter::factory(); - control.getContext()->handler = &sax; - - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - control.enable_processingInstruction(false); - control.enable_processingInstruction(true); - assert(sax.start_document == cppCallbackAdapter::start_document); - assert(sax.end_document == cppCallbackAdapter::end_document); - assert(sax.start_root == cppCallbackAdapter::start_root); - assert(sax.start_unit == cppCallbackAdapter::start_unit); - assert(sax.start_element == cppCallbackAdapter::start_element); - assert(sax.end_root == cppCallbackAdapter::end_root); - assert(sax.end_unit == cppCallbackAdapter::end_unit); - assert(sax.end_element == cppCallbackAdapter::end_element); - assert(sax.characters_root == cppCallbackAdapter::characters_root); - assert(sax.characters_unit == cppCallbackAdapter::characters_unit); - assert(sax.meta_tag == cppCallbackAdapter::meta_tag); - assert(sax.comment == cppCallbackAdapter::comment); - assert(sax.cdata_block == cppCallbackAdapter::cdata_block); - assert(sax.processing_instruction == cppCallbackAdapter::processing_instruction); - } - - /* - parse - */ - - { - - srcSAXController control(std::string("<unit/>")); - srcSAXHandler handler; - try { - control.parse(&handler); - } catch(SAXError error) { assert(false); } - - } - - { - - srcSAXController control(__FILE__); - srcSAXHandler handler; - try { - control.parse(&handler); - assert(false); - } catch(SAXError error) { - assert(error.message != ""); - assert(error.error_code != 0); - } - - } - - return 0; -} - - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <exception> -#include <vector> -#include <ParamTypePolicy.hpp> -class FunctionSignaturePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - struct SignatureData{ - SignatureData():isConst{false}, constPointerReturn{false}, isMethod{false}, isStatic{false}, pointerToConstReturn{false}, hasAliasedReturn{false} {} - int linenumber; - std::string returnType; - std::string functionName; - std::string returnTypeModifier; - std::vector<std::string> functionNamespaces; - std::vector<std::string> returnTypeNamespaces; - std::vector<ParamTypePolicy::ParamData> parameters; - bool isConst; - bool isMethod; - bool isStatic; - bool pointerToConstReturn; - bool constPointerReturn; - bool hasAliasedReturn; - /**command */ - void clear(){ - returnType.clear(); - functionName.clear(); - parameters.clear(); - returnTypeModifier.clear(); - isConst = false; - isMethod = false; - isStatic = false; - pointerToConstReturn = false; - constPointerReturn = false; - hasAliasedReturn = false; - } - }; - ~FunctionSignaturePolicy(){} - FunctionSignaturePolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}) : srcSAXEventDispatch::PolicyDispatcher(listeners ){ - currentArgPosition = 1; - parampolicy.AddListener(this); - InitializeEventHandlers(); - } - /**command collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - paramdata = policy->Data<ParamTypePolicy::ParamData>(); - data.parameters.push_back(*paramdata); - } - protected: - /**voidaccessor */ - void * DataInner() const override { - return new SignatureData(data); - } - private: - bool seenModifier; - ParamTypePolicy parampolicy; - ParamTypePolicy::ParamData* paramdata; - SignatureData data; - size_t currentArgPosition; - std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; - - /**command collaborator */ - void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; - openEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { - data.linenumber = ctx.currentLineNumber; - ctx.dispatcher->AddListener(&parampolicy); - }; - openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::type, ParserState::function}) && ctx.Nor({ParserState::parameterlist, ParserState::functionblock, ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - data.returnTypeNamespaces.push_back(ctx.currentToken); - } - if(ctx.IsOpen(ParserState::function) && ctx.Nor({ParserState::type, ParserState::parameterlist, ParserState::functionblock, ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - data.functionNamespaces.push_back(ctx.currentToken); - } - }; - openEventMap[ParserState::functionblock] = [this](srcSAXEventContext& ctx){//incomplete. Blocks count too. - if(ctx.IsOpen(ParserState::classn)){ - data.isMethod = true; - } - NotifyAll(ctx); - seenModifier = false; - data.clear(); - }; - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) { - if(currentModifier == "*") { - if(ctx.And({ParserState::type, ParserState::function}) && ctx.IsClosed(ParserState::parameterlist)){ - seenModifier = true; - data.hasAliasedReturn = true; - } - } - else if(currentModifier == "&") {} - }; - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::name, ParserState::function}) && ctx.Nor({ParserState::functionblock, ParserState::type, ParserState::parameterlist, ParserState::genericargumentlist})){ - data.functionName = ctx.currentToken; - } - if(ctx.And({ParserState::name, ParserState::type, ParserState::function}) && ctx.Nor({ParserState::functionblock, ParserState::parameterlist, ParserState::genericargumentlist})){ - data.returnType = ctx.currentToken; - } - if(ctx.And({ParserState::modifier, ParserState::type, ParserState::function}) && ctx.Nor({ParserState::parameterlist, ParserState::genericargumentlist})){ - data.returnTypeModifier = ctx.currentToken; - } - if(ctx.And({ParserState::specifier, ParserState::function}) && ctx.Nor({ParserState::parameterlist, ParserState::functionblock, ParserState::genericargumentlist})){ - currentSpecifier = ctx.currentToken; - } - if(ctx.And({ParserState::modifier, ParserState::function}) && ctx.Nor({ParserState::parameterlist, ParserState::functionblock, ParserState::genericargumentlist})){ - currentModifier = ctx.currentToken; - } - }; - closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { - if(currentSpecifier == "const" && ctx.Nor({ParserState::parameterlist, ParserState::type})){ - data.isConst = true; - } - if(currentSpecifier == "const" && ctx.IsOpen(ParserState::function) && ctx.IsOpen(ParserState::type)){ - if(!seenModifier){ - data.pointerToConstReturn = true; - }else{ - data.constPointerReturn = true; - } - } - if(currentSpecifier == "static" && ctx.Nor({ParserState::parameterlist, ParserState::type})){ - data.isStatic = true; - } - currentSpecifier.clear(); - }; - closeEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { - ctx.dispatcher->RemoveListener(&parampolicy); - }; - } - -}; - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <exception> - -class ParamTypePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener{ - public: - struct ParamData{ - ParamData(): linenumber{0}, isConst{false}, isConstAlias{false}, isAliasToConst{false}, isReference{false}, isPointer{false}, isStatic{false} {} - /**command */ - void clear(){ - nameoftype.clear(); - nameofidentifier.clear(); - namespaces.clear(); - linenumber = -1; - isConst = false; - isReference = false; - isPointer = false; - isStatic = false; - } - std::string nameoftype; - std::string nameofidentifier; - std::vector<std::string> namespaces; - int linenumber; - bool isConst; - bool isConstAlias; - bool isAliasToConst; - bool isReference; - bool isPointer; - bool isStatic; - }; - ParamTypePolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners ){ - InitializeEventHandlers(); - } - /**collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - - //data.name = policy->Data<NamePolicy::NameData>(); - - } - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return new ParamData(data); - } - private: - ParamData data; - std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; - - /**command collaborator */ - void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; - openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::type, ParserState::parameter}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - data.namespaces.push_back(ctx.currentToken); - } - }; - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx){ - if(ctx.IsOpen(ParserState::parameter)){ - if(currentModifier == "*"){ - data.isPointer = true; - } - else if(currentModifier == "&"){ - data.isReference = true; - } - } - }; - - closeEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::parameter})){ - data.linenumber = ctx.currentLineNumber; - data.nameofidentifier = currentDeclName; - } - }; - - closeEventMap[ParserState::type] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::parameter})){ - data.nameoftype = currentTypeName; - } - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - //TODO: possibly, this if-statement is suppressing more than just unmarked whitespace. Investigate. - if(!(ctx.currentToken.empty() || ctx.currentToken[0] == ' ')){ - if(ctx.And({ParserState::name, ParserState::type, ParserState::decl, ParserState::parameter}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - currentTypeName = ctx.currentToken; - } - if(ctx.And({ParserState::name, ParserState::decl, ParserState::parameter}) && - ctx.Nor({ParserState::type, ParserState::index/*skip array portion*/, ParserState::argumentlist/*skip init list portion*/, - ParserState::init, ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - currentDeclName = ctx.currentToken; - } - if(ctx.And({ParserState::specifier, ParserState::decl, ParserState::parameter})){ - currentSpecifier = ctx.currentToken; - } - if(ctx.And({ParserState::modifier, ParserState::type, ParserState::parameter})){ - currentModifier = ctx.currentToken; - } - } - }; - closeEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx){ - NotifyAll(ctx); - data.clear(); - }; - closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx){ - if(ctx.IsOpen(ParserState::parameter)){ - if(currentSpecifier == "static"){ - data.isStatic = true; - } - if(currentSpecifier == "const"){ - data.isConst = true; - } - } - currentSpecifier.clear(); - }; - - } -}; - -#include <srcSAXEventDispatchUtilities.hpp> - -#include <TypePolicySingleEvent.hpp> -#include <TemplateArgumentPolicySingleEvent.hpp> - -#include <string> -#include <vector> -#include <iostream> - -#ifndef INCLUDED_NAME_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_NAME_POLICY_SINGLE_EVENT_HPP - -class NamePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - -public: - - struct NameData { - - std::string name; - std::vector<NameData *> names; - std::vector<TemplateArgumentPolicy::TemplateArgumentData *> templateArguments; - std::vector<std::string> arrayIndices; - - /**get */ - std::string SimpleName() const { - - if(!name.empty()) - return name; - - return names.back()->SimpleName(); - - } - - /**property collaborator */ - std::string ToString() const { - - std::string str = name; - - for(std::size_t pos = 0; pos < names.size(); ++pos) { - - if(pos != 0) - str += ' '; - str += names[pos]->ToString(); - - } - - return str; - - } - - friend /**collaborator */ -friend std::ostream & operator<<(std::ostream & out, const NameData & nameData) { - - if(!nameData.name.empty()) { - out << nameData.name; - } - - for(size_t pos = 0; pos < nameData.names.size(); ++pos) { - - if(pos != 0) out << "::"; - out << (*nameData.names[pos]); - - } - - if(!nameData.templateArguments.empty()) { - out << '<'; - for(const TemplateArgumentPolicy::TemplateArgumentData * arg : nameData.templateArguments) { - out << *arg; - } - out << '>'; - } - - for(const std::string & index : nameData.arrayIndices) { - out << '[' << index << ']'; - } - - return out; - - - } - - }; - -private: - - NameData data; - std::size_t nameDepth; - - NamePolicy * namePolicy; - TemplateArgumentPolicy * templateArgumentPolicy; - -public: - - - NamePolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), - data{}, - nameDepth(0), - namePolicy(nullptr), - templateArgumentPolicy(nullptr) { - - InitializeNamePolicyHandlers(); - - } - - ~NamePolicy() { - - if(namePolicy) delete namePolicy; - if(templateArgumentPolicy) delete templateArgumentPolicy; - - } - -protected: - void * DataInner() const override { - - return new NameData(data); - - } - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - - if(typeid(NamePolicy) == typeid(*policy)) { - - data.names.push_back(policy->Data<NameData>()); - ctx.dispatcher->RemoveListener(nullptr); - - } else if(typeid(TemplateArgumentPolicy) == typeid(*policy)) { - - data.templateArguments.push_back(policy->Data<TemplateArgumentPolicy::TemplateArgumentData>()); - ctx.dispatcher->RemoveListener(nullptr); - - } - - } - -private: - - void InitializeNamePolicyHandlers() { - using namespace srcSAXEventDispatch; - - // start of policy - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - - if(!nameDepth) { - - nameDepth = ctx.depth; - data = NameData{}; - - CollectTemplateArgumentsHandlers(); - CollectArrayIndicesHandlers(); - - } else if((nameDepth + 1) == ctx.depth) { - - NopCloseEvents({ParserState::tokenstring}); - if(!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); - - } - - }; - - // end of policy - closeEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - - if(nameDepth && nameDepth == ctx.depth) { - - nameDepth = 0; - - NotifyAll(ctx); - InitializeNamePolicyHandlers(); - - } - - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - - if(nameDepth && nameDepth == ctx.depth) { - - data.name += ctx.currentToken; - - } - - }; - - } - - void CollectTemplateArgumentsHandlers() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext& ctx) { - - if(nameDepth && (nameDepth + 1) == ctx.depth) { - - openEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { - - if(nameDepth && (nameDepth + 2) == ctx.depth) { - - if(!templateArgumentPolicy) templateArgumentPolicy = new TemplateArgumentPolicy{this}; - ctx.dispatcher->AddListenerDispatch(templateArgumentPolicy); - - } - - }; - - } - - }; - - closeEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext& ctx) { - - if(nameDepth && (nameDepth + 1) == ctx.depth) { - - NopOpenEvents({ParserState::argument}); - - } - - }; - - } - - void CollectArrayIndicesHandlers() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::index] = [this](srcSAXEventContext& ctx) { - - if(nameDepth && (nameDepth + 1) == ctx.depth) { - - data.arrayIndices.push_back(std::string()); - - } - - }; - - closeEventMap[ParserState::index] = [this](srcSAXEventContext& ctx) { - - if(nameDepth && (nameDepth + 1) == ctx.depth) { - - NopOpenEvents({ParserState::expr}); - NopCloseEvents({ParserState::expr}); - - } - - }; - - openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - - size_t num_elements = ctx.elementStack.size(); - if(nameDepth && (nameDepth + 2) == ctx.depth && num_elements > 1 && ctx.elementStack[num_elements - 2] == "index") { - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { data.arrayIndices.back() += ctx.currentToken; }; - - } - - }; - - closeEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - - size_t num_elements = ctx.elementStack.size(); - if(nameDepth && (nameDepth + 2) == ctx.depth && num_elements > 0 && ctx.elementStack.back() == "index") { - - NopCloseEvents({ParserState::tokenstring}); - - } - - }; - - } - -}; - -#endif - - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <exception> - -class SourceNLPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - public: - struct SourceNLData{ - SourceNLData(){} - /**command */ - void clear(){ - category.clear(); - identifiername.clear(); - } - std::string category; - std::string identifiername; - }; - SourceNLData data; - ~SourceNLPolicy(){} - SourceNLPolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners ){ - InitializeEventHandlers(); - } - /**collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return new SourceNLData(data); - } - private: - std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; - /**command collaborator */ - void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; - closeEventMap[ParserState::snoun] = [this](srcSAXEventContext& ctx){ - //std::cerr<<ctx.currentTag<<" "<<data.identifiername<<std::endl; - data.category = "snoun"; - NotifyAll(ctx); - data.identifiername.clear(); - }; - - closeEventMap[ParserState::propersnoun] = [this](srcSAXEventContext& ctx){ - //std::cerr<<ctx.currentTag<<" "<<data.identifiername<<std::endl; - data.category = "propersnoun"; - NotifyAll(ctx); - data.identifiername.clear(); - }; - - closeEventMap[ParserState::spronoun] = [this](srcSAXEventContext& ctx){ - //std::cerr<<ctx.currentTag<<" "<<data.identifiername<<std::endl; - data.category = "spronoun"; - NotifyAll(ctx); - data.identifiername.clear(); - }; - - closeEventMap[ParserState::sadjective] = [this](srcSAXEventContext& ctx){ - //std::cerr<<ctx.currentTag<<" "<<data.identifiername<<std::endl; - data.category = "sadjective"; - NotifyAll(ctx); - data.identifiername.clear(); - }; - - closeEventMap[ParserState::sverb] = [this](srcSAXEventContext& ctx){ - //std::cerr<<ctx.currentTag<<" "<<data.identifiername<<std::endl; - data.category = "sverb"; - NotifyAll(ctx); - data.identifiername.clear(); - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - //TODO: possibly, this if-statement is suppressing more than just unmarked whitespace. Investigate. - if(ctx.Or({ParserState::snoun, ParserState::spronoun, ParserState::propersnoun, ParserState::sverb, ParserState::sadjective})){ - data.identifiername.append(ctx.currentToken); - } - }; - closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx){ - //NotifyAll(ctx); - data.clear(); - }; - - } -}; - -#include <srcSAXEventDispatchUtilities.hpp> - -#include <TypePolicySingleEvent.hpp> -#include <NamePolicySingleEvent.hpp> - -#include <string> -#include <vector> - -#ifndef INCLUDED_PARAM_TYPE_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_PARAM_TYPE_POLICY_SINGLE_EVENT_HPP - -class ParamTypePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - -public: - - struct ParamTypeData { - - TypePolicy::TypeData * type; - NamePolicy::NameData * name; - - friend /**collaborator */ -friend std::ostream & operator<<(std::ostream & out, const ParamTypeData & paramData) { - - out << *paramData.type; - - if(paramData.name) - out << ' ' << *paramData.name; - - return out; - - } - - }; - -private: - - - ParamTypeData data; - std::size_t paramDepth; - - TypePolicy * typePolicy; - NamePolicy * namePolicy; - -public: - - ParamTypePolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), - data{}, - paramDepth(0), - typePolicy(nullptr), - namePolicy(nullptr) { - - InitializeParamTypePolicyHandlers(); - - } - - ~ParamTypePolicy() { - - if(typePolicy) delete typePolicy; - if(namePolicy) delete namePolicy; - - } - -protected: - void * DataInner() const override { - - return new ParamTypeData(data); - - } - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - - if(typeid(TypePolicy) == typeid(*policy)) { - - data.type = policy->Data<TypePolicy::TypeData>(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - - } else if(typeid(NamePolicy) == typeid(*policy)) { - - data.name = policy->Data<NamePolicy::NameData>(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - - } - - } - -private: - - void InitializeParamTypePolicyHandlers() { - using namespace srcSAXEventDispatch; - - // start of policy - openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { - - if(!paramDepth) { - - paramDepth = ctx.depth; - data = ParamTypeData{}; - - CollectTypeHandlers(); - CollectNameHandlers(); - - } - - }; - - // end of policy - closeEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { - - if(paramDepth && paramDepth == ctx.depth) { - - paramDepth = 0; - - NotifyAll(ctx); - InitializeParamTypePolicyHandlers(); - - } - - }; - - } - - void CollectTypeHandlers() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - - if(paramDepth && (paramDepth + 2) == ctx.depth) { - - if(!typePolicy) typePolicy = new TypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(typePolicy); - - } - - }; - - } - - void CollectNameHandlers() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - - if(paramDepth && (paramDepth + 2) == ctx.depth) { - - if(!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); - - } - - }; - - } - -}; - -#endif - - -#include <srcSAXEventDispatchUtilities.hpp> - -#include <exception> - -#ifndef INCLUDED_TEMPLATE_ARGUMENT_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_TEMPLATE_ARGUMENT_POLICY_SINGLE_EVENT_HPP - -class NamePolicy; -class TemplateArgumentPolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - -public: - enum TemplateArgumentType { NAME, LITERAL, MODIFIER, POINTER, REFERENCE, RVALUE, OPERATOR, CALL }; - - struct TemplateArgumentData { - std::vector<std::pair<void *, TemplateArgumentType>> data; - - friend std::ostream & operator<<(std::ostream & out, const TemplateArgumentData & argumentData); - - }; - private: - TemplateArgumentData data; - std::size_t argumentDepth; - NamePolicy * namePolicy; - - public: - TemplateArgumentPolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners); - ~TemplateArgumentPolicy(); - virtual void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override; - protected: - virtual void * DataInnerDataInner() const override; - private: - void InitializeTemplateArgumentPolicyHandlers(); - - void CollectNamesHandler(); - void CollectOthersHandler(); - -}; - -#endif - - -#include <srcSAXEventDispatchUtilities.hpp> - -#include <TypePolicySingleEvent.hpp> -#include <NamePolicySingleEvent.hpp> -#include <ParamTypePolicySingleEvent.hpp> - -#include <string> -#include <vector> - -#ifndef INCLUDED_FUNCTION_SIGNATURE_POLICY_SINGE_EVENT_HPP -#define INCLUDED_FUNCTION_SIGNATURE_POLICY_SINGE_EVENT_HPP - -class FunctionSignaturePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - -public: - - enum FunctionSignatureType { CONSTRUCTOR, DESTURCTOR, OPERATOR, FUNCTION }; - - struct FunctionSignatureData { - - FunctionSignatureType type; - std::string stereotype; - - TypePolicy::TypeData * returnType; - NamePolicy::NameData * name; - - std::vector<ParamTypePolicy::ParamTypeData *> parameters; - - bool isVirtual; - bool isPureVirtual; - bool isConst; - bool isStatic; - bool isInline; - bool isFinal; - bool isOverride; - bool isConstExpr; - bool isDelete; - - /**property collaborator */ - std::string ToString() const { - - std::string signature = name->ToString(); - signature += '('; - for(std::size_t pos = 0; pos < parameters.size(); ++pos) { - if(pos > 0) - signature += ", "; - signature += parameters[pos]->type->ToString(); - } - signature += ')'; - if(isConst) - signature += " const"; - - return signature; - - } - - friend /**collaborator */ -friend std::ostream & operator<<(std::ostream & out, const FunctionSignatureData & functionData) { - - out << *functionData.returnType << ' ' << *functionData.name; - - out << '('; - - for(std::size_t pos = 0; pos < functionData.parameters.size(); ++pos) { - - if(pos != 0) - out << ", "; - - out << *functionData.parameters[pos]; - - } - - out << ')'; - - return out; - - } - - }; - -private: - - FunctionSignatureData data; - std::size_t functionDepth; - - TypePolicy * typePolicy; - NamePolicy * namePolicy; - ParamTypePolicy * paramPolicy; - -public: - - FunctionSignaturePolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), - data{}, - functionDepth(0), - typePolicy(nullptr), - namePolicy(nullptr), - paramPolicy(nullptr) { - - InitializeFunctionSignaturePolicyHandlers(); - - } - - ~FunctionSignaturePolicy() { - - if(typePolicy) delete typePolicy; - if(namePolicy) delete namePolicy; - if(paramPolicy) delete paramPolicy; - - } - -protected: - void * DataInner() const override { - - return new FunctionSignatureData(data); - - } - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override { - - if(typeid(TypePolicy) == typeid(*policy)) { - - data.returnType = policy->Data<TypePolicy::TypeData>(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - - } else if(typeid(NamePolicy) == typeid(*policy)) { - - data.name = policy->Data<NamePolicy::NameData>(); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - - } else if(typeid(ParamTypePolicy) == typeid(*policy)) { - - data.parameters.push_back(policy->Data<ParamTypePolicy::ParamTypeData>()); - ctx.dispatcher->RemoveListenerDispatch(nullptr); - - } - - } - -private: - - void InitializeFunctionSignaturePolicyHandlers() { - using namespace srcSAXEventDispatch; - - // start of policy - std::function<void (srcSAXEventContext& ctx)> functionStart = [this](srcSAXEventContext& ctx) { - - if(!functionDepth) { - - functionDepth = ctx.depth; - data = FunctionSignatureData{}; - - if(ctx.elementStack.back() == "function" || ctx.elementStack.back() == "function_decl") { - - if(ctx.isOperator) - data.type = OPERATOR; - else - data.type = FUNCTION; - - } else if(ctx.elementStack.back() == "constructor" || ctx.elementStack.back() == "constructor_decl") { - data.type = CONSTRUCTOR; - } else if(ctx.elementStack.back() == "destructor" || ctx.elementStack.back() == "destructor_decl") { - data.type = DESTURCTOR; - } - - CollectXMLAttributeHandlers(); - CollectTypeHandlers(); - CollectNameHandlers(); - CollectParameterHandlers(); - CollectOtherHandlers(); - - } - - }; - - // end of policy - std::function<void (srcSAXEventContext& ctx)> functionEnd = [this](srcSAXEventContext& ctx) { - - if(functionDepth && functionDepth == ctx.depth) { - - functionDepth = 0; - - NotifyAll(ctx); - InitializeFunctionSignaturePolicyHandlers(); - - } - - }; - - openEventMap[ParserState::function] = functionStart; - openEventMap[ParserState::functiondecl] = functionStart; - openEventMap[ParserState::constructor] = functionStart; - openEventMap[ParserState::constructordecl] = functionStart; - openEventMap[ParserState::destructor] = functionStart; - openEventMap[ParserState::destructordecl] = functionStart; - - closeEventMap[ParserState::functiondecl] = functionEnd; - closeEventMap[ParserState::constructordecl] = functionEnd; - closeEventMap[ParserState::destructordecl] = functionEnd; - - openEventMap[ParserState::functionblock] = [this](srcSAXEventContext& ctx) { - - if(functionDepth && (functionDepth + 1) == ctx.depth) { - - functionDepth = 0; - - NotifyAll(ctx); - InitializeFunctionSignaturePolicyHandlers(); - - } - - }; - - } - - void CollectXMLAttributeHandlers() { - using namespace srcSAXEventDispatch; - - closeEventMap[ParserState::xmlattribute] = [this](srcSAXEventContext& ctx) { - - if(functionDepth == ctx.depth && ctx.currentAttributeName == "stereotype") { - - data.stereotype = ctx.currentAttributeValue; - - } - - }; - - } - - void CollectTypeHandlers() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - - if(functionDepth && (functionDepth + 1) == ctx.depth) { - - if(!typePolicy) typePolicy = new TypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(typePolicy); - - } - - }; - - } - - void CollectNameHandlers() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - - if(functionDepth && (functionDepth + 1) == ctx.depth) { - - if(!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); - - } - - }; - - } - - - void CollectParameterHandlers() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { - - if(functionDepth && (functionDepth + 1) == ctx.depth) { - - openEventMap[ParserState::parameter] = [this](srcSAXEventContext& ctx) { - - if(functionDepth && (functionDepth + 2) == ctx.depth) { - - if(!paramPolicy) paramPolicy = new ParamTypePolicy{this}; - ctx.dispatcher->AddListenerDispatch(paramPolicy); - - } - - }; - - } - - }; - - closeEventMap[ParserState::parameterlist] = [this](srcSAXEventContext& ctx) { - - if(functionDepth && (functionDepth + 1) == ctx.depth) { - - NopOpenEvents({ParserState::parameter}); - - } - - }; - - } - - - void CollectOtherHandlers() { - using namespace srcSAXEventDispatch; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - - if(functionDepth && (functionDepth + 1) == ctx.depth) { - - if(ctx.And({ParserState::specifier})) { - - if(ctx.currentToken == "virtual") - data.isVirtual = true; - else if(ctx.currentToken == "static") - data.isStatic = true; - else if(ctx.currentToken == "const") - data.isConst = true; - else if(ctx.currentToken == "final") - data.isFinal = true; - else if(ctx.currentToken == "override") - data.isOverride = true; - else if(ctx.currentToken == "delete") - data.isDelete = true; - else if(ctx.currentToken == "inline") - data.isInline = true; - else if(ctx.currentToken == "constexpr") - data.isConstExpr = true; - - } else if(ctx.And({ParserState::literal})) { - - data.isPureVirtual = true; - - } - - } - - }; - - } - -}; - -#endif - - -#include <srcSAXEventDispatchUtilities.hpp> - -#include <exception> - -#ifndef INCLUDED_TYPE_POLICY_SINGLE_EVENT_HPP -#define INCLUDED_TYPE_POLICY_SINGLE_EVENT_HPP - -class NamePolicy; -class TypePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - -public: - enum TypeType { NAME, POINTER, REFERENCE, RVALUE, SPECIFIER, NONE }; - - struct TypeData { - std::vector<std::pair<void *, TypeType>> types; - - std::string ToString() const; - friend std::ostream & operator<<(std::ostream & out, const TypeData & typeData); - - }; - private: - TypeData data; - std::size_t typeDepth; - - NamePolicy * namePolicy; - - public: - TypePolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners); - ~TypePolicy(); - virtual void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override; - protected: - virtual void * DataInnerDataInner() const override; - private: - void InitializeTypePolicyHandlers(); - - void CollectNamesHandler(); - void CollectModifersHandler(); - void CollectSpecifiersHandler(); - -}; - -#endif - - -#include <TypePolicySingleEvent.hpp> - -#include <NamePolicySingleEvent.hpp> - -/**property collaborator */ -std::string TypePolicy::TypeData::ToString() const { - - std::string type_str; - - for(std::size_t pos = 0; pos < types.size(); ++pos) { - - if(pos != 0) type_str += ' '; - - const std::pair<void *, TypePolicy::TypeType> & type = types[pos]; - - if(type.second == TypePolicy::POINTER) - type_str += '*'; - else if(type.second == TypePolicy::REFERENCE) - type_str += '&'; - else if(type.second == TypePolicy::RVALUE) - type_str += "&&"; - else if(type.second == TypePolicy::SPECIFIER) - type_str += *static_cast<std::string *>(type.first); - else if(type.second == TypePolicy::NAME) - type_str += static_cast<NamePolicy::NameData *>(type.first)->ToString(); - - } - - return type_str; - - -} - -std::ostream & operator<<(std::ostream & out, const TypePolicy::TypeData & typeData) { - - for(std::size_t pos = 0; pos < typeData.types.size(); ++pos) { - - if(pos != 0) out << ' '; - - const std::pair<void *, TypePolicy::TypeType> & type = typeData.types[pos]; - - if(type.second == TypePolicy::POINTER) - out << '*'; - else if(type.second == TypePolicy::REFERENCE) - out << '&'; - else if(type.second == TypePolicy::RVALUE) - out << "&&"; - else if(type.second == TypePolicy::SPECIFIER) - out << *static_cast<std::string *>(type.first); - else if(type.second == TypePolicy::NAME) - out << *static_cast<NamePolicy::NameData *>(type.first); - - } - - return out; - -} - -TypePolicy::TypePolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), - data{}, - typeDepth(0), - namePolicy(nullptr) { - - InitializeTypePolicyHandlers(); - -} - -TypePolicy::~TypePolicy(){ - - if(namePolicy) delete namePolicy; - -} - -/**command collaborator */ -void TypePolicy::Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) { - - data.types.back().first = policy->Data<NamePolicy::NameData>Data(); - ctx.dispatcher->RemoveListenerDispatchRemoveListenerDispatch(nullptr); - -} - -/**voidaccessor */ -void * TypePolicy::DataInner() const { - return new TypePolicy::TypeData(data); -} - -/**command collaborator */ -void TypePolicy::InitializeTypePolicyHandlers() { - using namespace srcSAXEventDispatch; - - // start of policy - openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - - if(!typeDepth) { - - typeDepth = ctx.depth; - data = TypePolicy::TypeData{}; - - CollectNamesHandler(); - CollectModifersHandler(); - CollectSpecifiersHandler(); - - } - - }; - - // end of policy - closeEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - - if(typeDepth && typeDepth == ctx.depth) { - - typeDepth = 0; - - NotifyAll(ctx); - InitializeTypePolicyHandlers(); - - } - - }; - -} - -/**command collaborator */ -void TypePolicy::CollectNamesHandler() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - - if(typeDepth && (typeDepth + 1) == ctx.depth) { - - data.types.push_back(std::make_pair(nullptr, TypePolicy::NAME)); - if(!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); - - } - - }; - -} - -/**command collaborator */ -void TypePolicy::CollectModifersHandler() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) { - - if(typeDepth && (typeDepth + 1) == ctx.depth) { - - data.types.push_back(std::make_pair(nullptr, NONE)); - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - - if(ctx.currentToken == "*") - data.types.back().second = TypePolicy::POINTER; - else if(ctx.currentToken == "&") - data.types.back().second = TypePolicy::REFERENCE; - else if(ctx.currentToken == "&&") - data.types.back().second = TypePolicy::RVALUE; - - }; - - } - - }; - - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) { - - if(typeDepth && (typeDepth + 1) == ctx.depth) { - - NopCloseEvents({ParserState::tokenstring}); - - } - - }; - -} - -/**command collaborator */ -void TypePolicy::CollectSpecifiersHandler() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { - - if(typeDepth && (typeDepth + 1) == ctx.depth) { - - data.types.push_back(std::make_pair(new std::string(), TypePolicy::SPECIFIER)); - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - - (*static_cast<std::string *>(data.types.back().first)) += ctx.currentToken; - - }; - - } - - }; - - closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx) { - - if(typeDepth && (typeDepth + 1) == ctx.depth) { - - NopCloseEvents({ParserState::tokenstring}); - - } - - }; - -} - - -#include <srcSAXEventDispatcher.hpp> -namespace srcSAXEventDispatch{ - -} - - -#include <srcSAXEventDispatcher.hpp> -#include <srcSAXHandler.hpp> -#include <exception> - -class srcSlicePolicy : public srcSAXEventDispatch::EventListener, public srcSAXEventDispatch::PolicyDispatcher, public srcSAXEventDispatch::PolicyListener { - public: - struct DeclTypeData{ - DeclTypeData(): linenumber{0}, isConst{false}, isReference{false}, isPointer{false}, isStatic{false} {} - /**command */ - void clear(){ - nameoftype.clear(); - nameofidentifier.clear(); - namespaces.clear(); - linenumber = -1; - isConst = false; - isReference = false; - isPointer = false; - isStatic = false; - } - std::string nameoftype; - std::string nameofidentifier; - std::vector<std::string> namespaces; - int linenumber; - bool isConst; - bool isReference; - bool isPointer; - bool isStatic; - }; - DeclTypeData data; - ~srcSlicePolicy(){} - srcSlicePolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners = {}): srcSAXEventDispatch::PolicyDispatcher(listeners ){ - InitializeEventHandlers(); - } - /**collaborator */ - void NotifyNotify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) override {} //doesn't use other parsers - protected: - /**voidaccessor */ - void * DataInnerDataInner() const override { - return new DeclTypeData(data); - } - private: - std::string currentTypeName, currentDeclName, currentModifier, currentSpecifier; - /**command collaborator */ - void InitializeEventHandlers(){ - using namespace srcSAXEventDispatch; - openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::type, ParserState::declstmt}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - data.namespaces.push_back(ctx.currentToken); - } - }; - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx){ - if(ctx.IsOpen(ParserState::declstmt)){ - if(currentModifier == "*"){ - data.isPointer = true; - } - if(currentModifier == "&"){ - data.isReference = true; - } - } - }; - - closeEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::declstmt})){ - data.linenumber = ctx.currentLineNumber; - data.nameofidentifier = currentDeclName; - } - }; - - closeEventMap[ParserState::type] = [this](srcSAXEventContext& ctx){ - if(ctx.And({ParserState::declstmt})){ - data.nameoftype = currentTypeName; - } - }; - - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx){ - //TODO: possibly, this if-statement is suppressing more than just unmarked whitespace. Investigate. - if(!(ctx.currentToken.empty() || ctx.currentToken[0] == ' ')){ - if(ctx.And({ParserState::name, ParserState::type, ParserState::decl, ParserState::declstmt}) && ctx.Nor({ParserState::specifier, ParserState::modifier, ParserState::genericargumentlist})){ - currentTypeName = ctx.currentToken; - } - if(ctx.And({ParserState::name, ParserState::decl, ParserState::declstmt}) && - ctx.Nor({ParserState::type, ParserState::index/*skip array portion*/, ParserState::argumentlist/*skip init list portion*/, ParserState::init, ParserState::specifier, ParserState::modifier})){ - currentDeclName = ctx.currentToken; - } - if(ctx.And({ParserState::specifier, ParserState::decl, ParserState::declstmt})){ - currentSpecifier = ctx.currentToken; - } - if(ctx.And({ParserState::modifier, ParserState::type, ParserState::declstmt})){ - currentModifier = ctx.currentToken; - } - } - }; - closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx){ - NotifyAll(ctx); - data.clear(); - }; - closeEventMap[ParserState::specifier] = [this](srcSAXEventContext& ctx){ - if(ctx.IsOpen(ParserState::declstmt)){ - if(currentSpecifier == "const"){ - data.isConst = true; - } - if(currentSpecifier == "static"){ - data.isStatic = true; - } - } - currentSpecifier.clear(); - }; - - } -}; - -#include <TemplateArgumentPolicySingleEvent.hpp> - -#include <NamePolicySingleEvent.hpp> - -std::ostream & operator<<(std::ostream & out, const TemplateArgumentPolicy::TemplateArgumentData & argumentData) { - - for(std::size_t pos = 0; pos < argumentData.data.size(); ++pos) { - - if(pos != 0) - out << ' '; - - const std::pair<void *, TemplateArgumentPolicy::TemplateArgumentType> & element = argumentData.data[pos]; - if(element.second == TemplateArgumentPolicy::NAME) - out << *static_cast<NamePolicy::NameData *>(element.first); - else if(element.second == TemplateArgumentPolicy::POINTER) - out << '*'; - else if(element.second == TemplateArgumentPolicy::REFERENCE) - out << '&'; - else if(element.second == TemplateArgumentPolicy::RVALUE) - out << "&&"; - else - out << *static_cast<std::string *>(element.first); - - } - - return out; - -} - -TemplateArgumentPolicy::TemplateArgumentPolicy(std::initializer_list<srcSAXEventDispatch::PolicyListener *> listeners) - : srcSAXEventDispatch::PolicyDispatcher(listeners), - data{}, - argumentDepth(0), - namePolicy(nullptr) { - - InitializeTemplateArgumentPolicyHandlers(); - -} - -TemplateArgumentPolicy::~TemplateArgumentPolicy() { - - if(namePolicy) delete namePolicy; - -} - -/**command collaborator */ -void TemplateArgumentPolicy::Notify(const PolicyDispatcher * policy, const srcSAXEventDispatch::srcSAXEventContext & ctx) { - - data.data.back().first = policy->Data<NamePolicy::NameData>Data(); - ctx.dispatcher->RemoveListenerDispatchRemoveListenerDispatch(nullptr); - -} - -/**voidaccessor */ -void * TemplateArgumentPolicy::DataInner() const { - return new TemplateArgumentPolicy::TemplateArgumentData(data); -} - -/**command collaborator */ -void TemplateArgumentPolicy::InitializeTemplateArgumentPolicyHandlers() { - using namespace srcSAXEventDispatch; - - // start of policy - openEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { - - if(!argumentDepth) { - - argumentDepth = ctx.depth; - data = TemplateArgumentPolicy::TemplateArgumentData{}; - - CollectNamesHandler(); - CollectOthersHandler(); - - } - - }; - - // end of policy - closeEventMap[ParserState::argument] = [this](srcSAXEventContext& ctx) { - - if(argumentDepth && argumentDepth == ctx.depth) { - - argumentDepth = 0; - - NotifyAll(ctx); - InitializeTemplateArgumentPolicyHandlers(); - - } - - }; - -} - -/**command collaborator */ -void TemplateArgumentPolicy::CollectNamesHandler() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::name] = [this](srcSAXEventContext& ctx) { - - // C++ has depth of 2 others 1 - std::size_t elementStackSize = ctx.elementStack.size(); - if( argumentDepth && (((argumentDepth + 2) == ctx.depth && elementStackSize > 1 && ctx.elementStack[elementStackSize - 2] == "expr") - || (argumentDepth + 1) == ctx.depth)) { - - data.data.push_back(std::make_pair(nullptr, TemplateArgumentPolicy::NAME)); - if(!namePolicy) namePolicy = new NamePolicy{this}; - ctx.dispatcher->AddListenerDispatch(namePolicy); - - } - - }; - -} - -/**command collaborator */ -void TemplateArgumentPolicy::CollectOthersHandler() { - using namespace srcSAXEventDispatch; - - openEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { - - // C++ has depth of 2 others 1 - std::size_t elementStackSize = ctx.elementStack.size(); - if( argumentDepth && (((argumentDepth + 2) == ctx.depth && elementStackSize > 1 && ctx.elementStack[elementStackSize - 2] == "expr") - || (argumentDepth + 1) == ctx.depth)) { - - data.data.push_back(std::make_pair(new std::string(), LITERAL)); - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - (*static_cast<std::string *>(data.data.back().first)) += ctx.currentToken; - }; - - } - - }; - - closeEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { - - if( argumentDepth && (((argumentDepth + 2) == ctx.depth && ctx.elementStack.back() == "expr") - || (argumentDepth + 1) == ctx.depth)) { - - NopCloseEvents({ParserState::tokenstring}); - - } - - }; - - openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { - - // C++ has depth of 2 others 1 - std::size_t elementStackSize = ctx.elementStack.size(); - if( argumentDepth && (((argumentDepth + 2) == ctx.depth && elementStackSize > 1 && ctx.elementStack[elementStackSize - 2] == "expr") - || (argumentDepth + 1) == ctx.depth)) { - - data.data.push_back(std::make_pair(new std::string(), OPERATOR)); - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - (*static_cast<std::string *>(data.data.back().first)) += ctx.currentToken; - }; - - } - - }; - - closeEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { - - if( argumentDepth && (((argumentDepth + 2) == ctx.depth && ctx.elementStack.back() == "expr") - || (argumentDepth + 1) == ctx.depth)) { - - NopCloseEvents({ParserState::tokenstring}); - - } - - }; - - openEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) { - - // C++ has depth of 2 others 1 - std::size_t elementStackSize = ctx.elementStack.size(); - if( argumentDepth && (((argumentDepth + 2) == ctx.depth && elementStackSize > 1 && ctx.elementStack[elementStackSize - 2] == "expr") - || (argumentDepth + 1) == ctx.depth)) { - - data.data.push_back(std::make_pair(nullptr, MODIFIER)); - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - - if(ctx.currentToken == "*") - data.data.back().second = POINTER; - else if(ctx.currentToken == "&") - data.data.back().second = REFERENCE; - else if(ctx.currentToken == "&&") - data.data.back().second = RVALUE; - - }; - - } - - }; - - closeEventMap[ParserState::modifier] = [this](srcSAXEventContext& ctx) { - - if( argumentDepth && (((argumentDepth + 2) == ctx.depth && ctx.elementStack.back() == "expr") - || (argumentDepth + 1) == ctx.depth)) { - - NopCloseEvents({ParserState::tokenstring}); - - } - - }; - - openEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { - - // C++ has depth of 2 others 1 - std::size_t elementStackSize = ctx.elementStack.size(); - if( argumentDepth && (((argumentDepth + 2) == ctx.depth && elementStackSize > 1 && ctx.elementStack[elementStackSize - 2] == "expr") - || (argumentDepth + 1) == ctx.depth)) { - - data.data.push_back(std::make_pair(new std::string(), CALL)); - closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { - (*static_cast<std::string *>(data.data.back().first)) += ctx.currentToken; - }; - - } - - }; - - closeEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { - - if( argumentDepth && (((argumentDepth + 2) == ctx.depth && ctx.elementStack.back() == "expr") - || (argumentDepth + 1) == ctx.depth)) { - - NopCloseEvents({ParserState::tokenstring}); - - } - - }; - -} - - -#ifndef INCLUDED_SRCSAX_SINGLE_EVENT_DISPATCHER_HPP -#define INCLUDED_SRCSAX_SINGLE_EVENT_DISPATCHER_HPP - -#include <srcSAXEventDispatcher.hpp> - -namespace srcSAXEventDispatch { - - class srcSAXSingleEventDispatcher : public srcSAXEventDispatcher<policies...> { - - private: - bool dispatched; - - public: - - srcSAXSingleEventDispatcher(PolicyListener * listener) : srcSAXEventDispatcher<policies...>(listener), dispatched(false) {} - /**command collaborational-command collaborator */ - virtual void AddListener(EventListener * listener) override { - EventDispatcher::elementListeners.back()->SetDispatched(false); - EventDispatcher::elementListeners.push_back(listener); - } - /**set collaborator */ - virtual void AddListenerDispatch(EventListener * listener) override { - AddListener(listener); - dispatched = false; - } - /**command collaborator stateless */ - virtual void AddListenerNoDispatch(EventListener * listener) override { - AddListener(listener); - } - /**command collaborational-command collaborator */ - virtual void RemoveListener(EventListener * listener) override { - EventDispatcher::elementListeners.back()->SetDispatched(false); - EventDispatcher::elementListeners.pop_back(); - } - /**set collaborator */ - virtual void RemoveListenerDispatch(EventListener * listener) override { - RemoveListener(listener); - dispatched = false; - } - /**command collaborator stateless */ - virtual void RemoveListenerNoDispatch(EventListener * listener) override { - RemoveListener(listener); - } - protected: - /**command collaborator */ - virtual void DispatchEvent(srcSAXEventDispatch::ParserState pstate, srcSAXEventDispatch::ElementState estate) override { - - while(!dispatched) { - - dispatched = true; - - EventDispatcher::elementListeners.back()->HandleEvent(pstate, estate, EventDispatcher::ctx); - EventDispatcher::elementListeners.back()->SetDispatched(false); - - } - - dispatched = false; - - } - - }; - -} - -#endif - - -#include <memory> -#include <unordered_map> -#include <functional> -#include <string> -#include <vector> -#include <list> -#include <initializer_list> -#include <algorithm> -#include <iostream> - -#ifndef INCLUDED_SRCSAX_EVENT_DISPATCH_UTILITIES_HPP -#define INCLUDED_SRCSAX_EVENT_DISPATCH_UTILITIES_HPP - -namespace srcSAXEventDispatch{ - class EventDispatcher; - enum ElementState {open, close}; - enum ParserState {decl, expr, parameter, declstmt, exprstmt, parameterlist, - argumentlist, argumentlisttemplate, call, templates, ctrlflow, endflow, genericargumentlist, - name, function, functiondecl, constructor, constructordecl, destructordecl, destructor, - argument, index, block, type, init, op, literal, modifier, memberlist, classn, structn, - super_list, super, publicaccess, privateaccess, protectedaccess, preproc, whilestmt, forstmt, - ifstmt, nonterminal, macro, classblock, functionblock, ifblock, whileblock, forblock, specifier, typedefexpr, - userdefined, snoun, propersnoun, spronoun, sadjective, sverb, - - // do not put anything after these - xmlattribute, tokenstring, empty, MAXENUMVALUE = empty}; - class srcSAXEventContext { - public: - srcSAXEventContext() = delete; - srcSAXEventContext(EventDispatcher * dispatcher, const std::vector<std::string> & elementStack) - : dispatcher(dispatcher), - elementStack(elementStack), - triggerField(std::vector<unsigned short int>(MAXENUMVALUE, 0)), - depth(0), - isOperator(false), - currentLineNumber{0} {} - - EventDispatcher * dispatcher; - const std::vector<std::string> & elementStack; - std::vector<int> genericDepth; - unsigned int currentLineNumber; - std::vector<unsigned short int> triggerField; - std::string currentFilePath, currentFileName, currentFileLanguage, currentsrcMLRevision, - currentTag, currentToken, currentAttributeName, currentAttributeValue; - std::size_t depth; - bool isOperator; - - public: - /**predicate collaborator */ - inline bool And(std::vector<ParserState> vec) const{ - for(auto field : vec){ - if(triggerField[field]) continue; - else return false; - } - return true; - } - /**predicate collaborator */ - inline bool Nand(std::vector<ParserState> vec) const{ - for(auto field : vec){ - if(triggerField[field]) return false; - else continue; - } - return true; - } - /**predicate collaborator */ - inline bool Or(std::vector<ParserState> vec) const{ - for(auto field : vec){ - if(triggerField[field]) return true; - else continue; - } - return false; - } - /**predicate collaborator */ - inline bool Nor(std::vector<ParserState> vec) const{ - for(auto field : vec){ - if(triggerField[field]) return false; - else continue; - } - return true; - } - /**predicate collaborator */ - inline bool IsEqualTo(ParserState lhs, ParserState rhs) const{ - return triggerField[lhs] == triggerField[rhs] ? true : false; - } - /**predicate collaborator */ - inline bool IsGreaterThan(ParserState lhs, ParserState rhs) const{ - return triggerField[lhs] > triggerField[rhs] ? true : false; - } - /**predicate collaborator */ - inline bool IsGreaterThanOrEqualTo(ParserState lhs, ParserState rhs) const{ - return triggerField[lhs] >= triggerField[rhs] ? true : false; - } - /**predicate collaborator */ - inline bool IsLessThan(ParserState lhs, ParserState rhs) const{ - return triggerField[lhs] < triggerField[rhs] ? true : false; - } - /**predicate collaborator */ - inline bool IsLessThanOrEqualTo(ParserState lhs, ParserState rhs) const{ - return triggerField[lhs] <= triggerField[rhs] ? true : false; - } - /**predicate collaborator */ - inline bool IsOpen(ParserState field) const{ - if(triggerField[field]) return true; - else return false; - } - /**predicate collaborator */ - inline bool IsClosed(ParserState field) const{ - if(triggerField[field]) return false; - else return true; - } - }; - - class EventListener { - typedef std::unordered_map<srcSAXEventDispatch::ParserState, std::function<void(srcSAXEventDispatch::srcSAXEventContext&)>, std::hash<int>> EventMap; - protected: - bool dispatched; - EventMap openEventMap, closeEventMap; - - - public: - - EventListener() : dispatched(false) { - DefaultEventHandlers(); - } - - /**set */ - void SetDispatched(bool isDispatched) { dispatched = isDispatched; } - - /**get collaborator */ - virtual const EventMap & GetOpenEventMap() const { return openEventMap; } - /**get collaborator */ - virtual const EventMap & GetCloseEventMap() const { return closeEventMap; } - - /**set */ - virtual void HandleEvent() { dispatched = true; } - /**command collaborator */ - virtual void HandleEvent(srcSAXEventDispatch::ParserState pstate, srcSAXEventDispatch::ElementState estate, srcSAXEventDispatch::srcSAXEventContext& ctx) { - - if(dispatched) return; - - dispatched = true; - - switch(estate){ - - case srcSAXEventDispatch::ElementState::open: { - auto event = openEventMap.find(pstate); - if(event != openEventMap.end()){ - event->second(ctx); - } - break; - } - - case srcSAXEventDispatch::ElementState::close: { - auto event = closeEventMap.find(pstate); - if(event != closeEventMap.end()){ - event->second(ctx); - } - break; - } - - default: - throw std::runtime_error("Something went terribly, terribly wrong"); - - } - - } - - protected: - /**collaborator */ - void NopOpenEvents(std::initializer_list<ParserState> states) { - - for(ParserState state : states) { - - openEventMap[state] = [this](const srcSAXEventContext& ctx) {}; - - } - - } - /**collaborator */ - void NopCloseEvents(std::initializer_list<ParserState> states) { - - for(ParserState state : states) { - - closeEventMap[state] = [this](const srcSAXEventContext& ctx) {}; - - } - - } - - private: - - /**command */ - void DefaultEventHandlers() { - using namespace srcSAXEventDispatch; - - NopOpenEvents({ - ParserState::declstmt, - ParserState::exprstmt, - ParserState::parameterlist, - ParserState::ifstmt, - ParserState::forstmt, - ParserState::whilestmt, - ParserState::templates, - ParserState::argumentlist, - ParserState::genericargumentlist, - ParserState::call, - ParserState::function, - ParserState::constructor, - ParserState::functiondecl, - ParserState::destructordecl, - ParserState::constructordecl, - ParserState::classn, - ParserState::structn, - ParserState::publicaccess, - ParserState::protectedaccess, - ParserState::privateaccess, - ParserState::destructor, - ParserState::parameter, - ParserState::memberlist, - ParserState::index, - ParserState::op, - ParserState::block, - ParserState::init, - ParserState::argument, - ParserState::literal, - ParserState::modifier, - ParserState::decl, - ParserState::type, - ParserState::typedefexpr, - ParserState::expr, - ParserState::name, - ParserState::macro, - ParserState::specifier, - ParserState::snoun, - ParserState::propersnoun, - ParserState::sadjective, - ParserState::spronoun, - ParserState::sverb, - }); - - NopCloseEvents({ - ParserState::declstmt, - ParserState::exprstmt, - ParserState::parameterlist, - ParserState::ifstmt, - ParserState::forstmt, - ParserState::whilestmt, - ParserState::templates, - ParserState::argumentlist, - ParserState::genericargumentlist, - ParserState::call, - ParserState::function, - ParserState::constructor, - ParserState::destructor, - ParserState::functiondecl, - ParserState::constructordecl, - ParserState::destructordecl, - ParserState::classn, - ParserState::structn, - ParserState::publicaccess, - ParserState::protectedaccess, - ParserState::privateaccess, - ParserState::parameter, - ParserState::memberlist, - ParserState::index, - ParserState::op, - ParserState::block, - ParserState::init, - ParserState::argument, - ParserState::literal, - ParserState::modifier, - ParserState::decl, - ParserState::type, - ParserState::typedefexpr, - ParserState::expr, - ParserState::name, - ParserState::macro, - ParserState::tokenstring, - ParserState::specifier, - ParserState::snoun, - ParserState::propersnoun, - ParserState::sadjective, - ParserState::spronoun, - ParserState::sverb, - }); - - } - - }; - class EventDispatcher { - public: - virtual void AddListener(EventListener* l) = 0; - virtual void AddListenerDispatch(EventListener* listener) = 0; - virtual void AddListenerNoDispatch(EventListener* listener) = 0; - virtual void RemoveListener(EventListener* l) = 0; - virtual void RemoveListenerDispatch(EventListener* listener) = 0; - virtual void RemoveListenerNoDispatch(EventListener* listener) = 0; - protected: - srcSAXEventContext ctx; - std::list<EventListener*> elementListeners; - - EventDispatcher(const std::vector<std::string> & elementStack) - : elementListeners(), ctx(this, elementStack) {} - virtual void DispatchEvent(ParserState , ElementState ) = 0; - }; - class PolicyDispatcher; - class PolicyListener{ - - public: - - PolicyListener() {} - virtual void Notify(const PolicyDispatcher * policy, const srcSAXEventContext & ctx) = 0; - - }; - class PolicyDispatcher{ - public: - PolicyDispatcher(std::initializer_list<PolicyListener *> listeners) : policyListeners(listeners){} - /**command collaborator stateless */ - virtual void AddListener(PolicyListener* listener){ - policyListeners.push_back(listener); - } - /**command collaborator */ - virtual void RemoveListener(PolicyListener* listener){ - policyListeners.erase(std::find(policyListeners.begin(), policyListeners.end(), listener)); - } - - /**property collaborator */ - - T * Data() const { - - return static_cast<T *>(DataInner()); - - } - - protected: - std::list<PolicyListener*> policyListeners; - virtual void * DataInner() const = 0; - /**command collaborator */ - virtual void NotifyAll(const srcSAXEventContext & ctx) { - std::cerr<<"Size: "<<policyListeners.size()<<std::endl; - for(std::list<PolicyListener*>::iterator listener = policyListeners.begin(); listener != policyListeners.end(); ++listener){ - std::cerr<<"Listen man"<<std::endl; - (*listener)->Notify(this, ctx); - } - - } - - }; -} - -#endif - - -/* This source file must have a .cpp extension so that all C++ compilers - recognize the extension without flags. Borland does not know .cxx for - example. */ -#ifndef __cplusplus -# error "A C compiler has been selected for C++." -#endif - -/* Version number components: V=Version, R=Revision, P=Patch - Version date components: YYYY=Year, MM=Month, DD=Day */ - -#if defined(__COMO__) -# define COMPILER_ID "Comeau" - /* __COMO_VERSION__ = VRR */ -# define COMPILER_VERSION_MAJOR DEC(__COMO_VERSION__ / 100) -# define COMPILER_VERSION_MINOR DEC(__COMO_VERSION__ % 100) - -#elif defined(__INTEL_COMPILER) || defined(__ICC) -# define COMPILER_ID "Intel" - /* __INTEL_COMPILER = VRP */ -# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) -# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) -# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) -# if defined(__INTEL_COMPILER_BUILD_DATE) - /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ -# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) -# endif - -#elif defined(__PATHCC__) -# define COMPILER_ID "PathScale" -# define COMPILER_VERSION_MAJOR DEC(__PATHCC__) -# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) -# if defined(__PATHCC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) -# endif - -#elif defined(__clang__) -# define COMPILER_ID "Clang" -# define COMPILER_VERSION_MAJOR DEC(__clang_major__) -# define COMPILER_VERSION_MINOR DEC(__clang_minor__) -# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) - -#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) -# define COMPILER_ID "Embarcadero" -# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) -# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) -# define COMPILER_VERSION_PATCH HEX(__CODEGEARC_VERSION__ & 0xFFFF) - -#elif defined(__BORLANDC__) -# define COMPILER_ID "Borland" - /* __BORLANDC__ = 0xVRR */ -# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) -# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) - -#elif defined(__WATCOMC__) -# define COMPILER_ID "Watcom" - /* __WATCOMC__ = VVRR */ -# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) -# define COMPILER_VERSION_MINOR DEC(__WATCOMC__ % 100) - -#elif defined(__SUNPRO_CC) -# define COMPILER_ID "SunPro" -# if __SUNPRO_CC >= 0x5100 - /* __SUNPRO_CC = 0xVRRP */ -# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>12) -# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xFF) -# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) -# else - /* __SUNPRO_CC = 0xVRP */ -# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>8) -# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xF) -# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) -# endif - -#elif defined(__HP_aCC) -# define COMPILER_ID "HP" - /* __HP_aCC = VVRRPP */ -# define COMPILER_VERSION_MAJOR DEC(__HP_aCC/10000) -# define COMPILER_VERSION_MINOR DEC(__HP_aCC/100 % 100) -# define COMPILER_VERSION_PATCH DEC(__HP_aCC % 100) - -#elif defined(__DECCXX) -# define COMPILER_ID "Compaq" - /* __DECCXX_VER = VVRRTPPPP */ -# define COMPILER_VERSION_MAJOR DEC(__DECCXX_VER/10000000) -# define COMPILER_VERSION_MINOR DEC(__DECCXX_VER/100000 % 100) -# define COMPILER_VERSION_PATCH DEC(__DECCXX_VER % 10000) - -#elif defined(__IBMCPP__) -# if defined(__COMPILER_VER__) -# define COMPILER_ID "zOS" -# else -# if __IBMCPP__ >= 800 -# define COMPILER_ID "XL" -# else -# define COMPILER_ID "VisualAge" -# endif - /* __IBMCPP__ = VRP */ -# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) -# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) -# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) -# endif - -#elif defined(__PGI) -# define COMPILER_ID "PGI" -# define COMPILER_VERSION_MAJOR DEC(__PGIC__) -# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) -# if defined(__PGIC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) -# endif - -#elif defined(_CRAYC) -# define COMPILER_ID "Cray" -# define COMPILER_VERSION_MAJOR DEC(_RELEASE) -# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR) - -#elif defined(__TI_COMPILER_VERSION__) -# define COMPILER_ID "TI" - /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ -# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) -# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) -# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000) - -#elif defined(__SCO_VERSION__) -# define COMPILER_ID "SCO" - -#elif defined(__GNUC__) -# define COMPILER_ID "GNU" -# define COMPILER_VERSION_MAJOR DEC(__GNUC__) -# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) -# if defined(__GNUC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) -# endif - -#elif defined(_MSC_VER) -# define COMPILER_ID "MSVC" - /* _MSC_VER = VVRR */ -# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) -# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) -# if defined(_MSC_FULL_VER) -# if _MSC_VER >= 1400 - /* _MSC_FULL_VER = VVRRPPPPP */ -# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) -# else - /* _MSC_FULL_VER = VVRRPPPP */ -# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) -# endif -# endif -# if defined(_MSC_BUILD) -# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) -# endif - -/* Analog VisualDSP++ >= 4.5.6 */ -#elif defined(__VISUALDSPVERSION__) -# define COMPILER_ID "ADSP" - /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ -# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) -# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) -# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) - -/* Analog VisualDSP++ < 4.5.6 */ -#elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) -# define COMPILER_ID "ADSP" - -/* IAR Systems compiler for embedded systems. - http://www.iar.com */ -#elif defined(__IAR_SYSTEMS_ICC__ ) || defined(__IAR_SYSTEMS_ICC) -# define COMPILER_ID "IAR" - -#elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION) -# define COMPILER_ID "MIPSpro" -# if defined(_SGI_COMPILER_VERSION) - /* _SGI_COMPILER_VERSION = VRP */ -# define COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100) -# define COMPILER_VERSION_MINOR DEC(_SGI_COMPILER_VERSION/10 % 10) -# define COMPILER_VERSION_PATCH DEC(_SGI_COMPILER_VERSION % 10) -# else - /* _COMPILER_VERSION = VRP */ -# define COMPILER_VERSION_MAJOR DEC(_COMPILER_VERSION/100) -# define COMPILER_VERSION_MINOR DEC(_COMPILER_VERSION/10 % 10) -# define COMPILER_VERSION_PATCH DEC(_COMPILER_VERSION % 10) -# endif - -/* This compiler is either not known or is too old to define an - identification macro. Try to identify the platform and guess that - it is the native compiler. */ -#elif defined(__sgi) -# define COMPILER_ID "MIPSpro" - -#elif defined(__hpux) || defined(__hpua) -# define COMPILER_ID "HP" - -#else /* unknown compiler */ -# define COMPILER_ID "" - -#endif - -/* Construct the string literal in pieces to prevent the source from - getting matched. Store it in a pointer rather than an array - because some compilers will just produce instructions to fill the - array rather than assigning a pointer to a static array. */ -char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]"; - -/* Identify known platforms by name. */ -#if defined(__linux) || defined(__linux__) || defined(linux) -# define PLATFORM_ID "Linux" - -#elif defined(__CYGWIN__) -# define PLATFORM_ID "Cygwin" - -#elif defined(__MINGW32__) -# define PLATFORM_ID "MinGW" - -#elif defined(__APPLE__) -# define PLATFORM_ID "Darwin" - -#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) -# define PLATFORM_ID "Windows" - -#elif defined(__FreeBSD__) || defined(__FreeBSD) -# define PLATFORM_ID "FreeBSD" - -#elif defined(__NetBSD__) || defined(__NetBSD) -# define PLATFORM_ID "NetBSD" - -#elif defined(__OpenBSD__) || defined(__OPENBSD) -# define PLATFORM_ID "OpenBSD" - -#elif defined(__sun) || defined(sun) -# define PLATFORM_ID "SunOS" - -#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__) -# define PLATFORM_ID "AIX" - -#elif defined(__sgi) || defined(__sgi__) || defined(_SGI) -# define PLATFORM_ID "IRIX" - -#elif defined(__hpux) || defined(__hpux__) -# define PLATFORM_ID "HP-UX" - -#elif defined(__HAIKU__) -# define PLATFORM_ID "Haiku" - -#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS) -# define PLATFORM_ID "BeOS" - -#elif defined(__QNX__) || defined(__QNXNTO__) -# define PLATFORM_ID "QNX" - -#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__) -# define PLATFORM_ID "Tru64" - -#elif defined(__riscos) || defined(__riscos__) -# define PLATFORM_ID "RISCos" - -#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__) -# define PLATFORM_ID "SINIX" - -#elif defined(__UNIX_SV__) -# define PLATFORM_ID "UNIX_SV" - -#elif defined(__bsdos__) -# define PLATFORM_ID "BSDOS" - -#elif defined(_MPRAS) || defined(MPRAS) -# define PLATFORM_ID "MP-RAS" - -#elif defined(__osf) || defined(__osf__) -# define PLATFORM_ID "OSF1" - -#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv) -# define PLATFORM_ID "SCO_SV" - -#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX) -# define PLATFORM_ID "ULTRIX" - -#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX) -# define PLATFORM_ID "Xenix" - -#else /* unknown platform */ -# define PLATFORM_ID "" - -#endif - -/* For windows compilers MSVC and Intel we can determine - the architecture of the compiler being used. This is because - the compilers do not have flags that can change the architecture, - but rather depend on which compiler is being used -*/ -#if defined(_WIN32) && defined(_MSC_VER) -# if defined(_M_IA64) -# define ARCHITECTURE_ID "IA64" - -# elif defined(_M_X64) || defined(_M_AMD64) -# define ARCHITECTURE_ID "x64" - -# elif defined(_M_IX86) -# define ARCHITECTURE_ID "X86" - -# elif defined(_M_ARM) -# define ARCHITECTURE_ID "ARM" - -# elif defined(_M_MIPS) -# define ARCHITECTURE_ID "MIPS" - -# elif defined(_M_SH) -# define ARCHITECTURE_ID "SHx" - -# else /* unknown architecture */ -# define ARCHITECTURE_ID "" -# endif - -#else -# define ARCHITECTURE_ID "" -#endif - -/* Convert integer to decimal digit literals. */ -#define DEC(n ) \ - ('0' + (((n) / 10000000)%10)), \ - ('0' + (((n) / 1000000)%10)), \ - ('0' + (((n) / 100000)%10)), \ - ('0' + (((n) / 10000)%10)), \ - ('0' + (((n) / 1000)%10)), \ - ('0' + (((n) / 100)%10)), \ - ('0' + (((n) / 10)%10)), \ - ('0' + ((n) % 10)) - -/* Convert integer to hex digit literals. */ -#define HEX(n ) \ - ('0' + ((n)>>28 & 0xF)), \ - ('0' + ((n)>>24 & 0xF)), \ - ('0' + ((n)>>20 & 0xF)), \ - ('0' + ((n)>>16 & 0xF)), \ - ('0' + ((n)>>12 & 0xF)), \ - ('0' + ((n)>>8 & 0xF)), \ - ('0' + ((n)>>4 & 0xF)), \ - ('0' + ((n) & 0xF)) - -/* Construct a string literal encoding the version number components. */ -#ifdef COMPILER_VERSION_MAJOR -char const info_version[] = { - 'I', 'N', 'F', 'O', ':', - 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[', - COMPILER_VERSION_MAJOR, -# ifdef COMPILER_VERSION_MINOR - '.', COMPILER_VERSION_MINOR, -# ifdef COMPILER_VERSION_PATCH - '.', COMPILER_VERSION_PATCH, -# ifdef COMPILER_VERSION_TWEAK - '.', COMPILER_VERSION_TWEAK, -# endif -# endif -# endif - ']','\0'}; -#endif - -/* Construct the string literal in pieces to prevent the source from - getting matched. Store it in a pointer rather than an array - because some compilers will just produce instructions to fill the - array rather than assigning a pointer to a static array. */ -char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]"; -char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]"; - - - -/*--------------------------------------------------------------------------*/ - -int main(int argc, char* argv[]) -{ - int require = 0; - require += info_compiler[argc]; - require += info_platform[argc]; -#ifdef COMPILER_VERSION_MAJOR - require += info_version[argc]; -#endif - (void)argv; - return require; -} - - -#ifdef __cplusplus -# error "A C++ compiler has been selected for C." -#endif - -/* Version number components: V=Version, R=Revision, P=Patch - Version date components: YYYY=Year, MM=Month, DD=Day */ - -#if defined(__18CXX) -# define ID_VOID_MAIN -#endif - -#if defined(__INTEL_COMPILER) || defined(__ICC) -# define COMPILER_ID "Intel" - /* __INTEL_COMPILER = VRP */ -# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) -# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) -# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) -# if defined(__INTEL_COMPILER_BUILD_DATE) - /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ -# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) -# endif - -#elif defined(__PATHCC__) -# define COMPILER_ID "PathScale" -# define COMPILER_VERSION_MAJOR DEC(__PATHCC__) -# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) -# if defined(__PATHCC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) -# endif - -#elif defined(__clang__) -# define COMPILER_ID "Clang" -# define COMPILER_VERSION_MAJOR DEC(__clang_major__) -# define COMPILER_VERSION_MINOR DEC(__clang_minor__) -# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) - -#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) -# define COMPILER_ID "Embarcadero" -# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) -# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) -# define COMPILER_VERSION_PATCH HEX(__CODEGEARC_VERSION__ & 0xFFFF) - -#elif defined(__BORLANDC__) -# define COMPILER_ID "Borland" - /* __BORLANDC__ = 0xVRR */ -# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) -# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) - -#elif defined(__WATCOMC__) -# define COMPILER_ID "Watcom" - /* __WATCOMC__ = VVRR */ -# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) -# define COMPILER_VERSION_MINOR DEC(__WATCOMC__ % 100) - -#elif defined(__SUNPRO_C) -# define COMPILER_ID "SunPro" -# if __SUNPRO_C >= 0x5100 - /* __SUNPRO_C = 0xVRRP */ -# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12) -# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF) -# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) -# else - /* __SUNPRO_C = 0xVRP */ -# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8) -# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF) -# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) -# endif - -#elif defined(__HP_cc) -# define COMPILER_ID "HP" - /* __HP_cc = VVRRPP */ -# define COMPILER_VERSION_MAJOR DEC(__HP_cc/10000) -# define COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100) -# define COMPILER_VERSION_PATCH DEC(__HP_cc % 100) - -#elif defined(__DECC) -# define COMPILER_ID "Compaq" - /* __DECC_VER = VVRRTPPPP */ -# define COMPILER_VERSION_MAJOR DEC(__DECC_VER/10000000) -# define COMPILER_VERSION_MINOR DEC(__DECC_VER/100000 % 100) -# define COMPILER_VERSION_PATCH DEC(__DECC_VER % 10000) - -#elif defined(__IBMC__) -# if defined(__COMPILER_VER__) -# define COMPILER_ID "zOS" -# else -# if __IBMC__ >= 800 -# define COMPILER_ID "XL" -# else -# define COMPILER_ID "VisualAge" -# endif - /* __IBMC__ = VRP */ -# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) -# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) -# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) -# endif - -#elif defined(__PGI) -# define COMPILER_ID "PGI" -# define COMPILER_VERSION_MAJOR DEC(__PGIC__) -# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) -# if defined(__PGIC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) -# endif - -#elif defined(_CRAYC) -# define COMPILER_ID "Cray" -# define COMPILER_VERSION_MAJOR DEC(_RELEASE) -# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR) - -#elif defined(__TI_COMPILER_VERSION__) -# define COMPILER_ID "TI" - /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ -# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) -# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) -# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000) - -#elif defined(__TINYC__) -# define COMPILER_ID "TinyCC" - -#elif defined(__SCO_VERSION__) -# define COMPILER_ID "SCO" - -#elif defined(__GNUC__) -# define COMPILER_ID "GNU" -# define COMPILER_VERSION_MAJOR DEC(__GNUC__) -# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) -# if defined(__GNUC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) -# endif - -#elif defined(_MSC_VER) -# define COMPILER_ID "MSVC" - /* _MSC_VER = VVRR */ -# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) -# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) -# if defined(_MSC_FULL_VER) -# if _MSC_VER >= 1400 - /* _MSC_FULL_VER = VVRRPPPPP */ -# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) -# else - /* _MSC_FULL_VER = VVRRPPPP */ -# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) -# endif -# endif -# if defined(_MSC_BUILD) -# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) -# endif - -/* Analog VisualDSP++ >= 4.5.6 */ -#elif defined(__VISUALDSPVERSION__) -# define COMPILER_ID "ADSP" - /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ -# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) -# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) -# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) - -/* Analog VisualDSP++ < 4.5.6 */ -#elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) -# define COMPILER_ID "ADSP" - -/* IAR Systems compiler for embedded systems. - http://www.iar.com */ -#elif defined(__IAR_SYSTEMS_ICC__ ) || defined(__IAR_SYSTEMS_ICC) -# define COMPILER_ID "IAR" - -/* sdcc, the small devices C compiler for embedded systems, - http://sdcc.sourceforge.net */ -#elif defined(SDCC) -# define COMPILER_ID "SDCC" - /* SDCC = VRP */ -# define COMPILER_VERSION_MAJOR DEC(SDCC/100) -# define COMPILER_VERSION_MINOR DEC(SDCC/10 % 10) -# define COMPILER_VERSION_PATCH DEC(SDCC % 10) - -#elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION) -# define COMPILER_ID "MIPSpro" -# if defined(_SGI_COMPILER_VERSION) - /* _SGI_COMPILER_VERSION = VRP */ -# define COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100) -# define COMPILER_VERSION_MINOR DEC(_SGI_COMPILER_VERSION/10 % 10) -# define COMPILER_VERSION_PATCH DEC(_SGI_COMPILER_VERSION % 10) -# else - /* _COMPILER_VERSION = VRP */ -# define COMPILER_VERSION_MAJOR DEC(_COMPILER_VERSION/100) -# define COMPILER_VERSION_MINOR DEC(_COMPILER_VERSION/10 % 10) -# define COMPILER_VERSION_PATCH DEC(_COMPILER_VERSION % 10) -# endif - -/* This compiler is either not known or is too old to define an - identification macro. Try to identify the platform and guess that - it is the native compiler. */ -#elif defined(__sgi) -# define COMPILER_ID "MIPSpro" - -#elif defined(__hpux) || defined(__hpua) -# define COMPILER_ID "HP" - -#else /* unknown compiler */ -# define COMPILER_ID "" - -#endif - -/* Construct the string literal in pieces to prevent the source from - getting matched. Store it in a pointer rather than an array - because some compilers will just produce instructions to fill the - array rather than assigning a pointer to a static array. */ -char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]"; - -/* Identify known platforms by name. */ -#if defined(__linux) || defined(__linux__) || defined(linux) -# define PLATFORM_ID "Linux" - -#elif defined(__CYGWIN__) -# define PLATFORM_ID "Cygwin" - -#elif defined(__MINGW32__) -# define PLATFORM_ID "MinGW" - -#elif defined(__APPLE__) -# define PLATFORM_ID "Darwin" - -#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) -# define PLATFORM_ID "Windows" - -#elif defined(__FreeBSD__) || defined(__FreeBSD) -# define PLATFORM_ID "FreeBSD" - -#elif defined(__NetBSD__) || defined(__NetBSD) -# define PLATFORM_ID "NetBSD" - -#elif defined(__OpenBSD__) || defined(__OPENBSD) -# define PLATFORM_ID "OpenBSD" - -#elif defined(__sun) || defined(sun) -# define PLATFORM_ID "SunOS" - -#elif defined(_AIX) || defined(__AIX) || defined(__AIX__) || defined(__aix) || defined(__aix__) -# define PLATFORM_ID "AIX" - -#elif defined(__sgi) || defined(__sgi__) || defined(_SGI) -# define PLATFORM_ID "IRIX" - -#elif defined(__hpux) || defined(__hpux__) -# define PLATFORM_ID "HP-UX" - -#elif defined(__HAIKU__) -# define PLATFORM_ID "Haiku" - -#elif defined(__BeOS) || defined(__BEOS__) || defined(_BEOS) -# define PLATFORM_ID "BeOS" - -#elif defined(__QNX__) || defined(__QNXNTO__) -# define PLATFORM_ID "QNX" - -#elif defined(__tru64) || defined(_tru64) || defined(__TRU64__) -# define PLATFORM_ID "Tru64" - -#elif defined(__riscos) || defined(__riscos__) -# define PLATFORM_ID "RISCos" - -#elif defined(__sinix) || defined(__sinix__) || defined(__SINIX__) -# define PLATFORM_ID "SINIX" - -#elif defined(__UNIX_SV__) -# define PLATFORM_ID "UNIX_SV" - -#elif defined(__bsdos__) -# define PLATFORM_ID "BSDOS" - -#elif defined(_MPRAS) || defined(MPRAS) -# define PLATFORM_ID "MP-RAS" - -#elif defined(__osf) || defined(__osf__) -# define PLATFORM_ID "OSF1" - -#elif defined(_SCO_SV) || defined(SCO_SV) || defined(sco_sv) -# define PLATFORM_ID "SCO_SV" - -#elif defined(__ultrix) || defined(__ultrix__) || defined(_ULTRIX) -# define PLATFORM_ID "ULTRIX" - -#elif defined(__XENIX__) || defined(_XENIX) || defined(XENIX) -# define PLATFORM_ID "Xenix" - -#else /* unknown platform */ -# define PLATFORM_ID "" - -#endif - -/* For windows compilers MSVC and Intel we can determine - the architecture of the compiler being used. This is because - the compilers do not have flags that can change the architecture, - but rather depend on which compiler is being used -*/ -#if defined(_WIN32) && defined(_MSC_VER) -# if defined(_M_IA64) -# define ARCHITECTURE_ID "IA64" - -# elif defined(_M_X64) || defined(_M_AMD64) -# define ARCHITECTURE_ID "x64" - -# elif defined(_M_IX86) -# define ARCHITECTURE_ID "X86" - -# elif defined(_M_ARM) -# define ARCHITECTURE_ID "ARM" - -# elif defined(_M_MIPS) -# define ARCHITECTURE_ID "MIPS" - -# elif defined(_M_SH) -# define ARCHITECTURE_ID "SHx" - -# else /* unknown architecture */ -# define ARCHITECTURE_ID "" -# endif - -#else -# define ARCHITECTURE_ID "" -#endif - -/* Convert integer to decimal digit literals. */ -#define DEC(n ) \ - ('0' + (((n) / 10000000)%10)), \ - ('0' + (((n) / 1000000)%10)), \ - ('0' + (((n) / 100000)%10)), \ - ('0' + (((n) / 10000)%10)), \ - ('0' + (((n) / 1000)%10)), \ - ('0' + (((n) / 100)%10)), \ - ('0' + (((n) / 10)%10)), \ - ('0' + ((n) % 10)) - -/* Convert integer to hex digit literals. */ -#define HEX(n ) \ - ('0' + ((n)>>28 & 0xF)), \ - ('0' + ((n)>>24 & 0xF)), \ - ('0' + ((n)>>20 & 0xF)), \ - ('0' + ((n)>>16 & 0xF)), \ - ('0' + ((n)>>12 & 0xF)), \ - ('0' + ((n)>>8 & 0xF)), \ - ('0' + ((n)>>4 & 0xF)), \ - ('0' + ((n) & 0xF)) - -/* Construct a string literal encoding the version number components. */ -#ifdef COMPILER_VERSION_MAJOR -char const info_version[] = { - 'I', 'N', 'F', 'O', ':', - 'c','o','m','p','i','l','e','r','_','v','e','r','s','i','o','n','[', - COMPILER_VERSION_MAJOR, -# ifdef COMPILER_VERSION_MINOR - '.', COMPILER_VERSION_MINOR, -# ifdef COMPILER_VERSION_PATCH - '.', COMPILER_VERSION_PATCH, -# ifdef COMPILER_VERSION_TWEAK - '.', COMPILER_VERSION_TWEAK, -# endif -# endif -# endif - ']','\0'}; -#endif - -/* Construct the string literal in pieces to prevent the source from - getting matched. Store it in a pointer rather than an array - because some compilers will just produce instructions to fill the - array rather than assigning a pointer to a static array. */ -char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]"; -char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]"; - - - -/*--------------------------------------------------------------------------*/ - -#ifdef ID_VOID_MAIN -void main() {} -#else -int main(int argc, char* argv[]) -{ - int require = 0; - require += info_compiler[argc]; - require += info_platform[argc]; - require += info_arch[argc]; -#ifdef COMPILER_VERSION_MAJOR - require += info_version[argc]; -#endif - (void)argv; - return require; -} -#endif - - -/** - * @file srcSAXEventDispatcher.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#ifndef INCLUDED_SRCSAXEVENTDISPATCHER_HPP -#define INCLUDED_SRCSAXEVENTDISPATCHER_HPP - -#include <srcSAXHandler.hpp> -#include <functional> -#include <iostream> -#include <map> -#include <unordered_map> -#include <vector> -#include <algorithm> -#include <srcSAXEventDispatchUtilities.hpp> -#include <vector> -#include <memory> -namespace srcSAXEventDispatch { - - - static std::list<EventListener*> CreateListenersImpl(PolicyListener * policyListener, std::list<EventListener*> & listeners); - - - static std::list<EventListener*> CreateListeners(PolicyListener * policyListener) { - std::list<EventListener*> listeners; - return CreateListenersImpl<policies...>(policyListener, listeners); - } - - - static std::list<EventListener*> CreateListenersHelper(PolicyListener * policyListener, std::list<EventListener*> & listeners); - - - static std::list<EventListener*> CreateListenersImpl(PolicyListener * policyListener, std::list<EventListener*> & listeners) { - return CreateListenersHelper<policies...>(policyListener, listeners); - } - - - static std::list<EventListener*> CreateListenersHelper(PolicyListener * policyListener, std::list<EventListener*> & listeners) { - listeners.emplace_back(new policy({policyListener})); - return CreateListenersImpl<remaining...>(policyListener, listeners); - } - - std::list<EventListener*> CreateListenersImpl<>(PolicyListener * listener, std::list<EventListener*> & listeners) { - return listeners; - } - - - class srcSAXEventDispatcher : public srcSAXHandler, public EventDispatcher { - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wunused-parameter" - - private: - std::unordered_map< std::string, std::function<void()>> process_map, process_map2; - bool classflagopen, functionflagopen, whileflagopen, ifflagopen, elseflagopen, ifelseflagopen, forflagopen, switchflagopen; - - bool dispatching; - ParserState currentPState; - ElementState currentEState; - - std::size_t numberAllocatedListeners; - - protected: - /**command collaborator */ - void DispatchEvent(ParserState pstate, ElementState estate) override { - - dispatching = true; - currentPState = pstate; - currentEState = estate; - - for(std::list<EventListener*>::iterator listener = elementListeners.begin(); listener != elementListeners.end(); ++listener ){ - (*listener)->HandleEvent(pstate, estate, ctx); - } - for(std::list<EventListener*>::iterator listener = elementListeners.begin(); listener != elementListeners.end(); ++listener ){ - (*listener)->SetDispatched(false); - } - - dispatching = false; - - } - - /**command collaborator */ - virtual void AddEvent(const std::string & event) { - - std::pair<std::string, std::function<void()>> openEvent(event, [this, event]() { - ctx.currentTag = event; - ++ctx.triggerField[ParserState::userdefined]; - DispatchEvent(ParserState::userdefined, ElementState::open); - } ); - process_map.insert(openEvent); - - std::pair<std::string, std::function<void()>> closeEvent(event, [this, event]() { - ctx.currentTag = event; - DispatchEvent(ParserState::userdefined, ElementState::close); - --ctx.triggerField[ParserState::userdefined]; - } ); - - process_map2.insert(closeEvent); - - } - - /**command collaborator stateless */ - virtual void AddEvents(std::initializer_list<std::string> events) { - - for(const std::string & event : events){ - AddEvent(event); - } - - } - - /**command */ - virtual void RemoveEvent(const std::string & event) { - process_map.erase(event); - process_map2.erase(event); - } - - /**command collaborator stateless */ - virtual void RemoveEvents(std::initializer_list<std::string> events) { - - for(const std::string & event : events){ - RemoveEvent(event); - } - - } - - public: - ~srcSAXEventDispatcher() { - for(std::size_t count = 0; count < numberAllocatedListeners; ++count) { - delete elementListeners.front(); - elementListeners.pop_front(); - } - } - - srcSAXEventDispatcher(PolicyListener * listener) : EventDispatcher(srcml_element_stack) { - elementListeners = CreateListeners<policies...>(listener); - numberAllocatedListeners = elementListeners.size(); - dispatching = false; - classflagopen = functionflagopen = whileflagopen = ifflagopen = elseflagopen = ifelseflagopen = forflagopen = switchflagopen = false; - InitializeHandlers(); - } - - /**command collaborator stateless */ - void AddListener(EventListener* listener) override { - elementListeners.push_back(listener); - } - /**command collaborator */ - void AddListenerDispatch(EventListener* listener) override { - if(dispatching){ - listener->HandleEvent(currentPState, currentEState, ctx); - } - AddListener(listener); - } - /**command collaborator */ - void AddListenerNoDispatch(EventListener* listener) override { - if(dispatching){ - listener->SetDispatched(true); - } - AddListener(listener); - } - /**command collaborator */ - void RemoveListener(EventListener* listener) override { - elementListeners.erase(std::find(elementListeners.begin(), elementListeners.end(), listener)); - } - /**command collaborator */ - void RemoveListenerDispatch(EventListener* listener) override { - if(dispatching){ - listener->HandleEvent(currentPState, currentEState, ctx); - } - RemoveListener(listener); - } - /**command collaborator */ - void RemoveListenerNoDispatch(EventListener* listener) override { - if(dispatching){ - listener->SetDispatched(true); - } - RemoveListener(listener); - } - /**command */ - void InitializeHandlers(){ - process_map = { - {"decl_stmt", [this](){ - ++ctx.triggerField[ParserState::declstmt]; - DispatchEvent(ParserState::declstmt, ElementState::open); - } }, - { "expr_stmt", [this](){ - ++ctx.triggerField[ParserState::exprstmt]; - DispatchEvent(ParserState::exprstmt, ElementState::open); - } }, - { "parameter_list", [this](){ - ++ctx.triggerField[ParserState::parameterlist]; - DispatchEvent(ParserState::parameterlist, ElementState::open); - } }, - { "if", [this](){ - ifflagopen = true; - ++ctx.triggerField[ParserState::ifstmt]; - DispatchEvent(ParserState::ifstmt, ElementState::open); - } }, - { "for", [this](){ - ++ctx.triggerField[ParserState::forstmt]; - DispatchEvent(ParserState::forstmt, ElementState::open); - } }, - { "while", [this](){ - whileflagopen = true; - ++ctx.triggerField[ParserState::whilestmt]; - DispatchEvent(ParserState::whilestmt, ElementState::open); - } }, - { "template", [this](){ - ++ctx.triggerField[ParserState::templates]; - DispatchEvent(ParserState::templates, ElementState::open); - } }, - { "argument_list", [this](){ - if(!ctx.genericDepth.empty()){ - if(ctx.genericDepth.back() == ctx.depth){ - ++ctx.triggerField[ParserState::genericargumentlist]; - DispatchEvent(ParserState::genericargumentlist, ElementState::open); - } - } - DispatchEvent(ParserState::argumentlist, ElementState::open); - ++ctx.triggerField[ParserState::argumentlist]; - } }, - { "call", [this](){ - ++ctx.triggerField[ParserState::call]; - DispatchEvent(ParserState::call, ElementState::open); - } }, - { "function", [this](){ - functionflagopen = true; - ++ctx.triggerField[ParserState::function]; - DispatchEvent(ParserState::function, ElementState::open); - } }, - { "constructor", [this](){ - functionflagopen = true; - ++ctx.triggerField[ParserState::constructor]; - DispatchEvent(ParserState::constructor, ElementState::open); - } }, - { "function_decl", [this](){ - ++ctx.triggerField[ParserState::functiondecl]; - DispatchEvent(ParserState::functiondecl, ElementState::open); - } }, - { "destructor_decl", [this](){ - ++ctx.triggerField[ParserState::destructordecl]; - DispatchEvent(ParserState::destructordecl, ElementState::open); - } }, - { "constructor_decl", [this](){ - ++ctx.triggerField[ParserState::constructordecl]; - DispatchEvent(ParserState::constructordecl, ElementState::open); - } }, - { "class", [this](){ - classflagopen = true; - ++ctx.triggerField[ParserState::classn]; - DispatchEvent(ParserState::classn, ElementState::open); - } }, - { "struct", [this](){ - classflagopen = true; - ++ctx.triggerField[ParserState::classn]; - DispatchEvent(ParserState::structn, ElementState::open); - } }, - { "super_list", [this](){ - ++ctx.triggerField[ParserState::super_list]; - DispatchEvent(ParserState::super_list, ElementState::open); - } }, - { "super", [this](){ - ++ctx.triggerField[ParserState::super]; - DispatchEvent(ParserState::super, ElementState::open); - } }, - { "public", [this](){ - ++ctx.triggerField[ParserState::publicaccess]; - DispatchEvent(ParserState::publicaccess, ElementState::open); - } }, - { "protected", [this](){ - ++ctx.triggerField[ParserState::protectedaccess]; - DispatchEvent(ParserState::protectedaccess, ElementState::open); - } }, - { "private", [this](){ - ++ctx.triggerField[ParserState::privateaccess]; - DispatchEvent(ParserState::privateaccess, ElementState::open); - } }, - { "destructor", [this](){ - functionflagopen = true; - ++ctx.triggerField[ParserState::destructor]; - DispatchEvent(ParserState::destructor, ElementState::open); - } }, - { "parameter", [this](){ - ++ctx.triggerField[ParserState::parameter]; - DispatchEvent(ParserState::parameter, ElementState::open); - } }, - { "member_list", [this](){ - ++ctx.triggerField[ParserState::memberlist]; - DispatchEvent(ParserState::memberlist, ElementState::open); - } }, - { "index", [this](){ - ++ctx.triggerField[ParserState::index]; - DispatchEvent(ParserState::index, ElementState::open); - } }, - { "operator", [this](){ - ++ctx.triggerField[ParserState::op]; - DispatchEvent(ParserState::op, ElementState::open); - } }, - { "block", [this](){ - ++ctx.triggerField[ParserState::block]; - if(functionflagopen){ - functionflagopen = false; - ++ctx.triggerField[ParserState::functionblock]; - DispatchEvent(ParserState::functionblock, ElementState::open); - } - if(classflagopen){ - classflagopen = false; //next time it's set to true, we definitely are in a new one. - ++ctx.triggerField[ParserState::classblock]; - } - if(whileflagopen){ - whileflagopen = false; - ++ctx.triggerField[ParserState::whileblock]; - } - if(ifelseflagopen){ - ifflagopen = false; - ++ctx.triggerField[ParserState::ifblock]; - } - if(forflagopen){ - forflagopen = false; - ++ctx.triggerField[ParserState::forblock]; - } - DispatchEvent(ParserState::block, ElementState::open); - } }, - { "init", [this](){ - ++ctx.triggerField[ParserState::init]; - DispatchEvent(ParserState::init, ElementState::open); - } }, - { "argument", [this](){ - ++ctx.triggerField[ParserState::argument]; - DispatchEvent(ParserState::argument, ElementState::open); - } }, - { "literal", [this](){ - ++ctx.triggerField[ParserState::literal]; - DispatchEvent(ParserState::literal, ElementState::open); - } }, - { "modifier", [this](){ - ++ctx.triggerField[ParserState::modifier]; - DispatchEvent(ParserState::modifier, ElementState::open); - } }, - { "decl", [this](){ - ++ctx.triggerField[ParserState::decl]; - DispatchEvent(ParserState::decl, ElementState::open); - } }, - { "type", [this](){ - ++ctx.triggerField[ParserState::type]; - DispatchEvent(ParserState::type, ElementState::open); - } }, - { "typedef", [this](){ - ++ctx.triggerField[ParserState::typedefexpr]; - DispatchEvent(ParserState::typedefexpr, ElementState::open); - } }, - { "expr", [this](){ - ++ctx.triggerField[ParserState::expr]; - DispatchEvent(ParserState::expr, ElementState::open); - } }, - { "name", [this](){ - ++ctx.triggerField[ParserState::name]; - DispatchEvent(ParserState::name, ElementState::open); - } }, - { "macro", [this](){ - ++ctx.triggerField[ParserState::macro]; - DispatchEvent(ParserState::macro, ElementState::open); - } }, - { "specifier", [this](){ - ++ctx.triggerField[ParserState::specifier]; - DispatchEvent(ParserState::specifier, ElementState::open); - } }, - { "noun", [this](){ - ++ctx.triggerField[ParserState::snoun]; - DispatchEvent(ParserState::snoun, ElementState::open); - } }, - { "propernoun", [this](){ - ++ctx.triggerField[ParserState::propersnoun]; - DispatchEvent(ParserState::propersnoun, ElementState::open); - } }, - { "pronoun", [this](){ - ++ctx.triggerField[ParserState::spronoun]; - DispatchEvent(ParserState::spronoun, ElementState::open); - } }, - { "adjective", [this](){ - ++ctx.triggerField[ParserState::sadjective]; - DispatchEvent(ParserState::sadjective, ElementState::open); - } }, - { "verb", [this](){ - ++ctx.triggerField[ParserState::sverb]; - DispatchEvent(ParserState::sverb, ElementState::open); - } } - }; - process_map2 = { - {"decl_stmt", [this](){ - DispatchEvent(ParserState::declstmt, ElementState::close); - --ctx.triggerField[ParserState::declstmt]; - } }, - { "expr_stmt", [this](){ - DispatchEvent(ParserState::exprstmt, ElementState::close); - --ctx.triggerField[ParserState::exprstmt]; - } }, - { "parameter_list", [this](){ - DispatchEvent(ParserState::parameterlist, ElementState::close); - --ctx.triggerField[ParserState::parameterlist]; - } }, - { "if", [this](){ - --ctx.triggerField[ParserState::ifblock]; - DispatchEvent(ParserState::ifstmt, ElementState::close); - --ctx.triggerField[ParserState::ifstmt]; - } }, - { "for", [this](){ - --ctx.triggerField[ParserState::forblock]; - DispatchEvent(ParserState::forstmt, ElementState::close); - --ctx.triggerField[ParserState::forstmt]; - } }, - { "while", [this](){ - --ctx.triggerField[ParserState::whileblock]; - DispatchEvent(ParserState::whilestmt, ElementState::close); - --ctx.triggerField[ParserState::whilestmt]; - } }, - { "template", [this](){ - DispatchEvent(ParserState::templates, ElementState::close); - --ctx.triggerField[ParserState::templates]; - } }, - { "argument_list", [this](){ - if(!ctx.genericDepth.empty()){ - if(ctx.genericDepth.back() == ctx.depth){ - DispatchEvent(ParserState::genericargumentlist, ElementState::close); - --ctx.triggerField[ParserState::genericargumentlist]; - ctx.genericDepth.pop_back(); - } - } - DispatchEvent(ParserState::argumentlist, ElementState::close); - --ctx.triggerField[ParserState::argumentlist]; - } }, - { "call", [this](){ - DispatchEvent(ParserState::call, ElementState::close); - --ctx.triggerField[ParserState::call]; - } }, - { "function", [this](){ - DispatchEvent(ParserState::functionblock, ElementState::close); - --ctx.triggerField[ParserState::functionblock]; - - DispatchEvent(ParserState::function, ElementState::close); - --ctx.triggerField[ParserState::function]; - } }, - { "constructor", [this](){ - DispatchEvent(ParserState::functionblock, ElementState::close); - --ctx.triggerField[ParserState::functionblock]; - - DispatchEvent(ParserState::constructor, ElementState::close); - --ctx.triggerField[ParserState::constructor]; - } }, - { "destructor", [this](){ - DispatchEvent(ParserState::functionblock, ElementState::close); - --ctx.triggerField[ParserState::functionblock]; - - DispatchEvent(ParserState::destructor, ElementState::close); - --ctx.triggerField[ParserState::destructor]; - } }, - { "function_decl", [this](){ - DispatchEvent(ParserState::functiondecl, ElementState::close); - --ctx.triggerField[ParserState::functiondecl]; - } }, - { "constructor_decl", [this](){ - DispatchEvent(ParserState::constructordecl, ElementState::close); - --ctx.triggerField[ParserState::constructordecl]; - } }, - { "destructor_decl", [this](){ - DispatchEvent(ParserState::destructordecl, ElementState::close); - --ctx.triggerField[ParserState::destructordecl]; - } }, - { "class", [this](){ - --ctx.triggerField[ParserState::classblock]; - DispatchEvent(ParserState::classn, ElementState::close); - --ctx.triggerField[ParserState::classn]; - } }, - { "struct", [this](){ - DispatchEvent(ParserState::structn, ElementState::close); - --ctx.triggerField[ParserState::classn]; - } }, - { "super_list", [this](){ - DispatchEvent(ParserState::super_list, ElementState::close); - --ctx.triggerField[ParserState::super_list]; - } }, - { "super", [this](){ - DispatchEvent(ParserState::super, ElementState::close); - --ctx.triggerField[ParserState::super]; - } }, - { "public", [this](){ - DispatchEvent(ParserState::publicaccess, ElementState::close); - --ctx.triggerField[ParserState::publicaccess]; - } }, - { "protected", [this](){ - DispatchEvent(ParserState::protectedaccess, ElementState::close); - --ctx.triggerField[ParserState::protectedaccess]; - } }, - { "private", [this](){ - DispatchEvent(ParserState::privateaccess, ElementState::close); - --ctx.triggerField[ParserState::privateaccess]; - } }, - { "parameter", [this](){ - DispatchEvent(ParserState::parameter, ElementState::close); - --ctx.triggerField[ParserState::parameter]; - } }, - { "member_list", [this](){ - DispatchEvent(ParserState::memberlist, ElementState::close); - --ctx.triggerField[ParserState::memberlist]; - } }, - { "index", [this](){ - DispatchEvent(ParserState::index, ElementState::close); - --ctx.triggerField[ParserState::index]; - } }, - { "operator", [this](){ - DispatchEvent(ParserState::op, ElementState::close); - --ctx.triggerField[ParserState::op]; - } }, - { "block", [this](){ - DispatchEvent(ParserState::block, ElementState::close); - --ctx.triggerField[ParserState::block]; - } }, - { "init", [this](){ - DispatchEvent(ParserState::init, ElementState::close); - --ctx.triggerField[ParserState::init]; - } }, - { "argument", [this](){ - DispatchEvent(ParserState::argument, ElementState::close); - --ctx.triggerField[ParserState::argument]; - } }, - { "literal", [this](){ - DispatchEvent(ParserState::literal, ElementState::close); - --ctx.triggerField[ParserState::literal]; - } }, - { "modifier", [this](){ - DispatchEvent(ParserState::modifier, ElementState::close); - --ctx.triggerField[ParserState::modifier]; - } }, - { "decl", [this](){ - DispatchEvent(ParserState::decl, ElementState::close); - --ctx.triggerField[ParserState::decl]; - } }, - { "type", [this](){ - DispatchEvent(ParserState::type, ElementState::close); - --ctx.triggerField[ParserState::type]; - } }, - { "typedef", [this](){ - DispatchEvent(ParserState::typedefexpr, ElementState::close); - --ctx.triggerField[ParserState::typedefexpr]; - } }, - { "expr", [this](){ - DispatchEvent(ParserState::expr, ElementState::close); - --ctx.triggerField[ParserState::expr]; - } }, - { "name", [this](){ - DispatchEvent(ParserState::name, ElementState::close); - --ctx.triggerField[ParserState::name]; - } }, - { "macro", [this](){ - DispatchEvent(ParserState::macro, ElementState::close); - --ctx.triggerField[ParserState::macro]; - } }, - { "specifier", [this](){ - DispatchEvent(ParserState::specifier, ElementState::close); - --ctx.triggerField[ParserState::specifier]; - } }, - { "noun", [this](){ - --ctx.triggerField[ParserState::snoun]; - DispatchEvent(ParserState::snoun, ElementState::close); - } }, - { "propernoun", [this](){ - --ctx.triggerField[ParserState::propersnoun]; - DispatchEvent(ParserState::propersnoun, ElementState::close); - } }, - { "pronoun", [this](){ - --ctx.triggerField[ParserState::spronoun]; - DispatchEvent(ParserState::spronoun, ElementState::close); - } }, - { "adjective", [this](){ - --ctx.triggerField[ParserState::sadjective]; - DispatchEvent(ParserState::sadjective, ElementState::close); - } }, - { "verb", [this](){ - --ctx.triggerField[ParserState::sverb]; - DispatchEvent(ParserState::sverb, ElementState::close); - } }, - { "xmlattribute", [this](){ - ctx.triggerField[ParserState::xmlattribute] = 1; - DispatchEvent(ParserState::xmlattribute, ElementState::close); - ctx.triggerField[ParserState::xmlattribute] = 0; - } }, - { "tokenstring", [this](){ - ctx.triggerField[ParserState::tokenstring] = 1; - DispatchEvent(ParserState::tokenstring, ElementState::close); - ctx.triggerField[ParserState::tokenstring] = 0; - } } - }; - } - - /* - virtual void startDocument() {} - virtual void endDocument() {} - */ - - /** - * startRoot - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param nb_defaulted the number of defaulted attributes - * @param attributes list of attribute name value pairs (localname/prefix/URI/value/end) - * - * SAX handler function for start of the root element. - * Counts the root unit (if an archive, to avoid double count with startUnit). - * Overide for desired behaviour. - */ - virtual void startRoot(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) override { - - } - /** - * startUnit - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param nb_defaulted the number of defaulted attributes - * @param attributes list of attribute name value pairs (localname/prefix/URI/value/end) - * - * SAX handler function for start of an unit. - * Counts each unit tag (= filecount non-archive, = filecount + 1 if archive). - * Overide for desired behaviour. - */ - virtual void startUnit(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) override { - if(num_attributes >= 3){ - ctx.currentFilePath = std::string(attributes[2].value); - ctx.currentFileLanguage = std::string(attributes[1].value); - ctx.currentsrcMLRevision = std::string(attributes[0].value); - } - } - /** - * startElementNs - * @param localname the name of the element tag - * @param prefix the tag prefix - * @param URI the namespace of tag - * @param nb_namespaces number of namespaces definitions - * @param namespaces the defined namespaces - * @param nb_attributes the number of attributes on the tag - * @param nb_defaulted the number of defaulted attributes - * @param attributes list of attribute name value pairs (localname/prefix/URI/value/end) - * - * SAX handler function for start of an element. - * Overide for desired behaviour. - */ - virtual void startElement(const char * localname, const char * prefix, const char * URI, - int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, - const struct srcsax_attribute * attributes) override { - - ++ctx.depth; - - std::string localName; - if(prefix) { - localName += prefix; - localName += ':'; - } - localName += localname; - - ctx.currentTag = localName; - - if(localName == "pos:position"){ - ctx.currentLineNumber = strtoul(attributes[0].value, NULL, 0); - } - std::string name; - if(num_attributes){ - name = attributes[0].value; - } - if(name == "generic" && localName == "argument_list"){ - ctx.genericDepth.push_back(ctx.depth); - } - - if(name == "operator" && (localName == "function" || localName == "function_decl")) { - ctx.isOperator = true; - } - - if(localName != ""){ - //std::cerr<<"local: "<<localname<<std::endl; - std::unordered_map<std::string, std::function<void()>>::const_iterator process = process_map.find(localname); - if (process != process_map.end()) { - process->second(); - } - } - - for(int pos = 0; pos < num_attributes; ++pos) { - - ctx.currentAttributeName = ""; - if(attributes[pos].prefix) { - ctx.currentAttributeName += attributes[pos].prefix; - ctx.currentAttributeName += ':'; - } - ctx.currentAttributeName += attributes[pos].localname; - ctx.currentAttributeValue = attributes[pos].value; - std::unordered_map<std::string, std::function<void()>>::const_iterator process = process_map2.find("xmlattribute"); - process->second(); - - } - - ctx.isOperator = false; - - } - /** - * charactersUnit - * @param ch the characers - * @param len number of characters - * - * SAX handler function for character handling within a unit. - * Overide for desired behaviour. - */ - virtual void charactersUnit(const char * ch, int len) override { - ctx.currentToken.clearclearclear(); - ctx.currentToken.append(ch, len); - std::unordered_map<std::string, std::function<void()>>::const_iterator process = process_map2.find("tokenstring"); - process->second(); - } - - // end elements may need to be used if you want to collect only on per file basis or some other granularity. - virtual void endRoot(const char * localname, const char * prefix, const char * URI) override { - - } - virtual void endUnit(const char * localname, const char * prefix, const char * URI) override { - - } - - virtual void endElement(const char * localname, const char * prefix, const char * URI) override { - - std::string localName; - if(prefix) { - localName += prefix; - localName += ':'; - } - localName += localname; - - ctx.currentTag = localName; - - std::unordered_map<std::string, std::function<void()>>::const_iterator process2 = process_map2.find(localname); - if (process2 != process_map2.end()) { - process2->second(); - } - - --ctx.depth; - - } - #pragma GCC diagnostic pop - - }; -} -#endif - - \ No newline at end of file From bfdc0265a4400428ec2dad388b94cdd36c27e97f Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 09:13:11 +0900 Subject: [PATCH 126/149] Fix build --- CMakeLists.txt | 10 +++++----- test/CMakeLists.txt | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b8c1f9..b2ea958 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,22 +33,22 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_definitions("-Wall") -add_subdirectory(srcDispatch/CMake) +add_subdirectory(srcSAX/CMake) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(SRCDIFF_DISPATCH_INCLUDE_DIR ${SRCSAX_INCLUDE_DIR} +set(SRCDISPATCH_INCLUDE_DIR ${SRCSAX_INCLUDE_DIR} src/policy_classes src/dispatcher CACHE INTERNAL "Include directories for srcDispatch") -set(SRCDIFF_DISPATCH_LIBRARIES ${SRCSAX_LIBRARIES} CACHE INTERNAL "Libraries for srcDiffDispatch") +set(SRCDISPATCH_LIBRARIES ${SRCSAX_LIBRARIES} CACHE INTERNAL "Libraries for srcDiffDispatch") # include needed includes -include_directories(${SRCDIFF_DISPATCH_INCLUDE_DIR}) +include_directories(${SRCDISPATCH_INCLUDE_DIR}) -# Continue to src +# Continue to src/test add_subdirectory(src) add_subdirectory(test) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ce54c13..6180033 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -31,7 +31,7 @@ macro(add_unit_test TEST_FILE) string(SUBSTRING ${TEST_NAME_WITH_EXTENSION} 0 ${EXTENSION_BEGIN} TEST_NAME) add_executable(${TEST_NAME} ${TEST_FILE}) - target_link_libraries(${TEST_NAME} $ $ $ LibXml2::LibXml2 Boost::boost ${ARGN}) + target_link_libraries(${TEST_NAME} $ $ LibXml2::LibXml2 Boost::boost ${ARGN}) add_test(NAME ${TEST_NAME} COMMAND $) set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) From 6e6b1ddd10ae8894f015ba8c113058e3328ec16e Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 09:13:52 +0900 Subject: [PATCH 127/149] Add back in AccessSpecifier --- src/policy_classes/AccessSpecifier.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/policy_classes/AccessSpecifier.hpp diff --git a/src/policy_classes/AccessSpecifier.hpp b/src/policy_classes/AccessSpecifier.hpp new file mode 100644 index 0000000..ef4b8bb --- /dev/null +++ b/src/policy_classes/AccessSpecifier.hpp @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file AccessSpecifier.hpp + * + * @copyright Copyright (C) 2025-2025 srcML, LLC. (www.srcML.org) + * + * This file is part of the srcML Infrastructure. + */ + +#ifndef INCLUDED_ACCESS_SPECIFIER_HPP +#define INCLUDED_ACCESS_SPECIFIER_HPP + +enum AccessSpecifier { + NONE = 0, + PUBLIC = 1, + PRIVATE = 2, + PROTECTED = 3 +}; + +#endif From a106b46da655b193690a53ffc65d591c4dd693a6 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 09:27:37 +0900 Subject: [PATCH 128/149] Finish build success --- src/policy_classes/BlockPolicy.cpp | 8 +- src/policy_classes/BlockPolicy.hpp | 8 +- src/policy_classes/CallPolicy.cpp | 8 +- src/policy_classes/CallPolicy.hpp | 8 +- src/policy_classes/CasePolicy.hpp | 8 +- src/policy_classes/CatchPolicy.hpp | 8 +- src/policy_classes/ClassPolicy.cpp | 8 +- src/policy_classes/ClassPolicy.hpp | 8 +- src/policy_classes/ConditionPolicy.hpp | 8 +- src/policy_classes/ConditionalPolicy.hpp | 8 +- src/policy_classes/ControlPolicy.hpp | 8 +- src/policy_classes/ConvertPlexerPolicy.hpp | 6 +- src/policy_classes/DeclPolicy.hpp | 8 +- src/policy_classes/DeclStmtPolicy.hpp | 8 +- src/policy_classes/DeltaElement.hpp | 6 +- src/policy_classes/DeltaElement.tcc | 8 +- src/policy_classes/DoPolicy.hpp | 8 +- src/policy_classes/ElseIfPolicy.hpp | 8 +- src/policy_classes/ElsePolicy.hpp | 8 +- src/policy_classes/ExprStmtPolicy.hpp | 8 +- src/policy_classes/ExprTypePolicy.hpp | 8 +- src/policy_classes/ExpressionPolicy.cpp | 8 +- src/policy_classes/ExpressionPolicy.hpp | 8 +- src/policy_classes/ForPolicy.hpp | 8 +- src/policy_classes/FunctionPolicy.hpp | 8 +- src/policy_classes/GenericArgumentsPolicy.cpp | 8 +- src/policy_classes/GenericArgumentsPolicy.hpp | 8 +- src/policy_classes/GenericPolicy.cpp | 8 +- src/policy_classes/GenericPolicy.hpp | 8 +- src/policy_classes/GotoPolicy.hpp | 8 +- src/policy_classes/IfPolicy.hpp | 8 +- src/policy_classes/IfStmtPolicy.hpp | 8 +- src/policy_classes/IncrPolicy.hpp | 8 +- src/policy_classes/InitPolicy.hpp | 8 +- src/policy_classes/LabelPolicy.hpp | 8 +- src/policy_classes/LiteralPolicy.hpp | 8 +- src/policy_classes/NamePolicy.cpp | 8 +- src/policy_classes/NamePolicy.hpp | 8 +- src/policy_classes/OperatorPolicy.hpp | 8 +- src/policy_classes/ReturnPolicy.hpp | 8 +- src/policy_classes/SwitchPolicy.hpp | 8 +- src/policy_classes/ThrowPolicy.hpp | 8 +- src/policy_classes/TryPolicy.hpp | 8 +- src/policy_classes/TypePolicy.cpp | 8 +- src/policy_classes/TypePolicy.hpp | 8 +- src/policy_classes/UnitPolicy.hpp | 8 +- src/policy_classes/WhilePolicy.hpp | 8 +- test/suite/testCall.cpp | 120 ++--- test/suite/testCase.cpp | 22 +- test/suite/testClass.cpp | 504 +++++++++--------- test/suite/testClassConvert.cpp | 16 +- test/suite/testCondition.cpp | 42 +- test/suite/testConditionalConvert.cpp | 52 +- test/suite/testControl.cpp | 296 +++++----- test/suite/testDecl.cpp | 482 ++++++++--------- test/suite/testDeclStmt.cpp | 18 +- test/suite/testDo.cpp | 46 +- test/suite/testExprConvert.cpp | 60 +-- test/suite/testExprStmt.cpp | 58 +- test/suite/testFor.cpp | 18 +- test/suite/testFunction.cpp | 178 +++---- test/suite/testGoto.cpp | 66 +-- test/suite/testIfStmt.cpp | 206 +++---- test/suite/testLabel.cpp | 8 +- test/suite/testReturn.cpp | 68 +-- test/suite/testSwitch.cpp | 46 +- test/suite/testTemplate.cpp | 56 +- test/suite/testThrow.cpp | 34 +- test/suite/testTry.cpp | 118 ++-- test/suite/testWhile.cpp | 72 +-- ...fDispatchRunner.hpp => DispatchRunner.hpp} | 19 +- 71 files changed, 1488 insertions(+), 1489 deletions(-) rename test/util/{srcDiffDispatchRunner.hpp => DispatchRunner.hpp} (83%) diff --git a/src/policy_classes/BlockPolicy.cpp b/src/policy_classes/BlockPolicy.cpp index d181dcb..bd43930 100644 --- a/src/policy_classes/BlockPolicy.cpp +++ b/src/policy_classes/BlockPolicy.cpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffBlockPolicy.cpp + * @file BlockPolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #include @@ -22,7 +22,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { BlockPolicy::BlockPolicy(std::initializer_list listeners) : srcDispatch::PolicyDispatcher(listeners), data{} { diff --git a/src/policy_classes/BlockPolicy.hpp b/src/policy_classes/BlockPolicy.hpp index 30b7217..2c9bdc9 100644 --- a/src/policy_classes/BlockPolicy.hpp +++ b/src/policy_classes/BlockPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffBlockPolicy.hpp + * @file BlockPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_BLOCK_POLICY_HPP @@ -27,7 +27,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { class IfStmtPolicy; class SwitchPolicy; diff --git a/src/policy_classes/CallPolicy.cpp b/src/policy_classes/CallPolicy.cpp index 2532b65..43e0762 100644 --- a/src/policy_classes/CallPolicy.cpp +++ b/src/policy_classes/CallPolicy.cpp @@ -1,16 +1,16 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffCallPolicy.cpp + * @file CallPolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { std::string CallData::ToString(srcDispatch::DiffOperation operation) const { diff --git a/src/policy_classes/CallPolicy.hpp b/src/policy_classes/CallPolicy.hpp index 2700faf..e7e7ebb 100644 --- a/src/policy_classes/CallPolicy.hpp +++ b/src/policy_classes/CallPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffCallPolicy.hpp + * @file CallPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_CALL_POLICY_HPP @@ -27,7 +27,7 @@ // Gets the name and list of arguments // -namespace srcDiffDispatch { +namespace srcDispatch { struct ExpressionData; class ExpressionPolicy; diff --git a/src/policy_classes/CasePolicy.hpp b/src/policy_classes/CasePolicy.hpp index 6c4361a..d9b7c2c 100644 --- a/src/policy_classes/CasePolicy.hpp +++ b/src/policy_classes/CasePolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffCasePolicy.hpp + * @file CasePolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_CASE_POLICY_HPP @@ -20,7 +20,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct CaseData { DeltaElement> expr; diff --git a/src/policy_classes/CatchPolicy.hpp b/src/policy_classes/CatchPolicy.hpp index f5c8736..f8654e3 100644 --- a/src/policy_classes/CatchPolicy.hpp +++ b/src/policy_classes/CatchPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffCatchPolicy.hpp + * @file CatchPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_CATCH_POLICY_HPP @@ -22,7 +22,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct CatchData { diff --git a/src/policy_classes/ClassPolicy.cpp b/src/policy_classes/ClassPolicy.cpp index a3f83ec..c4214d2 100644 --- a/src/policy_classes/ClassPolicy.cpp +++ b/src/policy_classes/ClassPolicy.cpp @@ -1,15 +1,15 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffBlockPolicy.cpp + * @file BlockPolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #include -namespace srcDiffDispatch { +namespace srcDispatch { const std::unordered_map ClassPolicy::stateToTypeMapper = { {srcDispatch::ParserState::classn, ClassData::CLASS}, diff --git a/src/policy_classes/ClassPolicy.hpp b/src/policy_classes/ClassPolicy.hpp index ce3dcd3..701b728 100644 --- a/src/policy_classes/ClassPolicy.hpp +++ b/src/policy_classes/ClassPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffClassPolicy.hpp + * @file ClassPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_CLASS_POLICY_HPP @@ -25,7 +25,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct ParentData; diff --git a/src/policy_classes/ConditionPolicy.hpp b/src/policy_classes/ConditionPolicy.hpp index 0eefaf8..f52dcad 100644 --- a/src/policy_classes/ConditionPolicy.hpp +++ b/src/policy_classes/ConditionPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffConditionPolicy.hpp + * @file ConditionPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_CONDITION_POLICY_HPP @@ -21,7 +21,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct ConditionData { std::vector> conditions; diff --git a/src/policy_classes/ConditionalPolicy.hpp b/src/policy_classes/ConditionalPolicy.hpp index 63d4e17..550a4bf 100644 --- a/src/policy_classes/ConditionalPolicy.hpp +++ b/src/policy_classes/ConditionalPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffConditionalPolicy.hpp + * @file ConditionalPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_CONDITIONAL_POLICY_HPP @@ -21,7 +21,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { template class ConditionalPolicy : diff --git a/src/policy_classes/ControlPolicy.hpp b/src/policy_classes/ControlPolicy.hpp index 6e28a73..04a0a5d 100644 --- a/src/policy_classes/ControlPolicy.hpp +++ b/src/policy_classes/ControlPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffControlPolicy.hpp + * @file ControlPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_CONTROL_POLICY_HPP @@ -23,7 +23,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct ControlData { diff --git a/src/policy_classes/ConvertPlexerPolicy.hpp b/src/policy_classes/ConvertPlexerPolicy.hpp index a747f5f..b812e2c 100644 --- a/src/policy_classes/ConvertPlexerPolicy.hpp +++ b/src/policy_classes/ConvertPlexerPolicy.hpp @@ -2,9 +2,9 @@ /** * @file ConvertPlexerPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_CONVERT_PLEXER_POLICY_HPP @@ -31,7 +31,7 @@ // #define CONVERT_DEBUG -namespace srcDiffDispatch { +namespace srcDispatch { struct ConvertData { DeltaElement construct; diff --git a/src/policy_classes/DeclPolicy.hpp b/src/policy_classes/DeclPolicy.hpp index 9071e3a..47ae17e 100644 --- a/src/policy_classes/DeclPolicy.hpp +++ b/src/policy_classes/DeclPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffDeclPolicy.hpp + * @file DeclPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_DECL_POLICY_HPP @@ -22,7 +22,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct DeclData { diff --git a/src/policy_classes/DeclStmtPolicy.hpp b/src/policy_classes/DeclStmtPolicy.hpp index a316ae8..9974095 100644 --- a/src/policy_classes/DeclStmtPolicy.hpp +++ b/src/policy_classes/DeclStmtPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffDeclStmtPolicy.hpp + * @file DeclStmtPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_DECL_TYPE_POLICY_HPP @@ -17,7 +17,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct DeclStmtData { diff --git a/src/policy_classes/DeltaElement.hpp b/src/policy_classes/DeltaElement.hpp index 51e1564..4e16764 100644 --- a/src/policy_classes/DeltaElement.hpp +++ b/src/policy_classes/DeltaElement.hpp @@ -2,9 +2,9 @@ /** * @file DeltaElement.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_DELTA_ELEMENT_HPP @@ -16,7 +16,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { template class DeltaElement { diff --git a/src/policy_classes/DeltaElement.tcc b/src/policy_classes/DeltaElement.tcc index 520a3c5..a416512 100644 --- a/src/policy_classes/DeltaElement.tcc +++ b/src/policy_classes/DeltaElement.tcc @@ -2,9 +2,9 @@ /** * @file DeltaElement.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #include @@ -42,13 +42,13 @@ struct ValueConst> { }; template -std::ostream& operator<<(std::ostream& out, const srcDiffDispatch::DeltaElement& element) { +std::ostream& operator<<(std::ostream& out, const srcDispatch::DeltaElement& element) { assert(element.GetOperation() != srcDispatch::NONE); return out << element.ToString(srcDispatch::NONE); } -namespace srcDiffDispatch { +namespace srcDispatch { template DeltaElement::DeltaElement() diff --git a/src/policy_classes/DoPolicy.hpp b/src/policy_classes/DoPolicy.hpp index 8c0f99f..a558c0f 100644 --- a/src/policy_classes/DoPolicy.hpp +++ b/src/policy_classes/DoPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffDoPolicy.hpp + * @file DoPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_DO_POLICY_HPP @@ -18,7 +18,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct DoData { diff --git a/src/policy_classes/ElseIfPolicy.hpp b/src/policy_classes/ElseIfPolicy.hpp index 48f5311..7505a46 100644 --- a/src/policy_classes/ElseIfPolicy.hpp +++ b/src/policy_classes/ElseIfPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffElseIfPolicy.hpp + * @file ElseIfPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_ELSEIF_POLICY_HPP @@ -18,7 +18,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct ElseIfData { diff --git a/src/policy_classes/ElsePolicy.hpp b/src/policy_classes/ElsePolicy.hpp index a2a425f..255f2d8 100644 --- a/src/policy_classes/ElsePolicy.hpp +++ b/src/policy_classes/ElsePolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffElsePolicy.hpp + * @file ElsePolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_ELSE_POLICY_HPP @@ -18,7 +18,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct ElseData { diff --git a/src/policy_classes/ExprStmtPolicy.hpp b/src/policy_classes/ExprStmtPolicy.hpp index 6d7a5fa..6cece16 100644 --- a/src/policy_classes/ExprStmtPolicy.hpp +++ b/src/policy_classes/ExprStmtPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffExprStmtPolicy.hpp + * @file ExprStmtPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_EXPR_STMT_POLICY_HPP @@ -20,7 +20,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct ExprStmtData { DeltaElement> expr; diff --git a/src/policy_classes/ExprTypePolicy.hpp b/src/policy_classes/ExprTypePolicy.hpp index a256e2e..67209d7 100644 --- a/src/policy_classes/ExprTypePolicy.hpp +++ b/src/policy_classes/ExprTypePolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffExprTypePolicy.hpp + * @file ExprTypePolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_EXPR_TYPE_POLICY_HPP @@ -20,7 +20,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { template class ExprTypePolicy : diff --git a/src/policy_classes/ExpressionPolicy.cpp b/src/policy_classes/ExpressionPolicy.cpp index de05b10..cd6701a 100644 --- a/src/policy_classes/ExpressionPolicy.cpp +++ b/src/policy_classes/ExpressionPolicy.cpp @@ -1,16 +1,16 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffExpressionPolicy.cpp + * @file ExpressionPolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { std::string ExpressionData::ToString(srcDispatch::DiffOperation operation) const { diff --git a/src/policy_classes/ExpressionPolicy.hpp b/src/policy_classes/ExpressionPolicy.hpp index e655044..b7b0d57 100644 --- a/src/policy_classes/ExpressionPolicy.hpp +++ b/src/policy_classes/ExpressionPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffExpressionPolicy.hpp + * @file ExpressionPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_EXPRESSION_POLICY_HPP @@ -23,7 +23,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct CallData; class CallPolicy; diff --git a/src/policy_classes/ForPolicy.hpp b/src/policy_classes/ForPolicy.hpp index 04dd39b..80ee293 100644 --- a/src/policy_classes/ForPolicy.hpp +++ b/src/policy_classes/ForPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffForPolicy.hpp + * @file ForPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_FOR_POLICY_HPP @@ -21,7 +21,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { class BlockPolicy; struct BlockData; diff --git a/src/policy_classes/FunctionPolicy.hpp b/src/policy_classes/FunctionPolicy.hpp index 3a5fd0a..38b4cda 100644 --- a/src/policy_classes/FunctionPolicy.hpp +++ b/src/policy_classes/FunctionPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffFunctionPolicy.hpp + * @file FunctionPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_FUNCTION_POLICY_HPP @@ -26,7 +26,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct FunctionData { diff --git a/src/policy_classes/GenericArgumentsPolicy.cpp b/src/policy_classes/GenericArgumentsPolicy.cpp index ad7ef53..d6325dd 100644 --- a/src/policy_classes/GenericArgumentsPolicy.cpp +++ b/src/policy_classes/GenericArgumentsPolicy.cpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffGenericArgumentsPolicy.cpp + * @file GenericArgumentsPolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #include @@ -13,7 +13,7 @@ #include -namespace srcDiffDispatch { +namespace srcDispatch { std::string GenericArgumentsData::ToString(srcDispatch::DiffOperation operation) const { diff --git a/src/policy_classes/GenericArgumentsPolicy.hpp b/src/policy_classes/GenericArgumentsPolicy.hpp index 5f83c9d..e131386 100644 --- a/src/policy_classes/GenericArgumentsPolicy.hpp +++ b/src/policy_classes/GenericArgumentsPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffGenericArgumentsPolicy.hpp + * @file GenericArgumentsPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_GENERIC_ARGUMENTS_POLICY_HPP @@ -14,7 +14,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { class NamePolicy; class ExpressionPolicy; diff --git a/src/policy_classes/GenericPolicy.cpp b/src/policy_classes/GenericPolicy.cpp index 31103e9..0a847b0 100644 --- a/src/policy_classes/GenericPolicy.cpp +++ b/src/policy_classes/GenericPolicy.cpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffGenericPolicy.cpp + * @file GenericPolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #include @@ -15,7 +15,7 @@ #include -namespace srcDiffDispatch { +namespace srcDispatch { std::string GenericData::ToString(srcDispatch::DiffOperation operation) const { diff --git a/src/policy_classes/GenericPolicy.hpp b/src/policy_classes/GenericPolicy.hpp index fd7a10d..84aa91d 100644 --- a/src/policy_classes/GenericPolicy.hpp +++ b/src/policy_classes/GenericPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffGenericPolicy.hpp + * @file GenericPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_GENERIC_POLICY_HPP @@ -15,7 +15,7 @@ #include -namespace srcDiffDispatch { +namespace srcDispatch { class DeclPolicy; struct DeclData; diff --git a/src/policy_classes/GotoPolicy.hpp b/src/policy_classes/GotoPolicy.hpp index 7b16e17..eabbb36 100644 --- a/src/policy_classes/GotoPolicy.hpp +++ b/src/policy_classes/GotoPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffGotoPolicy.hpp + * @file GotoPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_GOTO_POLICY_HPP @@ -21,7 +21,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct GotoData { enum GotoType { GOTO, BREAK, CONTINUE }; diff --git a/src/policy_classes/IfPolicy.hpp b/src/policy_classes/IfPolicy.hpp index 1869283..5d9680f 100644 --- a/src/policy_classes/IfPolicy.hpp +++ b/src/policy_classes/IfPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffIfPolicy.hpp + * @file IfPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_IF_POLICY_HPP @@ -18,7 +18,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct IfData { diff --git a/src/policy_classes/IfStmtPolicy.hpp b/src/policy_classes/IfStmtPolicy.hpp index 8d6d93c..930684d 100644 --- a/src/policy_classes/IfStmtPolicy.hpp +++ b/src/policy_classes/IfStmtPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffIfStmtPolicy.hpp + * @file IfStmtPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_IF_STMT_POLICY_HPP @@ -22,7 +22,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct IfStmtData { diff --git a/src/policy_classes/IncrPolicy.hpp b/src/policy_classes/IncrPolicy.hpp index de9af60..c2799f8 100644 --- a/src/policy_classes/IncrPolicy.hpp +++ b/src/policy_classes/IncrPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffIncrPolicy.hpp + * @file IncrPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_INCR_POLICY_HPP @@ -21,7 +21,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct IncrData { diff --git a/src/policy_classes/InitPolicy.hpp b/src/policy_classes/InitPolicy.hpp index 4bf9bbc..3cc8097 100644 --- a/src/policy_classes/InitPolicy.hpp +++ b/src/policy_classes/InitPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffInitPolicy.hpp + * @file InitPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_INIT_POLICY_HPP @@ -21,7 +21,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct InitData { diff --git a/src/policy_classes/LabelPolicy.hpp b/src/policy_classes/LabelPolicy.hpp index b8b7dd8..504fdc0 100644 --- a/src/policy_classes/LabelPolicy.hpp +++ b/src/policy_classes/LabelPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffLabelPolicy.hpp + * @file LabelPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_LABEL_POLICY_HPP @@ -21,7 +21,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct LabelData { DeltaElement> name; diff --git a/src/policy_classes/LiteralPolicy.hpp b/src/policy_classes/LiteralPolicy.hpp index 8bcaa82..9f87a7b 100644 --- a/src/policy_classes/LiteralPolicy.hpp +++ b/src/policy_classes/LiteralPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffLiteralPolicy.hpp + * @file LiteralPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_LITERAL_POLICY_HPP @@ -18,7 +18,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct LiteralData { diff --git a/src/policy_classes/NamePolicy.cpp b/src/policy_classes/NamePolicy.cpp index d1c55df..9470c9d 100644 --- a/src/policy_classes/NamePolicy.cpp +++ b/src/policy_classes/NamePolicy.cpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffNamePolicy.cpp + * @file NamePolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #include @@ -13,7 +13,7 @@ #include -namespace srcDiffDispatch { +namespace srcDispatch { std::string NameData::SimpleName() const { if(name) return name.ToString(); diff --git a/src/policy_classes/NamePolicy.hpp b/src/policy_classes/NamePolicy.hpp index baeb014..c51c189 100644 --- a/src/policy_classes/NamePolicy.hpp +++ b/src/policy_classes/NamePolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffNamePolicy.hpp + * @file NamePolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_NAME_POLICY_HPP @@ -19,7 +19,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { class ExpressionPolicy; struct ExpressionData; diff --git a/src/policy_classes/OperatorPolicy.hpp b/src/policy_classes/OperatorPolicy.hpp index 6344865..e835574 100644 --- a/src/policy_classes/OperatorPolicy.hpp +++ b/src/policy_classes/OperatorPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffOperatorPolicy.hpp + * @file OperatorPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_OPERATOR_POLICY_HPP @@ -18,7 +18,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct OperatorData { diff --git a/src/policy_classes/ReturnPolicy.hpp b/src/policy_classes/ReturnPolicy.hpp index aada20b..881b01a 100644 --- a/src/policy_classes/ReturnPolicy.hpp +++ b/src/policy_classes/ReturnPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffReturnPolicy.hpp + * @file ReturnPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_RETURN_POLICY_HPP @@ -20,7 +20,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct ReturnData { DeltaElement> expr; diff --git a/src/policy_classes/SwitchPolicy.hpp b/src/policy_classes/SwitchPolicy.hpp index e2ea1c7..2ab27fe 100644 --- a/src/policy_classes/SwitchPolicy.hpp +++ b/src/policy_classes/SwitchPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffSwitchPolicy.hpp + * @file SwitchPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_SWITCH_POLICY_HPP @@ -18,7 +18,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct SwitchData { diff --git a/src/policy_classes/ThrowPolicy.hpp b/src/policy_classes/ThrowPolicy.hpp index 2bdd076..9e7e42c 100644 --- a/src/policy_classes/ThrowPolicy.hpp +++ b/src/policy_classes/ThrowPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffThrowPolicy.hpp + * @file ThrowPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_THROW_POLICY_HPP @@ -20,7 +20,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct ThrowData { DeltaElement> expr; diff --git a/src/policy_classes/TryPolicy.hpp b/src/policy_classes/TryPolicy.hpp index 40b140b..43924dd 100644 --- a/src/policy_classes/TryPolicy.hpp +++ b/src/policy_classes/TryPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffTryPolicy.hpp + * @file TryPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_TRY_POLICY_HPP @@ -22,7 +22,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct TryData { diff --git a/src/policy_classes/TypePolicy.cpp b/src/policy_classes/TypePolicy.cpp index 6381899..1a80fb3 100644 --- a/src/policy_classes/TypePolicy.cpp +++ b/src/policy_classes/TypePolicy.cpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffTypePolicy.cpp + * @file TypePolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #include @@ -12,7 +12,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { std::string TypeData::ToString(srcDispatch::DiffOperation operation) const { std::string str; diff --git a/src/policy_classes/TypePolicy.hpp b/src/policy_classes/TypePolicy.hpp index e3bf040..b4595f0 100644 --- a/src/policy_classes/TypePolicy.hpp +++ b/src/policy_classes/TypePolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffTypePolicy.hpp + * @file TypePolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_TYPE_POLICY_HPP @@ -16,7 +16,7 @@ #include -namespace srcDiffDispatch { +namespace srcDispatch { class NamePolicy; diff --git a/src/policy_classes/UnitPolicy.hpp b/src/policy_classes/UnitPolicy.hpp index 84c49c8..5d798de 100644 --- a/src/policy_classes/UnitPolicy.hpp +++ b/src/policy_classes/UnitPolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffUnitPolicy.hpp + * @file UnitPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. * * Policy for srcDispatch * Listens for both classes and functions @@ -29,7 +29,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct UnitData { std::vector>> classInfo; diff --git a/src/policy_classes/WhilePolicy.hpp b/src/policy_classes/WhilePolicy.hpp index d57389e..8094539 100644 --- a/src/policy_classes/WhilePolicy.hpp +++ b/src/policy_classes/WhilePolicy.hpp @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffWhilePolicy.hpp + * @file WhilePolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www..org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ #ifndef INCLUDED_SRCDIFF_SRCDIFF_WHILE_POLICY_HPP @@ -18,7 +18,7 @@ #include #include -namespace srcDiffDispatch { +namespace srcDispatch { struct WhileData { diff --git a/test/suite/testCall.cpp b/test/suite/testCall.cpp index 74b463d..6f84af5 100644 --- a/test/suite/testCall.cpp +++ b/test/suite/testCall.cpp @@ -21,7 +21,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(call_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { f(); }", "void foo() { f(); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -33,23 +33,23 @@ BOOST_AUTO_TEST_CASE(call_common) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(stmt.expr.IsCommon()); BOOST_TEST(stmt.expr->expr.size() == 1); BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); - const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + const srcDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); BOOST_TEST(call.name.ToString() == "f"); BOOST_TEST(call.arguments.size() == 0); - BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f()"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f()"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f()"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f()"); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(call_insert_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { f(); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -61,23 +61,23 @@ BOOST_AUTO_TEST_CASE(call_insert_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(stmt.expr.IsInsert()); BOOST_TEST(stmt.expr->expr.size() == 1); BOOST_TEST(stmt.expr->expr.at(0).IsInsert()); - const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + const srcDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); BOOST_TEST(call.name.ToString() == "|f"); BOOST_TEST(call.arguments.size() == 0); - BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "|f()"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "|f()"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|f()"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|f()"); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(call_delete_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { f(); }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -89,23 +89,23 @@ BOOST_AUTO_TEST_CASE(call_delete_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(stmt.expr.IsDelete()); BOOST_TEST(stmt.expr->expr.size() == 1); BOOST_TEST(stmt.expr->expr.at(0).IsDelete()); - const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + const srcDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); BOOST_TEST(call.name.ToString() == "f|"); BOOST_TEST(call.arguments.size() == 0); - BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f()|"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f()|"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f()|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f()|"); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(call_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { a = b; }", "void foo() { a = b + f(); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE(call_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(stmt.expr.IsCommon()); BOOST_TEST(stmt.expr->expr.size() == 5); BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); @@ -126,18 +126,18 @@ BOOST_AUTO_TEST_CASE(call_insert) { BOOST_TEST(stmt.expr->expr.at(3).IsInsert()); BOOST_TEST(stmt.expr->expr.at(4).IsInsert()); - const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(4).GetElement()); + const srcDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(4).GetElement()); BOOST_TEST(call.name.ToString() == "|f"); BOOST_TEST(call.arguments.size() == 0); - BOOST_TEST(stmt.expr->expr.at(4).ToString>() == "|f()"); + BOOST_TEST(stmt.expr->expr.at(4).ToString>() == "|f()"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a = b|a = b + f()"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a = b|a = b + f()"); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(call_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { a = b + f(); }", "void foo() { a = b; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -149,7 +149,7 @@ BOOST_AUTO_TEST_CASE(call_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(stmt.expr.IsCommon()); BOOST_TEST(stmt.expr->expr.size() == 5); BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); @@ -158,19 +158,19 @@ BOOST_AUTO_TEST_CASE(call_delete) { BOOST_TEST(stmt.expr->expr.at(3).IsDelete()); BOOST_TEST(stmt.expr->expr.at(4).IsDelete()); - const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(4).GetElement()); + const srcDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(4).GetElement()); BOOST_TEST(call.name.ToString() == "f|"); BOOST_TEST(call.arguments.size() == 0); - BOOST_TEST(stmt.expr->expr.at(4).ToString>() == "f()|"); + BOOST_TEST(stmt.expr->expr.at(4).ToString>() == "f()|"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a = b + f()|a = b"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a = b + f()|a = b"); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } // args BOOST_AUTO_TEST_CASE(call_arg_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { f(a); }", "void foo() { f(a); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -182,25 +182,25 @@ BOOST_AUTO_TEST_CASE(call_arg_common) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(stmt.expr.IsCommon()); BOOST_TEST(stmt.expr->expr.size() == 1); BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); - const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + const srcDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); BOOST_TEST(call.name.ToString() == "f"); BOOST_TEST(call.arguments.size() == 1); BOOST_TEST(call.arguments.at(0).IsCommon()); BOOST_TEST(call.arguments.at(0).ToString() == "a"); - BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a)"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a)"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a)"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a)"); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(call_arg_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { f(); }", "void foo() { f(a); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -212,25 +212,25 @@ BOOST_AUTO_TEST_CASE(call_arg_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(stmt.expr.IsCommon()); BOOST_TEST(stmt.expr->expr.size() == 1); BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); - const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + const srcDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); BOOST_TEST(call.name.ToString() == "f"); BOOST_TEST(call.arguments.size() == 1); BOOST_TEST(call.arguments.at(0).IsInsert()); BOOST_TEST(call.arguments.at(0).ToString() == "|a"); - BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f()|f(a)"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f()|f(a)"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f()|f(a)"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f()|f(a)"); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(call_arg_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { f(a); }", "void foo() { f(); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -242,25 +242,25 @@ BOOST_AUTO_TEST_CASE(call_arg_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(stmt.expr.IsCommon()); BOOST_TEST(stmt.expr->expr.size() == 1); BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); - const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + const srcDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); BOOST_TEST(call.name.ToString() == "f"); BOOST_TEST(call.arguments.size() == 1); BOOST_TEST(call.arguments.at(0).IsDelete()); BOOST_TEST(call.arguments.at(0).ToString() == "a|"); - BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a)|f()"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a)|f()"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a)|f()"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a)|f()"); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(call_arg_insert_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { f(a); }", "void foo() { f(0, a); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -272,27 +272,27 @@ BOOST_AUTO_TEST_CASE(call_arg_insert_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(stmt.expr.IsCommon()); BOOST_TEST(stmt.expr->expr.size() == 1); BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); - const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + const srcDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); BOOST_TEST(call.name.ToString() == "f"); BOOST_TEST(call.arguments.size() == 2); BOOST_TEST(call.arguments.at(0).IsInsert()); BOOST_TEST(call.arguments.at(0).ToString() == "|0"); BOOST_TEST(call.arguments.at(1).IsCommon()); BOOST_TEST(call.arguments.at(1).ToString() == "a"); - BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a)|f(0, a)"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a)|f(0, a)"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a)|f(0, a)"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a)|f(0, a)"); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(call_arg_insert_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { f(a); }", "void foo() { f(a, b + 1); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -304,21 +304,21 @@ BOOST_AUTO_TEST_CASE(call_arg_insert_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(stmt.expr.IsCommon()); BOOST_TEST(stmt.expr->expr.size() == 1); BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); - const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + const srcDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); BOOST_TEST(call.name.ToString() == "f"); BOOST_TEST(call.arguments.size() == 2); BOOST_TEST(call.arguments.at(0).IsCommon()); BOOST_TEST(call.arguments.at(0).ToString() == "a"); BOOST_TEST(call.arguments.at(1).IsInsert()); BOOST_TEST(call.arguments.at(1).ToString() == "|b + 1"); - BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a)|f(a, b + 1)"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a)|f(a, b + 1)"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a)|f(a, b + 1)"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a)|f(a, b + 1)"); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } @@ -326,7 +326,7 @@ BOOST_AUTO_TEST_CASE(call_arg_insert_back) { BOOST_AUTO_TEST_CASE(call_arg_delete_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { f(0, a); }", "void foo() { f(a); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -338,27 +338,27 @@ BOOST_AUTO_TEST_CASE(call_arg_delete_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(stmt.expr.IsCommon()); BOOST_TEST(stmt.expr->expr.size() == 1); BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); - const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + const srcDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); BOOST_TEST(call.name.ToString() == "f"); BOOST_TEST(call.arguments.size() == 2); BOOST_TEST(call.arguments.at(0).IsDelete()); BOOST_TEST(call.arguments.at(0).ToString() == "0|"); BOOST_TEST(call.arguments.at(1).IsCommon()); BOOST_TEST(call.arguments.at(1).ToString() == "a"); - BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(0, a)|f(a)"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(0, a)|f(a)"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(0, a)|f(a)"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(0, a)|f(a)"); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(call_arg_delete_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { f(a, b + 1); }", "void foo() { f(a); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -370,20 +370,20 @@ BOOST_AUTO_TEST_CASE(call_arg_delete_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& stmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(stmt.expr.IsCommon()); BOOST_TEST(stmt.expr->expr.size() == 1); BOOST_TEST(stmt.expr->expr.at(0).IsCommon()); - const srcDiffDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); + const srcDispatch::CallData& call = *std::any_cast>(stmt.expr->expr.at(0).GetElement()); BOOST_TEST(call.name.ToString() == "f"); BOOST_TEST(call.arguments.size() == 2); BOOST_TEST(call.arguments.at(0).IsCommon()); BOOST_TEST(call.arguments.at(0).ToString() == "a"); BOOST_TEST(call.arguments.at(1).IsDelete()); BOOST_TEST(call.arguments.at(1).ToString() == "b + 1|"); - BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a, b + 1)|f(a)"); + BOOST_TEST(stmt.expr->expr.at(0).ToString>() == "f(a, b + 1)|f(a)"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a, b + 1)|f(a)"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "f(a, b + 1)|f(a)"); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } diff --git a/test/suite/testCase.cpp b/test/suite/testCase.cpp index 4f8fbbd..752e7e7 100644 --- a/test/suite/testCase.cpp +++ b/test/suite/testCase.cpp @@ -23,7 +23,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_common_case) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { switch(1) { case foo; } }", "void foo() { switch(1) { case foo: }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE(block_common_case) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); - const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(switchData.block.IsCommon()); BOOST_TEST(switchData.block->statements.size() == 0); @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(block_common_case) { BOOST_AUTO_TEST_CASE(block_insert_case) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { switch(1) {} }", "void foo() { switch(1) { case foo: }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(block_insert_case) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); - const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(switchData.block.IsCommon()); BOOST_TEST(switchData.block->statements.size() == 0); @@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(block_insert_case) { BOOST_AUTO_TEST_CASE(block_delete_case) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { switch(1) { case foo: } }", "void foo() { switch(1) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(block_delete_case) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); - const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(switchData.block.IsCommon()); BOOST_TEST(switchData.block->statements.size() == 0); @@ -122,7 +122,7 @@ BOOST_AUTO_TEST_CASE(block_delete_case) { BOOST_AUTO_TEST_CASE(block_case_rename) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { switch(1) { case foo: } }", "void foo() { switch(1) { case bar: } }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE(block_case_rename) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); - const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(switchData.block.IsCommon()); BOOST_TEST(switchData.block->statements.size() == 0); @@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(block_case_rename) { BOOST_TEST(switchData.block->cases.at(0)->expr.IsCommon()); BOOST_TEST(switchData.block->cases.at(0)->expr->expr.size() == 1); BOOST_TEST(switchData.block->cases.at(0)->expr->expr.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(switchData.block->cases.at(0)->expr->expr.at(0).GetElement())->name.IsChange()); + BOOST_TEST(std::any_cast>(switchData.block->cases.at(0)->expr->expr.at(0).GetElement())->name.IsChange()); BOOST_TEST(switchData.block->cases.at(0).ToString() == "foo|bar"); BOOST_TEST(switchData.block->blocks.size() == 0); @@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE(block_case_rename) { BOOST_AUTO_TEST_CASE(block_case_expr_replace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { switch(1) { case 0: } }", "void foo() { switch(1) { case foo: } }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(block_case_expr_replace) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); - const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(switchData.block.IsCommon()); BOOST_TEST(switchData.block->statements.size() == 0); diff --git a/test/suite/testClass.cpp b/test/suite/testClass.cpp index 9a8fb88..55ba757 100644 --- a/test/suite/testClass.cpp +++ b/test/suite/testClass.cpp @@ -23,19 +23,19 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(class_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo {};", "class foo {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -54,19 +54,19 @@ BOOST_AUTO_TEST_CASE(class_common) { BOOST_AUTO_TEST_CASE(struct_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("struct foo {};", "struct bar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::STRUCT); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::STRUCT); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo|bar"); @@ -85,19 +85,19 @@ BOOST_AUTO_TEST_CASE(struct_common) { BOOST_AUTO_TEST_CASE(class_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("", "class foo {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsInsert()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsInsert()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsInsert()); BOOST_TEST(classData->name.ToString() == "|foo"); @@ -116,19 +116,19 @@ BOOST_AUTO_TEST_CASE(class_insert) { BOOST_AUTO_TEST_CASE(class_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo {};", ""); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsDelete()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsDelete()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsDelete()); BOOST_TEST(classData->name.ToString() == "foo|"); @@ -147,19 +147,19 @@ BOOST_AUTO_TEST_CASE(class_delete) { BOOST_AUTO_TEST_CASE(class_rename) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo {};", "class bar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo|bar"); @@ -179,19 +179,19 @@ BOOST_AUTO_TEST_CASE(class_rename) { // parents BOOST_AUTO_TEST_CASE(class_parent_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo : bar {};", "class foo : bar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -216,19 +216,19 @@ BOOST_AUTO_TEST_CASE(class_parent_common) { BOOST_AUTO_TEST_CASE(class_parent_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo {};", "class foo : bar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -253,19 +253,19 @@ BOOST_AUTO_TEST_CASE(class_parent_insert) { BOOST_AUTO_TEST_CASE(class_parent_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo : bar {};", "class foo {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -290,19 +290,19 @@ BOOST_AUTO_TEST_CASE(class_parent_delete) { BOOST_AUTO_TEST_CASE(class_parent_rename) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo : public bar {};", "class foo : public foobar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -328,19 +328,19 @@ BOOST_AUTO_TEST_CASE(class_parent_rename) { BOOST_AUTO_TEST_CASE(class_parent_common_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo : public bar {};", "class foo : public bar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -367,19 +367,19 @@ BOOST_AUTO_TEST_CASE(class_parent_common_access) { BOOST_AUTO_TEST_CASE(class_parent_insert_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo : bar {};", "class foo : public bar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -406,19 +406,19 @@ BOOST_AUTO_TEST_CASE(class_parent_insert_access) { BOOST_AUTO_TEST_CASE(class_parent_delete_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo : public bar {};", "class foo : bar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -445,19 +445,19 @@ BOOST_AUTO_TEST_CASE(class_parent_delete_access) { BOOST_AUTO_TEST_CASE(class_parent_change_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo : public bar {};", "class foo : private bar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -485,19 +485,19 @@ BOOST_AUTO_TEST_CASE(class_parent_change_access) { BOOST_AUTO_TEST_CASE(class_parent_common_virtual) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo : virtual bar {};", "class foo : virtual bar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -523,19 +523,19 @@ BOOST_AUTO_TEST_CASE(class_parent_common_virtual) { BOOST_AUTO_TEST_CASE(class_parent_insert_virtual) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo : bar {};", "class foo : virtual bar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -561,19 +561,19 @@ BOOST_AUTO_TEST_CASE(class_parent_insert_virtual) { BOOST_AUTO_TEST_CASE(class_parent_delete_virtual) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo : virtual bar {};", "class foo : bar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -599,19 +599,19 @@ BOOST_AUTO_TEST_CASE(class_parent_delete_virtual) { BOOST_AUTO_TEST_CASE(class_parent_replace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo : bar {};", "class foo : foobar {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -645,19 +645,19 @@ BOOST_AUTO_TEST_CASE(class_parent_replace) { // fields BOOST_AUTO_TEST_CASE(class_fields_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { int i; };", "class foo { int i; };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -683,19 +683,19 @@ BOOST_AUTO_TEST_CASE(class_fields_common) { BOOST_AUTO_TEST_CASE(class_fields_private) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: int i; };", "class foo { private: int i; };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -721,19 +721,19 @@ BOOST_AUTO_TEST_CASE(class_fields_private) { BOOST_AUTO_TEST_CASE(class_fields_private_default) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { int i; };", "class foo { private: int i; };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -759,19 +759,19 @@ BOOST_AUTO_TEST_CASE(class_fields_private_default) { BOOST_AUTO_TEST_CASE(class_fields_public) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: int i; };", "class foo { public: int i; };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -797,19 +797,19 @@ BOOST_AUTO_TEST_CASE(class_fields_public) { BOOST_AUTO_TEST_CASE(class_fields_protected) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { protected: int i; };", "class foo { protected: int i; };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -835,19 +835,19 @@ BOOST_AUTO_TEST_CASE(class_fields_protected) { BOOST_AUTO_TEST_CASE(class_fields_access_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: int i; };", "class foo { protected: int i; };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -874,19 +874,19 @@ BOOST_AUTO_TEST_CASE(class_fields_access_change) { BOOST_AUTO_TEST_CASE(class_fields_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: };", "class foo { private: int i; };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -912,19 +912,19 @@ BOOST_AUTO_TEST_CASE(class_fields_insert) { BOOST_AUTO_TEST_CASE(class_fields_insert_with_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: };", "class foo { private: int i; };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -950,19 +950,19 @@ BOOST_AUTO_TEST_CASE(class_fields_insert_with_access) { BOOST_AUTO_TEST_CASE(class_fields_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: int i; };", "class foo { private: };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -988,19 +988,19 @@ BOOST_AUTO_TEST_CASE(class_fields_delete) { BOOST_AUTO_TEST_CASE(class_fields_delete_with_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: int i; };", "class foo { private: };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1026,19 +1026,19 @@ BOOST_AUTO_TEST_CASE(class_fields_delete_with_access) { BOOST_AUTO_TEST_CASE(class_fields_replace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: int i; };", "class foo { private: double d; };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1071,19 +1071,19 @@ BOOST_AUTO_TEST_CASE(class_fields_replace) { BOOST_AUTO_TEST_CASE(class_fields_replace_with_namespace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: int i; };", "class foo { private: double d; };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1117,19 +1117,19 @@ BOOST_AUTO_TEST_CASE(class_fields_replace_with_namespace) { // constructor BOOST_AUTO_TEST_CASE(class_constructors_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { foo() {} };", "class foo { foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1153,19 +1153,19 @@ BOOST_AUTO_TEST_CASE(class_constructors_common) { BOOST_AUTO_TEST_CASE(class_constructors_private) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: foo() {} };", "class foo { private: foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1189,19 +1189,19 @@ BOOST_AUTO_TEST_CASE(class_constructors_private) { BOOST_AUTO_TEST_CASE(class_constructors_private_default) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { foo() {} };", "class foo { private: foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1225,19 +1225,19 @@ BOOST_AUTO_TEST_CASE(class_constructors_private_default) { BOOST_AUTO_TEST_CASE(class_constructors_public) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: foo() {} };", "class foo { public: foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1261,19 +1261,19 @@ BOOST_AUTO_TEST_CASE(class_constructors_public) { BOOST_AUTO_TEST_CASE(class_constructors_protected) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { protected: foo() {} };", "class foo { protected: foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1297,19 +1297,19 @@ BOOST_AUTO_TEST_CASE(class_constructors_protected) { BOOST_AUTO_TEST_CASE(class_constructors_access_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: foo() {} };", "class foo { protected: foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1334,19 +1334,19 @@ BOOST_AUTO_TEST_CASE(class_constructors_access_change) { BOOST_AUTO_TEST_CASE(class_constructors_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: };", "class foo { private: foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1370,19 +1370,19 @@ BOOST_AUTO_TEST_CASE(class_constructors_insert) { BOOST_AUTO_TEST_CASE(class_constructors_insert_with_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: };", "class foo { private: foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1406,19 +1406,19 @@ BOOST_AUTO_TEST_CASE(class_constructors_insert_with_access) { BOOST_AUTO_TEST_CASE(class_constructors_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: foo() {} };", "class foo { private: };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1442,19 +1442,19 @@ BOOST_AUTO_TEST_CASE(class_constructors_delete) { BOOST_AUTO_TEST_CASE(class_constructors_delete_with_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: foo() {} };", "class foo { private: };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1478,19 +1478,19 @@ BOOST_AUTO_TEST_CASE(class_constructors_delete_with_access) { BOOST_AUTO_TEST_CASE(class_constructors_replace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: foo() { ab; } public: void f() { c; d; } };", "class bar { private: bar() { b; } public: void f() { c; d; } };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo|bar"); @@ -1519,19 +1519,19 @@ BOOST_AUTO_TEST_CASE(class_constructors_replace) { BOOST_AUTO_TEST_CASE(class_constructors_replace_with_namespace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: foo() { a; } public: void f() { c + d + e + f; } };", "class bar { private: bar() { a; } public: void f() { c + d + e + f; } };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo|bar"); @@ -1561,19 +1561,19 @@ BOOST_AUTO_TEST_CASE(class_constructors_replace_with_namespace) { // destructor BOOST_AUTO_TEST_CASE(class_destructors_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { ~foo() {} };", "class foo { ~foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1597,19 +1597,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_common) { BOOST_AUTO_TEST_CASE(class_destructors_private) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: ~foo() {} };", "class foo { private: ~foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1633,19 +1633,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_private) { BOOST_AUTO_TEST_CASE(class_destructors_private_default) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { ~foo() {} };", "class foo { private: ~foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1669,19 +1669,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_private_default) { BOOST_AUTO_TEST_CASE(class_destructors_public) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: ~foo() {} };", "class foo { public: ~foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1705,19 +1705,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_public) { BOOST_AUTO_TEST_CASE(class_destructors_protected) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { protected: ~foo() {} };", "class foo { protected: ~foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1741,19 +1741,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_protected) { BOOST_AUTO_TEST_CASE(class_destructors_access_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: ~foo() {} };", "class foo { protected: ~foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1778,19 +1778,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_access_change) { BOOST_AUTO_TEST_CASE(class_destructors_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: };", "class foo { private: ~foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1814,19 +1814,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_insert) { BOOST_AUTO_TEST_CASE(class_destructors_insert_with_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: };", "class foo { private: ~foo() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1850,19 +1850,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_insert_with_access) { BOOST_AUTO_TEST_CASE(class_destructors_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: ~foo() {} };", "class foo { private: };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1886,19 +1886,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_delete) { BOOST_AUTO_TEST_CASE(class_destructors_delete_with_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: ~foo() {} };", "class foo { private: };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -1922,19 +1922,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_delete_with_access) { BOOST_AUTO_TEST_CASE(class_destructors_replace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: ~foo() { ab; } public: void f() { c; d; } };", "class bar { private: ~bar() { b; } public: void f() { c; d; } };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo|bar"); @@ -1958,19 +1958,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_replace) { BOOST_AUTO_TEST_CASE(class_destructors_replace_with_namespace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: ~foo() { a; } public: void f() { c + d + e + f; } };", "class bar { private: ~bar() { a; } public: void f() { c + d + e + f; } };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo|bar"); @@ -1994,19 +1994,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_replace_with_namespace) { BOOST_AUTO_TEST_CASE(class_destructors_replace_with_convert_namespace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: ~foo() {} void f(int c, double d, long e, float f) { c + d + e + f; } };", "class bar { private: ~bar() { delete a; } void f(int c, double d, long e, float f) { c + d + e + f; } };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo|bar"); @@ -2032,19 +2032,19 @@ BOOST_AUTO_TEST_CASE(class_destructors_replace_with_convert_namespace) { // operators BOOST_AUTO_TEST_CASE(class_operators_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { bool operator==() {} };", "class foo { bool operator==() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2068,19 +2068,19 @@ BOOST_AUTO_TEST_CASE(class_operators_common) { BOOST_AUTO_TEST_CASE(class_operators_private) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: bool operator==() {} };", "class foo { private: bool operator==() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2104,19 +2104,19 @@ BOOST_AUTO_TEST_CASE(class_operators_private) { BOOST_AUTO_TEST_CASE(class_operators_private_default) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { bool operator==() {} };", "class foo { private: bool operator==() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2140,19 +2140,19 @@ BOOST_AUTO_TEST_CASE(class_operators_private_default) { BOOST_AUTO_TEST_CASE(class_operators_public) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: bool operator==() {} };", "class foo { public: bool operator==() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2176,19 +2176,19 @@ BOOST_AUTO_TEST_CASE(class_operators_public) { BOOST_AUTO_TEST_CASE(class_operators_protected) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { protected: bool operator==() {} };", "class foo { protected: bool operator==() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2212,19 +2212,19 @@ BOOST_AUTO_TEST_CASE(class_operators_protected) { BOOST_AUTO_TEST_CASE(class_operators_access_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: bool operator==() {} };", "class foo { protected: bool operator==() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2249,19 +2249,19 @@ BOOST_AUTO_TEST_CASE(class_operators_access_change) { BOOST_AUTO_TEST_CASE(class_operators_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: };", "class foo { private: bool operator==() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2285,19 +2285,19 @@ BOOST_AUTO_TEST_CASE(class_operators_insert) { BOOST_AUTO_TEST_CASE(class_operators_insert_with_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: };", "class foo { private: bool operator==() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2321,19 +2321,19 @@ BOOST_AUTO_TEST_CASE(class_operators_insert_with_access) { BOOST_AUTO_TEST_CASE(class_operators_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: bool operator==() {} };", "class foo { private: };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2357,19 +2357,19 @@ BOOST_AUTO_TEST_CASE(class_operators_delete) { BOOST_AUTO_TEST_CASE(class_operators_delete_with_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: bool operator==() {} };", "class foo { private: };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2393,19 +2393,19 @@ BOOST_AUTO_TEST_CASE(class_operators_delete_with_access) { BOOST_AUTO_TEST_CASE(class_operators_replace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: bool operator==(int b) { return std::max(b - a, 0); } };", "class foo { private: bool operator!=(const object& that) { return *this != that; } };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2434,19 +2434,19 @@ BOOST_AUTO_TEST_CASE(class_operators_replace) { BOOST_AUTO_TEST_CASE(class_operators_replace_with_namespace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: bool operator==(int b) { return std::max(b - a, 0); } };", "class foo { private: bool operator!=(const object& that) { return *this != that; } };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2476,19 +2476,19 @@ BOOST_AUTO_TEST_CASE(class_operators_replace_with_namespace) { // methods BOOST_AUTO_TEST_CASE(class_methods_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { void f() {} };", "class foo { void f() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2512,19 +2512,19 @@ BOOST_AUTO_TEST_CASE(class_methods_common) { BOOST_AUTO_TEST_CASE(class_methods_private) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: void f() {} };", "class foo { private: void f() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2548,19 +2548,19 @@ BOOST_AUTO_TEST_CASE(class_methods_private) { BOOST_AUTO_TEST_CASE(class_methods_private_default) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { void f() {} };", "class foo { private: void f() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2584,19 +2584,19 @@ BOOST_AUTO_TEST_CASE(class_methods_private_default) { BOOST_AUTO_TEST_CASE(class_methods_public) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: void f() {} };", "class foo { public: void f() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2620,19 +2620,19 @@ BOOST_AUTO_TEST_CASE(class_methods_public) { BOOST_AUTO_TEST_CASE(class_methods_protected) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { protected: void f() {} };", "class foo { protected: void f() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2656,19 +2656,19 @@ BOOST_AUTO_TEST_CASE(class_methods_protected) { BOOST_AUTO_TEST_CASE(class_methods_access_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: void f() {} };", "class foo { protected: void f() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2693,19 +2693,19 @@ BOOST_AUTO_TEST_CASE(class_methods_access_change) { BOOST_AUTO_TEST_CASE(class_methods_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: };", "class foo { private: void f() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2729,19 +2729,19 @@ BOOST_AUTO_TEST_CASE(class_methods_insert) { BOOST_AUTO_TEST_CASE(class_methods_insert_with_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: };", "class foo { private: void f() {} };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2765,19 +2765,19 @@ BOOST_AUTO_TEST_CASE(class_methods_insert_with_access) { BOOST_AUTO_TEST_CASE(class_methods_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: void f() {} };", "class foo { private: };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2801,19 +2801,19 @@ BOOST_AUTO_TEST_CASE(class_methods_delete) { BOOST_AUTO_TEST_CASE(class_methods_delete_with_access) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: void f() {} };", "class foo { private: };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2837,19 +2837,19 @@ BOOST_AUTO_TEST_CASE(class_methods_delete_with_access) { BOOST_AUTO_TEST_CASE(class_methods_replace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { private: void f() { a; } };", "class foo { private: int g() { b; } };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2878,19 +2878,19 @@ BOOST_AUTO_TEST_CASE(class_methods_replace) { BOOST_AUTO_TEST_CASE(class_methods_replace_with_namespace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { public: void f() { a; } };", "class foo { private: int g() { b; } };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2920,19 +2920,19 @@ BOOST_AUTO_TEST_CASE(class_methods_replace_with_namespace) { // abstract BOOST_AUTO_TEST_CASE(class_is_abstract) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { virtual void f() = 0; };", "class foo { virtual void f() = 0; };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2953,19 +2953,19 @@ BOOST_AUTO_TEST_CASE(class_is_abstract) { BOOST_AUTO_TEST_CASE(class_becomes_abstract) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { };", "class foo { virtual void f() = 0; };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -2986,19 +2986,19 @@ BOOST_AUTO_TEST_CASE(class_becomes_abstract) { BOOST_AUTO_TEST_CASE(class_was_abstract) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo { virtual void f() = 0; };", "class foo { };"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -3020,14 +3020,14 @@ BOOST_AUTO_TEST_CASE(class_was_abstract) { // generic BOOST_AUTO_TEST_CASE(class_is_generic) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template class foo {};", "template class foo {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.size() == 1); @@ -3035,7 +3035,7 @@ BOOST_AUTO_TEST_CASE(class_is_generic) { BOOST_TEST(classData->generics.at(0).ToString() == "template"); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -3054,14 +3054,14 @@ BOOST_AUTO_TEST_CASE(class_is_generic) { BOOST_AUTO_TEST_CASE(class_becomes_generic) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo {};", "template class foo {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.size() == 1); @@ -3069,7 +3069,7 @@ BOOST_AUTO_TEST_CASE(class_becomes_generic) { BOOST_TEST(classData->generics.at(0).ToString() == "|template"); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -3088,14 +3088,14 @@ BOOST_AUTO_TEST_CASE(class_becomes_generic) { BOOST_AUTO_TEST_CASE(class_was_generic) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template class foo {};", "class foo {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.size() == 1); @@ -3103,7 +3103,7 @@ BOOST_AUTO_TEST_CASE(class_was_generic) { BOOST_TEST(classData->generics.at(0).ToString() == "template|"); BOOST_TEST(classData->type.IsCommon()); - BOOST_TEST(classData->type.GetElement() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetElement() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); diff --git a/test/suite/testClassConvert.cpp b/test/suite/testClassConvert.cpp index b8f65d8..844a642 100644 --- a/test/suite/testClassConvert.cpp +++ b/test/suite/testClassConvert.cpp @@ -23,20 +23,20 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(class_to_struct) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("class foo {};", "struct foo {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsChange()); - BOOST_TEST(classData->type.GetOriginal() == srcDiffDispatch::ClassData::CLASS); - BOOST_TEST(classData->type.GetModified() == srcDiffDispatch::ClassData::STRUCT); + BOOST_TEST(classData->type.GetOriginal() == srcDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetModified() == srcDispatch::ClassData::STRUCT); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); @@ -55,20 +55,20 @@ BOOST_AUTO_TEST_CASE(class_to_struct) { BOOST_AUTO_TEST_CASE(struct_to_class) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("struct foo {};", "class foo {};"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); BOOST_TEST(runner.GetClassInfo().size() == 1); - const srcDiffDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); + const srcDispatch::DeltaElement>& classData = runner.GetClassInfo().at(0); BOOST_TEST(classData.IsCommon()); BOOST_TEST(classData->generics.empty()); BOOST_TEST(classData->type.IsChange()); - BOOST_TEST(classData->type.GetOriginal() == srcDiffDispatch::ClassData::STRUCT); - BOOST_TEST(classData->type.GetModified() == srcDiffDispatch::ClassData::CLASS); + BOOST_TEST(classData->type.GetOriginal() == srcDispatch::ClassData::STRUCT); + BOOST_TEST(classData->type.GetModified() == srcDispatch::ClassData::CLASS); BOOST_TEST(classData->name.IsCommon()); BOOST_TEST(classData->name.ToString() == "foo"); diff --git a/test/suite/testCondition.cpp b/test/suite/testCondition.cpp index db58418..4cad4a4 100644 --- a/test/suite/testCondition.cpp +++ b/test/suite/testCondition.cpp @@ -24,7 +24,7 @@ namespace data = boost::unit_test; // condition decl BOOST_AUTO_TEST_CASE(decl_condition_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { while(int i = 1) {} }", "void foo() { while(int i = 1) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -36,19 +36,19 @@ BOOST_AUTO_TEST_CASE(decl_condition_common) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(whileData.condition); BOOST_TEST(whileData.condition.IsCommon()); BOOST_TEST(whileData.condition->conditions.size() == 1); BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); - BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "int i = 1"); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "int i = 1"); BOOST_TEST(whileData.condition.ToString() == "int i = 1"); BOOST_TEST(whileData.block.IsCommon()); BOOST_TEST(whileData.block->statements.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(decl_condition_common) { BOOST_AUTO_TEST_CASE(decl_condition_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { while(int i = 1) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -70,18 +70,18 @@ BOOST_AUTO_TEST_CASE(decl_condition_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(whileData.condition); BOOST_TEST(whileData.condition.IsInsert()); BOOST_TEST(whileData.condition->conditions.size() == 1); BOOST_TEST(whileData.condition->conditions.at(0).IsInsert()); - BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "|int i = 1"); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "|int i = 1"); BOOST_TEST(whileData.condition.ToString() == "|int i = 1"); BOOST_TEST(whileData.block.IsInsert()); BOOST_TEST(whileData.block->statements.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|int i = 1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|int i = 1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -91,7 +91,7 @@ BOOST_AUTO_TEST_CASE(decl_condition_insert) { BOOST_AUTO_TEST_CASE(decl_condition_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { while(int i = 1) {} }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -104,18 +104,18 @@ BOOST_AUTO_TEST_CASE(decl_condition_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(whileData.condition); BOOST_TEST(whileData.condition.IsDelete()); BOOST_TEST(whileData.condition->conditions.size() == 1); BOOST_TEST(whileData.condition->conditions.at(0).IsDelete()); - BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "int i = 1|"); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "int i = 1|"); BOOST_TEST(whileData.condition.ToString() == "int i = 1|"); BOOST_TEST(whileData.block.IsDelete()); BOOST_TEST(whileData.block->statements.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 1|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 1|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(decl_condition_delete) { BOOST_AUTO_TEST_CASE(decl_condition_replace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { while(int i = 1) {} }", "void foo() { while(double d = 1.0) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -138,20 +138,20 @@ BOOST_AUTO_TEST_CASE(decl_condition_replace) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(whileData.condition); BOOST_TEST(whileData.condition.IsCommon()); BOOST_TEST(whileData.condition->conditions.size() == 2); BOOST_TEST(whileData.condition->conditions.at(0).IsDelete()); - BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "int i = 1|"); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "int i = 1|"); BOOST_TEST(whileData.condition->conditions.at(1).IsInsert()); - BOOST_TEST(whileData.condition->conditions.at(1).ToString>() == "|double d = 1.0"); + BOOST_TEST(whileData.condition->conditions.at(1).ToString>() == "|double d = 1.0"); BOOST_TEST(whileData.condition.ToString() == "int i = 1|double d = 1.0"); BOOST_TEST(whileData.block.IsCommon()); BOOST_TEST(whileData.block->statements.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 1|double d = 1.0"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 1|double d = 1.0"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -161,7 +161,7 @@ BOOST_AUTO_TEST_CASE(decl_condition_replace) { BOOST_AUTO_TEST_CASE(decl_condition_modify) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { while(int i = 1) {} }", "void foo() { while(int i = 2) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -174,18 +174,18 @@ BOOST_AUTO_TEST_CASE(decl_condition_modify) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(whileData.condition); BOOST_TEST(whileData.condition.IsCommon()); BOOST_TEST(whileData.condition->conditions.size() == 1); BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); - BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "int i = 1|int i = 2"); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "int i = 1|int i = 2"); BOOST_TEST(whileData.condition.ToString() == "int i = 1|int i = 2"); BOOST_TEST(whileData.block.IsCommon()); BOOST_TEST(whileData.block->statements.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 1|int i = 2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 1|int i = 2"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); diff --git a/test/suite/testConditionalConvert.cpp b/test/suite/testConditionalConvert.cpp index 11d3b3c..af1fd4b 100644 --- a/test/suite/testConditionalConvert.cpp +++ b/test/suite/testConditionalConvert.cpp @@ -25,7 +25,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(if_to_while) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { while(1) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -38,10 +38,10 @@ BOOST_AUTO_TEST_CASE(if_to_while) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(ifData.clauses.size() == 1); - const srcDiffDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); + const srcDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); BOOST_TEST(ifData.clauses.at(0).IsDelete()); BOOST_TEST(ifClause.condition.IsCommon()); BOOST_TEST(ifClause.condition->conditions.size() == 1); @@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE(if_to_while) { BOOST_TEST(ifClause.block.IsCommon()); BOOST_TEST(ifClause.block->statements.size() == 0); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(whileData.condition); BOOST_TEST(whileData.condition.IsCommon()); BOOST_TEST(whileData.condition->conditions.size() == 1); @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(if_to_while) { BOOST_AUTO_TEST_CASE(while_to_if) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { while(1) {} }", "void foo() { if(1) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(while_to_if) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(whileData.condition); BOOST_TEST(whileData.condition.IsCommon()); BOOST_TEST(whileData.condition->conditions.size() == 1); @@ -90,10 +90,10 @@ BOOST_AUTO_TEST_CASE(while_to_if) { BOOST_TEST(whileData.block.IsCommon()); BOOST_TEST(whileData.block->statements.size() == 0); - const srcDiffDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(ifData.clauses.size() == 1); - const srcDiffDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); + const srcDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); BOOST_TEST(ifData.clauses.at(0).IsInsert()); BOOST_TEST(ifClause.condition.IsCommon()); BOOST_TEST(ifClause.condition->conditions.size() == 1); @@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(while_to_if) { BOOST_AUTO_TEST_CASE(while_to_if_with_convert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { while(1) { while(2) {} } }", "void foo() { if(1) { if(2) {} } }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -125,17 +125,17 @@ BOOST_AUTO_TEST_CASE(while_to_if_with_convert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(whileData.condition); BOOST_TEST(whileData.condition.IsCommon()); BOOST_TEST(whileData.condition->conditions.size() == 1); BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); BOOST_TEST(whileData.condition.ToString() == "1"); - const srcDiffDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(ifData.clauses.size() == 1); - const srcDiffDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); + const srcDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); BOOST_TEST(ifData.clauses.at(0).IsInsert()); BOOST_TEST(ifClause.condition.IsCommon()); BOOST_TEST(ifClause.condition->conditions.size() == 1); @@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE(while_to_if_with_convert) { BOOST_AUTO_TEST_CASE(if_to_for) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { if(i < 10) { sum += i; } }", "void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -169,10 +169,10 @@ BOOST_AUTO_TEST_CASE(if_to_for) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(ifData.clauses.size() == 1); - const srcDiffDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); + const srcDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); BOOST_TEST(ifData.clauses.at(0).IsDelete()); BOOST_TEST(ifClause.condition.IsCommon()); BOOST_TEST(ifClause.condition->conditions.size() == 1); @@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(if_to_for) { BOOST_TEST(ifClause.block.IsCommon()); BOOST_TEST(ifClause.block->statements.size() == 1); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(forData.control); BOOST_TEST(forData.control.IsInsert()); @@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE(if_to_for) { BOOST_AUTO_TEST_CASE(for_to_if) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }", "void foo() { if(i < 10) { sum += i; } }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -223,7 +223,7 @@ BOOST_AUTO_TEST_CASE(for_to_if) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(forData.control); BOOST_TEST(forData.control.IsDelete()); @@ -243,10 +243,10 @@ BOOST_AUTO_TEST_CASE(for_to_if) { BOOST_TEST(forData.block.IsCommon()); BOOST_TEST(forData.block->statements.size() == 1); - const srcDiffDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::IfStmtData& ifData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(ifData.clauses.size() == 1); - const srcDiffDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); + const srcDispatch::IfData& ifClause = *std::any_cast>(ifData.clauses.at(0).GetElement()); BOOST_TEST(ifData.clauses.at(0).IsInsert()); BOOST_TEST(ifClause.condition.IsCommon()); BOOST_TEST(ifClause.condition->conditions.size() == 1); @@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE(for_to_if) { BOOST_AUTO_TEST_CASE(while_to_for) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { while(i < 10) { sum += i; } }", "void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE(while_to_for) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(whileData.condition.IsCommon()); BOOST_TEST(whileData.condition->conditions.size() == 1); BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); @@ -285,7 +285,7 @@ BOOST_AUTO_TEST_CASE(while_to_for) { BOOST_TEST(whileData.block.IsCommon()); BOOST_TEST(whileData.block->statements.size() == 1); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(forData.control); BOOST_TEST(forData.control.IsInsert()); @@ -314,7 +314,7 @@ BOOST_AUTO_TEST_CASE(while_to_for) { BOOST_AUTO_TEST_CASE(for_to_while) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }", "void foo() { while(i < 10) { sum += i; } }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE(for_to_while) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(forData.control); BOOST_TEST(forData.control.IsDelete()); @@ -347,7 +347,7 @@ BOOST_AUTO_TEST_CASE(for_to_while) { BOOST_TEST(forData.block.IsCommon()); BOOST_TEST(forData.block->statements.size() == 1); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(whileData.condition.IsCommon()); BOOST_TEST(whileData.condition->conditions.size() == 1); BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); diff --git a/test/suite/testControl.cpp b/test/suite/testControl.cpp index c394164..570179b 100644 --- a/test/suite/testControl.cpp +++ b/test/suite/testControl.cpp @@ -23,7 +23,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_common_control) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; 1; ++i) {} }", "void foo() { for(int i = 0; 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -37,14 +37,14 @@ BOOST_AUTO_TEST_CASE(block_common_control) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(block_common_control) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE(block_common_control) { BOOST_AUTO_TEST_CASE(block_change_control) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 1; i < 2; ++j) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -79,14 +79,14 @@ BOOST_AUTO_TEST_CASE(block_change_control) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0|int i = 1"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0|int i = 1"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -97,7 +97,7 @@ BOOST_AUTO_TEST_CASE(block_change_control) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i|++ j"); BOOST_TEST(forData.control->incr.ToString() == "++ i|++ j"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|int i = 1; i < 2; ++ j"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|int i = 1; i < 2; ++ j"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(block_change_control) { BOOST_AUTO_TEST_CASE(block_expr_init_control_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -121,14 +121,14 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_common) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_common) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -149,7 +149,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_common) { BOOST_AUTO_TEST_CASE(block_expr_init_control_minor_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(i = 1; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -163,14 +163,14 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_minor_change) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|i = 1"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|i = 1"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_minor_change) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|i = 1; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|i = 1; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_minor_change) { BOOST_AUTO_TEST_CASE(block_expr_init_control_replace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(j = 1; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -205,14 +205,14 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_replace) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsChange()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|j = 1"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|j = 1"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -223,7 +223,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_replace) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|j = 1; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|j = 1; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -233,7 +233,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_replace) { BOOST_AUTO_TEST_CASE(block_expr_init_control_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -247,14 +247,14 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsInsert()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "|i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "|i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -265,7 +265,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_insert) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "; i < 1; ++ i|i = 0; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "; i < 1; ++ i|i = 0; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -275,7 +275,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_insert) { BOOST_AUTO_TEST_CASE(block_expr_init_control_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -289,14 +289,14 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsDelete()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -307,7 +307,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_delete) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -317,7 +317,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_delete) { BOOST_AUTO_TEST_CASE(block_decl_init_control_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -331,14 +331,14 @@ BOOST_AUTO_TEST_CASE(block_decl_init_control_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsInsert()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "|int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "|int i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -349,7 +349,7 @@ BOOST_AUTO_TEST_CASE(block_decl_init_control_insert) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "; i < 1; ++ i|int i = 0; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "; i < 1; ++ i|int i = 0; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -359,7 +359,7 @@ BOOST_AUTO_TEST_CASE(block_decl_init_control_insert) { BOOST_AUTO_TEST_CASE(block_decl_init_control_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -373,14 +373,14 @@ BOOST_AUTO_TEST_CASE(block_decl_init_control_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsDelete()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0|"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0|"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -391,7 +391,7 @@ BOOST_AUTO_TEST_CASE(block_decl_init_control_delete) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -401,7 +401,7 @@ BOOST_AUTO_TEST_CASE(block_decl_init_control_delete) { BOOST_AUTO_TEST_CASE(block_init_control_decl_to_expr) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -415,16 +415,16 @@ BOOST_AUTO_TEST_CASE(block_init_control_decl_to_expr) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 2); BOOST_TEST(forData.control->init->inits.at(0).IsDelete()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0|"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0|"); BOOST_TEST(forData.control->init->inits.at(1).IsInsert()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -435,7 +435,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_decl_to_expr) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|i = 0; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|i = 0; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -445,7 +445,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_decl_to_expr) { BOOST_AUTO_TEST_CASE(block_init_control_expr_to_decl) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -459,16 +459,16 @@ BOOST_AUTO_TEST_CASE(block_init_control_expr_to_decl) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 2); BOOST_TEST(forData.control->init->inits.at(0).IsDelete()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|"); BOOST_TEST(forData.control->init->inits.at(1).IsInsert()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|int i = 0"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|int i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -479,7 +479,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_expr_to_decl) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|int i = 0; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|int i = 0; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -489,7 +489,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_expr_to_decl) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -503,16 +503,16 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 2); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->init->inits.at(1).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -523,7 +523,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int j = 1; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int j = 1; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -533,7 +533,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int j = 1; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -547,16 +547,16 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 2); BOOST_TEST(forData.control->init->inits.at(0).IsInsert()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "|int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "|int i = 0"); BOOST_TEST(forData.control->init->inits.at(1).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -567,7 +567,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_front) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int j = 1; i < 1; ++ i|int i = 0, int j = 1; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int j = 1; i < 1; ++ i|int i = 0, int j = 1; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -577,7 +577,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_front) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -591,16 +591,16 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 2); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->init->inits.at(1).IsInsert()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|int j = 1"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|int j = 1"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -611,7 +611,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_back) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|int i = 0, int j = 1; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|int i = 0, int j = 1; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -621,7 +621,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_back) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_middle) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0, k = 2; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1, k = 2; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -635,18 +635,18 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_middle) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 3); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->init->inits.at(1).IsInsert()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|int j = 1"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|int j = 1"); BOOST_TEST(forData.control->init->inits.at(2).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(2).ToString>() == "int k = 2"); + BOOST_TEST(forData.control->init->inits.at(2).ToString>() == "int k = 2"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -657,7 +657,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_middle) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int k = 2; i < 1; ++ i|int i = 0, int j = 1, int k = 2; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int k = 2; i < 1; ++ i|int i = 0, int j = 1, int k = 2; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -667,7 +667,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_middle) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(int j = 1; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -681,16 +681,16 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 2); BOOST_TEST(forData.control->init->inits.at(0).IsDelete()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0|"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0|"); BOOST_TEST(forData.control->init->inits.at(1).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -701,7 +701,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_front) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int j = 1; i < 1; ++ i|int j = 1; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int j = 1; i < 1; ++ i|int j = 1; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -711,7 +711,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_front) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -725,16 +725,16 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 2); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->init->inits.at(1).IsDelete()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1|"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1|"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -745,7 +745,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_back) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int j = 1; i < 1; ++ i|int i = 0; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int j = 1; i < 1; ++ i|int i = 0; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -756,7 +756,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_back) { // multi decl BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_middle) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0, j = 1, k = 2; i < 1; ++i) {} }", "void foo() { for(int i = 0, k = 2; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -770,18 +770,18 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_middle) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 3); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->init->inits.at(1).IsDelete()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1|"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "int j = 1|"); BOOST_TEST(forData.control->init->inits.at(2).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(2).ToString>() == "int k = 2"); + BOOST_TEST(forData.control->init->inits.at(2).ToString>() == "int k = 2"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -792,7 +792,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_middle) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int j = 1, int k = 2; i < 1; ++ i|int i = 0, int k = 2; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0, int j = 1, int k = 2; i < 1; ++ i|int i = 0, int k = 2; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -803,7 +803,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_middle) { // multi expr BOOST_AUTO_TEST_CASE(block_init_control_multi_expr) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -817,16 +817,16 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 2); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); BOOST_TEST(forData.control->init->inits.at(1).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -837,7 +837,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, j = 1; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, j = 1; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -847,7 +847,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(j = 1; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -861,16 +861,16 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 2); BOOST_TEST(forData.control->init->inits.at(0).IsInsert()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "|i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "|i = 0"); BOOST_TEST(forData.control->init->inits.at(1).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -881,7 +881,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_front) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "j = 1; i < 1; ++ i|i = 0, j = 1; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "j = 1; i < 1; ++ i|i = 0, j = 1; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -891,7 +891,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_front) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -905,16 +905,16 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 2); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); BOOST_TEST(forData.control->init->inits.at(1).IsInsert()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|j = 1"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|j = 1"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -925,7 +925,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_back) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|i = 0, j = 1; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0; i < 1; ++ i|i = 0, j = 1; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -935,7 +935,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_back) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_middle) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(i = 0, k = 2; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1, k = 2; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -949,18 +949,18 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_middle) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 3); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); BOOST_TEST(forData.control->init->inits.at(1).IsInsert()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|j = 1"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "|j = 1"); BOOST_TEST(forData.control->init->inits.at(2).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(2).ToString>() == "k = 2"); + BOOST_TEST(forData.control->init->inits.at(2).ToString>() == "k = 2"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -971,7 +971,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_middle) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, k = 2; i < 1; ++ i|i = 0, j = 1, k = 2; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, k = 2; i < 1; ++ i|i = 0, j = 1, k = 2; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -981,7 +981,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_middle) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(j = 1; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -995,16 +995,16 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 2); BOOST_TEST(forData.control->init->inits.at(0).IsDelete()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0|"); BOOST_TEST(forData.control->init->inits.at(1).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -1015,7 +1015,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_front) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, j = 1; i < 1; ++ i|j = 1; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, j = 1; i < 1; ++ i|j = 1; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -1025,7 +1025,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_front) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1039,16 +1039,16 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 2); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); BOOST_TEST(forData.control->init->inits.at(1).IsDelete()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1|"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1|"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -1059,7 +1059,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_back) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, j = 1; i < 1; ++ i|i = 0; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, j = 1; i < 1; ++ i|i = 0; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -1069,7 +1069,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_back) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_middle) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(i = 0, j = 1, k = 2; i < 1; ++i) {} }", "void foo() { for(i = 0, k = 2; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1083,18 +1083,18 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_middle) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 3); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "i = 0"); BOOST_TEST(forData.control->init->inits.at(1).IsDelete()); - BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1|"); + BOOST_TEST(forData.control->init->inits.at(1).ToString>() == "j = 1|"); BOOST_TEST(forData.control->init->inits.at(2).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(2).ToString>() == "k = 2"); + BOOST_TEST(forData.control->init->inits.at(2).ToString>() == "k = 2"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -1105,7 +1105,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_middle) { BOOST_TEST(forData.control->incr->exprs.at(0).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(0).ToString() == "++ i"); BOOST_TEST(forData.control->incr.ToString() == "++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, j = 1, k = 2; i < 1; ++ i|i = 0, k = 2; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "i = 0, j = 1, k = 2; i < 1; ++ i|i = 0, k = 2; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -1116,7 +1116,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_middle) { // multi incr BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, --j) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1130,14 +1130,14 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -1150,7 +1150,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr) { BOOST_TEST(forData.control->incr->exprs.at(1).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(1).ToString() == "-- j"); BOOST_TEST(forData.control->incr.ToString() == "++ i, -- j"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, -- j"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, -- j"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -1160,7 +1160,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 1; --j) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1174,14 +1174,14 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -1194,7 +1194,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_front) { BOOST_TEST(forData.control->incr->exprs.at(1).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(1).ToString() == "-- j"); BOOST_TEST(forData.control->incr.ToString() == "-- j|++ i, -- j"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; -- j|int i = 0; i < 1; ++ i, -- j"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; -- j|int i = 0; i < 1; ++ i, -- j"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -1204,7 +1204,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_front) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1218,14 +1218,14 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -1238,7 +1238,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_back) { BOOST_TEST(forData.control->incr->exprs.at(1).IsInsert()); BOOST_TEST(forData.control->incr->exprs.at(1).ToString() == "|-- j"); BOOST_TEST(forData.control->incr.ToString() == "++ i|++ i, -- j"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|int i = 0; i < 1; ++ i, -- j"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i|int i = 0; i < 1; ++ i, -- j"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -1248,7 +1248,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_back) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_middle) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, k /= 2) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j, k /= 2) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1262,14 +1262,14 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_middle) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -1284,7 +1284,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_middle) { BOOST_TEST(forData.control->incr->exprs.at(2).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(2).ToString() == "k /= 2"); BOOST_TEST(forData.control->incr.ToString() == "++ i, k /= 2|++ i, -- j, k /= 2"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, k /= 2|int i = 0; i < 1; ++ i, -- j, k /= 2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, k /= 2|int i = 0; i < 1; ++ i, -- j, k /= 2"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -1294,7 +1294,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_middle) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, --j) {} }", "void foo() { for(int i = 0; i < 1; --j) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1308,14 +1308,14 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -1328,7 +1328,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_front) { BOOST_TEST(forData.control->incr->exprs.at(1).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(1).ToString() == "-- j"); BOOST_TEST(forData.control->incr.ToString() == "++ i, -- j|-- j"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, -- j|int i = 0; i < 1; -- j"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, -- j|int i = 0; i < 1; -- j"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -1338,7 +1338,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_front) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, --j) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1352,14 +1352,14 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -1372,7 +1372,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_back) { BOOST_TEST(forData.control->incr->exprs.at(1).IsDelete()); BOOST_TEST(forData.control->incr->exprs.at(1).ToString() == "-- j|"); BOOST_TEST(forData.control->incr.ToString() == "++ i, -- j|++ i"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, -- j|int i = 0; i < 1; ++ i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, -- j|int i = 0; i < 1; ++ i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -1382,7 +1382,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_back) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_middle) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, --j, k /= 2) {} }", "void foo() { for(int i = 0; i < 1; ++i, k /= 2) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1396,14 +1396,14 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_middle) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); BOOST_TEST(forData.control->init.IsCommon()); BOOST_TEST(forData.control->init->inits.size() == 1); BOOST_TEST(forData.control->init->inits.at(0).IsCommon()); - BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); + BOOST_TEST(forData.control->init->inits.at(0).ToString>() == "int i = 0"); BOOST_TEST(forData.control->condition.IsCommon()); BOOST_TEST(forData.control->condition->conditions.size() == 1); BOOST_TEST(forData.control->condition->conditions.at(0).IsCommon()); @@ -1418,7 +1418,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_middle) { BOOST_TEST(forData.control->incr->exprs.at(2).IsCommon()); BOOST_TEST(forData.control->incr->exprs.at(2).ToString() == "k /= 2"); BOOST_TEST(forData.control->incr.ToString() == "++ i, -- j, k /= 2|++ i, k /= 2"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, -- j, k /= 2|int i = 0; i < 1; ++ i, k /= 2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i = 0; i < 1; ++ i, -- j, k /= 2|int i = 0; i < 1; ++ i, k /= 2"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); diff --git a/test/suite/testDecl.cpp b/test/suite/testDecl.cpp index c2fcc9f..03decee 100644 --- a/test/suite/testDecl.cpp +++ b/test/suite/testDecl.cpp @@ -23,7 +23,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(decl_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a = 0;", "type a = 0;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -38,7 +38,7 @@ BOOST_AUTO_TEST_CASE(decl_common) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(decl_common) { BOOST_AUTO_TEST_CASE(decl_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("", "type a = 0;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE(decl_insert) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsInsert()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsInsert()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsInsert()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "|type"); @@ -91,7 +91,7 @@ BOOST_AUTO_TEST_CASE(decl_insert) { BOOST_AUTO_TEST_CASE(decl_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a = 0;", ""); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(decl_delete) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsDelete()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsDelete()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsDelete()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|"); @@ -125,7 +125,7 @@ BOOST_AUTO_TEST_CASE(decl_delete) { BOOST_AUTO_TEST_CASE(name_rename) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a = 0;", "type b = 0;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(name_rename) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); @@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE(name_rename) { BOOST_AUTO_TEST_CASE(type_rename) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("foo a;", "bar a;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -175,9 +175,9 @@ BOOST_AUTO_TEST_CASE(type_rename) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name.IsChange()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name.IsChange()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "foo|bar"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); @@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(type_rename) { BOOST_AUTO_TEST_CASE(type_rename_two) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("foo a;", "foo* a;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -206,12 +206,12 @@ BOOST_AUTO_TEST_CASE(type_rename_two) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 2); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.IsInsert()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDiffDispatch::TypeData::TypeType::POINTER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDispatch::TypeData::TypeType::POINTER); BOOST_TEST(!runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "foo|foo *"); @@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(type_rename_two) { BOOST_AUTO_TEST_CASE(decl_init_literal_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a = 0;", "type a = 1;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE(decl_init_literal_change) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); @@ -257,17 +257,17 @@ BOOST_AUTO_TEST_CASE(decl_init_literal_change) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetOriginal()->expr.at(0).IsDelete()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetModified()->expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetOriginal()->expr.at(0).GetOriginal())->literal.IsDelete()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetModified()->expr.at(0).GetModified())->literal.IsInsert()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetOriginal()->expr.at(0).GetOriginal())->literal.ToString() == "0|"); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetModified()->expr.at(0).GetModified())->literal.ToString() == "|1"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetOriginal()->expr.at(0).GetOriginal())->literal.IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetModified()->expr.at(0).GetModified())->literal.IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetOriginal()->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.GetModified()->expr.at(0).GetModified())->literal.ToString() == "|1"); BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a = 0|type a = 1"); } BOOST_AUTO_TEST_CASE(init_literal_change_2) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a(0);", "type a = 1;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -282,7 +282,7 @@ BOOST_AUTO_TEST_CASE(init_literal_change_2) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); @@ -296,22 +296,22 @@ BOOST_AUTO_TEST_CASE(init_literal_change_2) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0).IsDelete()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.IsDelete()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsInsert()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.IsInsert()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.ToString() == "|1"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.ToString() == "|1"); BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a(0)|type a = 1"); } BOOST_AUTO_TEST_CASE(init_literal_change_3) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a{0};", "type a = 1;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -326,7 +326,7 @@ BOOST_AUTO_TEST_CASE(init_literal_change_3) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); @@ -340,22 +340,22 @@ BOOST_AUTO_TEST_CASE(init_literal_change_3) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0).IsDelete()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.IsDelete()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsInsert()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.IsInsert()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.ToString() == "|1"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.ToString() == "|1"); BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type a(0)|type a = 1"); } BOOST_AUTO_TEST_CASE(name_only_match) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type* a(0);", "typePtr a = 1;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -370,12 +370,12 @@ BOOST_AUTO_TEST_CASE(name_only_match) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 2); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name.IsChange()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "type|typePtr"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name.IsChange()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "type|typePtr"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.IsDelete()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDiffDispatch::TypeData::TypeType::POINTER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDispatch::TypeData::TypeType::POINTER); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type *|typePtr"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); @@ -388,22 +388,22 @@ BOOST_AUTO_TEST_CASE(name_only_match) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0).IsDelete()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.IsDelete()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->arguments.at(0)->expr.at(0).GetOriginal())->literal.ToString() == "0|"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init.IsInsert()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.IsInsert()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.ToString() == "|1"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->init->expr.at(0).GetModified())->literal.ToString() == "|1"); BOOST_TEST(runner.GetDeclStmtInfo().at(0).ToString() == "type * a(0)|typePtr a = 1"); } BOOST_AUTO_TEST_CASE(comma_separated_decl) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a = 0, b = 1, c = 2;", "type a = 0, c = 2, d = 3;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -418,7 +418,7 @@ BOOST_AUTO_TEST_CASE(comma_separated_decl) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); @@ -437,7 +437,7 @@ BOOST_AUTO_TEST_CASE(comma_separated_decl) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(1)->type.ToString() == "type"); @@ -456,7 +456,7 @@ BOOST_AUTO_TEST_CASE(comma_separated_decl) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(2)->type.ToString() == "type"); @@ -474,7 +474,7 @@ BOOST_AUTO_TEST_CASE(comma_separated_decl) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(3)->type.ToString() == "type"); @@ -498,7 +498,7 @@ BOOST_AUTO_TEST_CASE(comma_separated_decl) { // compound name BOOST_AUTO_TEST_CASE(decl_compound_name_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("std::string str = \"\";", "std::string str = \"\";"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -513,50 +513,50 @@ BOOST_AUTO_TEST_CASE(decl_compound_name_common) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); - BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 3); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first).IsCommon()); + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 3); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first).IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0)).IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->names.size() == 0); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->name.IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->name.ToString() == "std"); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1)).IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1).GetElement())->op.IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1).GetElement())->op.ToString() == "::"); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2)).IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->names.size() == 0); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->name.IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->name.ToString() == "string"); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "std::string"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "std::string"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "std::string"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); @@ -574,7 +574,7 @@ BOOST_AUTO_TEST_CASE(decl_compound_name_common) { BOOST_AUTO_TEST_CASE(decl_compound_name_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("std::string str = \"\";", "std::wstring str = \"\";"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -589,50 +589,50 @@ BOOST_AUTO_TEST_CASE(decl_compound_name_change) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); - BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 3); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first).IsCommon()); + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 3); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first).IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0)).IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->names.size() == 0); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->name.IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->name.ToString() == "std"); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1)).IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1).GetElement())->op.IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1).GetElement())->op.ToString() == "::"); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2)).IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->names.size() == 0); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->name.IsChange()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->name.ToString() == "string|wstring"); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "std::string|std::wstring"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "std::string|std::wstring"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "std::string|std::wstring"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); @@ -650,7 +650,7 @@ BOOST_AUTO_TEST_CASE(decl_compound_name_change) { BOOST_AUTO_TEST_CASE(decl_simple_to_complex_name) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("string str = \"\";", "std::string str = \"\";"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -665,50 +665,50 @@ BOOST_AUTO_TEST_CASE(decl_simple_to_complex_name) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsInsert()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsInsert()); - BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 3); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first).IsInsert()); + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 3); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first).IsInsert()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0)).IsInsert()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->names.size() == 0); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->name.IsInsert()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement())->name.ToString() == "|std"); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1)).IsInsert()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1).GetElement())->op.IsInsert()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(1).GetElement())->op.ToString() == "|::"); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2)).IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->names.size() == 0); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->name.IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(2).GetElement())->name.ToString() == "string"); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "string|std::string"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "string|std::string"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "string|std::string"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); @@ -727,7 +727,7 @@ BOOST_AUTO_TEST_CASE(decl_simple_to_complex_name) { // specifier test BOOST_AUTO_TEST_CASE(decl_add_specifier) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a = 0;", "const type a = 0;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -743,14 +743,14 @@ BOOST_AUTO_TEST_CASE(decl_add_specifier) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 2); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsInsert()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::SPECIFIER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::SPECIFIER); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsInsert()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "|const"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.ToString>() == "type"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.ToString>() == "type"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|const type"); @@ -770,7 +770,7 @@ BOOST_AUTO_TEST_CASE(decl_add_specifier) { // specifier test BOOST_AUTO_TEST_CASE(decl_remove_specifier) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("const type a = 0;", "type a = 0;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -786,14 +786,14 @@ BOOST_AUTO_TEST_CASE(decl_remove_specifier) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 2); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsDelete()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::SPECIFIER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::SPECIFIER); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsDelete()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "const|"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.ToString>() == "type"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.ToString>() == "type"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "const type|type"); @@ -813,7 +813,7 @@ BOOST_AUTO_TEST_CASE(decl_remove_specifier) { // specifier test BOOST_AUTO_TEST_CASE(decl_change_specifier) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("static type a = 0;", "const type a = 0;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -829,19 +829,19 @@ BOOST_AUTO_TEST_CASE(decl_change_specifier) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 3); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsDelete()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::SPECIFIER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::SPECIFIER); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsDelete()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "static|"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.IsInsert()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDiffDispatch::TypeData::TypeType::SPECIFIER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetElement() == srcDispatch::TypeData::TypeType::SPECIFIER); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.IsInsert()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).first.ToString>() == "|const"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(2).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(2).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(2).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(2).first.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(2).first.ToString>() == "type"); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(2).first.ToString>() == "type"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "static type|const type"); @@ -861,7 +861,7 @@ BOOST_AUTO_TEST_CASE(decl_change_specifier) { // modifier change test BOOST_AUTO_TEST_CASE(decl_modifier_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type* a;", "type& a;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -876,13 +876,13 @@ BOOST_AUTO_TEST_CASE(decl_modifier_change) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 2); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "type"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name.IsCommon()); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.ToString>() == "type"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.IsChange()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetOriginal() == srcDiffDispatch::TypeData::TypeType::POINTER); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetModified() == srcDiffDispatch::TypeData::TypeType::REFERENCE); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetOriginal() == srcDispatch::TypeData::TypeType::POINTER); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(1).second.GetModified() == srcDispatch::TypeData::TypeType::REFERENCE); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type *|type &"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->name.IsCommon()); @@ -897,7 +897,7 @@ BOOST_AUTO_TEST_CASE(decl_modifier_change) { // templated name BOOST_AUTO_TEST_CASE(decl_template_argument_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a;", "type a;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -912,24 +912,24 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_common) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); - BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); - BOOST_TEST(std::any_cast>( - std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() )->name.IsCommon() ); - BOOST_TEST(std::any_cast>( - std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() )->name.ToString() == "type" ); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 1); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "arg"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 1); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "arg"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); @@ -944,7 +944,7 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_common) { BOOST_AUTO_TEST_CASE(decl_template_argument_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a;", "type a;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -959,24 +959,24 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_insert) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsInsert()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsInsert()); - BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); - BOOST_TEST(std::any_cast>( - std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() )->name.IsCommon() ); - BOOST_TEST(std::any_cast>( - std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() )->name.ToString() == "type" ); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsInsert()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 1); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "|arg"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 1); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "|arg"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|type"); @@ -991,7 +991,7 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_insert) { BOOST_AUTO_TEST_CASE(decl_template_argument_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a;", "type a;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -1006,24 +1006,24 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_delete) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsDelete()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsDelete()); - BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); - BOOST_TEST(std::any_cast>( - std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() )->name.IsCommon() ); - BOOST_TEST(std::any_cast>( - std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() )->name.ToString() == "type" ); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsDelete()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 1); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "arg|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 1); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "arg|"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|type"); @@ -1038,7 +1038,7 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_delete) { BOOST_AUTO_TEST_CASE(decl_template_argument_insert_arg) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a;", "type a;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -1053,26 +1053,26 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_insert_arg) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); - BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); - BOOST_TEST(std::any_cast>( - std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() )->name.IsCommon() ); - BOOST_TEST(std::any_cast>( - std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() )->name.ToString() == "type" ); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 2); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "foo"); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(1).IsInsert()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(1).ToString() == "|bar"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 2); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "foo"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(1).IsInsert()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(1).ToString() == "|bar"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|type"); @@ -1087,7 +1087,7 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_insert_arg) { BOOST_AUTO_TEST_CASE(decl_template_argument_delete_arg) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a;", "type a;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -1102,26 +1102,26 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_delete_arg) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); - BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); - BOOST_TEST(std::any_cast>( - std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() )->name.IsCommon() ); - BOOST_TEST(std::any_cast>( - std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() )->name.ToString() == "type" ); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 2); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "foo|"); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(1).IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(1).ToString() == "bar"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 2); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsDelete()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "foo|"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(1).IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(1).ToString() == "bar"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|type"); @@ -1136,7 +1136,7 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_delete_arg) { BOOST_AUTO_TEST_CASE(decl_template_argument_change_arg) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("type a;", "type a;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -1151,46 +1151,46 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_change_arg) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); - BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); - BOOST_TEST(std::any_cast>( - std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + BOOST_TEST(!std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->name); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.size() == 1); + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() )->name.IsCommon() ); - BOOST_TEST(std::any_cast>( - std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() + BOOST_TEST(std::any_cast>( + std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->names.at(0).GetElement() )->name.ToString() == "type" ); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 1); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.size() == 1); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.at(0).IsCommon()); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.size() == 1); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.size() == 1); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.at(0).IsCommon()); + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.at(0).GetElement() )->names.size() == 0 ); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.at(0).GetElement() )->name.IsChange() ); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.at(0).GetElement() )->name.GetOriginal() == "foo" ); - BOOST_TEST(std::any_cast>( - std::any_cast>( + BOOST_TEST(std::any_cast>( + std::any_cast>( runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0)->expr.at(0).GetElement() )->name.GetModified() == "bar" ); - BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "foo|bar"); + BOOST_TEST(std::any_cast>(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.GetElement())->templateArgumentList->arguments.at(0).ToString() == "foo|bar"); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type|type"); @@ -1206,7 +1206,7 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_change_arg) { // templated BOOST_AUTO_TEST_CASE(decl_template_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template type a = 0;", "template type a = 0;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); @@ -1223,7 +1223,7 @@ BOOST_AUTO_TEST_CASE(decl_template_common) { BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetDeclStmtInfo().at(0)->decls.at(0)->type.ToString() == "type"); diff --git a/test/suite/testDeclStmt.cpp b/test/suite/testDeclStmt.cpp index 88c3995..dd55589 100644 --- a/test/suite/testDeclStmt.cpp +++ b/test/suite/testDeclStmt.cpp @@ -21,7 +21,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_common_decl_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { int i; }", "void foo() { int i; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(block_common_decl_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "int i"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(block_common_decl_stmt) { BOOST_AUTO_TEST_CASE(block_insert_decl_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { foo bar; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(block_insert_decl_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|foo bar"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|foo bar"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -67,7 +67,7 @@ BOOST_AUTO_TEST_CASE(block_insert_decl_stmt) { BOOST_AUTO_TEST_CASE(block_delete_decl_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { foo bar; }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(block_delete_decl_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "foo bar|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "foo bar|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(block_delete_decl_stmt) { BOOST_AUTO_TEST_CASE(block_replace_decl_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { foo f; }", "void foo() { bar b; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -100,9 +100,9 @@ BOOST_AUTO_TEST_CASE(block_replace_decl_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 2); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "foo f|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "foo f|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).IsInsert()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|bar b"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|bar b"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); diff --git a/test/suite/testDo.cpp b/test/suite/testDo.cpp index 88f4027..b2bbf1b 100644 --- a/test/suite/testDo.cpp +++ b/test/suite/testDo.cpp @@ -23,7 +23,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_change_common_do) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { do {} while(1); }", "void foo() { do {} while(1); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_do) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_do) { BOOST_AUTO_TEST_CASE(block_insert_do) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { do {} while(1);"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -57,25 +57,25 @@ BOOST_AUTO_TEST_CASE(block_insert_do) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::DoData& doData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::DoData& doData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(doData.condition); BOOST_TEST(doData.condition.IsInsert()); BOOST_TEST(doData.condition->conditions.size() == 1); BOOST_TEST(doData.condition->conditions.at(0).IsInsert()); - const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(doData.condition->conditions.at(0).GetElement()); + const srcDispatch::ExpressionData& expr = *std::any_cast>(doData.condition->conditions.at(0).GetElement()); BOOST_TEST(expr.expr.size() == 1); BOOST_TEST(expr.expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "|1"); - BOOST_TEST(expr.expr.at(0).ToString>() == "|1"); - BOOST_TEST(doData.condition->conditions.at(0).ToString>() == "|1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "|1"); + BOOST_TEST(expr.expr.at(0).ToString>() == "|1"); + BOOST_TEST(doData.condition->conditions.at(0).ToString>() == "|1"); BOOST_TEST(doData.condition.ToString() == "|1"); BOOST_TEST(doData.block.IsInsert()); BOOST_TEST(doData.block->statements.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(block_insert_do) { BOOST_AUTO_TEST_CASE(block_delete_do) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { do {} while(1);", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -98,25 +98,25 @@ BOOST_AUTO_TEST_CASE(block_delete_do) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::DoData& doData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::DoData& doData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(doData.condition); BOOST_TEST(doData.condition.IsDelete()); BOOST_TEST(doData.condition->conditions.size() == 1); BOOST_TEST(doData.condition->conditions.at(0).IsDelete()); - const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(doData.condition->conditions.at(0).GetElement()); + const srcDispatch::ExpressionData& expr = *std::any_cast>(doData.condition->conditions.at(0).GetElement()); BOOST_TEST(expr.expr.size() == 1); BOOST_TEST(expr.expr.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "1|"); - BOOST_TEST(expr.expr.at(0).ToString>() == "1|"); - BOOST_TEST(doData.condition->conditions.at(0).ToString>() == "1|"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "1|"); + BOOST_TEST(expr.expr.at(0).ToString>() == "1|"); + BOOST_TEST(doData.condition->conditions.at(0).ToString>() == "1|"); BOOST_TEST(doData.condition.ToString() == "1|"); BOOST_TEST(doData.block.IsDelete()); BOOST_TEST(doData.block->statements.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(block_delete_do) { BOOST_AUTO_TEST_CASE(block_replace_do) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { do { a; } while(1); }", "void foo() { do { b; } while(2); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -139,19 +139,19 @@ BOOST_AUTO_TEST_CASE(block_replace_do) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 2); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::DoData& deletedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::DoData& deletedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(deletedData.condition.IsDelete()); BOOST_TEST(deletedData.block.IsDelete()); BOOST_TEST(deletedData.block->statements.size() == 1); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).IsInsert()); - const srcDiffDispatch::DoData& insertedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(1).GetElement()); + const srcDispatch::DoData& insertedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(1).GetElement()); BOOST_TEST(insertedData.condition.IsInsert()); BOOST_TEST(insertedData.block.IsInsert()); BOOST_TEST(insertedData.block->statements.size() == 1); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|2"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); diff --git a/test/suite/testExprConvert.cpp b/test/suite/testExprConvert.cpp index 168c654..f3abf24 100644 --- a/test/suite/testExprConvert.cpp +++ b/test/suite/testExprConvert.cpp @@ -25,7 +25,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(decl_to_expr) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { int i = 0; }", "void foo() { 0; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -38,7 +38,7 @@ BOOST_AUTO_TEST_CASE(decl_to_expr) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::DeclStmtData& declStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::DeclStmtData& declStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(declStmtData.decls.size() == 1); BOOST_TEST(declStmtData.decls.at(0).IsDelete()); BOOST_TEST(declStmtData.decls.at(0)->type.IsDelete()); @@ -48,15 +48,15 @@ BOOST_AUTO_TEST_CASE(decl_to_expr) { BOOST_TEST(declStmtData.decls.at(0)->init.IsCommon()); BOOST_TEST(declStmtData.decls.at(0)->init->expr.size() == 1); BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).IsCommon()); - BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).ToString>() == "0"); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).ToString>() == "0"); BOOST_TEST(declStmtData.decls.at(0)->init.ToString() == "0"); BOOST_TEST(declStmtData.decls.at(0).ToString(srcDispatch::DELETE) == "int i = 0"); - const srcDiffDispatch::ExprStmtData& exprStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::ExprStmtData& exprStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(exprStmtData.expr.IsCommon()); BOOST_TEST(exprStmtData.expr->expr.size() == 1); BOOST_TEST(exprStmtData.expr->expr.at(0).IsCommon()); - BOOST_TEST(exprStmtData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(exprStmtData.expr->expr.at(0).ToString>() == "0"); BOOST_TEST(exprStmtData.expr.ToString() == "0"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(decl_to_expr) { BOOST_AUTO_TEST_CASE(expr_to_decl) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { 0; }", "void foo() { int i = 0; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -81,14 +81,14 @@ BOOST_AUTO_TEST_CASE(expr_to_decl) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::ExprStmtData& exprStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::ExprStmtData& exprStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(exprStmtData.expr.IsCommon()); BOOST_TEST(exprStmtData.expr->expr.size() == 1); BOOST_TEST(exprStmtData.expr->expr.at(0).IsCommon()); - BOOST_TEST(exprStmtData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(exprStmtData.expr->expr.at(0).ToString>() == "0"); BOOST_TEST(exprStmtData.expr.ToString() == "0"); - const srcDiffDispatch::DeclStmtData& declStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::DeclStmtData& declStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(declStmtData.decls.size() == 1); BOOST_TEST(declStmtData.decls.at(0).IsInsert()); BOOST_TEST(declStmtData.decls.at(0)->type.IsInsert()); @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(expr_to_decl) { BOOST_TEST(declStmtData.decls.at(0)->init.IsCommon()); BOOST_TEST(declStmtData.decls.at(0)->init->expr.size() == 1); BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).IsCommon()); - BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).ToString>() == "0"); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).ToString>() == "0"); BOOST_TEST(declStmtData.decls.at(0)->init.ToString() == "0"); BOOST_TEST(declStmtData.decls.at(0).ToString(srcDispatch::INSERT) == "int i = 0"); @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE(expr_to_decl) { BOOST_AUTO_TEST_CASE(expr_to_return) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { 0; }", "void foo() { return 0; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -124,18 +124,18 @@ BOOST_AUTO_TEST_CASE(expr_to_return) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::ExprStmtData& exprStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::ExprStmtData& exprStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(exprStmtData.expr.IsCommon()); BOOST_TEST(exprStmtData.expr->expr.size() == 1); BOOST_TEST(exprStmtData.expr->expr.at(0).IsCommon()); - BOOST_TEST(exprStmtData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(exprStmtData.expr->expr.at(0).ToString>() == "0"); BOOST_TEST(exprStmtData.expr.ToString() == "0"); - const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(returnData.expr.IsCommon()); BOOST_TEST(returnData.expr->expr.size() == 1); BOOST_TEST(returnData.expr->expr.at(0).IsCommon()); - BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "0"); BOOST_TEST(returnData.expr.ToString() == "0"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE(expr_to_return) { BOOST_AUTO_TEST_CASE(return_to_expr) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { return 0; }", "void foo() { 0; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -160,18 +160,18 @@ BOOST_AUTO_TEST_CASE(return_to_expr) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(returnData.expr.IsCommon()); BOOST_TEST(returnData.expr->expr.size() == 1); BOOST_TEST(returnData.expr->expr.at(0).IsCommon()); - BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "0"); BOOST_TEST(returnData.expr.ToString() == "0"); - const srcDiffDispatch::ExprStmtData& exprStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::ExprStmtData& exprStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(exprStmtData.expr.IsCommon()); BOOST_TEST(exprStmtData.expr->expr.size() == 1); BOOST_TEST(exprStmtData.expr->expr.at(0).IsCommon()); - BOOST_TEST(exprStmtData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(exprStmtData.expr->expr.at(0).ToString>() == "0"); BOOST_TEST(exprStmtData.expr.ToString() == "0"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -183,7 +183,7 @@ BOOST_AUTO_TEST_CASE(return_to_expr) { BOOST_AUTO_TEST_CASE(decl_to_return) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { int i = 0; }", "void foo() { return 0; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -196,7 +196,7 @@ BOOST_AUTO_TEST_CASE(decl_to_return) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::DeclStmtData& declStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::DeclStmtData& declStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(declStmtData.decls.size() == 1); BOOST_TEST(declStmtData.decls.at(0).IsDelete()); BOOST_TEST(declStmtData.decls.at(0)->type.IsDelete()); @@ -206,15 +206,15 @@ BOOST_AUTO_TEST_CASE(decl_to_return) { BOOST_TEST(declStmtData.decls.at(0)->init.IsCommon()); BOOST_TEST(declStmtData.decls.at(0)->init->expr.size() == 1); BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).IsCommon()); - BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).ToString>() == "0"); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).ToString>() == "0"); BOOST_TEST(declStmtData.decls.at(0)->init.ToString() == "0"); BOOST_TEST(declStmtData.decls.at(0).ToString(srcDispatch::DELETE) == "int i = 0"); - const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(returnData.expr.IsCommon()); BOOST_TEST(returnData.expr->expr.size() == 1); BOOST_TEST(returnData.expr->expr.at(0).IsCommon()); - BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "0"); BOOST_TEST(returnData.expr.ToString() == "0"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(decl_to_return) { BOOST_AUTO_TEST_CASE(return_to_decl) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { return 0; }", "void foo() { int i = 0; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -239,14 +239,14 @@ BOOST_AUTO_TEST_CASE(return_to_decl) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsChange()); - const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); + const srcDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetOriginal()); BOOST_TEST(returnData.expr.IsCommon()); BOOST_TEST(returnData.expr->expr.size() == 1); BOOST_TEST(returnData.expr->expr.at(0).IsCommon()); - BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "0"); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "0"); BOOST_TEST(returnData.expr.ToString() == "0"); - const srcDiffDispatch::DeclStmtData& declStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); + const srcDispatch::DeclStmtData& declStmtData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetModified()); BOOST_TEST(declStmtData.decls.size() == 1); BOOST_TEST(declStmtData.decls.at(0).IsInsert()); BOOST_TEST(declStmtData.decls.at(0)->type.IsInsert()); @@ -256,7 +256,7 @@ BOOST_AUTO_TEST_CASE(return_to_decl) { BOOST_TEST(declStmtData.decls.at(0)->init.IsCommon()); BOOST_TEST(declStmtData.decls.at(0)->init->expr.size() == 1); BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).IsCommon()); - BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).ToString>() == "0"); + BOOST_TEST(declStmtData.decls.at(0)->init->expr.at(0).ToString>() == "0"); BOOST_TEST(declStmtData.decls.at(0)->init.ToString() == "0"); BOOST_TEST(declStmtData.decls.at(0).ToString(srcDispatch::INSERT) == "int i = 0"); diff --git a/test/suite/testExprStmt.cpp b/test/suite/testExprStmt.cpp index a22cd4a..2a3fb63 100644 --- a/test/suite/testExprStmt.cpp +++ b/test/suite/testExprStmt.cpp @@ -21,7 +21,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_change_common_expr_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { a; }", "void foo() { a; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_expr_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_expr_stmt) { BOOST_AUTO_TEST_CASE(block_insert_expr_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { a; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -56,15 +56,15 @@ BOOST_AUTO_TEST_CASE(block_insert_expr_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::ExprStmtData& expr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& expr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(expr.expr); BOOST_TEST(expr.expr.IsInsert()); BOOST_TEST(expr.expr->expr.size() == 1); BOOST_TEST(expr.expr->expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(expr.expr->expr.at(0).GetElement())->name.IsInsert()); - BOOST_TEST(expr.expr->expr.at(0).ToString>() == "|a"); + BOOST_TEST(std::any_cast>(expr.expr->expr.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(expr.expr->expr.at(0).ToString>() == "|a"); BOOST_TEST(expr.expr.ToString() == "|a"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|a"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|a"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(block_insert_expr_stmt) { BOOST_AUTO_TEST_CASE(block_delete_expr_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { a; }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -87,15 +87,15 @@ BOOST_AUTO_TEST_CASE(block_delete_expr_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::ExprStmtData& expr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& expr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(expr.expr); BOOST_TEST(expr.expr.IsDelete()); BOOST_TEST(expr.expr->expr.size() == 1); BOOST_TEST(expr.expr->expr.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(expr.expr->expr.at(0).GetElement())->name.IsDelete()); - BOOST_TEST(expr.expr->expr.at(0).ToString>() == "a|"); + BOOST_TEST(std::any_cast>(expr.expr->expr.at(0).GetElement())->name.IsDelete()); + BOOST_TEST(expr.expr->expr.at(0).ToString>() == "a|"); BOOST_TEST(expr.expr.ToString() == "a|"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(block_delete_expr_stmt) { BOOST_AUTO_TEST_CASE(block_change_expr_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { a - b; }", "void foo() { a + b; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -118,20 +118,20 @@ BOOST_AUTO_TEST_CASE(block_change_expr_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ExprStmtData& expr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& expr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(expr.expr); BOOST_TEST(expr.expr.IsCommon()); BOOST_TEST(expr.expr->expr.size() == 3); BOOST_TEST(expr.expr->expr.at(0).IsCommon()); - BOOST_TEST(expr.expr->expr.at(0).ToString>() == "a"); + BOOST_TEST(expr.expr->expr.at(0).ToString>() == "a"); BOOST_TEST(expr.expr->expr.at(1).IsCommon()); - BOOST_TEST(std::any_cast>(expr.expr->expr.at(1).GetElement())->op.IsChange()); - BOOST_TEST(std::any_cast>(expr.expr->expr.at(1).GetElement())->op.ToString() == "-|+"); - BOOST_TEST(expr.expr->expr.at(1).ToString>() == "-|+"); + BOOST_TEST(std::any_cast>(expr.expr->expr.at(1).GetElement())->op.IsChange()); + BOOST_TEST(std::any_cast>(expr.expr->expr.at(1).GetElement())->op.ToString() == "-|+"); + BOOST_TEST(expr.expr->expr.at(1).ToString>() == "-|+"); BOOST_TEST(expr.expr->expr.at(2).IsCommon()); - BOOST_TEST(expr.expr->expr.at(2).ToString>() == "b"); + BOOST_TEST(expr.expr->expr.at(2).ToString>() == "b"); BOOST_TEST(expr.expr.ToString() == "a - b|a + b"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a - b|a + b"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a - b|a + b"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -142,7 +142,7 @@ BOOST_AUTO_TEST_CASE(block_change_expr_stmt) { BOOST_AUTO_TEST_CASE(block_replace_expr_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { a; }", "void foo() { b; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -154,28 +154,28 @@ BOOST_AUTO_TEST_CASE(block_replace_expr_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 2); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::ExprStmtData& deletedExpr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& deletedExpr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(deletedExpr.expr); BOOST_TEST(deletedExpr.expr.IsDelete()); BOOST_TEST(deletedExpr.expr->expr.size() == 1); BOOST_TEST(deletedExpr.expr->expr.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(deletedExpr.expr->expr.at(0).GetElement())->name.IsDelete()); - BOOST_TEST(deletedExpr.expr->expr.at(0).ToString>() == "a|"); + BOOST_TEST(std::any_cast>(deletedExpr.expr->expr.at(0).GetElement())->name.IsDelete()); + BOOST_TEST(deletedExpr.expr->expr.at(0).ToString>() == "a|"); BOOST_TEST(deletedExpr.expr.ToString() == "a|"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).IsInsert()); - const srcDiffDispatch::ExprStmtData& insertedExpr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(1).GetElement()); + const srcDispatch::ExprStmtData& insertedExpr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(1).GetElement()); BOOST_TEST(insertedExpr.expr); BOOST_TEST(insertedExpr.expr.IsInsert()); BOOST_TEST(insertedExpr.expr->expr.size() == 1); BOOST_TEST(insertedExpr.expr->expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(insertedExpr.expr->expr.at(0).GetElement())->name.IsInsert()); - BOOST_TEST(insertedExpr.expr->expr.at(0).ToString>() == "|b"); + BOOST_TEST(std::any_cast>(insertedExpr.expr->expr.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(insertedExpr.expr->expr.at(0).ToString>() == "|b"); BOOST_TEST(insertedExpr.expr.ToString() == "|b"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|b"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|b"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); diff --git a/test/suite/testFor.cpp b/test/suite/testFor.cpp index afd9982..9b2acf1 100644 --- a/test/suite/testFor.cpp +++ b/test/suite/testFor.cpp @@ -24,7 +24,7 @@ namespace data = boost::unit_test; // // for and control BOOST_AUTO_TEST_CASE(block_common_for) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(; 1; ) {} }", "void foo() { for(; 1; ) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE(block_common_for) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsCommon()); BOOST_TEST(forData.control->init); @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(block_common_for) { BOOST_TEST(forData.control->condition.ToString() == "1"); BOOST_TEST(forData.control->incr.IsCommon()); BOOST_TEST(forData.control->incr->exprs.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "; 1; "); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "; 1; "); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(block_common_for) { BOOST_AUTO_TEST_CASE(block_insert_for) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { for(; 1; ) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(block_insert_for) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsInsert()); BOOST_TEST(forData.control->init); @@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(block_insert_for) { BOOST_TEST(forData.control->incr); BOOST_TEST(forData.control->incr.IsInsert()); BOOST_TEST(forData.control->incr->exprs.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|; 1; "); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|; 1; "); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -91,7 +91,7 @@ BOOST_AUTO_TEST_CASE(block_insert_for) { BOOST_AUTO_TEST_CASE(block_delete_for) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { for(; 1; ) {} }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(block_delete_for) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ForData& forData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(forData.control.IsDelete()); BOOST_TEST(forData.control->init); @@ -114,7 +114,7 @@ BOOST_AUTO_TEST_CASE(block_delete_for) { BOOST_TEST(forData.control->incr); BOOST_TEST(forData.control->incr.IsDelete()); BOOST_TEST(forData.control->incr->exprs.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "; 1; |"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "; 1; |"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); diff --git a/test/suite/testFunction.cpp b/test/suite/testFunction.cpp index d478974..fde1113 100644 --- a/test/suite/testFunction.cpp +++ b/test/suite/testFunction.cpp @@ -21,7 +21,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(function_foo) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("#include \n#include \n\nclass Person {\nprivate:\n std::string name_;\n int age_;\n\npublic:\n // Constructor\n Person(const std::string& NAME, int AGE): name_(NAME), age_(AGE) {}\n\n // Getter\n std::string getName() const {\n return name_;\n }\n\n // Setter\n void setName(const std::string& newName) {\n name_ = newName;\n }\n\n // Method\n void sayHello() const {\n std::cout << \"Hi, my name is \" << name_ << \" and I am \" << age_ << \" years old.\n\";\n }\n", "#include \n#include \n\nclass Person {\nprivate:\n std::string name_;\n int age_;\n\npublic:\n // Constructor\n Person(const std::string& NAME, int AGE): name_(NAME), age_(AGE) {}\n\n // Getter\n std::string getName() const {\n return name_;\n }\n\n // Setter\n void setName(const std::string& newName) {\n name_ = newName;\n }\n\n // Method\n void sayHello() const {\n std::cout << \"Hi, my name is \" << name_ << \" and I am \" << age_ << \" years old.\n\";\n }\n"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(function_foo) { BOOST_AUTO_TEST_CASE(function_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE(function_common) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(function_common) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(function_common) { BOOST_AUTO_TEST_CASE(function_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -83,7 +83,7 @@ BOOST_AUTO_TEST_CASE(function_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -95,7 +95,7 @@ BOOST_AUTO_TEST_CASE(function_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsInsert()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "|void"); @@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(function_insert) { BOOST_AUTO_TEST_CASE(function_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", ""); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(function_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(function_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsDelete()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void|"); @@ -156,7 +156,7 @@ BOOST_AUTO_TEST_CASE(function_delete) { BOOST_AUTO_TEST_CASE(function_name_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void bar() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -165,7 +165,7 @@ BOOST_AUTO_TEST_CASE(function_name_change) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(function_name_change) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -198,7 +198,7 @@ BOOST_AUTO_TEST_CASE(function_name_change) { BOOST_AUTO_TEST_CASE(function_return_type_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "int foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(function_return_type_change) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -219,9 +219,9 @@ BOOST_AUTO_TEST_CASE(function_return_type_change) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.GetElement())->name.IsChange()); + BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.GetElement())->name.IsChange()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void|int"); BOOST_TEST(runner.GetFunctionInfo().at(0)->name.IsCommon()); @@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE(function_return_type_change) { BOOST_AUTO_TEST_CASE(function_add_parameter) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo(int i) {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -249,7 +249,7 @@ BOOST_AUTO_TEST_CASE(function_add_parameter) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(function_add_parameter) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -276,7 +276,7 @@ BOOST_AUTO_TEST_CASE(function_add_parameter) { BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.IsInsert()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).first.IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.ToString() == "|int"); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.IsInsert()); @@ -290,7 +290,7 @@ BOOST_AUTO_TEST_CASE(function_add_parameter) { BOOST_AUTO_TEST_CASE(function_remove_parameter) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo(double d) {}", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -299,7 +299,7 @@ BOOST_AUTO_TEST_CASE(function_remove_parameter) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -311,7 +311,7 @@ BOOST_AUTO_TEST_CASE(function_remove_parameter) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -325,7 +325,7 @@ BOOST_AUTO_TEST_CASE(function_remove_parameter) { BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0).IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.IsDelete()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).first.IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.ToString() == "double|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.IsDelete()); @@ -339,7 +339,7 @@ BOOST_AUTO_TEST_CASE(function_remove_parameter) { BOOST_AUTO_TEST_CASE(function_parameter_type_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo(double d) {}", "void foo(int d) {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -348,7 +348,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_type_change) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -360,7 +360,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_type_change) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -374,7 +374,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_type_change) { BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).first.IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).first.GetElement())->name.IsChange()); + BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).first.GetElement())->name.IsChange()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.ToString() == "double|int"); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.ToString() == "d"); @@ -387,7 +387,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_type_change) { BOOST_AUTO_TEST_CASE(function_parameter_name_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo(double d) {}", "void foo(double num) {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -396,7 +396,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_name_change) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -408,7 +408,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_name_change) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -436,7 +436,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_name_change) { BOOST_AUTO_TEST_CASE(function_parameter_multi_change) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo(int i, double d) {}", "void foo(double d, long l) {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -445,7 +445,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_multi_change) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -457,7 +457,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_multi_change) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -471,7 +471,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_multi_change) { BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0).IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.IsDelete()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type->types.at(0).first.IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->type.ToString() == "int|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(0)->name.IsDelete()); @@ -480,7 +480,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_multi_change) { BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(1).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(1)->type.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(1)->type->types.at(0).first.IsCommon()); - BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->parameters.at(1)->type->types.at(0).first.GetElement())->name.IsCommon()); + BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->parameters.at(1)->type->types.at(0).first.GetElement())->name.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(1)->type.ToString() == "double"); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(1)->name.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(1)->name.ToString() == "d"); @@ -489,7 +489,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_multi_change) { BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type.IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type->types.at(0).second.IsInsert()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type->types.at(0).first.IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->type.ToString() == "|long"); BOOST_TEST(runner.GetFunctionInfo().at(0)->parameters.at(2)->name.IsInsert()); @@ -504,7 +504,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_multi_change) { // decl to def BOOST_AUTO_TEST_CASE(function_decl_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo();", "void foo();"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -513,7 +513,7 @@ BOOST_AUTO_TEST_CASE(function_decl_common) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -525,7 +525,7 @@ BOOST_AUTO_TEST_CASE(function_decl_common) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -545,7 +545,7 @@ BOOST_AUTO_TEST_CASE(function_decl_common) { // specifiers BOOST_AUTO_TEST_CASE(function_specifier_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo();", "void foo() const;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -554,7 +554,7 @@ BOOST_AUTO_TEST_CASE(function_specifier_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -569,7 +569,7 @@ BOOST_AUTO_TEST_CASE(function_specifier_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -588,7 +588,7 @@ BOOST_AUTO_TEST_CASE(function_specifier_insert) { BOOST_AUTO_TEST_CASE(function_specifier_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() const;", "void foo();"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -597,7 +597,7 @@ BOOST_AUTO_TEST_CASE(function_specifier_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -612,7 +612,7 @@ BOOST_AUTO_TEST_CASE(function_specifier_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -631,7 +631,7 @@ BOOST_AUTO_TEST_CASE(function_specifier_delete) { BOOST_AUTO_TEST_CASE(function_pure_virtual_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo();", "void foo() = 0;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -640,7 +640,7 @@ BOOST_AUTO_TEST_CASE(function_pure_virtual_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -656,7 +656,7 @@ BOOST_AUTO_TEST_CASE(function_pure_virtual_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -675,7 +675,7 @@ BOOST_AUTO_TEST_CASE(function_pure_virtual_insert) { BOOST_AUTO_TEST_CASE(function_pure_virtual_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() = 0;", "void foo();"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -684,7 +684,7 @@ BOOST_AUTO_TEST_CASE(function_pure_virtual_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); @@ -701,7 +701,7 @@ BOOST_AUTO_TEST_CASE(function_pure_virtual_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -720,7 +720,7 @@ BOOST_AUTO_TEST_CASE(function_pure_virtual_delete) { BOOST_AUTO_TEST_CASE(function_pure_delete_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo();", "void foo() = delete;"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -729,7 +729,7 @@ BOOST_AUTO_TEST_CASE(function_pure_delete_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -744,7 +744,7 @@ BOOST_AUTO_TEST_CASE(function_pure_delete_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -763,7 +763,7 @@ BOOST_AUTO_TEST_CASE(function_pure_delete_insert) { BOOST_AUTO_TEST_CASE(function_pure_delete_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() = delete;", "void foo();"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -772,7 +772,7 @@ BOOST_AUTO_TEST_CASE(function_pure_delete_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -786,7 +786,7 @@ BOOST_AUTO_TEST_CASE(function_pure_delete_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -806,7 +806,7 @@ BOOST_AUTO_TEST_CASE(function_pure_delete_delete) { // block BOOST_AUTO_TEST_CASE(function_block_insert_expr_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { a; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -815,7 +815,7 @@ BOOST_AUTO_TEST_CASE(function_block_insert_expr_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -827,7 +827,7 @@ BOOST_AUTO_TEST_CASE(function_block_insert_expr_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -846,15 +846,15 @@ BOOST_AUTO_TEST_CASE(function_block_insert_expr_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::ExprStmtData& expr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ExprStmtData& expr = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(expr.expr); BOOST_TEST(expr.expr.IsInsert()); BOOST_TEST(expr.expr->expr.size() == 1); BOOST_TEST(expr.expr->expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(expr.expr->expr.at(0).GetElement())->name.IsInsert()); - BOOST_TEST(expr.expr->expr.at(0).ToString>() == "|a"); + BOOST_TEST(std::any_cast>(expr.expr->expr.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(expr.expr->expr.at(0).ToString>() == "|a"); BOOST_TEST(expr.expr.ToString() == "|a"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|a"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|a"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->blocks.size() == 0); @@ -865,7 +865,7 @@ BOOST_AUTO_TEST_CASE(function_block_insert_expr_stmt) { // operator BOOST_AUTO_TEST_CASE(function_operator_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("bool operator==() {}", "bool operator==() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -874,7 +874,7 @@ BOOST_AUTO_TEST_CASE(function_operator_common) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::OPERATOR); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::OPERATOR); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -886,7 +886,7 @@ BOOST_AUTO_TEST_CASE(function_operator_common) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "bool"); @@ -906,7 +906,7 @@ BOOST_AUTO_TEST_CASE(function_operator_common) { BOOST_AUTO_TEST_CASE(function_operator_common_decl) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("bool operator==();", "bool operator==();"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -915,7 +915,7 @@ BOOST_AUTO_TEST_CASE(function_operator_common_decl) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::OPERATOR); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::OPERATOR); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -927,7 +927,7 @@ BOOST_AUTO_TEST_CASE(function_operator_common_decl) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "bool"); @@ -945,7 +945,7 @@ BOOST_AUTO_TEST_CASE(function_operator_common_decl) { BOOST_AUTO_TEST_CASE(function_operator_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("", "bool operator==() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -954,7 +954,7 @@ BOOST_AUTO_TEST_CASE(function_operator_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::OPERATOR); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::OPERATOR); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -966,7 +966,7 @@ BOOST_AUTO_TEST_CASE(function_operator_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsInsert()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "|bool"); @@ -986,7 +986,7 @@ BOOST_AUTO_TEST_CASE(function_operator_insert) { BOOST_AUTO_TEST_CASE(function_operator_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("bool operator==() {}", ""); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -995,7 +995,7 @@ BOOST_AUTO_TEST_CASE(function_operator_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::OPERATOR); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::OPERATOR); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -1007,7 +1007,7 @@ BOOST_AUTO_TEST_CASE(function_operator_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsDelete()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "bool|"); @@ -1027,7 +1027,7 @@ BOOST_AUTO_TEST_CASE(function_operator_delete) { BOOST_AUTO_TEST_CASE(function_operator_type) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("operator bool() {}", "operator bool() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1036,7 +1036,7 @@ BOOST_AUTO_TEST_CASE(function_operator_type) { BOOST_TEST(runner.GetFunctionInfo().at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.empty()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::OPERATOR); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::OPERATOR); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -1064,7 +1064,7 @@ BOOST_AUTO_TEST_CASE(function_operator_type) { // template function BOOST_AUTO_TEST_CASE(function_template_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void foo() {}", "template void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1075,7 +1075,7 @@ BOOST_AUTO_TEST_CASE(function_template_common) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -1087,7 +1087,7 @@ BOOST_AUTO_TEST_CASE(function_template_common) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -1107,7 +1107,7 @@ BOOST_AUTO_TEST_CASE(function_template_common) { BOOST_AUTO_TEST_CASE(function_template_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "template void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1118,7 +1118,7 @@ BOOST_AUTO_TEST_CASE(function_template_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "|template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -1130,7 +1130,7 @@ BOOST_AUTO_TEST_CASE(function_template_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); @@ -1150,7 +1150,7 @@ BOOST_AUTO_TEST_CASE(function_template_insert) { BOOST_AUTO_TEST_CASE(function_template_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void foo() {}", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -1161,7 +1161,7 @@ BOOST_AUTO_TEST_CASE(function_template_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(!runner.GetFunctionInfo().at(0)->accessSpecifier); BOOST_TEST(!runner.GetFunctionInfo().at(0)->isPureVirtual); @@ -1173,7 +1173,7 @@ BOOST_AUTO_TEST_CASE(function_template_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDiffDispatch::TypeData::TypeType::TYPENAME); + BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).second.GetElement() == srcDispatch::TypeData::TypeType::TYPENAME); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType->types.at(0).first.IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->returnType.ToString() == "void"); diff --git a/test/suite/testGoto.cpp b/test/suite/testGoto.cpp index cd26db9..4509cad 100644 --- a/test/suite/testGoto.cpp +++ b/test/suite/testGoto.cpp @@ -24,7 +24,7 @@ namespace data = boost::unit_test; // goto/break/continue BOOST_AUTO_TEST_CASE(block_change_common_break) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { break; }", "void foo() { break; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -36,10 +36,10 @@ BOOST_AUTO_TEST_CASE(block_change_common_break) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(gotoData.type.IsCommon()); - BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::BREAK); + BOOST_TEST(gotoData.type.GetElement() == srcDispatch::GotoData::BREAK); BOOST_TEST(!gotoData.label); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_break) { BOOST_AUTO_TEST_CASE(block_change_insert_break) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { break; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -63,10 +63,10 @@ BOOST_AUTO_TEST_CASE(block_change_insert_break) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(gotoData.type.IsInsert()); - BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::BREAK); + BOOST_TEST(gotoData.type.GetElement() == srcDispatch::GotoData::BREAK); BOOST_TEST(!gotoData.label); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(block_change_insert_break) { BOOST_AUTO_TEST_CASE(block_change_delete_break) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { break; }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -90,10 +90,10 @@ BOOST_AUTO_TEST_CASE(block_change_delete_break) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(gotoData.type.IsDelete()); - BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::BREAK); + BOOST_TEST(gotoData.type.GetElement() == srcDispatch::GotoData::BREAK); BOOST_TEST(!gotoData.label); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE(block_change_delete_break) { BOOST_AUTO_TEST_CASE(block_change_common_continue) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { continue; }", "void foo() { continue; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -117,10 +117,10 @@ BOOST_AUTO_TEST_CASE(block_change_common_continue) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(gotoData.type.IsCommon()); - BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::CONTINUE); + BOOST_TEST(gotoData.type.GetElement() == srcDispatch::GotoData::CONTINUE); BOOST_TEST(!gotoData.label); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -132,7 +132,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_continue) { BOOST_AUTO_TEST_CASE(block_change_insert_continue) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { continue; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -144,10 +144,10 @@ BOOST_AUTO_TEST_CASE(block_change_insert_continue) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(gotoData.type.IsInsert()); - BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::CONTINUE); + BOOST_TEST(gotoData.type.GetElement() == srcDispatch::GotoData::CONTINUE); BOOST_TEST(!gotoData.label); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -159,7 +159,7 @@ BOOST_AUTO_TEST_CASE(block_change_insert_continue) { BOOST_AUTO_TEST_CASE(block_change_delete_continue) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { continue; }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -171,10 +171,10 @@ BOOST_AUTO_TEST_CASE(block_change_delete_continue) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(gotoData.type.IsDelete()); - BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::CONTINUE); + BOOST_TEST(gotoData.type.GetElement() == srcDispatch::GotoData::CONTINUE); BOOST_TEST(!gotoData.label); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -186,7 +186,7 @@ BOOST_AUTO_TEST_CASE(block_change_delete_continue) { BOOST_AUTO_TEST_CASE(block_change_common_goto) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { goto; }", "void foo() { goto; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -198,10 +198,10 @@ BOOST_AUTO_TEST_CASE(block_change_common_goto) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(gotoData.type.IsCommon()); - BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::GOTO); + BOOST_TEST(gotoData.type.GetElement() == srcDispatch::GotoData::GOTO); BOOST_TEST(!gotoData.label); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -213,7 +213,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_goto) { BOOST_AUTO_TEST_CASE(block_change_insert_goto) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { goto; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -225,10 +225,10 @@ BOOST_AUTO_TEST_CASE(block_change_insert_goto) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(gotoData.type.IsInsert()); - BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::GOTO); + BOOST_TEST(gotoData.type.GetElement() == srcDispatch::GotoData::GOTO); BOOST_TEST(!gotoData.label); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE(block_change_insert_goto) { BOOST_AUTO_TEST_CASE(block_change_delete_goto) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { goto; }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -252,10 +252,10 @@ BOOST_AUTO_TEST_CASE(block_change_delete_goto) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(gotoData.type.IsDelete()); - BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::GOTO); + BOOST_TEST(gotoData.type.GetElement() == srcDispatch::GotoData::GOTO); BOOST_TEST(!gotoData.label); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); @@ -267,7 +267,7 @@ BOOST_AUTO_TEST_CASE(block_change_delete_goto) { BOOST_AUTO_TEST_CASE(block_change_common_label_goto) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { goto foo; }", "void foo() { goto foo; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -279,10 +279,10 @@ BOOST_AUTO_TEST_CASE(block_change_common_label_goto) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(gotoData.type.IsCommon()); - BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::GOTO); + BOOST_TEST(gotoData.type.GetElement() == srcDispatch::GotoData::GOTO); BOOST_TEST(gotoData.label.IsCommon()); BOOST_TEST(gotoData.label.ToString() == "foo"); @@ -295,7 +295,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_label_goto) { BOOST_AUTO_TEST_CASE(block_change_rename_label_goto) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { goto foo; }", "void foo() { goto bar; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -307,10 +307,10 @@ BOOST_AUTO_TEST_CASE(block_change_rename_label_goto) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::GotoData& gotoData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(gotoData.type.IsCommon()); - BOOST_TEST(gotoData.type.GetElement() == srcDiffDispatch::GotoData::GOTO); + BOOST_TEST(gotoData.type.GetElement() == srcDispatch::GotoData::GOTO); BOOST_TEST(gotoData.label.IsCommon()); BOOST_TEST(gotoData.label->name.IsChange()); BOOST_TEST(gotoData.label.ToString() == "foo|bar"); diff --git a/test/suite/testIfStmt.cpp b/test/suite/testIfStmt.cpp index 3084aff..24670b5 100644 --- a/test/suite/testIfStmt.cpp +++ b/test/suite/testIfStmt.cpp @@ -26,7 +26,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_change_common_if_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { if(1) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -38,7 +38,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_if_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_if_stmt) { BOOST_AUTO_TEST_CASE(block_insert_if_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { if(1) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -61,13 +61,13 @@ BOOST_AUTO_TEST_CASE(block_insert_if_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 1); BOOST_TEST(ifStmt.clauses.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsInsert()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "|1"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "|1"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "|1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "|1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(block_insert_if_stmt) { BOOST_AUTO_TEST_CASE(block_delete_if_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { if(1) {} }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -90,13 +90,13 @@ BOOST_AUTO_TEST_CASE(block_delete_if_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 1); BOOST_TEST(ifStmt.clauses.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsDelete()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1|"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1|"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1|"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(block_delete_if_stmt) { BOOST_AUTO_TEST_CASE(block_change_condition_if_stmt) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { if(2) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -119,13 +119,13 @@ BOOST_AUTO_TEST_CASE(block_change_condition_if_stmt) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 1); BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1|2"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1|2"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|2"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1|2"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1|2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|2"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(block_change_condition_if_stmt) { BOOST_AUTO_TEST_CASE(block_common_elseif) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { if(1) {} else if(2) {} }", "void foo() { if(1) {} else if(2) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -148,19 +148,19 @@ BOOST_AUTO_TEST_CASE(block_common_elseif) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 2); BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); BOOST_TEST(ifStmt.clauses.at(1).IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "2"); - BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "2"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "2"); + BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE(block_common_elseif) { BOOST_AUTO_TEST_CASE(block_insert_elseif_whole) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { if(1) {} else if(2) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -183,19 +183,19 @@ BOOST_AUTO_TEST_CASE(block_insert_elseif_whole) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 2); BOOST_TEST(ifStmt.clauses.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsInsert()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "|1"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "|1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "|1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "|1"); BOOST_TEST(ifStmt.clauses.at(1).IsInsert()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsInsert()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "|2"); - BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "|2"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "|2"); + BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "|2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(block_insert_elseif_whole) { BOOST_AUTO_TEST_CASE(block_delete_elseif_whole) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {if(1) {} else if(2) {} }", "void foo() { }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -218,19 +218,19 @@ BOOST_AUTO_TEST_CASE(block_delete_elseif_whole) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 2); BOOST_TEST(ifStmt.clauses.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsDelete()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1|"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1|"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1|"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1|"); BOOST_TEST(ifStmt.clauses.at(1).IsDelete()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsDelete()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "2|"); - BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "2|"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "2|"); + BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "2|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE(block_delete_elseif_whole) { BOOST_AUTO_TEST_CASE(block_insert_elseif) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { if(1) {} else if(2) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -253,19 +253,19 @@ BOOST_AUTO_TEST_CASE(block_insert_elseif) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 2); BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); BOOST_TEST(ifStmt.clauses.at(1).IsInsert()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsInsert()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "|2"); - BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "|2"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "|2"); + BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "|2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -276,7 +276,7 @@ BOOST_AUTO_TEST_CASE(block_insert_elseif) { BOOST_AUTO_TEST_CASE(block_delete_elseif) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { if(1) {} else if(2) {} }", "void foo() { if(1) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -288,19 +288,19 @@ BOOST_AUTO_TEST_CASE(block_delete_elseif) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 2); BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); BOOST_TEST(ifStmt.clauses.at(1).IsDelete()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsDelete()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "2|"); - BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "2|"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition.ToString() == "2|"); + BOOST_TEST(ifStmt.clauses.at(1).ToString>() == "2|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -311,7 +311,7 @@ BOOST_AUTO_TEST_CASE(block_delete_elseif) { BOOST_AUTO_TEST_CASE(block_common_else) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { if(1) {} else {} }", "void foo() { if(1) {} else {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -323,17 +323,17 @@ BOOST_AUTO_TEST_CASE(block_common_else) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 2); BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); BOOST_TEST(ifStmt.clauses.at(1).IsCommon()); - BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -344,7 +344,7 @@ BOOST_AUTO_TEST_CASE(block_common_else) { BOOST_AUTO_TEST_CASE(block_insert_else_whole) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { if(1) {} else {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -356,17 +356,17 @@ BOOST_AUTO_TEST_CASE(block_insert_else_whole) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 2); BOOST_TEST(ifStmt.clauses.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsInsert()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "|1"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "|1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsInsert()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "|1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "|1"); BOOST_TEST(ifStmt.clauses.at(1).IsInsert()); - BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); + BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -377,7 +377,7 @@ BOOST_AUTO_TEST_CASE(block_insert_else_whole) { BOOST_AUTO_TEST_CASE(block_delete_else_whole) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {if(1) {} else {} }", "void foo() { }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -389,18 +389,18 @@ BOOST_AUTO_TEST_CASE(block_delete_else_whole) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 2); BOOST_TEST(ifStmt.clauses.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsDelete()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1|"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1|"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsDelete()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1|"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); BOOST_TEST(ifStmt.clauses.at(1).IsDelete()); - BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -411,7 +411,7 @@ BOOST_AUTO_TEST_CASE(block_delete_else_whole) { BOOST_AUTO_TEST_CASE(block_insert_else) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { if(1) {} else {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -423,18 +423,18 @@ BOOST_AUTO_TEST_CASE(block_insert_else) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 2); BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); BOOST_TEST(ifStmt.clauses.at(1).IsInsert()); - BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -445,7 +445,7 @@ BOOST_AUTO_TEST_CASE(block_insert_else) { BOOST_AUTO_TEST_CASE(block_delete_else) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { if(1) {} else {} }", "void foo() { if(1) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -457,18 +457,18 @@ BOOST_AUTO_TEST_CASE(block_delete_else) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::IfStmtData& ifStmt = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(ifStmt.clauses.size() == 2); BOOST_TEST(ifStmt.clauses.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); - BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); - BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.IsCommon()); + BOOST_TEST(std::any_cast>(ifStmt.clauses.at(0).GetElement())->condition.ToString() == "1"); + BOOST_TEST(ifStmt.clauses.at(0).ToString>() == "1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); BOOST_TEST(ifStmt.clauses.at(1).IsDelete()); - BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + BOOST_TEST(!std::any_cast>(ifStmt.clauses.at(1).GetElement())->condition); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); diff --git a/test/suite/testLabel.cpp b/test/suite/testLabel.cpp index b51f719..a7de16c 100644 --- a/test/suite/testLabel.cpp +++ b/test/suite/testLabel.cpp @@ -21,7 +21,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_common_label) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { label: }", "void foo() { label: }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(block_common_label) { BOOST_AUTO_TEST_CASE(block_insert_label) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { label: }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(block_insert_label) { BOOST_AUTO_TEST_CASE(block_delete_label) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { label: }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -93,7 +93,7 @@ BOOST_AUTO_TEST_CASE(block_delete_label) { BOOST_AUTO_TEST_CASE(block_replace_label) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { foo: }", "void foo() { bar: }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); diff --git a/test/suite/testReturn.cpp b/test/suite/testReturn.cpp index 4eaa81d..9e1f461 100644 --- a/test/suite/testReturn.cpp +++ b/test/suite/testReturn.cpp @@ -21,7 +21,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_change_common_return) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { return 0; }", "void foo() { return 0; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_return) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "0"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "0"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_return) { BOOST_AUTO_TEST_CASE(block_insert_return) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { return a; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -56,15 +56,15 @@ BOOST_AUTO_TEST_CASE(block_insert_return) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(returnData.expr); BOOST_TEST(returnData.expr.IsInsert()); BOOST_TEST(returnData.expr->expr.size() == 1); BOOST_TEST(returnData.expr->expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(returnData.expr->expr.at(0).GetElement())->name.IsInsert()); - BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "|a"); + BOOST_TEST(std::any_cast>(returnData.expr->expr.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "|a"); BOOST_TEST(returnData.expr.ToString() == "|a"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|a"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|a"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(block_insert_return) { BOOST_AUTO_TEST_CASE(block_delete_return) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { return a; }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -87,15 +87,15 @@ BOOST_AUTO_TEST_CASE(block_delete_return) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(returnData.expr); BOOST_TEST(returnData.expr.IsDelete()); BOOST_TEST(returnData.expr->expr.size() == 1); BOOST_TEST(returnData.expr->expr.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(returnData.expr->expr.at(0).GetElement())->name.IsDelete()); - BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "a|"); + BOOST_TEST(std::any_cast>(returnData.expr->expr.at(0).GetElement())->name.IsDelete()); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "a|"); BOOST_TEST(returnData.expr.ToString() == "a|"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(block_delete_return) { BOOST_AUTO_TEST_CASE(block_change_return) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { return a - b; }", "void foo() { return a + b; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -118,20 +118,20 @@ BOOST_AUTO_TEST_CASE(block_change_return) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(returnData.expr); BOOST_TEST(returnData.expr.IsCommon()); BOOST_TEST(returnData.expr->expr.size() == 3); BOOST_TEST(returnData.expr->expr.at(0).IsCommon()); - BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "a"); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "a"); BOOST_TEST(returnData.expr->expr.at(1).IsCommon()); - BOOST_TEST(std::any_cast>(returnData.expr->expr.at(1).GetElement())->op.IsChange()); - BOOST_TEST(std::any_cast>(returnData.expr->expr.at(1).GetElement())->op.ToString() == "-|+"); - BOOST_TEST(returnData.expr->expr.at(1).ToString>() == "-|+"); + BOOST_TEST(std::any_cast>(returnData.expr->expr.at(1).GetElement())->op.IsChange()); + BOOST_TEST(std::any_cast>(returnData.expr->expr.at(1).GetElement())->op.ToString() == "-|+"); + BOOST_TEST(returnData.expr->expr.at(1).ToString>() == "-|+"); BOOST_TEST(returnData.expr->expr.at(2).IsCommon()); - BOOST_TEST(returnData.expr->expr.at(2).ToString>() == "b"); + BOOST_TEST(returnData.expr->expr.at(2).ToString>() == "b"); BOOST_TEST(returnData.expr.ToString() == "a - b|a + b"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a - b|a + b"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a - b|a + b"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -142,7 +142,7 @@ BOOST_AUTO_TEST_CASE(block_change_return) { BOOST_AUTO_TEST_CASE(block_change_return_expr) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { return a; }", "void foo() { return b; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -154,15 +154,15 @@ BOOST_AUTO_TEST_CASE(block_change_return_expr) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(returnData.expr); BOOST_TEST(returnData.expr.IsCommon()); BOOST_TEST(returnData.expr->expr.size() == 1); BOOST_TEST(returnData.expr->expr.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(returnData.expr->expr.at(0).GetElement())->name.IsChange()); - BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "a|b"); + BOOST_TEST(std::any_cast>(returnData.expr->expr.at(0).GetElement())->name.IsChange()); + BOOST_TEST(returnData.expr->expr.at(0).ToString>() == "a|b"); BOOST_TEST(returnData.expr.ToString() == "a|b"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a|b"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "a|b"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -173,7 +173,7 @@ BOOST_AUTO_TEST_CASE(block_change_return_expr) { BOOST_AUTO_TEST_CASE(block_change_whole_return) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { return 0; }", "void foo() { return a; }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -185,26 +185,26 @@ BOOST_AUTO_TEST_CASE(block_change_whole_return) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ReturnData& returnData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(returnData.expr); BOOST_TEST(returnData.expr.IsChange()); BOOST_TEST(returnData.expr.GetOriginal()->expr.size() == 1); BOOST_TEST(returnData.expr.GetOriginal()->expr.at(0).IsDelete()); BOOST_TEST(returnData.expr.GetOriginal()->expr.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(returnData.expr.GetOriginal()->expr.at(0).GetElement())->literal.IsDelete()); - BOOST_TEST(std::any_cast>(returnData.expr.GetOriginal()->expr.at(0).GetElement())->literal.ToString() == "0|"); - BOOST_TEST(returnData.expr.GetOriginal()->expr.at(0).ToString>() == "0|"); + BOOST_TEST(std::any_cast>(returnData.expr.GetOriginal()->expr.at(0).GetElement())->literal.IsDelete()); + BOOST_TEST(std::any_cast>(returnData.expr.GetOriginal()->expr.at(0).GetElement())->literal.ToString() == "0|"); + BOOST_TEST(returnData.expr.GetOriginal()->expr.at(0).ToString>() == "0|"); BOOST_TEST(returnData.expr.GetModified()->expr.size() == 1); BOOST_TEST(returnData.expr.GetModified()->expr.at(0).IsInsert()); BOOST_TEST(returnData.expr.GetModified()->expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(returnData.expr.GetModified()->expr.at(0).GetElement())->name.IsInsert()); - BOOST_TEST(std::any_cast>(returnData.expr.GetModified()->expr.at(0).GetElement())->name.ToString() == "|a"); - BOOST_TEST(returnData.expr.GetModified()->expr.at(0).ToString>() == "|a"); + BOOST_TEST(std::any_cast>(returnData.expr.GetModified()->expr.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(std::any_cast>(returnData.expr.GetModified()->expr.at(0).GetElement())->name.ToString() == "|a"); + BOOST_TEST(returnData.expr.GetModified()->expr.at(0).ToString>() == "|a"); BOOST_TEST(returnData.expr.ToString() == "0|a"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "0|a"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "0|a"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); diff --git a/test/suite/testSwitch.cpp b/test/suite/testSwitch.cpp index a87a116..baeb450 100644 --- a/test/suite/testSwitch.cpp +++ b/test/suite/testSwitch.cpp @@ -24,7 +24,7 @@ namespace data = boost::unit_test; // switch BOOST_AUTO_TEST_CASE(block_change_common_switch) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { switch(1) {} }", "void foo() { switch(1) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_switch) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_switch) { BOOST_AUTO_TEST_CASE(block_insert_switch) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { switch(1) {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -60,25 +60,25 @@ BOOST_AUTO_TEST_CASE(block_insert_switch) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(switchData.condition); BOOST_TEST(switchData.condition.IsInsert()); BOOST_TEST(switchData.condition->conditions.size() == 1); BOOST_TEST(switchData.condition->conditions.at(0).IsInsert()); - const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(switchData.condition->conditions.at(0).GetElement()); + const srcDispatch::ExpressionData& expr = *std::any_cast>(switchData.condition->conditions.at(0).GetElement()); BOOST_TEST(expr.expr.size() == 1); BOOST_TEST(expr.expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "|1"); - BOOST_TEST(expr.expr.at(0).ToString>() == "|1"); - BOOST_TEST(switchData.condition->conditions.at(0).ToString>() == "|1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "|1"); + BOOST_TEST(expr.expr.at(0).ToString>() == "|1"); + BOOST_TEST(switchData.condition->conditions.at(0).ToString>() == "|1"); BOOST_TEST(switchData.condition.ToString() == "|1"); BOOST_TEST(switchData.block.IsInsert()); BOOST_TEST(switchData.block->statements.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE(block_insert_switch) { BOOST_AUTO_TEST_CASE(block_delete_switch) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { switch(1) {}", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -101,25 +101,25 @@ BOOST_AUTO_TEST_CASE(block_delete_switch) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::SwitchData& switchData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(switchData.condition); BOOST_TEST(switchData.condition.IsDelete()); BOOST_TEST(switchData.condition->conditions.size() == 1); BOOST_TEST(switchData.condition->conditions.at(0).IsDelete()); - const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(switchData.condition->conditions.at(0).GetElement()); + const srcDispatch::ExpressionData& expr = *std::any_cast>(switchData.condition->conditions.at(0).GetElement()); BOOST_TEST(expr.expr.size() == 1); BOOST_TEST(expr.expr.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "1|"); - BOOST_TEST(expr.expr.at(0).ToString>() == "1|"); - BOOST_TEST(switchData.condition->conditions.at(0).ToString>() == "1|"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "1|"); + BOOST_TEST(expr.expr.at(0).ToString>() == "1|"); + BOOST_TEST(switchData.condition->conditions.at(0).ToString>() == "1|"); BOOST_TEST(switchData.condition.ToString() == "1|"); BOOST_TEST(switchData.block.IsDelete()); BOOST_TEST(switchData.block->statements.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(block_delete_switch) { BOOST_AUTO_TEST_CASE(block_replace_switch) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { switch(1) { default: a; } }", "void foo() { switch(2) { default: b; } }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -142,19 +142,19 @@ BOOST_AUTO_TEST_CASE(block_replace_switch) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 2); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::SwitchData& deletedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::SwitchData& deletedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(deletedData.condition.IsDelete()); BOOST_TEST(deletedData.block.IsDelete()); BOOST_TEST(deletedData.block->statements.size() == 1); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).IsInsert()); - const srcDiffDispatch::SwitchData& insertedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(1).GetElement()); + const srcDispatch::SwitchData& insertedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(1).GetElement()); BOOST_TEST(insertedData.condition.IsInsert()); BOOST_TEST(insertedData.block.IsInsert()); BOOST_TEST(insertedData.block->statements.size() == 1); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|2"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); diff --git a/test/suite/testTemplate.cpp b/test/suite/testTemplate.cpp index 1400a74..70cacd5 100644 --- a/test/suite/testTemplate.cpp +++ b/test/suite/testTemplate.cpp @@ -21,7 +21,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(template_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void foo() {}", "template void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -33,14 +33,14 @@ BOOST_AUTO_TEST_CASE(template_common) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(template_insert_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void func() {}", "template template void func() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -56,14 +56,14 @@ BOOST_AUTO_TEST_CASE(template_insert_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).ToString() == "template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void func() {}"); } BOOST_AUTO_TEST_CASE(template_insert_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void func() {}", "template template void func() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -79,14 +79,14 @@ BOOST_AUTO_TEST_CASE(template_insert_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).ToString() == "|template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void func() {}"); } BOOST_AUTO_TEST_CASE(template_delete_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template template void func() {}", "template void func() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -102,14 +102,14 @@ BOOST_AUTO_TEST_CASE(template_delete_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).ToString() == "template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void func() {}"); } BOOST_AUTO_TEST_CASE(template_delete_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template template void func() {}", "template void func() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -125,14 +125,14 @@ BOOST_AUTO_TEST_CASE(template_delete_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(1).ToString() == "template|"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void func() {}"); } BOOST_AUTO_TEST_CASE(template_insert_parameter_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void foo() {}", "template void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -147,14 +147,14 @@ BOOST_AUTO_TEST_CASE(template_insert_parameter_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(1).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(template_insert_parameter_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void foo() {}", "template void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -169,14 +169,14 @@ BOOST_AUTO_TEST_CASE(template_insert_parameter_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(1).IsInsert()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(template_delete_parameter_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void foo() {}", "template void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -191,14 +191,14 @@ BOOST_AUTO_TEST_CASE(template_delete_parameter_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(1).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(template_delete_parameter_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void foo() {}", "template void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -213,14 +213,14 @@ BOOST_AUTO_TEST_CASE(template_delete_parameter_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(1).IsDelete()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(template_modify_parameter_type) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void foo() {}", "template void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -239,14 +239,14 @@ BOOST_AUTO_TEST_CASE(template_modify_parameter_type) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).ToString() == "typename type|class type"); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(template_modify_parameter_name) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void foo() {}", "template void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -265,14 +265,14 @@ BOOST_AUTO_TEST_CASE(template_modify_parameter_name) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).ToString() == "typename type|typename T"); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(template_modify_parameter_init) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void foo() {}", "template void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -291,14 +291,14 @@ BOOST_AUTO_TEST_CASE(template_modify_parameter_init) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0)->parameters.at(0).ToString() == "typename type|typename type = object"); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(template_common_int) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void foo() {}", "template void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -310,14 +310,14 @@ BOOST_AUTO_TEST_CASE(template_common_int) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } BOOST_AUTO_TEST_CASE(template_common_int_insert_init) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("template void foo() {}", "template void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -329,7 +329,7 @@ BOOST_AUTO_TEST_CASE(template_common_int_insert_init) { BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).IsCommon()); BOOST_TEST(runner.GetFunctionInfo().at(0)->generics.at(0).ToString() == "template|template"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDiffDispatch::FunctionData::FUNCTION); + BOOST_TEST(runner.GetFunctionInfo().at(0)->type.GetElement() == srcDispatch::FunctionData::FUNCTION); BOOST_TEST(runner.GetFunctionInfo().at(0).ToString() == "void foo() {}"); } diff --git a/test/suite/testThrow.cpp b/test/suite/testThrow.cpp index 117afb5..7536532 100644 --- a/test/suite/testThrow.cpp +++ b/test/suite/testThrow.cpp @@ -21,7 +21,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_change_common_throw) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { throw std::string(); }", "void foo() { throw std::string(); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_throw) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "std::string()"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "std::string()"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_throw) { BOOST_AUTO_TEST_CASE(block_insert_throw) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { throw Exception(); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -56,15 +56,15 @@ BOOST_AUTO_TEST_CASE(block_insert_throw) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::ThrowData& throwData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ThrowData& throwData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(throwData.expr); BOOST_TEST(throwData.expr.IsInsert()); BOOST_TEST(throwData.expr->expr.size() == 1); BOOST_TEST(throwData.expr->expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(throwData.expr->expr.at(0).GetElement())->name.IsInsert()); - BOOST_TEST(throwData.expr->expr.at(0).ToString>() == "|Exception()"); + BOOST_TEST(std::any_cast>(throwData.expr->expr.at(0).GetElement())->name.IsInsert()); + BOOST_TEST(throwData.expr->expr.at(0).ToString>() == "|Exception()"); BOOST_TEST(throwData.expr.ToString() == "|Exception()"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|Exception()"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|Exception()"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -75,7 +75,7 @@ BOOST_AUTO_TEST_CASE(block_insert_throw) { BOOST_AUTO_TEST_CASE(block_delete_throw) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { throw Exception(); }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -87,15 +87,15 @@ BOOST_AUTO_TEST_CASE(block_delete_throw) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::ThrowData& throwData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ThrowData& throwData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(throwData.expr); BOOST_TEST(throwData.expr.IsDelete()); BOOST_TEST(throwData.expr->expr.size() == 1); BOOST_TEST(throwData.expr->expr.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(throwData.expr->expr.at(0).GetElement())->name.IsDelete()); - BOOST_TEST(throwData.expr->expr.at(0).ToString>() == "Exception()|"); + BOOST_TEST(std::any_cast>(throwData.expr->expr.at(0).GetElement())->name.IsDelete()); + BOOST_TEST(throwData.expr->expr.at(0).ToString>() == "Exception()|"); BOOST_TEST(throwData.expr.ToString() == "Exception()|"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "Exception()|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "Exception()|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(block_delete_throw) { BOOST_AUTO_TEST_CASE(block_change_throw) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { throw std::string(); }", "void foo() { throw Exception(); }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -118,17 +118,17 @@ BOOST_AUTO_TEST_CASE(block_change_throw) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::ThrowData& throwData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::ThrowData& throwData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(throwData.expr); BOOST_TEST(throwData.expr.IsChange()); BOOST_TEST(throwData.expr.GetOriginal()->expr.size() == 1); BOOST_TEST(throwData.expr.GetOriginal()->expr.at(0).IsDelete()); - BOOST_TEST(throwData.expr.GetOriginal()->expr.at(0).ToString>() == "std::string()|"); + BOOST_TEST(throwData.expr.GetOriginal()->expr.at(0).ToString>() == "std::string()|"); BOOST_TEST(throwData.expr.GetModified()->expr.size() == 1); BOOST_TEST(throwData.expr.GetModified()->expr.at(0).IsInsert()); - BOOST_TEST(throwData.expr.GetModified()->expr.at(0).ToString>() == "|Exception()"); + BOOST_TEST(throwData.expr.GetModified()->expr.at(0).ToString>() == "|Exception()"); BOOST_TEST(throwData.expr.ToString() == "std::string()|Exception()"); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "std::string()|Exception()"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "std::string()|Exception()"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); diff --git a/test/suite/testTry.cpp b/test/suite/testTry.cpp index dc01d3b..26045dd 100644 --- a/test/suite/testTry.cpp +++ b/test/suite/testTry.cpp @@ -24,7 +24,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(try_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} }", "void foo() { try {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -36,10 +36,10 @@ BOOST_AUTO_TEST_CASE(try_common) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block)); - BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block.IsCommon())); - BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->clauses.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block)); + BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block.IsCommon())); + BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->clauses.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE(try_common) { BOOST_AUTO_TEST_CASE(try_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { try {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -62,10 +62,10 @@ BOOST_AUTO_TEST_CASE(try_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ModifiedType().name() == typeid(std::shared_ptr).name()); - BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block)); - BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block.IsInsert())); - BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->clauses.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ModifiedType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block)); + BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block.IsInsert())); + BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->clauses.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(try_insert) { BOOST_AUTO_TEST_CASE(try_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} }", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -88,10 +88,10 @@ BOOST_AUTO_TEST_CASE(try_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block)); - BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block.IsDelete())); - BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->clauses.size() == 0); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block)); + BOOST_TEST(bool(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->block.IsDelete())); + BOOST_TEST(std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement())->clauses.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(try_delete) { BOOST_AUTO_TEST_CASE(catch_common) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} catch() {} }", "void foo() { try {} catch() {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -114,16 +114,16 @@ BOOST_AUTO_TEST_CASE(catch_common) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(bool(tryData.block)); BOOST_TEST(bool(tryData.block.IsCommon())); BOOST_TEST(tryData.clauses.size() == 1); BOOST_TEST(tryData.clauses.at(0).IsCommon()); - const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + const srcDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); BOOST_TEST(catchData.parameters.size() == 0); BOOST_TEST(catchData.block.IsCommon()); @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(catch_common) { BOOST_AUTO_TEST_CASE(catch_insert) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} }", "void foo() { try {} catch() {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -148,16 +148,16 @@ BOOST_AUTO_TEST_CASE(catch_insert) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(bool(tryData.block)); BOOST_TEST(bool(tryData.block.IsCommon())); BOOST_TEST(tryData.clauses.size() == 1); BOOST_TEST(tryData.clauses.at(0).IsInsert()); - const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + const srcDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); BOOST_TEST(catchData.parameters.size() == 0); BOOST_TEST(catchData.block.IsInsert()); @@ -170,7 +170,7 @@ BOOST_AUTO_TEST_CASE(catch_insert) { BOOST_AUTO_TEST_CASE(catch_delete) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} catch() {} }", "void foo() { try {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -182,16 +182,16 @@ BOOST_AUTO_TEST_CASE(catch_delete) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(bool(tryData.block)); BOOST_TEST(bool(tryData.block.IsCommon())); BOOST_TEST(tryData.clauses.size() == 1); BOOST_TEST(tryData.clauses.at(0).IsDelete()); - const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + const srcDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); BOOST_TEST(catchData.parameters.size() == 0); BOOST_TEST(catchData.block.IsDelete()); @@ -204,7 +204,7 @@ BOOST_AUTO_TEST_CASE(catch_delete) { BOOST_AUTO_TEST_CASE(catch_common_param) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch(Exception e) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -216,16 +216,16 @@ BOOST_AUTO_TEST_CASE(catch_common_param) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(bool(tryData.block)); BOOST_TEST(bool(tryData.block.IsCommon())); BOOST_TEST(tryData.clauses.size() == 1); BOOST_TEST(tryData.clauses.at(0).IsCommon()); - const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + const srcDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); BOOST_TEST(catchData.parameters.size() == 1); BOOST_TEST(catchData.parameters.at(0).IsCommon()); BOOST_TEST(catchData.parameters.at(0).ToString() == "Exception e"); @@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE(catch_common_param) { BOOST_AUTO_TEST_CASE(catch_insert_param) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} catch() {} }", "void foo() { try {} catch(Exception e) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -253,16 +253,16 @@ BOOST_AUTO_TEST_CASE(catch_insert_param) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(bool(tryData.block)); BOOST_TEST(bool(tryData.block.IsCommon())); BOOST_TEST(tryData.clauses.size() == 1); BOOST_TEST(tryData.clauses.at(0).IsCommon()); - const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + const srcDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); BOOST_TEST(catchData.parameters.size() == 1); BOOST_TEST(catchData.parameters.at(0).IsInsert()); BOOST_TEST(catchData.parameters.at(0).ToString() == "|Exception e"); @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE(catch_insert_param) { BOOST_AUTO_TEST_CASE(catch_delete_param) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch() {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -290,16 +290,16 @@ BOOST_AUTO_TEST_CASE(catch_delete_param) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(bool(tryData.block)); BOOST_TEST(bool(tryData.block.IsCommon())); BOOST_TEST(tryData.clauses.size() == 1); BOOST_TEST(tryData.clauses.at(0).IsCommon()); - const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + const srcDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); BOOST_TEST(catchData.parameters.size() == 1); BOOST_TEST(catchData.parameters.at(0).IsDelete()); BOOST_TEST(catchData.parameters.at(0).ToString() == "Exception e|"); @@ -315,7 +315,7 @@ BOOST_AUTO_TEST_CASE(catch_delete_param) { BOOST_AUTO_TEST_CASE(catch_common_param_insert_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch(foo bar, Exception e) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -327,16 +327,16 @@ BOOST_AUTO_TEST_CASE(catch_common_param_insert_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(bool(tryData.block)); BOOST_TEST(bool(tryData.block.IsCommon())); BOOST_TEST(tryData.clauses.size() == 1); BOOST_TEST(tryData.clauses.at(0).IsCommon()); - const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + const srcDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); BOOST_TEST(catchData.parameters.size() == 2); BOOST_TEST(catchData.parameters.at(0).IsInsert()); BOOST_TEST(catchData.parameters.at(0).ToString() == "|foo bar"); @@ -354,7 +354,7 @@ BOOST_AUTO_TEST_CASE(catch_common_param_insert_front) { BOOST_AUTO_TEST_CASE(catch_common_param_insert_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch(Exception e, foo bar) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -366,16 +366,16 @@ BOOST_AUTO_TEST_CASE(catch_common_param_insert_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(bool(tryData.block)); BOOST_TEST(bool(tryData.block.IsCommon())); BOOST_TEST(tryData.clauses.size() == 1); BOOST_TEST(tryData.clauses.at(0).IsCommon()); - const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + const srcDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); BOOST_TEST(catchData.parameters.size() == 2); BOOST_TEST(catchData.parameters.at(0).IsCommon()); BOOST_TEST(catchData.parameters.at(0).ToString() == "Exception e"); @@ -393,7 +393,7 @@ BOOST_AUTO_TEST_CASE(catch_common_param_insert_back) { BOOST_AUTO_TEST_CASE(catch_common_param_delete_front) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} catch(foo bar, Exception e) {} }", "void foo() { try {} catch(Exception e) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -405,16 +405,16 @@ BOOST_AUTO_TEST_CASE(catch_common_param_delete_front) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(bool(tryData.block)); BOOST_TEST(bool(tryData.block.IsCommon())); BOOST_TEST(tryData.clauses.size() == 1); BOOST_TEST(tryData.clauses.at(0).IsCommon()); - const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + const srcDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); BOOST_TEST(catchData.parameters.size() == 2); BOOST_TEST(catchData.parameters.at(0).IsDelete()); BOOST_TEST(catchData.parameters.at(0).ToString() == "foo bar|"); @@ -432,7 +432,7 @@ BOOST_AUTO_TEST_CASE(catch_common_param_delete_front) { BOOST_AUTO_TEST_CASE(catch_common_param_delete_back) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} catch(Exception e, foo bar) {} }", "void foo() { try {} catch(Exception e) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -444,16 +444,16 @@ BOOST_AUTO_TEST_CASE(catch_common_param_delete_back) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(bool(tryData.block)); BOOST_TEST(bool(tryData.block.IsCommon())); BOOST_TEST(tryData.clauses.size() == 1); BOOST_TEST(tryData.clauses.at(0).IsCommon()); - const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + const srcDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); BOOST_TEST(catchData.parameters.size() == 2); BOOST_TEST(catchData.parameters.at(0).IsCommon()); BOOST_TEST(catchData.parameters.at(0).ToString() == "Exception e"); @@ -471,7 +471,7 @@ BOOST_AUTO_TEST_CASE(catch_common_param_delete_back) { BOOST_AUTO_TEST_CASE(catch_common_param_replace) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { try {} catch(std::string str) {} }", "void foo() { try {} catch(Exception e) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -483,16 +483,16 @@ BOOST_AUTO_TEST_CASE(catch_common_param_replace) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).OriginalType().name() == typeid(std::shared_ptr).name()); - const srcDiffDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::TryData& tryData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(bool(tryData.block)); BOOST_TEST(bool(tryData.block.IsCommon())); BOOST_TEST(tryData.clauses.size() == 1); BOOST_TEST(tryData.clauses.at(0).IsCommon()); - const srcDiffDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); + const srcDispatch::CatchData& catchData = *std::any_cast>(tryData.clauses.at(0).GetElement()); BOOST_TEST(catchData.parameters.size() == 2); BOOST_TEST(catchData.parameters.at(0).IsDelete()); BOOST_TEST(catchData.parameters.at(0).ToString() == "std::string str|"); diff --git a/test/suite/testWhile.cpp b/test/suite/testWhile.cpp index 9a5992b..03664b0 100644 --- a/test/suite/testWhile.cpp +++ b/test/suite/testWhile.cpp @@ -23,7 +23,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_common_while) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { while(1) {} }", "void foo() { while(1) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -35,19 +35,19 @@ BOOST_AUTO_TEST_CASE(block_common_while) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(whileData.condition); BOOST_TEST(whileData.condition.IsCommon()); BOOST_TEST(whileData.condition->conditions.size() == 1); BOOST_TEST(whileData.condition->conditions.at(0).IsCommon()); - const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(whileData.condition->conditions.at(0).GetElement()); + const srcDispatch::ExpressionData& expr = *std::any_cast>(whileData.condition->conditions.at(0).GetElement()); BOOST_TEST(expr.expr.size() == 1); BOOST_TEST(expr.expr.at(0).IsCommon()); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "1"); - BOOST_TEST(expr.expr.at(0).ToString>() == "1"); - BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "1"); + BOOST_TEST(expr.expr.at(0).ToString>() == "1"); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "1"); BOOST_TEST(whileData.condition.ToString() == "1"); BOOST_TEST(whileData.block.IsCommon()); @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE(block_common_while) { BOOST_AUTO_TEST_CASE(block_insert_while) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() {}", "void foo() { while(1) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -73,25 +73,25 @@ BOOST_AUTO_TEST_CASE(block_insert_while) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsInsert()); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(whileData.condition); BOOST_TEST(whileData.condition.IsInsert()); BOOST_TEST(whileData.condition->conditions.size() == 1); BOOST_TEST(whileData.condition->conditions.at(0).IsInsert()); - const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(whileData.condition->conditions.at(0).GetElement()); + const srcDispatch::ExpressionData& expr = *std::any_cast>(whileData.condition->conditions.at(0).GetElement()); BOOST_TEST(expr.expr.size() == 1); BOOST_TEST(expr.expr.at(0).IsInsert()); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "|1"); - BOOST_TEST(expr.expr.at(0).ToString>() == "|1"); - BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "|1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "|1"); + BOOST_TEST(expr.expr.at(0).ToString>() == "|1"); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "|1"); BOOST_TEST(whileData.condition.ToString() == "|1"); BOOST_TEST(whileData.block.IsInsert()); BOOST_TEST(whileData.block->statements.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "|1"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -102,7 +102,7 @@ BOOST_AUTO_TEST_CASE(block_insert_while) { BOOST_AUTO_TEST_CASE(block_delete_while) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { while(1) {}", "void foo() {}"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -114,25 +114,25 @@ BOOST_AUTO_TEST_CASE(block_delete_while) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(whileData.condition); BOOST_TEST(whileData.condition.IsDelete()); BOOST_TEST(whileData.condition->conditions.size() == 1); BOOST_TEST(whileData.condition->conditions.at(0).IsDelete()); - const srcDiffDispatch::ExpressionData& expr = *std::any_cast>(whileData.condition->conditions.at(0).GetElement()); + const srcDispatch::ExpressionData& expr = *std::any_cast>(whileData.condition->conditions.at(0).GetElement()); BOOST_TEST(expr.expr.size() == 1); BOOST_TEST(expr.expr.at(0).IsDelete()); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); - BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "1|"); - BOOST_TEST(expr.expr.at(0).ToString>() == "1|"); - BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "1|"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.GetElement() == "1"); + BOOST_TEST(std::any_cast>(expr.expr.at(0).GetElement())->literal.ToString() == "1|"); + BOOST_TEST(expr.expr.at(0).ToString>() == "1|"); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "1|"); BOOST_TEST(whileData.condition.ToString() == "1|"); BOOST_TEST(whileData.block.IsDelete()); BOOST_TEST(whileData.block->statements.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(block_delete_while) { BOOST_AUTO_TEST_CASE(block_change_condition_expr_while) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { while(1) {}", "void foo() { while(2) {} }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -155,31 +155,31 @@ BOOST_AUTO_TEST_CASE(block_change_condition_expr_while) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 1); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsCommon()); - const srcDiffDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::WhileData& whileData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(whileData.condition); BOOST_TEST(whileData.condition.IsCommon()); BOOST_TEST(whileData.condition->conditions.size() == 1); BOOST_TEST(whileData.condition->conditions.at(0).IsChange()); - const srcDiffDispatch::ExpressionData& originalExpr = *std::any_cast>(whileData.condition->conditions.at(0).GetOriginal()); + const srcDispatch::ExpressionData& originalExpr = *std::any_cast>(whileData.condition->conditions.at(0).GetOriginal()); BOOST_TEST(originalExpr.expr.size() == 1); BOOST_TEST(originalExpr.expr.at(0).IsDelete()); BOOST_TEST(originalExpr.expr.at(0).IsDelete()); - BOOST_TEST(originalExpr.expr.at(0).ToString>() == "1|"); + BOOST_TEST(originalExpr.expr.at(0).ToString>() == "1|"); - const srcDiffDispatch::ExpressionData& modifiedExpr = *std::any_cast>(whileData.condition->conditions.at(0).GetModified()); + const srcDispatch::ExpressionData& modifiedExpr = *std::any_cast>(whileData.condition->conditions.at(0).GetModified()); BOOST_TEST(modifiedExpr.expr.size() == 1); BOOST_TEST(modifiedExpr.expr.at(0).IsInsert()); BOOST_TEST(modifiedExpr.expr.at(0).IsInsert()); - BOOST_TEST(modifiedExpr.expr.at(0).ToString>() == "|2"); + BOOST_TEST(modifiedExpr.expr.at(0).ToString>() == "|2"); - BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "1|2"); + BOOST_TEST(whileData.condition->conditions.at(0).ToString>() == "1|2"); BOOST_TEST(whileData.condition.ToString() == "1|2"); BOOST_TEST(whileData.block.IsCommon()); BOOST_TEST(whileData.block->statements.size() == 0); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|2"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); @@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(block_change_condition_expr_while) { BOOST_AUTO_TEST_CASE(block_replace_while) { - srcDiffDispatch::srcDiffDispatchRunner runner; + srcDispatch::DispatchRunner runner; runner.RunDispatcher("void foo() { while(1) { a; }", "void foo() { while(2) { b; } }"); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); @@ -202,19 +202,19 @@ BOOST_AUTO_TEST_CASE(block_replace_while) { BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.size() == 2); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).IsDelete()); - const srcDiffDispatch::WhileData& deletedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); + const srcDispatch::WhileData& deletedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(0).GetElement()); BOOST_TEST(deletedData.condition.IsDelete()); BOOST_TEST(deletedData.block.IsDelete()); BOOST_TEST(deletedData.block->statements.size() == 1); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(0).ToString>() == "1|"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).IsInsert()); - const srcDiffDispatch::WhileData& insertedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(1).GetElement()); + const srcDispatch::WhileData& insertedData = *std::any_cast>(runner.GetFunctionInfo().at(0)->block->statements.at(1).GetElement()); BOOST_TEST(insertedData.condition.IsInsert()); BOOST_TEST(insertedData.block.IsInsert()); BOOST_TEST(insertedData.block->statements.size() == 1); - BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|2"); + BOOST_TEST(runner.GetFunctionInfo().at(0)->block->statements.at(1).ToString>() == "|2"); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->labels.size() == 0); BOOST_TEST(runner.GetFunctionInfo().at(0)->block->cases.size() == 0); diff --git a/test/util/srcDiffDispatchRunner.hpp b/test/util/DispatchRunner.hpp similarity index 83% rename from test/util/srcDiffDispatchRunner.hpp rename to test/util/DispatchRunner.hpp index 612b5fc..c32f716 100644 --- a/test/util/srcDiffDispatchRunner.hpp +++ b/test/util/DispatchRunner.hpp @@ -1,28 +1,27 @@ // SPDX-License-Identifier: GPL-3.0-only /** - * @file srcDiffDispatchRunner.hpp + * @file DispatchRunner.hpp * * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) * - * This file is part of the srcDiffDispatch Infrastructure. + * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_DISPATCH_RUNNER_HPP -#define INCLUDED_SRCDIFF_DISPATCH_RUNNER_HPP - +#ifndef INCLUDED_DISPATCH_RUNNER_HPP +#define INCLUDED_DISPATCH_RUNNER_HPP #include #include #include -#include +#include #include #include -namespace srcDiffDispatch { +namespace srcDispatch { -class srcDiffDispatchRunner : public srcDispatch::PolicyListener { +class DispatchRunner : public srcDispatch::PolicyListener { private: std::string srcDiff(const std::string& original, const std::string& modified) { @@ -53,7 +52,7 @@ class srcDiffDispatchRunner : public srcDispatch::PolicyListener { std::shared_ptr unit; public: - srcDiffDispatchRunner() {} + DispatchRunner() {} const std::vector>>& GetClassInfo() const { return unit->classInfo; @@ -80,7 +79,7 @@ class srcDiffDispatchRunner : public srcDispatch::PolicyListener { std::string srcDiffStr = srcDiff(original, modified); try { srcSAXController control(srcDiffStr); - srcDispatch::srcDispatcherSingleEvent dispatch(this); + srcDispatch::srcDispatcherSingleEvent dispatch(this); control.parse(&dispatch); //Start parsing } catch(SAXError error) { std::cerr << error.message; From b77c455a750326beb4c4e97cbf143514fff23222 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 09:37:27 +0900 Subject: [PATCH 129/149] Make single event the default --- src/dispatcher/srcDispatcher.hpp | 53 ++++++------- src/dispatcher/srcDispatcherMultiEvent.hpp | 86 +++++++++++++++++++++ src/dispatcher/srcDispatcherSingleEvent.hpp | 80 ------------------- test/util/DispatchRunner.hpp | 4 +- 4 files changed, 111 insertions(+), 112 deletions(-) create mode 100644 src/dispatcher/srcDispatcherMultiEvent.hpp delete mode 100644 src/dispatcher/srcDispatcherSingleEvent.hpp diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index b53750d..eae12d9 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -78,6 +78,7 @@ namespace srcDispatch { std::vector elseif_positions; bool dispatching; + bool dispatched; bool generateArchive; std::size_t numberAllocatedListeners; @@ -87,21 +88,21 @@ namespace srcDispatch { protected: + virtual void DispatchEvent(srcDispatch::ParserState pstate, srcDispatch::ElementState estate) override { - void DispatchEvent(ParserState pstate, ElementState estate) override { + srcDispatcher::currentPState = pstate; + srcDispatcher::currentEState = estate; - dispatching = true; - currentPState = pstate; - currentEState = estate; + while(!dispatched) { + + dispatched = true; + + EventDispatcher::elementListeners.back()->HandleEvent(pstate, estate, EventDispatcher::ctx); + EventDispatcher::elementListeners.back()->SetDispatched(false); - for(std::list::iterator listener = elementListeners.begin(); listener != elementListeners.end(); ++listener ) { - (*listener)->HandleEvent(pstate, estate, ctx); - } - for(std::list::iterator listener = elementListeners.begin(); listener != elementListeners.end(); ++listener ) { - (*listener)->SetDispatched(false); } - dispatching = false; + dispatched = false; } @@ -180,34 +181,26 @@ namespace srcDispatch { } InitializeHandlers(); } - void AddListener(EventListener* listener) override { - elementListeners.push_back(listener); + virtual void AddListener(EventListener * listener) override { + EventDispatcher::elementListeners.back()->SetDispatched(false); + EventDispatcher::elementListeners.push_back(listener); } - void AddListenerDispatch(EventListener* listener) override { - if(dispatching) { - listener->HandleEvent(currentPState, currentEState, ctx); - } + virtual void AddListenerDispatch(EventListener * listener) override { AddListener(listener); + dispatched = false; } - void AddListenerNoDispatch(EventListener* listener) override { - if(dispatching) { - listener->SetDispatched(true); - } + virtual void AddListenerNoDispatch(EventListener * listener) override { AddListener(listener); } - void RemoveListener(EventListener* listener) override { - elementListeners.erase(std::find(elementListeners.begin(), elementListeners.end(), listener)); + virtual void RemoveListener(EventListener * listener) override { + EventDispatcher::elementListeners.back()->SetDispatched(false); + EventDispatcher::elementListeners.pop_back(); } - void RemoveListenerDispatch(EventListener* listener) override { - if(dispatching) { - listener->HandleEvent(currentPState, currentEState, ctx); - } + virtual void RemoveListenerDispatch(EventListener * listener) override { RemoveListener(listener); + dispatched = false; } - void RemoveListenerNoDispatch(EventListener* listener) override { - if(dispatching) { - listener->SetDispatched(true); - } + virtual void RemoveListenerNoDispatch(EventListener * listener) override { RemoveListener(listener); } void InitializeHandlers() { diff --git a/src/dispatcher/srcDispatcherMultiEvent.hpp b/src/dispatcher/srcDispatcherMultiEvent.hpp new file mode 100644 index 0000000..83acd9d --- /dev/null +++ b/src/dispatcher/srcDispatcherMultiEvent.hpp @@ -0,0 +1,86 @@ +/** + * @file srcDispatcherMultiEvent.hpp + * + * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) + * + * The srcML Toolkit is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * The srcML Toolkit is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with the srcML Toolkit; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef INCLUDED_SRC_DISPATCH_SINGLE_EVENT_HPP +#define INCLUDED_SRC_DISPATCH_SINGLE_EVENT_HPP + +#include + +namespace srcDispatch { + template + class srcDispatcherMultiEvent : public srcDispatcher { + + public: + + srcDispatcherMultiEvent(PolicyListener * listener) : srcDispatcher(listener), dispatched(false) {} + + void AddListener(EventListener* listener) override { + elementListeners.push_back(listener); + } + void AddListenerDispatch(EventListener* listener) override { + if(dispatching) { + listener->HandleEvent(currentPState, currentEState, ctx); + } + AddListener(listener); + } + void AddListenerNoDispatch(EventListener* listener) override { + if(dispatching) { + listener->SetDispatched(true); + } + AddListener(listener); + } + void RemoveListener(EventListener* listener) override { + elementListeners.erase(std::find(elementListeners.begin(), elementListeners.end(), listener)); + } + void RemoveListenerDispatch(EventListener* listener) override { + if(dispatching) { + listener->HandleEvent(currentPState, currentEState, ctx); + } + RemoveListener(listener); + } + void RemoveListenerNoDispatch(EventListener* listener) override { + if(dispatching) { + listener->SetDispatched(true); + } + RemoveListener(listener); + } + protected: + + void DispatchEvent(ParserState pstate, ElementState estate) override { + + dispatching = true; + currentPState = pstate; + currentEState = estate; + + for(std::list::iterator listener = elementListeners.begin(); listener != elementListeners.end(); ++listener ) { + (*listener)->HandleEvent(pstate, estate, ctx); + } + for(std::list::iterator listener = elementListeners.begin(); listener != elementListeners.end(); ++listener ) { + (*listener)->SetDispatched(false); + } + + dispatching = false; + + } + + }; + +} + +#endif diff --git a/src/dispatcher/srcDispatcherSingleEvent.hpp b/src/dispatcher/srcDispatcherSingleEvent.hpp deleted file mode 100644 index 593239a..0000000 --- a/src/dispatcher/srcDispatcherSingleEvent.hpp +++ /dev/null @@ -1,80 +0,0 @@ -/** - * @file srcDispatcherSingleEvent.hpp - * - * @copyright Copyright (C) 2013-2014 SDML (www.srcML.org) - * - * The srcML Toolkit is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * The srcML Toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the srcML Toolkit; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef INCLUDED_SRC_DISPATCH_SINGLE_EVENT_HPP -#define INCLUDED_SRC_DISPATCH_SINGLE_EVENT_HPP - -#include - -namespace srcDispatch { - template - class srcDispatcherSingleEvent : public srcDispatcher { - - private: - bool dispatched; - - public: - - srcDispatcherSingleEvent(PolicyListener * listener) : srcDispatcher(listener), dispatched(false) {} - virtual void AddListener(EventListener * listener) override { - EventDispatcher::elementListeners.back()->SetDispatched(false); - EventDispatcher::elementListeners.push_back(listener); - } - virtual void AddListenerDispatch(EventListener * listener) override { - AddListener(listener); - dispatched = false; - } - virtual void AddListenerNoDispatch(EventListener * listener) override { - AddListener(listener); - } - virtual void RemoveListener(EventListener * listener) override { - EventDispatcher::elementListeners.back()->SetDispatched(false); - EventDispatcher::elementListeners.pop_back(); - } - virtual void RemoveListenerDispatch(EventListener * listener) override { - RemoveListener(listener); - dispatched = false; - } - virtual void RemoveListenerNoDispatch(EventListener * listener) override { - RemoveListener(listener); - } - protected: - virtual void DispatchEvent(srcDispatch::ParserState pstate, srcDispatch::ElementState estate) override { - - srcDispatcher::currentPState = pstate; - srcDispatcher::currentEState = estate; - - while(!dispatched) { - - dispatched = true; - - EventDispatcher::elementListeners.back()->HandleEvent(pstate, estate, EventDispatcher::ctx); - EventDispatcher::elementListeners.back()->SetDispatched(false); - - } - - dispatched = false; - - } - - }; - -} - -#endif diff --git a/test/util/DispatchRunner.hpp b/test/util/DispatchRunner.hpp index c32f716..ba5a31a 100644 --- a/test/util/DispatchRunner.hpp +++ b/test/util/DispatchRunner.hpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include @@ -79,7 +79,7 @@ class DispatchRunner : public srcDispatch::PolicyListener { std::string srcDiffStr = srcDiff(original, modified); try { srcSAXController control(srcDiffStr); - srcDispatch::srcDispatcherSingleEvent dispatch(this); + srcDispatch::srcDispatcher dispatch(this); control.parse(&dispatch); //Start parsing } catch(SAXError error) { std::cerr << error.message; From 0394de984b458ded57a672543769bb380fed3a91 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 09:44:03 +0900 Subject: [PATCH 130/149] Fix copyright --- src/policy_classes/BlockPolicy.cpp | 2 +- src/policy_classes/BlockPolicy.hpp | 2 +- src/policy_classes/CallPolicy.cpp | 2 +- src/policy_classes/CallPolicy.hpp | 2 +- src/policy_classes/CasePolicy.hpp | 2 +- src/policy_classes/CatchPolicy.hpp | 2 +- src/policy_classes/ClassPolicy.cpp | 2 +- src/policy_classes/ClassPolicy.hpp | 2 +- src/policy_classes/ConditionPolicy.hpp | 2 +- src/policy_classes/ConditionalPolicy.hpp | 2 +- src/policy_classes/ControlPolicy.hpp | 2 +- src/policy_classes/ConvertPlexerPolicy.hpp | 2 +- src/policy_classes/DeclPolicy.hpp | 2 +- src/policy_classes/DeclStmtPolicy.hpp | 2 +- src/policy_classes/DeltaElement.hpp | 2 +- src/policy_classes/DeltaElement.tcc | 2 +- src/policy_classes/DoPolicy.hpp | 2 +- src/policy_classes/ElseIfPolicy.hpp | 2 +- src/policy_classes/ElsePolicy.hpp | 2 +- src/policy_classes/ExprStmtPolicy.hpp | 2 +- src/policy_classes/ExprTypePolicy.hpp | 2 +- src/policy_classes/ExpressionPolicy.cpp | 2 +- src/policy_classes/ExpressionPolicy.hpp | 2 +- src/policy_classes/ForPolicy.hpp | 2 +- src/policy_classes/FunctionPolicy.hpp | 2 +- src/policy_classes/GenericArgumentsPolicy.cpp | 2 +- src/policy_classes/GenericArgumentsPolicy.hpp | 2 +- src/policy_classes/GenericPolicy.cpp | 2 +- src/policy_classes/GenericPolicy.hpp | 2 +- src/policy_classes/GotoPolicy.hpp | 2 +- src/policy_classes/IfPolicy.hpp | 2 +- src/policy_classes/IfStmtPolicy.hpp | 2 +- src/policy_classes/IncrPolicy.hpp | 2 +- src/policy_classes/InitPolicy.hpp | 2 +- src/policy_classes/LabelPolicy.hpp | 2 +- src/policy_classes/LiteralPolicy.hpp | 2 +- src/policy_classes/NamePolicy.cpp | 2 +- src/policy_classes/NamePolicy.hpp | 2 +- src/policy_classes/OperatorPolicy.hpp | 2 +- src/policy_classes/ReturnPolicy.hpp | 2 +- src/policy_classes/SwitchPolicy.hpp | 2 +- src/policy_classes/ThrowPolicy.hpp | 2 +- src/policy_classes/TryPolicy.hpp | 2 +- src/policy_classes/TypePolicy.cpp | 2 +- src/policy_classes/TypePolicy.hpp | 2 +- src/policy_classes/UnitPolicy.hpp | 2 +- src/policy_classes/WhilePolicy.hpp | 2 +- 47 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/policy_classes/BlockPolicy.cpp b/src/policy_classes/BlockPolicy.cpp index bd43930..b257997 100644 --- a/src/policy_classes/BlockPolicy.cpp +++ b/src/policy_classes/BlockPolicy.cpp @@ -2,7 +2,7 @@ /** * @file BlockPolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/BlockPolicy.hpp b/src/policy_classes/BlockPolicy.hpp index 2c9bdc9..8d6db2b 100644 --- a/src/policy_classes/BlockPolicy.hpp +++ b/src/policy_classes/BlockPolicy.hpp @@ -2,7 +2,7 @@ /** * @file BlockPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/CallPolicy.cpp b/src/policy_classes/CallPolicy.cpp index 43e0762..50de00f 100644 --- a/src/policy_classes/CallPolicy.cpp +++ b/src/policy_classes/CallPolicy.cpp @@ -2,7 +2,7 @@ /** * @file CallPolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/CallPolicy.hpp b/src/policy_classes/CallPolicy.hpp index e7e7ebb..f5cd297 100644 --- a/src/policy_classes/CallPolicy.hpp +++ b/src/policy_classes/CallPolicy.hpp @@ -2,7 +2,7 @@ /** * @file CallPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/CasePolicy.hpp b/src/policy_classes/CasePolicy.hpp index d9b7c2c..909d838 100644 --- a/src/policy_classes/CasePolicy.hpp +++ b/src/policy_classes/CasePolicy.hpp @@ -2,7 +2,7 @@ /** * @file CasePolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/CatchPolicy.hpp b/src/policy_classes/CatchPolicy.hpp index f8654e3..0fef80a 100644 --- a/src/policy_classes/CatchPolicy.hpp +++ b/src/policy_classes/CatchPolicy.hpp @@ -2,7 +2,7 @@ /** * @file CatchPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ClassPolicy.cpp b/src/policy_classes/ClassPolicy.cpp index c4214d2..a21bb87 100644 --- a/src/policy_classes/ClassPolicy.cpp +++ b/src/policy_classes/ClassPolicy.cpp @@ -2,7 +2,7 @@ /** * @file BlockPolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ClassPolicy.hpp b/src/policy_classes/ClassPolicy.hpp index 701b728..98812f9 100644 --- a/src/policy_classes/ClassPolicy.hpp +++ b/src/policy_classes/ClassPolicy.hpp @@ -2,7 +2,7 @@ /** * @file ClassPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ConditionPolicy.hpp b/src/policy_classes/ConditionPolicy.hpp index f52dcad..000e846 100644 --- a/src/policy_classes/ConditionPolicy.hpp +++ b/src/policy_classes/ConditionPolicy.hpp @@ -2,7 +2,7 @@ /** * @file ConditionPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ConditionalPolicy.hpp b/src/policy_classes/ConditionalPolicy.hpp index 550a4bf..446862e 100644 --- a/src/policy_classes/ConditionalPolicy.hpp +++ b/src/policy_classes/ConditionalPolicy.hpp @@ -2,7 +2,7 @@ /** * @file ConditionalPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ControlPolicy.hpp b/src/policy_classes/ControlPolicy.hpp index 04a0a5d..72299e7 100644 --- a/src/policy_classes/ControlPolicy.hpp +++ b/src/policy_classes/ControlPolicy.hpp @@ -2,7 +2,7 @@ /** * @file ControlPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ConvertPlexerPolicy.hpp b/src/policy_classes/ConvertPlexerPolicy.hpp index b812e2c..394100e 100644 --- a/src/policy_classes/ConvertPlexerPolicy.hpp +++ b/src/policy_classes/ConvertPlexerPolicy.hpp @@ -2,7 +2,7 @@ /** * @file ConvertPlexerPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/DeclPolicy.hpp b/src/policy_classes/DeclPolicy.hpp index 47ae17e..4150edf 100644 --- a/src/policy_classes/DeclPolicy.hpp +++ b/src/policy_classes/DeclPolicy.hpp @@ -2,7 +2,7 @@ /** * @file DeclPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/DeclStmtPolicy.hpp b/src/policy_classes/DeclStmtPolicy.hpp index 9974095..6673ec2 100644 --- a/src/policy_classes/DeclStmtPolicy.hpp +++ b/src/policy_classes/DeclStmtPolicy.hpp @@ -2,7 +2,7 @@ /** * @file DeclStmtPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/DeltaElement.hpp b/src/policy_classes/DeltaElement.hpp index 4e16764..b4c137b 100644 --- a/src/policy_classes/DeltaElement.hpp +++ b/src/policy_classes/DeltaElement.hpp @@ -2,7 +2,7 @@ /** * @file DeltaElement.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/DeltaElement.tcc b/src/policy_classes/DeltaElement.tcc index a416512..8ec1add 100644 --- a/src/policy_classes/DeltaElement.tcc +++ b/src/policy_classes/DeltaElement.tcc @@ -2,7 +2,7 @@ /** * @file DeltaElement.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/DoPolicy.hpp b/src/policy_classes/DoPolicy.hpp index a558c0f..7de4c08 100644 --- a/src/policy_classes/DoPolicy.hpp +++ b/src/policy_classes/DoPolicy.hpp @@ -2,7 +2,7 @@ /** * @file DoPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ElseIfPolicy.hpp b/src/policy_classes/ElseIfPolicy.hpp index 7505a46..42056a8 100644 --- a/src/policy_classes/ElseIfPolicy.hpp +++ b/src/policy_classes/ElseIfPolicy.hpp @@ -2,7 +2,7 @@ /** * @file ElseIfPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ElsePolicy.hpp b/src/policy_classes/ElsePolicy.hpp index 255f2d8..4eeac22 100644 --- a/src/policy_classes/ElsePolicy.hpp +++ b/src/policy_classes/ElsePolicy.hpp @@ -2,7 +2,7 @@ /** * @file ElsePolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ExprStmtPolicy.hpp b/src/policy_classes/ExprStmtPolicy.hpp index 6cece16..af18450 100644 --- a/src/policy_classes/ExprStmtPolicy.hpp +++ b/src/policy_classes/ExprStmtPolicy.hpp @@ -2,7 +2,7 @@ /** * @file ExprStmtPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ExprTypePolicy.hpp b/src/policy_classes/ExprTypePolicy.hpp index 67209d7..9abe50b 100644 --- a/src/policy_classes/ExprTypePolicy.hpp +++ b/src/policy_classes/ExprTypePolicy.hpp @@ -2,7 +2,7 @@ /** * @file ExprTypePolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ExpressionPolicy.cpp b/src/policy_classes/ExpressionPolicy.cpp index cd6701a..e25373c 100644 --- a/src/policy_classes/ExpressionPolicy.cpp +++ b/src/policy_classes/ExpressionPolicy.cpp @@ -2,7 +2,7 @@ /** * @file ExpressionPolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ExpressionPolicy.hpp b/src/policy_classes/ExpressionPolicy.hpp index b7b0d57..b81578d 100644 --- a/src/policy_classes/ExpressionPolicy.hpp +++ b/src/policy_classes/ExpressionPolicy.hpp @@ -2,7 +2,7 @@ /** * @file ExpressionPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ForPolicy.hpp b/src/policy_classes/ForPolicy.hpp index 80ee293..5d34ded 100644 --- a/src/policy_classes/ForPolicy.hpp +++ b/src/policy_classes/ForPolicy.hpp @@ -2,7 +2,7 @@ /** * @file ForPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/FunctionPolicy.hpp b/src/policy_classes/FunctionPolicy.hpp index 38b4cda..8aa16e5 100644 --- a/src/policy_classes/FunctionPolicy.hpp +++ b/src/policy_classes/FunctionPolicy.hpp @@ -2,7 +2,7 @@ /** * @file FunctionPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/GenericArgumentsPolicy.cpp b/src/policy_classes/GenericArgumentsPolicy.cpp index d6325dd..1242800 100644 --- a/src/policy_classes/GenericArgumentsPolicy.cpp +++ b/src/policy_classes/GenericArgumentsPolicy.cpp @@ -2,7 +2,7 @@ /** * @file GenericArgumentsPolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/GenericArgumentsPolicy.hpp b/src/policy_classes/GenericArgumentsPolicy.hpp index e131386..41f73b1 100644 --- a/src/policy_classes/GenericArgumentsPolicy.hpp +++ b/src/policy_classes/GenericArgumentsPolicy.hpp @@ -2,7 +2,7 @@ /** * @file GenericArgumentsPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/GenericPolicy.cpp b/src/policy_classes/GenericPolicy.cpp index 0a847b0..c27f5b2 100644 --- a/src/policy_classes/GenericPolicy.cpp +++ b/src/policy_classes/GenericPolicy.cpp @@ -2,7 +2,7 @@ /** * @file GenericPolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/GenericPolicy.hpp b/src/policy_classes/GenericPolicy.hpp index 84aa91d..1ed9c4e 100644 --- a/src/policy_classes/GenericPolicy.hpp +++ b/src/policy_classes/GenericPolicy.hpp @@ -2,7 +2,7 @@ /** * @file GenericPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/GotoPolicy.hpp b/src/policy_classes/GotoPolicy.hpp index eabbb36..9da5768 100644 --- a/src/policy_classes/GotoPolicy.hpp +++ b/src/policy_classes/GotoPolicy.hpp @@ -2,7 +2,7 @@ /** * @file GotoPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/IfPolicy.hpp b/src/policy_classes/IfPolicy.hpp index 5d9680f..e567c9e 100644 --- a/src/policy_classes/IfPolicy.hpp +++ b/src/policy_classes/IfPolicy.hpp @@ -2,7 +2,7 @@ /** * @file IfPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/IfStmtPolicy.hpp b/src/policy_classes/IfStmtPolicy.hpp index 930684d..8bf8a5f 100644 --- a/src/policy_classes/IfStmtPolicy.hpp +++ b/src/policy_classes/IfStmtPolicy.hpp @@ -2,7 +2,7 @@ /** * @file IfStmtPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/IncrPolicy.hpp b/src/policy_classes/IncrPolicy.hpp index c2799f8..e9ce8dc 100644 --- a/src/policy_classes/IncrPolicy.hpp +++ b/src/policy_classes/IncrPolicy.hpp @@ -2,7 +2,7 @@ /** * @file IncrPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/InitPolicy.hpp b/src/policy_classes/InitPolicy.hpp index 3cc8097..ed23c4b 100644 --- a/src/policy_classes/InitPolicy.hpp +++ b/src/policy_classes/InitPolicy.hpp @@ -2,7 +2,7 @@ /** * @file InitPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/LabelPolicy.hpp b/src/policy_classes/LabelPolicy.hpp index 504fdc0..5f84b72 100644 --- a/src/policy_classes/LabelPolicy.hpp +++ b/src/policy_classes/LabelPolicy.hpp @@ -2,7 +2,7 @@ /** * @file LabelPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/LiteralPolicy.hpp b/src/policy_classes/LiteralPolicy.hpp index 9f87a7b..53da13f 100644 --- a/src/policy_classes/LiteralPolicy.hpp +++ b/src/policy_classes/LiteralPolicy.hpp @@ -2,7 +2,7 @@ /** * @file LiteralPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/NamePolicy.cpp b/src/policy_classes/NamePolicy.cpp index 9470c9d..be194a4 100644 --- a/src/policy_classes/NamePolicy.cpp +++ b/src/policy_classes/NamePolicy.cpp @@ -2,7 +2,7 @@ /** * @file NamePolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/NamePolicy.hpp b/src/policy_classes/NamePolicy.hpp index c51c189..dee9369 100644 --- a/src/policy_classes/NamePolicy.hpp +++ b/src/policy_classes/NamePolicy.hpp @@ -2,7 +2,7 @@ /** * @file NamePolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/OperatorPolicy.hpp b/src/policy_classes/OperatorPolicy.hpp index e835574..3644b62 100644 --- a/src/policy_classes/OperatorPolicy.hpp +++ b/src/policy_classes/OperatorPolicy.hpp @@ -2,7 +2,7 @@ /** * @file OperatorPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ReturnPolicy.hpp b/src/policy_classes/ReturnPolicy.hpp index 881b01a..d3b2049 100644 --- a/src/policy_classes/ReturnPolicy.hpp +++ b/src/policy_classes/ReturnPolicy.hpp @@ -2,7 +2,7 @@ /** * @file ReturnPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/SwitchPolicy.hpp b/src/policy_classes/SwitchPolicy.hpp index 2ab27fe..8a881fc 100644 --- a/src/policy_classes/SwitchPolicy.hpp +++ b/src/policy_classes/SwitchPolicy.hpp @@ -2,7 +2,7 @@ /** * @file SwitchPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/ThrowPolicy.hpp b/src/policy_classes/ThrowPolicy.hpp index 9e7e42c..ea19f8d 100644 --- a/src/policy_classes/ThrowPolicy.hpp +++ b/src/policy_classes/ThrowPolicy.hpp @@ -2,7 +2,7 @@ /** * @file ThrowPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/TryPolicy.hpp b/src/policy_classes/TryPolicy.hpp index 43924dd..e34c21b 100644 --- a/src/policy_classes/TryPolicy.hpp +++ b/src/policy_classes/TryPolicy.hpp @@ -2,7 +2,7 @@ /** * @file TryPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/TypePolicy.cpp b/src/policy_classes/TypePolicy.cpp index 1a80fb3..ae8ddfa 100644 --- a/src/policy_classes/TypePolicy.cpp +++ b/src/policy_classes/TypePolicy.cpp @@ -2,7 +2,7 @@ /** * @file TypePolicy.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/TypePolicy.hpp b/src/policy_classes/TypePolicy.hpp index b4595f0..c5a634d 100644 --- a/src/policy_classes/TypePolicy.hpp +++ b/src/policy_classes/TypePolicy.hpp @@ -2,7 +2,7 @@ /** * @file TypePolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ diff --git a/src/policy_classes/UnitPolicy.hpp b/src/policy_classes/UnitPolicy.hpp index 5d798de..333a5c2 100644 --- a/src/policy_classes/UnitPolicy.hpp +++ b/src/policy_classes/UnitPolicy.hpp @@ -2,7 +2,7 @@ /** * @file UnitPolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. * diff --git a/src/policy_classes/WhilePolicy.hpp b/src/policy_classes/WhilePolicy.hpp index 8094539..56de862 100644 --- a/src/policy_classes/WhilePolicy.hpp +++ b/src/policy_classes/WhilePolicy.hpp @@ -2,7 +2,7 @@ /** * @file WhilePolicy.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www..org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ From 978a0a1c207e01adadf15ca43960dd19908543f0 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 09:46:27 +0900 Subject: [PATCH 131/149] Fix copyright for tests --- CMakeLists.txt | 12 ++++++------ test/suite/CMakeLists.txt | 2 +- test/suite/testCall.cpp | 2 +- test/suite/testCase.cpp | 2 +- test/suite/testClass.cpp | 2 +- test/suite/testClassConvert.cpp | 2 +- test/suite/testCondition.cpp | 2 +- test/suite/testConditionalConvert.cpp | 2 +- test/suite/testControl.cpp | 2 +- test/suite/testDecl.cpp | 2 +- test/suite/testDeclStmt.cpp | 2 +- test/suite/testDo.cpp | 2 +- test/suite/testExprConvert.cpp | 2 +- test/suite/testExprStmt.cpp | 2 +- test/suite/testFor.cpp | 2 +- test/suite/testFunction.cpp | 2 +- test/suite/testGoto.cpp | 2 +- test/suite/testIfStmt.cpp | 2 +- test/suite/testLabel.cpp | 2 +- test/suite/testReturn.cpp | 2 +- test/suite/testSwitch.cpp | 2 +- test/suite/testTemplate.cpp | 2 +- test/suite/testThrow.cpp | 2 +- test/suite/testTry.cpp | 2 +- test/suite/testWhile.cpp | 2 +- test/util/DispatchRunner.hpp | 2 +- 26 files changed, 31 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2ea958..91aba02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,22 +1,22 @@ ## # CMakeLists.txt # -# Copyright (C) 2025-2025 srcML, LLC. (www.srcDiff.org) +# Copyright (C) 2025-2025 srcML, LLC. (www.srcML.org) # -# This file is part of the srcDiffDispatch. +# This file is part of the srcDispatch. # -# The srcDiffDispatch is free software; you can redistribute it and/or modify +# The srcDispatch is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # -# The srcDiffDispatch is distributed in the hope that it will be useful, +# The srcDispatch is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with the srcDiffDispatch; if not, write to the Free Software +# along with the srcDispatch; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA cmake_minimum_required(VERSION 3.14) @@ -44,7 +44,7 @@ set(SRCDISPATCH_INCLUDE_DIR ${SRCSAX_INCLUDE_DIR} src/dispatcher CACHE INTERNAL "Include directories for srcDispatch") -set(SRCDISPATCH_LIBRARIES ${SRCSAX_LIBRARIES} CACHE INTERNAL "Libraries for srcDiffDispatch") +set(SRCDISPATCH_LIBRARIES ${SRCSAX_LIBRARIES} CACHE INTERNAL "Libraries for srcDispatch") # include needed includes include_directories(${SRCDISPATCH_INCLUDE_DIR}) diff --git a/test/suite/CMakeLists.txt b/test/suite/CMakeLists.txt index b44c6dc..5de2770 100644 --- a/test/suite/CMakeLists.txt +++ b/test/suite/CMakeLists.txt @@ -1,7 +1,7 @@ ## # CMakeLists.txt # -# Copyright (C) 2025-2025 srcML, LLC. (www.srcDiff.org) +# Copyright (C) 2025-2025 srcML, LLC. (www.srcML.org) # # This file is part of the srcDiffDispatch. # diff --git a/test/suite/testCall.cpp b/test/suite/testCall.cpp index 6f84af5..7624f70 100644 --- a/test/suite/testCall.cpp +++ b/test/suite/testCall.cpp @@ -2,7 +2,7 @@ /** * @file testCall.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testCase.cpp b/test/suite/testCase.cpp index 752e7e7..da12920 100644 --- a/test/suite/testCase.cpp +++ b/test/suite/testCase.cpp @@ -2,7 +2,7 @@ /** * @file testCase.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testClass.cpp b/test/suite/testClass.cpp index 55ba757..ed2af90 100644 --- a/test/suite/testClass.cpp +++ b/test/suite/testClass.cpp @@ -2,7 +2,7 @@ /** * @file testClass.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testClassConvert.cpp b/test/suite/testClassConvert.cpp index 844a642..30623c1 100644 --- a/test/suite/testClassConvert.cpp +++ b/test/suite/testClassConvert.cpp @@ -2,7 +2,7 @@ /** * @file testClassConvert.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testCondition.cpp b/test/suite/testCondition.cpp index 4cad4a4..548effe 100644 --- a/test/suite/testCondition.cpp +++ b/test/suite/testCondition.cpp @@ -2,7 +2,7 @@ /** * @file testCondition.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testConditionalConvert.cpp b/test/suite/testConditionalConvert.cpp index af1fd4b..0f887fc 100644 --- a/test/suite/testConditionalConvert.cpp +++ b/test/suite/testConditionalConvert.cpp @@ -2,7 +2,7 @@ /** * @file testConditionalConvert.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testControl.cpp b/test/suite/testControl.cpp index 570179b..1909c0f 100644 --- a/test/suite/testControl.cpp +++ b/test/suite/testControl.cpp @@ -2,7 +2,7 @@ /** * @file testControl.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testDecl.cpp b/test/suite/testDecl.cpp index 03decee..f4998aa 100644 --- a/test/suite/testDecl.cpp +++ b/test/suite/testDecl.cpp @@ -2,7 +2,7 @@ /** * @file testDecl.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testDeclStmt.cpp b/test/suite/testDeclStmt.cpp index dd55589..e5e8331 100644 --- a/test/suite/testDeclStmt.cpp +++ b/test/suite/testDeclStmt.cpp @@ -2,7 +2,7 @@ /** * @file testDeclStmt.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testDo.cpp b/test/suite/testDo.cpp index b2bbf1b..93ddcc0 100644 --- a/test/suite/testDo.cpp +++ b/test/suite/testDo.cpp @@ -2,7 +2,7 @@ /** * @file testDo.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testExprConvert.cpp b/test/suite/testExprConvert.cpp index f3abf24..c3cafc3 100644 --- a/test/suite/testExprConvert.cpp +++ b/test/suite/testExprConvert.cpp @@ -2,7 +2,7 @@ /** * @file testExprConvert.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testExprStmt.cpp b/test/suite/testExprStmt.cpp index 2a3fb63..472e08e 100644 --- a/test/suite/testExprStmt.cpp +++ b/test/suite/testExprStmt.cpp @@ -2,7 +2,7 @@ /** * @file testExprStmt.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testFor.cpp b/test/suite/testFor.cpp index 9b2acf1..20bb7da 100644 --- a/test/suite/testFor.cpp +++ b/test/suite/testFor.cpp @@ -2,7 +2,7 @@ /** * @file testFor.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testFunction.cpp b/test/suite/testFunction.cpp index fde1113..1978a6a 100644 --- a/test/suite/testFunction.cpp +++ b/test/suite/testFunction.cpp @@ -2,7 +2,7 @@ /** * @file testFunction.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testGoto.cpp b/test/suite/testGoto.cpp index 4509cad..45981b6 100644 --- a/test/suite/testGoto.cpp +++ b/test/suite/testGoto.cpp @@ -2,7 +2,7 @@ /** * @file testGoto.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testIfStmt.cpp b/test/suite/testIfStmt.cpp index 24670b5..771cd93 100644 --- a/test/suite/testIfStmt.cpp +++ b/test/suite/testIfStmt.cpp @@ -2,7 +2,7 @@ /** * @file testIfStmt.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testLabel.cpp b/test/suite/testLabel.cpp index a7de16c..1b0b614 100644 --- a/test/suite/testLabel.cpp +++ b/test/suite/testLabel.cpp @@ -2,7 +2,7 @@ /** * @file testLabel.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testReturn.cpp b/test/suite/testReturn.cpp index 9e1f461..3247891 100644 --- a/test/suite/testReturn.cpp +++ b/test/suite/testReturn.cpp @@ -2,7 +2,7 @@ /** * @file testReturn.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testSwitch.cpp b/test/suite/testSwitch.cpp index baeb450..acc294b 100644 --- a/test/suite/testSwitch.cpp +++ b/test/suite/testSwitch.cpp @@ -2,7 +2,7 @@ /** * @file testSwitch.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testTemplate.cpp b/test/suite/testTemplate.cpp index 70cacd5..0094026 100644 --- a/test/suite/testTemplate.cpp +++ b/test/suite/testTemplate.cpp @@ -2,7 +2,7 @@ /** * @file testFunction.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testThrow.cpp b/test/suite/testThrow.cpp index 7536532..0589e8b 100644 --- a/test/suite/testThrow.cpp +++ b/test/suite/testThrow.cpp @@ -2,7 +2,7 @@ /** * @file testThrow.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testTry.cpp b/test/suite/testTry.cpp index 26045dd..65541ba 100644 --- a/test/suite/testTry.cpp +++ b/test/suite/testTry.cpp @@ -2,7 +2,7 @@ /** * @file testIfStmt.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/suite/testWhile.cpp b/test/suite/testWhile.cpp index 03664b0..ac0eee1 100644 --- a/test/suite/testWhile.cpp +++ b/test/suite/testWhile.cpp @@ -2,7 +2,7 @@ /** * @file testWhile.cpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the srcDiff Infrastructure. */ diff --git a/test/util/DispatchRunner.hpp b/test/util/DispatchRunner.hpp index ba5a31a..fc7c7b1 100644 --- a/test/util/DispatchRunner.hpp +++ b/test/util/DispatchRunner.hpp @@ -2,7 +2,7 @@ /** * @file DispatchRunner.hpp * - * @copyright Copyright (C) 2025-2025 SDML (www.srcDiff.org) + * @copyright Copyright (C) 2025-2025 SDML (www.srcML.org) * * This file is part of the Dispatch Infrastructure. */ From 7fd255793a27dd2cdc1efb017b6dfeab619cae68 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 09:48:10 +0900 Subject: [PATCH 132/149] Fix include guards --- src/policy_classes/BlockPolicy.hpp | 4 ++-- src/policy_classes/CallPolicy.hpp | 4 ++-- src/policy_classes/CasePolicy.hpp | 4 ++-- src/policy_classes/CatchPolicy.hpp | 4 ++-- src/policy_classes/ClassPolicy.hpp | 4 ++-- src/policy_classes/ConditionPolicy.hpp | 4 ++-- src/policy_classes/ConditionalPolicy.hpp | 4 ++-- src/policy_classes/ControlPolicy.hpp | 4 ++-- src/policy_classes/DeclPolicy.hpp | 4 ++-- src/policy_classes/DeclStmtPolicy.hpp | 4 ++-- src/policy_classes/DoPolicy.hpp | 4 ++-- src/policy_classes/ElseIfPolicy.hpp | 4 ++-- src/policy_classes/ElsePolicy.hpp | 4 ++-- src/policy_classes/ExprStmtPolicy.hpp | 4 ++-- src/policy_classes/ExprTypePolicy.hpp | 4 ++-- src/policy_classes/ExpressionPolicy.hpp | 4 ++-- src/policy_classes/ForPolicy.hpp | 4 ++-- src/policy_classes/FunctionPolicy.hpp | 4 ++-- src/policy_classes/GenericArgumentsPolicy.hpp | 4 ++-- src/policy_classes/GenericPolicy.hpp | 4 ++-- src/policy_classes/GotoPolicy.hpp | 4 ++-- src/policy_classes/IfPolicy.hpp | 4 ++-- src/policy_classes/IfStmtPolicy.hpp | 4 ++-- src/policy_classes/IncrPolicy.hpp | 4 ++-- src/policy_classes/InitPolicy.hpp | 4 ++-- src/policy_classes/LabelPolicy.hpp | 4 ++-- src/policy_classes/LiteralPolicy.hpp | 4 ++-- src/policy_classes/NamePolicy.hpp | 4 ++-- src/policy_classes/OperatorPolicy.hpp | 4 ++-- src/policy_classes/ReturnPolicy.hpp | 4 ++-- src/policy_classes/SwitchPolicy.hpp | 4 ++-- src/policy_classes/ThrowPolicy.hpp | 4 ++-- src/policy_classes/TryPolicy.hpp | 4 ++-- src/policy_classes/TypePolicy.hpp | 4 ++-- src/policy_classes/UnitPolicy.hpp | 4 ++-- src/policy_classes/WhilePolicy.hpp | 4 ++-- 36 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/policy_classes/BlockPolicy.hpp b/src/policy_classes/BlockPolicy.hpp index 8d6db2b..efc1bf6 100644 --- a/src/policy_classes/BlockPolicy.hpp +++ b/src/policy_classes/BlockPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_BLOCK_POLICY_HPP -#define INCLUDED_SRCDIFF_BLOCK_POLICY_HPP +#ifndef INCLUDED_BLOCK_POLICY_HPP +#define INCLUDED_BLOCK_POLICY_HPP #include #include diff --git a/src/policy_classes/CallPolicy.hpp b/src/policy_classes/CallPolicy.hpp index f5cd297..263a2d3 100644 --- a/src/policy_classes/CallPolicy.hpp +++ b/src/policy_classes/CallPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_CALL_POLICY_HPP -#define INCLUDED_SRCDIFF_CALL_POLICY_HPP +#ifndef INCLUDED_CALL_POLICY_HPP +#define INCLUDED_CALL_POLICY_HPP #include #include diff --git a/src/policy_classes/CasePolicy.hpp b/src/policy_classes/CasePolicy.hpp index 909d838..1e75fda 100644 --- a/src/policy_classes/CasePolicy.hpp +++ b/src/policy_classes/CasePolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_CASE_POLICY_HPP -#define INCLUDED_SRCDIFF_CASE_POLICY_HPP +#ifndef INCLUDED_CASE_POLICY_HPP +#define INCLUDED_CASE_POLICY_HPP #include #include diff --git a/src/policy_classes/CatchPolicy.hpp b/src/policy_classes/CatchPolicy.hpp index 0fef80a..b379f5e 100644 --- a/src/policy_classes/CatchPolicy.hpp +++ b/src/policy_classes/CatchPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_CATCH_POLICY_HPP -#define INCLUDED_SRCDIFF_CATCH_POLICY_HPP +#ifndef INCLUDED_CATCH_POLICY_HPP +#define INCLUDED_CATCH_POLICY_HPP #include #include diff --git a/src/policy_classes/ClassPolicy.hpp b/src/policy_classes/ClassPolicy.hpp index 98812f9..58d0993 100644 --- a/src/policy_classes/ClassPolicy.hpp +++ b/src/policy_classes/ClassPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_CLASS_POLICY_HPP -#define INCLUDED_SRCDIFF_CLASS_POLICY_HPP +#ifndef INCLUDED_CLASS_POLICY_HPP +#define INCLUDED_CLASS_POLICY_HPP #include #include diff --git a/src/policy_classes/ConditionPolicy.hpp b/src/policy_classes/ConditionPolicy.hpp index 000e846..d0f8d30 100644 --- a/src/policy_classes/ConditionPolicy.hpp +++ b/src/policy_classes/ConditionPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_CONDITION_POLICY_HPP -#define INCLUDED_SRCDIFF_CONDITION_POLICY_HPP +#ifndef INCLUDED_CONDITION_POLICY_HPP +#define INCLUDED_CONDITION_POLICY_HPP #include #include diff --git a/src/policy_classes/ConditionalPolicy.hpp b/src/policy_classes/ConditionalPolicy.hpp index 446862e..27000fd 100644 --- a/src/policy_classes/ConditionalPolicy.hpp +++ b/src/policy_classes/ConditionalPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_CONDITIONAL_POLICY_HPP -#define INCLUDED_SRCDIFF_CONDITIONAL_POLICY_HPP +#ifndef INCLUDED_CONDITIONAL_POLICY_HPP +#define INCLUDED_CONDITIONAL_POLICY_HPP #include #include diff --git a/src/policy_classes/ControlPolicy.hpp b/src/policy_classes/ControlPolicy.hpp index 72299e7..4fa3c73 100644 --- a/src/policy_classes/ControlPolicy.hpp +++ b/src/policy_classes/ControlPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_CONTROL_POLICY_HPP -#define INCLUDED_SRCDIFF_CONTROL_POLICY_HPP +#ifndef INCLUDED_CONTROL_POLICY_HPP +#define INCLUDED_CONTROL_POLICY_HPP #include #include diff --git a/src/policy_classes/DeclPolicy.hpp b/src/policy_classes/DeclPolicy.hpp index 4150edf..10c0741 100644 --- a/src/policy_classes/DeclPolicy.hpp +++ b/src/policy_classes/DeclPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_DECL_POLICY_HPP -#define INCLUDED_SRCDIFF_DECL_POLICY_HPP +#ifndef INCLUDED_DECL_POLICY_HPP +#define INCLUDED_DECL_POLICY_HPP #include #include diff --git a/src/policy_classes/DeclStmtPolicy.hpp b/src/policy_classes/DeclStmtPolicy.hpp index 6673ec2..f9a21e1 100644 --- a/src/policy_classes/DeclStmtPolicy.hpp +++ b/src/policy_classes/DeclStmtPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_DECL_TYPE_POLICY_HPP -#define INCLUDED_SRCDIFF_DECL_TYPE_POLICY_HPP +#ifndef INCLUDED_DECL_TYPE_POLICY_HPP +#define INCLUDED_DECL_TYPE_POLICY_HPP #include #include diff --git a/src/policy_classes/DoPolicy.hpp b/src/policy_classes/DoPolicy.hpp index 7de4c08..47484b4 100644 --- a/src/policy_classes/DoPolicy.hpp +++ b/src/policy_classes/DoPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_DO_POLICY_HPP -#define INCLUDED_SRCDIFF_DO_POLICY_HPP +#ifndef INCLUDED_DO_POLICY_HPP +#define INCLUDED_DO_POLICY_HPP #include #include diff --git a/src/policy_classes/ElseIfPolicy.hpp b/src/policy_classes/ElseIfPolicy.hpp index 42056a8..2e1b66f 100644 --- a/src/policy_classes/ElseIfPolicy.hpp +++ b/src/policy_classes/ElseIfPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_ELSEIF_POLICY_HPP -#define INCLUDED_SRCDIFF_ELSEIF_POLICY_HPP +#ifndef INCLUDED_ELSEIF_POLICY_HPP +#define INCLUDED_ELSEIF_POLICY_HPP #include #include diff --git a/src/policy_classes/ElsePolicy.hpp b/src/policy_classes/ElsePolicy.hpp index 4eeac22..02e1c6a 100644 --- a/src/policy_classes/ElsePolicy.hpp +++ b/src/policy_classes/ElsePolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_ELSE_POLICY_HPP -#define INCLUDED_SRCDIFF_ELSE_POLICY_HPP +#ifndef INCLUDED_ELSE_POLICY_HPP +#define INCLUDED_ELSE_POLICY_HPP #include #include diff --git a/src/policy_classes/ExprStmtPolicy.hpp b/src/policy_classes/ExprStmtPolicy.hpp index af18450..8e4b5be 100644 --- a/src/policy_classes/ExprStmtPolicy.hpp +++ b/src/policy_classes/ExprStmtPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_EXPR_STMT_POLICY_HPP -#define INCLUDED_SRCDIFF_EXPR_STMT_POLICY_HPP +#ifndef INCLUDED_EXPR_STMT_POLICY_HPP +#define INCLUDED_EXPR_STMT_POLICY_HPP #include #include diff --git a/src/policy_classes/ExprTypePolicy.hpp b/src/policy_classes/ExprTypePolicy.hpp index 9abe50b..8045a50 100644 --- a/src/policy_classes/ExprTypePolicy.hpp +++ b/src/policy_classes/ExprTypePolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_EXPR_TYPE_POLICY_HPP -#define INCLUDED_SRCDIFF_EXPR_TYPE_POLICY_HPP +#ifndef INCLUDED_EXPR_TYPE_POLICY_HPP +#define INCLUDED_EXPR_TYPE_POLICY_HPP #include #include diff --git a/src/policy_classes/ExpressionPolicy.hpp b/src/policy_classes/ExpressionPolicy.hpp index b81578d..620d03f 100644 --- a/src/policy_classes/ExpressionPolicy.hpp +++ b/src/policy_classes/ExpressionPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_EXPRESSION_POLICY_HPP -#define INCLUDED_SRCDIFF_EXPRESSION_POLICY_HPP +#ifndef INCLUDED_EXPRESSION_POLICY_HPP +#define INCLUDED_EXPRESSION_POLICY_HPP #include #include diff --git a/src/policy_classes/ForPolicy.hpp b/src/policy_classes/ForPolicy.hpp index 5d34ded..3ca7147 100644 --- a/src/policy_classes/ForPolicy.hpp +++ b/src/policy_classes/ForPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_FOR_POLICY_HPP -#define INCLUDED_SRCDIFF_FOR_POLICY_HPP +#ifndef INCLUDED_FOR_POLICY_HPP +#define INCLUDED_FOR_POLICY_HPP #include #include diff --git a/src/policy_classes/FunctionPolicy.hpp b/src/policy_classes/FunctionPolicy.hpp index 8aa16e5..ddac37a 100644 --- a/src/policy_classes/FunctionPolicy.hpp +++ b/src/policy_classes/FunctionPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_FUNCTION_POLICY_HPP -#define INCLUDED_SRCDIFF_FUNCTION_POLICY_HPP +#ifndef INCLUDED_FUNCTION_POLICY_HPP +#define INCLUDED_FUNCTION_POLICY_HPP #include #include diff --git a/src/policy_classes/GenericArgumentsPolicy.hpp b/src/policy_classes/GenericArgumentsPolicy.hpp index 41f73b1..d700ebf 100644 --- a/src/policy_classes/GenericArgumentsPolicy.hpp +++ b/src/policy_classes/GenericArgumentsPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_GENERIC_ARGUMENTS_POLICY_HPP -#define INCLUDED_SRCDIFF_GENERIC_ARGUMENTS_POLICY_HPP +#ifndef INCLUDED_GENERIC_ARGUMENTS_POLICY_HPP +#define INCLUDED_GENERIC_ARGUMENTS_POLICY_HPP #include #include diff --git a/src/policy_classes/GenericPolicy.hpp b/src/policy_classes/GenericPolicy.hpp index 1ed9c4e..f594da3 100644 --- a/src/policy_classes/GenericPolicy.hpp +++ b/src/policy_classes/GenericPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_GENERIC_POLICY_HPP -#define INCLUDED_SRCDIFF_GENERIC_POLICY_HPP +#ifndef INCLUDED_GENERIC_POLICY_HPP +#define INCLUDED_GENERIC_POLICY_HPP #include diff --git a/src/policy_classes/GotoPolicy.hpp b/src/policy_classes/GotoPolicy.hpp index 9da5768..198f460 100644 --- a/src/policy_classes/GotoPolicy.hpp +++ b/src/policy_classes/GotoPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_GOTO_POLICY_HPP -#define INCLUDED_SRCDIFF_GOTO_POLICY_HPP +#ifndef INCLUDED_GOTO_POLICY_HPP +#define INCLUDED_GOTO_POLICY_HPP #include #include diff --git a/src/policy_classes/IfPolicy.hpp b/src/policy_classes/IfPolicy.hpp index e567c9e..a956f93 100644 --- a/src/policy_classes/IfPolicy.hpp +++ b/src/policy_classes/IfPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_IF_POLICY_HPP -#define INCLUDED_SRCDIFF_IF_POLICY_HPP +#ifndef INCLUDED_IF_POLICY_HPP +#define INCLUDED_IF_POLICY_HPP #include #include diff --git a/src/policy_classes/IfStmtPolicy.hpp b/src/policy_classes/IfStmtPolicy.hpp index 8bf8a5f..3f84d9a 100644 --- a/src/policy_classes/IfStmtPolicy.hpp +++ b/src/policy_classes/IfStmtPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_IF_STMT_POLICY_HPP -#define INCLUDED_SRCDIFF_IF_STMT_POLICY_HPP +#ifndef INCLUDED_IF_STMT_POLICY_HPP +#define INCLUDED_IF_STMT_POLICY_HPP #include #include diff --git a/src/policy_classes/IncrPolicy.hpp b/src/policy_classes/IncrPolicy.hpp index e9ce8dc..091bbd0 100644 --- a/src/policy_classes/IncrPolicy.hpp +++ b/src/policy_classes/IncrPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_INCR_POLICY_HPP -#define INCLUDED_SRCDIFF_INCR_POLICY_HPP +#ifndef INCLUDED_INCR_POLICY_HPP +#define INCLUDED_INCR_POLICY_HPP #include #include diff --git a/src/policy_classes/InitPolicy.hpp b/src/policy_classes/InitPolicy.hpp index ed23c4b..3064195 100644 --- a/src/policy_classes/InitPolicy.hpp +++ b/src/policy_classes/InitPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_INIT_POLICY_HPP -#define INCLUDED_SRCDIFF_INIT_POLICY_HPP +#ifndef INCLUDED_INIT_POLICY_HPP +#define INCLUDED_INIT_POLICY_HPP #include #include diff --git a/src/policy_classes/LabelPolicy.hpp b/src/policy_classes/LabelPolicy.hpp index 5f84b72..d87cf86 100644 --- a/src/policy_classes/LabelPolicy.hpp +++ b/src/policy_classes/LabelPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_LABEL_POLICY_HPP -#define INCLUDED_SRCDIFF_LABEL_POLICY_HPP +#ifndef INCLUDED_LABEL_POLICY_HPP +#define INCLUDED_LABEL_POLICY_HPP #include #include diff --git a/src/policy_classes/LiteralPolicy.hpp b/src/policy_classes/LiteralPolicy.hpp index 53da13f..9cb6d4f 100644 --- a/src/policy_classes/LiteralPolicy.hpp +++ b/src/policy_classes/LiteralPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_LITERAL_POLICY_HPP -#define INCLUDED_SRCDIFF_LITERAL_POLICY_HPP +#ifndef INCLUDED_LITERAL_POLICY_HPP +#define INCLUDED_LITERAL_POLICY_HPP #include #include diff --git a/src/policy_classes/NamePolicy.hpp b/src/policy_classes/NamePolicy.hpp index dee9369..4eb74b7 100644 --- a/src/policy_classes/NamePolicy.hpp +++ b/src/policy_classes/NamePolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_NAME_POLICY_HPP -#define INCLUDED_SRCDIFF_NAME_POLICY_HPP +#ifndef INCLUDED_NAME_POLICY_HPP +#define INCLUDED_NAME_POLICY_HPP #include #include diff --git a/src/policy_classes/OperatorPolicy.hpp b/src/policy_classes/OperatorPolicy.hpp index 3644b62..756c901 100644 --- a/src/policy_classes/OperatorPolicy.hpp +++ b/src/policy_classes/OperatorPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_OPERATOR_POLICY_HPP -#define INCLUDED_SRCDIFF_OPERATOR_POLICY_HPP +#ifndef INCLUDED_OPERATOR_POLICY_HPP +#define INCLUDED_OPERATOR_POLICY_HPP #include #include diff --git a/src/policy_classes/ReturnPolicy.hpp b/src/policy_classes/ReturnPolicy.hpp index d3b2049..361d3de 100644 --- a/src/policy_classes/ReturnPolicy.hpp +++ b/src/policy_classes/ReturnPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_RETURN_POLICY_HPP -#define INCLUDED_SRCDIFF_RETURN_POLICY_HPP +#ifndef INCLUDED_RETURN_POLICY_HPP +#define INCLUDED_RETURN_POLICY_HPP #include #include diff --git a/src/policy_classes/SwitchPolicy.hpp b/src/policy_classes/SwitchPolicy.hpp index 8a881fc..9121d39 100644 --- a/src/policy_classes/SwitchPolicy.hpp +++ b/src/policy_classes/SwitchPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_SWITCH_POLICY_HPP -#define INCLUDED_SRCDIFF_SWITCH_POLICY_HPP +#ifndef INCLUDED_SWITCH_POLICY_HPP +#define INCLUDED_SWITCH_POLICY_HPP #include #include diff --git a/src/policy_classes/ThrowPolicy.hpp b/src/policy_classes/ThrowPolicy.hpp index ea19f8d..031fcdf 100644 --- a/src/policy_classes/ThrowPolicy.hpp +++ b/src/policy_classes/ThrowPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_THROW_POLICY_HPP -#define INCLUDED_SRCDIFF_THROW_POLICY_HPP +#ifndef INCLUDED_THROW_POLICY_HPP +#define INCLUDED_THROW_POLICY_HPP #include #include diff --git a/src/policy_classes/TryPolicy.hpp b/src/policy_classes/TryPolicy.hpp index e34c21b..1c47deb 100644 --- a/src/policy_classes/TryPolicy.hpp +++ b/src/policy_classes/TryPolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_TRY_POLICY_HPP -#define INCLUDED_SRCDIFF_TRY_POLICY_HPP +#ifndef INCLUDED_TRY_POLICY_HPP +#define INCLUDED_TRY_POLICY_HPP #include #include diff --git a/src/policy_classes/TypePolicy.hpp b/src/policy_classes/TypePolicy.hpp index c5a634d..b342914 100644 --- a/src/policy_classes/TypePolicy.hpp +++ b/src/policy_classes/TypePolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_TYPE_POLICY_HPP -#define INCLUDED_SRCDIFF_TYPE_POLICY_HPP +#ifndef INCLUDED_TYPE_POLICY_HPP +#define INCLUDED_TYPE_POLICY_HPP #include #include diff --git a/src/policy_classes/UnitPolicy.hpp b/src/policy_classes/UnitPolicy.hpp index 333a5c2..e917811 100644 --- a/src/policy_classes/UnitPolicy.hpp +++ b/src/policy_classes/UnitPolicy.hpp @@ -12,8 +12,8 @@ * Calls the FunctionPolicy for function * */ -#ifndef INCLUDED_SRCDIFF_UNIT_POLICY_HPP -#define INCLUDED_SRCDIFF_UNIT_POLICY_HPP +#ifndef INCLUDED_UNIT_POLICY_HPP +#define INCLUDED_UNIT_POLICY_HPP #include #include diff --git a/src/policy_classes/WhilePolicy.hpp b/src/policy_classes/WhilePolicy.hpp index 56de862..809a327 100644 --- a/src/policy_classes/WhilePolicy.hpp +++ b/src/policy_classes/WhilePolicy.hpp @@ -7,8 +7,8 @@ * This file is part of the Dispatch Infrastructure. */ -#ifndef INCLUDED_SRCDIFF_SRCDIFF_WHILE_POLICY_HPP -#define INCLUDED_SRCDIFF_SRCDIFF_WHILE_POLICY_HPP +#ifndef INCLUDED_WHILE_POLICY_HPP +#define INCLUDED_WHILE_POLICY_HPP #include #include From 7527275a32ce8ef39abf1ab04b335b98c7113362 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 09:49:13 +0900 Subject: [PATCH 133/149] Fix cmake copyright --- test/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6180033..d4cf8f0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,22 +1,22 @@ ## # CMakeLists.txt # -# Copyright (C) 2025-2025 srcML, LLC. (www.srcDiff.org) +# Copyright (C) 2025-2025 srcML, LLC. (www.srcML.org) # -# This file is part of the srcDiffDispatch. +# This file is part of the srcDispatch. # -# The srcDiffDispatch is free software; you can redistribute it and/or modify +# The srcDispatch is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # -# The srcDiffDispatch is distributed in the hope that it will be useful, +# The srcDispatch is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with the srcDiffDispatch; if not, write to the Free Software +# along with the srcDispatch; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA find_package(LibXml2 REQUIRED) From 80bb3ef5e89c077468b6ec924d9b6b0997612e2c Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Thu, 26 Jun 2025 16:56:40 +0900 Subject: [PATCH 134/149] Fix issue where expr does not appear in argument --- src/policy_classes/DeclPolicy.hpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/policy_classes/DeclPolicy.hpp b/src/policy_classes/DeclPolicy.hpp index 10c0741..f140196 100644 --- a/src/policy_classes/DeclPolicy.hpp +++ b/src/policy_classes/DeclPolicy.hpp @@ -270,10 +270,12 @@ namespace srcDispatch { if(!depth) return; openEventMap[ParserState::argument] = [this](srcSAXEventContext &ctx) { - if(!exprPolicy) { - exprPolicy = make_unique_policy({this}); - } - ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); + openEventMap[ParserState::expr] = [this](srcSAXEventContext &ctx) { + if(!exprPolicy) {fprintf(stderr, "HERE: %s %s %d\n", __FILE__, __FUNCTION__, __LINE__); + exprPolicy = make_unique_policy({this}); + } + ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); + }; }; closeEventMap[ParserState::argument] = [this](srcSAXEventContext &ctx) { From d9e32ddb7a5d9a6748ea35af3cff679910275a6c Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 27 Jun 2025 14:42:46 +0900 Subject: [PATCH 135/149] Fix handling of an archive --- src/dispatcher/srcDispatcher.hpp | 3 +++ src/policy_classes/UnitPolicy.hpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index eae12d9..ac54fa3 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -851,6 +851,7 @@ namespace srcDispatch { int num_namespaces, const struct srcsax_namespace * namespaces, int num_attributes, const struct srcsax_attribute * attributes) override { ctx.isArchive = is_archive; + ++ctx.depth; if (generateArchive) { ctx.write_start_tag(localname, prefix, URI, num_namespaces, namespaces, num_attributes, attributes); } @@ -1038,6 +1039,8 @@ namespace srcDispatch { } if (generateArchive) { xmlTextWriterEndElement(ctx.writer); } + --ctx.depth; + } virtual void endElement(const char * localname, const char * prefix, const char * URI) override { diff --git a/src/policy_classes/UnitPolicy.hpp b/src/policy_classes/UnitPolicy.hpp index e917811..c9c10bb 100644 --- a/src/policy_classes/UnitPolicy.hpp +++ b/src/policy_classes/UnitPolicy.hpp @@ -84,7 +84,7 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[ParserState::unit] = [this](srcSAXEventContext& ctx) { - if (unitDepth == MAX_DEPTH && (!ctx.isArchive || ctx.depth > 0)) { + if (unitDepth == MAX_DEPTH && (ctx.isArchive || ctx.depth > 0)) { unitDepth = ctx.depth; data = UnitData{}; } From 40cd6aa9cb47307b7509f4eb78db47b6b2542f19 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 27 Jun 2025 16:15:29 +0900 Subject: [PATCH 136/149] Refactor DispatchRunner and add multi file support --- test/util/DispatchRunner.hpp | 72 +++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/test/util/DispatchRunner.hpp b/test/util/DispatchRunner.hpp index fc7c7b1..3c460ba 100644 --- a/test/util/DispatchRunner.hpp +++ b/test/util/DispatchRunner.hpp @@ -21,26 +21,34 @@ namespace srcDispatch { +typedef std::pair SourcePair; + class DispatchRunner : public srcDispatch::PolicyListener { private: - std::string srcDiff(const std::string& original, const std::string& modified) { - - std::ofstream originalFile("original.cpp"); - originalFile << original; - originalFile.close(); - std::ofstream modifiedFile("modified.cpp"); - modifiedFile << modified; - modifiedFile.close(); - - std::system("srcdiff original.cpp modified.cpp -o srcdiff.xml"); + void writeFile(const std::string& filename, const std::string& contents) { + std::ofstream file(filename); + file << contents; + } + std::string readDiffFile() { std::ifstream srcDiffFile("srcdiff.xml", std::ios::ate); std::size_t size = srcDiffFile.tellg(); srcDiffFile.seekg(0); std::string srcDiffStr(size, '\0'); srcDiffFile.read(&srcDiffStr[0], size); + return srcDiffStr; + } + + std::string srcDiff(const std::string& original, const std::string& modified) { + + writeFile("original.cpp", original); + writeFile("modified.cpp", modified); + + std::system("srcdiff original.cpp modified.cpp -o srcdiff.xml"); + + std::string srcDiffStr = readDiffFile(); std::remove("original.cpp"); std::remove("modified.cpp"); @@ -49,6 +57,30 @@ class DispatchRunner : public srcDispatch::PolicyListener { return srcDiffStr; } + std::string srcDiff(const std::vector& sourcePairs) { + + std::filesystem::create_directory("original"); + std::filesystem::create_directory("modified"); + + int pairNum = 0; + for(const SourcePair& pair : sourcePairs) { + std::string numStr = std::to_string(pairNum); + writeFile("original/file" + numStr + ".cpp", pair.first); + writeFile("modified/file" + numStr + ".cpp", pair.second); + ++pairNum; + } + + std::system("srcdiff original modified -o srcdiff.xml"); + + std::string srcDiffStr = readDiffFile(); + + std::filesystem::remove_all("original"); + std::filesystem::remove_all("modified"); + std::remove("srcdiff.xml"); + + return srcDiffStr; + } + std::shared_ptr unit; public: @@ -87,6 +119,26 @@ class DispatchRunner : public srcDispatch::PolicyListener { } } + void RunDispatcher(const std::vector& sourcePairs) { + + std::string srcDiffStr; + if(sourcePairs.size() == 1) { + srcDiffStr = srcDiff(sourcePairs.at(0).first, sourcePairs.at(0).second); + } else { + srcDiffStr = srcDiff(sourcePairs); + } + + try { + srcSAXController control(srcDiffStr); + srcDispatch::srcDispatcher dispatch(this); + control.parse(&dispatch); //Start parsing + } catch(SAXError error) { + std::cerr << error.message; + exit(1); + } + } + + }; } From 7adae7887affb21637b8682b02f7f63efddf3cb4 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 27 Jun 2025 16:28:43 +0900 Subject: [PATCH 137/149] Refactor to have/use the single RunDispatcher --- test/suite/testCall.cpp | 24 ++-- test/suite/testCase.cpp | 10 +- test/suite/testClass.cpp | 168 +++++++++++++------------- test/suite/testClassConvert.cpp | 4 +- test/suite/testCondition.cpp | 10 +- test/suite/testConditionalConvert.cpp | 14 +-- test/suite/testControl.cpp | 64 +++++----- test/suite/testDecl.cpp | 50 ++++---- test/suite/testDeclStmt.cpp | 8 +- test/suite/testDo.cpp | 8 +- test/suite/testExprConvert.cpp | 12 +- test/suite/testExprStmt.cpp | 10 +- test/suite/testFor.cpp | 6 +- test/suite/testFunction.cpp | 64 ++++------ test/suite/testGoto.cpp | 22 ++-- test/suite/testIfStmt.cpp | 28 ++--- test/suite/testLabel.cpp | 8 +- test/suite/testReturn.cpp | 12 +- test/suite/testSwitch.cpp | 8 +- test/suite/testTemplate.cpp | 28 ++--- test/suite/testThrow.cpp | 8 +- test/suite/testTry.cpp | 28 ++--- test/suite/testWhile.cpp | 10 +- test/util/DispatchRunner.hpp | 14 --- 24 files changed, 296 insertions(+), 322 deletions(-) diff --git a/test/suite/testCall.cpp b/test/suite/testCall.cpp index 7624f70..28a777e 100644 --- a/test/suite/testCall.cpp +++ b/test/suite/testCall.cpp @@ -22,7 +22,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(call_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { f(); }", "void foo() { f(); }"); + runner.RunDispatcher({{"void foo() { f(); }", "void foo() { f(); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE(call_common) { BOOST_AUTO_TEST_CASE(call_insert_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { f(); }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { f(); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(call_insert_stmt) { BOOST_AUTO_TEST_CASE(call_delete_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { f(); }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { f(); }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(call_delete_stmt) { BOOST_AUTO_TEST_CASE(call_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { a = b; }", "void foo() { a = b + f(); }"); + runner.RunDispatcher({{"void foo() { a = b; }", "void foo() { a = b + f(); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE(call_insert) { BOOST_AUTO_TEST_CASE(call_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { a = b + f(); }", "void foo() { a = b; }"); + runner.RunDispatcher({{"void foo() { a = b + f(); }", "void foo() { a = b; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE(call_delete) { BOOST_AUTO_TEST_CASE(call_arg_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { f(a); }", "void foo() { f(a); }"); + runner.RunDispatcher({{"void foo() { f(a); }", "void foo() { f(a); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -201,7 +201,7 @@ BOOST_AUTO_TEST_CASE(call_arg_common) { BOOST_AUTO_TEST_CASE(call_arg_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { f(); }", "void foo() { f(a); }"); + runner.RunDispatcher({{"void foo() { f(); }", "void foo() { f(a); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -231,7 +231,7 @@ BOOST_AUTO_TEST_CASE(call_arg_insert) { BOOST_AUTO_TEST_CASE(call_arg_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { f(a); }", "void foo() { f(); }"); + runner.RunDispatcher({{"void foo() { f(a); }", "void foo() { f(); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(call_arg_delete) { BOOST_AUTO_TEST_CASE(call_arg_insert_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { f(a); }", "void foo() { f(0, a); }"); + runner.RunDispatcher({{"void foo() { f(a); }", "void foo() { f(0, a); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -293,7 +293,7 @@ BOOST_AUTO_TEST_CASE(call_arg_insert_front) { BOOST_AUTO_TEST_CASE(call_arg_insert_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { f(a); }", "void foo() { f(a, b + 1); }"); + runner.RunDispatcher({{"void foo() { f(a); }", "void foo() { f(a, b + 1); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE(call_arg_insert_back) { BOOST_AUTO_TEST_CASE(call_arg_delete_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { f(0, a); }", "void foo() { f(a); }"); + runner.RunDispatcher({{"void foo() { f(0, a); }", "void foo() { f(a); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -359,7 +359,7 @@ BOOST_AUTO_TEST_CASE(call_arg_delete_front) { BOOST_AUTO_TEST_CASE(call_arg_delete_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { f(a, b + 1); }", "void foo() { f(a); }"); + runner.RunDispatcher({{"void foo() { f(a, b + 1); }", "void foo() { f(a); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testCase.cpp b/test/suite/testCase.cpp index da12920..8b2ba8e 100644 --- a/test/suite/testCase.cpp +++ b/test/suite/testCase.cpp @@ -24,7 +24,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_common_case) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { switch(1) { case foo; } }", "void foo() { switch(1) { case foo: }"); + runner.RunDispatcher({{"void foo() { switch(1) { case foo; } }", "void foo() { switch(1) { case foo: }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(block_common_case) { BOOST_AUTO_TEST_CASE(block_insert_case) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { switch(1) {} }", "void foo() { switch(1) { case foo: }"); + runner.RunDispatcher({{"void foo() { switch(1) {} }", "void foo() { switch(1) { case foo: }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(block_insert_case) { BOOST_AUTO_TEST_CASE(block_delete_case) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { switch(1) { case foo: } }", "void foo() { switch(1) {} }"); + runner.RunDispatcher({{"void foo() { switch(1) { case foo: } }", "void foo() { switch(1) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE(block_delete_case) { BOOST_AUTO_TEST_CASE(block_case_rename) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { switch(1) { case foo: } }", "void foo() { switch(1) { case bar: } }"); + runner.RunDispatcher({{"void foo() { switch(1) { case foo: } }", "void foo() { switch(1) { case bar: } }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(block_case_rename) { BOOST_AUTO_TEST_CASE(block_case_expr_replace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { switch(1) { case 0: } }", "void foo() { switch(1) { case foo: } }"); + runner.RunDispatcher({{"void foo() { switch(1) { case 0: } }", "void foo() { switch(1) { case foo: } }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testClass.cpp b/test/suite/testClass.cpp index ed2af90..6274918 100644 --- a/test/suite/testClass.cpp +++ b/test/suite/testClass.cpp @@ -24,7 +24,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(class_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo {};", "class foo {};"); + runner.RunDispatcher({{"class foo {};", "class foo {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(class_common) { BOOST_AUTO_TEST_CASE(struct_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("struct foo {};", "struct bar {};"); + runner.RunDispatcher({{"struct foo {};", "struct bar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(struct_common) { BOOST_AUTO_TEST_CASE(class_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("", "class foo {};"); + runner.RunDispatcher({{"", "class foo {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE(class_insert) { BOOST_AUTO_TEST_CASE(class_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo {};", ""); + runner.RunDispatcher({{"class foo {};", ""}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(class_delete) { BOOST_AUTO_TEST_CASE(class_rename) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo {};", "class bar {};"); + runner.RunDispatcher({{"class foo {};", "class bar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(class_rename) { BOOST_AUTO_TEST_CASE(class_parent_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo : bar {};", "class foo : bar {};"); + runner.RunDispatcher({{"class foo : bar {};", "class foo : bar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -217,7 +217,7 @@ BOOST_AUTO_TEST_CASE(class_parent_common) { BOOST_AUTO_TEST_CASE(class_parent_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo {};", "class foo : bar {};"); + runner.RunDispatcher({{"class foo {};", "class foo : bar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -254,7 +254,7 @@ BOOST_AUTO_TEST_CASE(class_parent_insert) { BOOST_AUTO_TEST_CASE(class_parent_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo : bar {};", "class foo {};"); + runner.RunDispatcher({{"class foo : bar {};", "class foo {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -291,7 +291,7 @@ BOOST_AUTO_TEST_CASE(class_parent_delete) { BOOST_AUTO_TEST_CASE(class_parent_rename) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo : public bar {};", "class foo : public foobar {};"); + runner.RunDispatcher({{"class foo : public bar {};", "class foo : public foobar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -329,7 +329,7 @@ BOOST_AUTO_TEST_CASE(class_parent_rename) { BOOST_AUTO_TEST_CASE(class_parent_common_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo : public bar {};", "class foo : public bar {};"); + runner.RunDispatcher({{"class foo : public bar {};", "class foo : public bar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -368,7 +368,7 @@ BOOST_AUTO_TEST_CASE(class_parent_common_access) { BOOST_AUTO_TEST_CASE(class_parent_insert_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo : bar {};", "class foo : public bar {};"); + runner.RunDispatcher({{"class foo : bar {};", "class foo : public bar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -407,7 +407,7 @@ BOOST_AUTO_TEST_CASE(class_parent_insert_access) { BOOST_AUTO_TEST_CASE(class_parent_delete_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo : public bar {};", "class foo : bar {};"); + runner.RunDispatcher({{"class foo : public bar {};", "class foo : bar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -446,7 +446,7 @@ BOOST_AUTO_TEST_CASE(class_parent_delete_access) { BOOST_AUTO_TEST_CASE(class_parent_change_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo : public bar {};", "class foo : private bar {};"); + runner.RunDispatcher({{"class foo : public bar {};", "class foo : private bar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -486,7 +486,7 @@ BOOST_AUTO_TEST_CASE(class_parent_change_access) { BOOST_AUTO_TEST_CASE(class_parent_common_virtual) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo : virtual bar {};", "class foo : virtual bar {};"); + runner.RunDispatcher({{"class foo : virtual bar {};", "class foo : virtual bar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -524,7 +524,7 @@ BOOST_AUTO_TEST_CASE(class_parent_common_virtual) { BOOST_AUTO_TEST_CASE(class_parent_insert_virtual) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo : bar {};", "class foo : virtual bar {};"); + runner.RunDispatcher({{"class foo : bar {};", "class foo : virtual bar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -562,7 +562,7 @@ BOOST_AUTO_TEST_CASE(class_parent_insert_virtual) { BOOST_AUTO_TEST_CASE(class_parent_delete_virtual) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo : virtual bar {};", "class foo : bar {};"); + runner.RunDispatcher({{"class foo : virtual bar {};", "class foo : bar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -600,7 +600,7 @@ BOOST_AUTO_TEST_CASE(class_parent_delete_virtual) { BOOST_AUTO_TEST_CASE(class_parent_replace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo : bar {};", "class foo : foobar {};"); + runner.RunDispatcher({{"class foo : bar {};", "class foo : foobar {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -646,7 +646,7 @@ BOOST_AUTO_TEST_CASE(class_parent_replace) { BOOST_AUTO_TEST_CASE(class_fields_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { int i; };", "class foo { int i; };"); + runner.RunDispatcher({{"class foo { int i; };", "class foo { int i; };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -684,7 +684,7 @@ BOOST_AUTO_TEST_CASE(class_fields_common) { BOOST_AUTO_TEST_CASE(class_fields_private) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: int i; };", "class foo { private: int i; };"); + runner.RunDispatcher({{"class foo { private: int i; };", "class foo { private: int i; };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -722,7 +722,7 @@ BOOST_AUTO_TEST_CASE(class_fields_private) { BOOST_AUTO_TEST_CASE(class_fields_private_default) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { int i; };", "class foo { private: int i; };"); + runner.RunDispatcher({{"class foo { int i; };", "class foo { private: int i; };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -760,7 +760,7 @@ BOOST_AUTO_TEST_CASE(class_fields_private_default) { BOOST_AUTO_TEST_CASE(class_fields_public) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: int i; };", "class foo { public: int i; };"); + runner.RunDispatcher({{"class foo { public: int i; };", "class foo { public: int i; };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -798,7 +798,7 @@ BOOST_AUTO_TEST_CASE(class_fields_public) { BOOST_AUTO_TEST_CASE(class_fields_protected) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { protected: int i; };", "class foo { protected: int i; };"); + runner.RunDispatcher({{"class foo { protected: int i; };", "class foo { protected: int i; };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -836,7 +836,7 @@ BOOST_AUTO_TEST_CASE(class_fields_protected) { BOOST_AUTO_TEST_CASE(class_fields_access_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: int i; };", "class foo { protected: int i; };"); + runner.RunDispatcher({{"class foo { private: int i; };", "class foo { protected: int i; };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -875,7 +875,7 @@ BOOST_AUTO_TEST_CASE(class_fields_access_change) { BOOST_AUTO_TEST_CASE(class_fields_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: };", "class foo { private: int i; };"); + runner.RunDispatcher({{"class foo { private: };", "class foo { private: int i; };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -913,7 +913,7 @@ BOOST_AUTO_TEST_CASE(class_fields_insert) { BOOST_AUTO_TEST_CASE(class_fields_insert_with_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: };", "class foo { private: int i; };"); + runner.RunDispatcher({{"class foo { public: };", "class foo { private: int i; };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -951,7 +951,7 @@ BOOST_AUTO_TEST_CASE(class_fields_insert_with_access) { BOOST_AUTO_TEST_CASE(class_fields_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: int i; };", "class foo { private: };"); + runner.RunDispatcher({{"class foo { private: int i; };", "class foo { private: };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -989,7 +989,7 @@ BOOST_AUTO_TEST_CASE(class_fields_delete) { BOOST_AUTO_TEST_CASE(class_fields_delete_with_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: int i; };", "class foo { private: };"); + runner.RunDispatcher({{"class foo { public: int i; };", "class foo { private: };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1027,7 +1027,7 @@ BOOST_AUTO_TEST_CASE(class_fields_delete_with_access) { BOOST_AUTO_TEST_CASE(class_fields_replace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: int i; };", "class foo { private: double d; };"); + runner.RunDispatcher({{"class foo { private: int i; };", "class foo { private: double d; };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1072,7 +1072,7 @@ BOOST_AUTO_TEST_CASE(class_fields_replace) { BOOST_AUTO_TEST_CASE(class_fields_replace_with_namespace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: int i; };", "class foo { private: double d; };"); + runner.RunDispatcher({{"class foo { public: int i; };", "class foo { private: double d; };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1118,7 +1118,7 @@ BOOST_AUTO_TEST_CASE(class_fields_replace_with_namespace) { BOOST_AUTO_TEST_CASE(class_constructors_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { foo() {} };", "class foo { foo() {} };"); + runner.RunDispatcher({{"class foo { foo() {} };", "class foo { foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1154,7 +1154,7 @@ BOOST_AUTO_TEST_CASE(class_constructors_common) { BOOST_AUTO_TEST_CASE(class_constructors_private) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: foo() {} };", "class foo { private: foo() {} };"); + runner.RunDispatcher({{"class foo { private: foo() {} };", "class foo { private: foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1190,7 +1190,7 @@ BOOST_AUTO_TEST_CASE(class_constructors_private) { BOOST_AUTO_TEST_CASE(class_constructors_private_default) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { foo() {} };", "class foo { private: foo() {} };"); + runner.RunDispatcher({{"class foo { foo() {} };", "class foo { private: foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1226,7 +1226,7 @@ BOOST_AUTO_TEST_CASE(class_constructors_private_default) { BOOST_AUTO_TEST_CASE(class_constructors_public) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: foo() {} };", "class foo { public: foo() {} };"); + runner.RunDispatcher({{"class foo { public: foo() {} };", "class foo { public: foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1262,7 +1262,7 @@ BOOST_AUTO_TEST_CASE(class_constructors_public) { BOOST_AUTO_TEST_CASE(class_constructors_protected) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { protected: foo() {} };", "class foo { protected: foo() {} };"); + runner.RunDispatcher({{"class foo { protected: foo() {} };", "class foo { protected: foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1298,7 +1298,7 @@ BOOST_AUTO_TEST_CASE(class_constructors_protected) { BOOST_AUTO_TEST_CASE(class_constructors_access_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: foo() {} };", "class foo { protected: foo() {} };"); + runner.RunDispatcher({{"class foo { private: foo() {} };", "class foo { protected: foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1335,7 +1335,7 @@ BOOST_AUTO_TEST_CASE(class_constructors_access_change) { BOOST_AUTO_TEST_CASE(class_constructors_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: };", "class foo { private: foo() {} };"); + runner.RunDispatcher({{"class foo { private: };", "class foo { private: foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1371,7 +1371,7 @@ BOOST_AUTO_TEST_CASE(class_constructors_insert) { BOOST_AUTO_TEST_CASE(class_constructors_insert_with_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: };", "class foo { private: foo() {} };"); + runner.RunDispatcher({{"class foo { public: };", "class foo { private: foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1407,7 +1407,7 @@ BOOST_AUTO_TEST_CASE(class_constructors_insert_with_access) { BOOST_AUTO_TEST_CASE(class_constructors_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: foo() {} };", "class foo { private: };"); + runner.RunDispatcher({{"class foo { private: foo() {} };", "class foo { private: };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1443,7 +1443,7 @@ BOOST_AUTO_TEST_CASE(class_constructors_delete) { BOOST_AUTO_TEST_CASE(class_constructors_delete_with_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: foo() {} };", "class foo { private: };"); + runner.RunDispatcher({{"class foo { public: foo() {} };", "class foo { private: };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1479,7 +1479,7 @@ BOOST_AUTO_TEST_CASE(class_constructors_delete_with_access) { BOOST_AUTO_TEST_CASE(class_constructors_replace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: foo() { ab; } public: void f() { c; d; } };", "class bar { private: bar() { b; } public: void f() { c; d; } };"); + runner.RunDispatcher({{"class foo { private: foo() { ab; } public: void f() { c; d; } };", "class bar { private: bar() { b; } public: void f() { c; d; } };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1520,7 +1520,7 @@ BOOST_AUTO_TEST_CASE(class_constructors_replace) { BOOST_AUTO_TEST_CASE(class_constructors_replace_with_namespace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: foo() { a; } public: void f() { c + d + e + f; } };", "class bar { private: bar() { a; } public: void f() { c + d + e + f; } };"); + runner.RunDispatcher({{"class foo { public: foo() { a; } public: void f() { c + d + e + f; } };", "class bar { private: bar() { a; } public: void f() { c + d + e + f; } };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1562,7 +1562,7 @@ BOOST_AUTO_TEST_CASE(class_constructors_replace_with_namespace) { BOOST_AUTO_TEST_CASE(class_destructors_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { ~foo() {} };", "class foo { ~foo() {} };"); + runner.RunDispatcher({{"class foo { ~foo() {} };", "class foo { ~foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1598,7 +1598,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_common) { BOOST_AUTO_TEST_CASE(class_destructors_private) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: ~foo() {} };", "class foo { private: ~foo() {} };"); + runner.RunDispatcher({{"class foo { private: ~foo() {} };", "class foo { private: ~foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1634,7 +1634,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_private) { BOOST_AUTO_TEST_CASE(class_destructors_private_default) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { ~foo() {} };", "class foo { private: ~foo() {} };"); + runner.RunDispatcher({{"class foo { ~foo() {} };", "class foo { private: ~foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1670,7 +1670,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_private_default) { BOOST_AUTO_TEST_CASE(class_destructors_public) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: ~foo() {} };", "class foo { public: ~foo() {} };"); + runner.RunDispatcher({{"class foo { public: ~foo() {} };", "class foo { public: ~foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1706,7 +1706,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_public) { BOOST_AUTO_TEST_CASE(class_destructors_protected) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { protected: ~foo() {} };", "class foo { protected: ~foo() {} };"); + runner.RunDispatcher({{"class foo { protected: ~foo() {} };", "class foo { protected: ~foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1742,7 +1742,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_protected) { BOOST_AUTO_TEST_CASE(class_destructors_access_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: ~foo() {} };", "class foo { protected: ~foo() {} };"); + runner.RunDispatcher({{"class foo { private: ~foo() {} };", "class foo { protected: ~foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1779,7 +1779,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_access_change) { BOOST_AUTO_TEST_CASE(class_destructors_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: };", "class foo { private: ~foo() {} };"); + runner.RunDispatcher({{"class foo { private: };", "class foo { private: ~foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1815,7 +1815,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_insert) { BOOST_AUTO_TEST_CASE(class_destructors_insert_with_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: };", "class foo { private: ~foo() {} };"); + runner.RunDispatcher({{"class foo { public: };", "class foo { private: ~foo() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1851,7 +1851,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_insert_with_access) { BOOST_AUTO_TEST_CASE(class_destructors_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: ~foo() {} };", "class foo { private: };"); + runner.RunDispatcher({{"class foo { private: ~foo() {} };", "class foo { private: };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1887,7 +1887,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_delete) { BOOST_AUTO_TEST_CASE(class_destructors_delete_with_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: ~foo() {} };", "class foo { private: };"); + runner.RunDispatcher({{"class foo { public: ~foo() {} };", "class foo { private: };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1923,7 +1923,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_delete_with_access) { BOOST_AUTO_TEST_CASE(class_destructors_replace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: ~foo() { ab; } public: void f() { c; d; } };", "class bar { private: ~bar() { b; } public: void f() { c; d; } };"); + runner.RunDispatcher({{"class foo { private: ~foo() { ab; } public: void f() { c; d; } };", "class bar { private: ~bar() { b; } public: void f() { c; d; } };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1959,7 +1959,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_replace) { BOOST_AUTO_TEST_CASE(class_destructors_replace_with_namespace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: ~foo() { a; } public: void f() { c + d + e + f; } };", "class bar { private: ~bar() { a; } public: void f() { c + d + e + f; } };"); + runner.RunDispatcher({{"class foo { public: ~foo() { a; } public: void f() { c + d + e + f; } };", "class bar { private: ~bar() { a; } public: void f() { c + d + e + f; } };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1995,7 +1995,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_replace_with_namespace) { BOOST_AUTO_TEST_CASE(class_destructors_replace_with_convert_namespace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: ~foo() {} void f(int c, double d, long e, float f) { c + d + e + f; } };", "class bar { private: ~bar() { delete a; } void f(int c, double d, long e, float f) { c + d + e + f; } };"); + runner.RunDispatcher({{"class foo { public: ~foo() {} void f(int c, double d, long e, float f) { c + d + e + f; } };", "class bar { private: ~bar() { delete a; } void f(int c, double d, long e, float f) { c + d + e + f; } };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2033,7 +2033,7 @@ BOOST_AUTO_TEST_CASE(class_destructors_replace_with_convert_namespace) { BOOST_AUTO_TEST_CASE(class_operators_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { bool operator==() {} };", "class foo { bool operator==() {} };"); + runner.RunDispatcher({{"class foo { bool operator==() {} };", "class foo { bool operator==() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2069,7 +2069,7 @@ BOOST_AUTO_TEST_CASE(class_operators_common) { BOOST_AUTO_TEST_CASE(class_operators_private) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: bool operator==() {} };", "class foo { private: bool operator==() {} };"); + runner.RunDispatcher({{"class foo { private: bool operator==() {} };", "class foo { private: bool operator==() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2105,7 +2105,7 @@ BOOST_AUTO_TEST_CASE(class_operators_private) { BOOST_AUTO_TEST_CASE(class_operators_private_default) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { bool operator==() {} };", "class foo { private: bool operator==() {} };"); + runner.RunDispatcher({{"class foo { bool operator==() {} };", "class foo { private: bool operator==() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2141,7 +2141,7 @@ BOOST_AUTO_TEST_CASE(class_operators_private_default) { BOOST_AUTO_TEST_CASE(class_operators_public) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: bool operator==() {} };", "class foo { public: bool operator==() {} };"); + runner.RunDispatcher({{"class foo { public: bool operator==() {} };", "class foo { public: bool operator==() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2177,7 +2177,7 @@ BOOST_AUTO_TEST_CASE(class_operators_public) { BOOST_AUTO_TEST_CASE(class_operators_protected) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { protected: bool operator==() {} };", "class foo { protected: bool operator==() {} };"); + runner.RunDispatcher({{"class foo { protected: bool operator==() {} };", "class foo { protected: bool operator==() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2213,7 +2213,7 @@ BOOST_AUTO_TEST_CASE(class_operators_protected) { BOOST_AUTO_TEST_CASE(class_operators_access_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: bool operator==() {} };", "class foo { protected: bool operator==() {} };"); + runner.RunDispatcher({{"class foo { private: bool operator==() {} };", "class foo { protected: bool operator==() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2250,7 +2250,7 @@ BOOST_AUTO_TEST_CASE(class_operators_access_change) { BOOST_AUTO_TEST_CASE(class_operators_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: };", "class foo { private: bool operator==() {} };"); + runner.RunDispatcher({{"class foo { private: };", "class foo { private: bool operator==() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2286,7 +2286,7 @@ BOOST_AUTO_TEST_CASE(class_operators_insert) { BOOST_AUTO_TEST_CASE(class_operators_insert_with_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: };", "class foo { private: bool operator==() {} };"); + runner.RunDispatcher({{"class foo { public: };", "class foo { private: bool operator==() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2322,7 +2322,7 @@ BOOST_AUTO_TEST_CASE(class_operators_insert_with_access) { BOOST_AUTO_TEST_CASE(class_operators_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: bool operator==() {} };", "class foo { private: };"); + runner.RunDispatcher({{"class foo { private: bool operator==() {} };", "class foo { private: };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2358,7 +2358,7 @@ BOOST_AUTO_TEST_CASE(class_operators_delete) { BOOST_AUTO_TEST_CASE(class_operators_delete_with_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: bool operator==() {} };", "class foo { private: };"); + runner.RunDispatcher({{"class foo { public: bool operator==() {} };", "class foo { private: };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2394,7 +2394,7 @@ BOOST_AUTO_TEST_CASE(class_operators_delete_with_access) { BOOST_AUTO_TEST_CASE(class_operators_replace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: bool operator==(int b) { return std::max(b - a, 0); } };", "class foo { private: bool operator!=(const object& that) { return *this != that; } };"); + runner.RunDispatcher({{"class foo { private: bool operator==(int b) { return std::max(b - a, 0); } };", "class foo { private: bool operator!=(const object& that) { return *this != that; } };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2435,7 +2435,7 @@ BOOST_AUTO_TEST_CASE(class_operators_replace) { BOOST_AUTO_TEST_CASE(class_operators_replace_with_namespace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: bool operator==(int b) { return std::max(b - a, 0); } };", "class foo { private: bool operator!=(const object& that) { return *this != that; } };"); + runner.RunDispatcher({{"class foo { public: bool operator==(int b) { return std::max(b - a, 0); } };", "class foo { private: bool operator!=(const object& that) { return *this != that; } };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2477,7 +2477,7 @@ BOOST_AUTO_TEST_CASE(class_operators_replace_with_namespace) { BOOST_AUTO_TEST_CASE(class_methods_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { void f() {} };", "class foo { void f() {} };"); + runner.RunDispatcher({{"class foo { void f() {} };", "class foo { void f() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2513,7 +2513,7 @@ BOOST_AUTO_TEST_CASE(class_methods_common) { BOOST_AUTO_TEST_CASE(class_methods_private) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: void f() {} };", "class foo { private: void f() {} };"); + runner.RunDispatcher({{"class foo { private: void f() {} };", "class foo { private: void f() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2549,7 +2549,7 @@ BOOST_AUTO_TEST_CASE(class_methods_private) { BOOST_AUTO_TEST_CASE(class_methods_private_default) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { void f() {} };", "class foo { private: void f() {} };"); + runner.RunDispatcher({{"class foo { void f() {} };", "class foo { private: void f() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2585,7 +2585,7 @@ BOOST_AUTO_TEST_CASE(class_methods_private_default) { BOOST_AUTO_TEST_CASE(class_methods_public) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: void f() {} };", "class foo { public: void f() {} };"); + runner.RunDispatcher({{"class foo { public: void f() {} };", "class foo { public: void f() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2621,7 +2621,7 @@ BOOST_AUTO_TEST_CASE(class_methods_public) { BOOST_AUTO_TEST_CASE(class_methods_protected) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { protected: void f() {} };", "class foo { protected: void f() {} };"); + runner.RunDispatcher({{"class foo { protected: void f() {} };", "class foo { protected: void f() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2657,7 +2657,7 @@ BOOST_AUTO_TEST_CASE(class_methods_protected) { BOOST_AUTO_TEST_CASE(class_methods_access_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: void f() {} };", "class foo { protected: void f() {} };"); + runner.RunDispatcher({{"class foo { private: void f() {} };", "class foo { protected: void f() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2694,7 +2694,7 @@ BOOST_AUTO_TEST_CASE(class_methods_access_change) { BOOST_AUTO_TEST_CASE(class_methods_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: };", "class foo { private: void f() {} };"); + runner.RunDispatcher({{"class foo { private: };", "class foo { private: void f() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2730,7 +2730,7 @@ BOOST_AUTO_TEST_CASE(class_methods_insert) { BOOST_AUTO_TEST_CASE(class_methods_insert_with_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: };", "class foo { private: void f() {} };"); + runner.RunDispatcher({{"class foo { public: };", "class foo { private: void f() {} };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2766,7 +2766,7 @@ BOOST_AUTO_TEST_CASE(class_methods_insert_with_access) { BOOST_AUTO_TEST_CASE(class_methods_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: void f() {} };", "class foo { private: };"); + runner.RunDispatcher({{"class foo { private: void f() {} };", "class foo { private: };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2802,7 +2802,7 @@ BOOST_AUTO_TEST_CASE(class_methods_delete) { BOOST_AUTO_TEST_CASE(class_methods_delete_with_access) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: void f() {} };", "class foo { private: };"); + runner.RunDispatcher({{"class foo { public: void f() {} };", "class foo { private: };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2838,7 +2838,7 @@ BOOST_AUTO_TEST_CASE(class_methods_delete_with_access) { BOOST_AUTO_TEST_CASE(class_methods_replace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { private: void f() { a; } };", "class foo { private: int g() { b; } };"); + runner.RunDispatcher({{"class foo { private: void f() { a; } };", "class foo { private: int g() { b; } };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2879,7 +2879,7 @@ BOOST_AUTO_TEST_CASE(class_methods_replace) { BOOST_AUTO_TEST_CASE(class_methods_replace_with_namespace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { public: void f() { a; } };", "class foo { private: int g() { b; } };"); + runner.RunDispatcher({{"class foo { public: void f() { a; } };", "class foo { private: int g() { b; } };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2921,7 +2921,7 @@ BOOST_AUTO_TEST_CASE(class_methods_replace_with_namespace) { BOOST_AUTO_TEST_CASE(class_is_abstract) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { virtual void f() = 0; };", "class foo { virtual void f() = 0; };"); + runner.RunDispatcher({{"class foo { virtual void f() = 0; };", "class foo { virtual void f() = 0; };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2954,7 +2954,7 @@ BOOST_AUTO_TEST_CASE(class_is_abstract) { BOOST_AUTO_TEST_CASE(class_becomes_abstract) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { };", "class foo { virtual void f() = 0; };"); + runner.RunDispatcher({{"class foo { };", "class foo { virtual void f() = 0; };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -2987,7 +2987,7 @@ BOOST_AUTO_TEST_CASE(class_becomes_abstract) { BOOST_AUTO_TEST_CASE(class_was_abstract) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo { virtual void f() = 0; };", "class foo { };"); + runner.RunDispatcher({{"class foo { virtual void f() = 0; };", "class foo { };"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -3021,7 +3021,7 @@ BOOST_AUTO_TEST_CASE(class_was_abstract) { BOOST_AUTO_TEST_CASE(class_is_generic) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template class foo {};", "template class foo {};"); + runner.RunDispatcher({{"template class foo {};", "template class foo {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -3055,7 +3055,7 @@ BOOST_AUTO_TEST_CASE(class_is_generic) { BOOST_AUTO_TEST_CASE(class_becomes_generic) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo {};", "template class foo {};"); + runner.RunDispatcher({{"class foo {};", "template class foo {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -3089,7 +3089,7 @@ BOOST_AUTO_TEST_CASE(class_becomes_generic) { BOOST_AUTO_TEST_CASE(class_was_generic) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template class foo {};", "class foo {};"); + runner.RunDispatcher({{"template class foo {};", "class foo {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); diff --git a/test/suite/testClassConvert.cpp b/test/suite/testClassConvert.cpp index 30623c1..2c5dae7 100644 --- a/test/suite/testClassConvert.cpp +++ b/test/suite/testClassConvert.cpp @@ -24,7 +24,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(class_to_struct) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("class foo {};", "struct foo {};"); + runner.RunDispatcher({{"class foo {};", "struct foo {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE(class_to_struct) { BOOST_AUTO_TEST_CASE(struct_to_class) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("struct foo {};", "class foo {};"); + runner.RunDispatcher({{"struct foo {};", "class foo {};"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 0); diff --git a/test/suite/testCondition.cpp b/test/suite/testCondition.cpp index 548effe..3a33893 100644 --- a/test/suite/testCondition.cpp +++ b/test/suite/testCondition.cpp @@ -25,7 +25,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(decl_condition_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { while(int i = 1) {} }", "void foo() { while(int i = 1) {} }"); + runner.RunDispatcher({{"void foo() { while(int i = 1) {} }", "void foo() { while(int i = 1) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -59,7 +59,7 @@ BOOST_AUTO_TEST_CASE(decl_condition_common) { BOOST_AUTO_TEST_CASE(decl_condition_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { while(int i = 1) {} }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { while(int i = 1) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(decl_condition_insert) { BOOST_AUTO_TEST_CASE(decl_condition_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { while(int i = 1) {} }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { while(int i = 1) {} }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(decl_condition_delete) { BOOST_AUTO_TEST_CASE(decl_condition_replace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { while(int i = 1) {} }", "void foo() { while(double d = 1.0) {} }"); + runner.RunDispatcher({{"void foo() { while(int i = 1) {} }", "void foo() { while(double d = 1.0) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(decl_condition_replace) { BOOST_AUTO_TEST_CASE(decl_condition_modify) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { while(int i = 1) {} }", "void foo() { while(int i = 2) {} }"); + runner.RunDispatcher({{"void foo() { while(int i = 1) {} }", "void foo() { while(int i = 2) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testConditionalConvert.cpp b/test/suite/testConditionalConvert.cpp index 0f887fc..2125054 100644 --- a/test/suite/testConditionalConvert.cpp +++ b/test/suite/testConditionalConvert.cpp @@ -26,7 +26,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(if_to_while) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { while(1) {} }"); + runner.RunDispatcher({{"void foo() { if(1) {} }", "void foo() { while(1) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(if_to_while) { BOOST_AUTO_TEST_CASE(while_to_if) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { while(1) {} }", "void foo() { if(1) {} }"); + runner.RunDispatcher({{"void foo() { while(1) {} }", "void foo() { if(1) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -113,7 +113,7 @@ BOOST_AUTO_TEST_CASE(while_to_if) { BOOST_AUTO_TEST_CASE(while_to_if_with_convert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { while(1) { while(2) {} } }", "void foo() { if(1) { if(2) {} } }"); + runner.RunDispatcher({{"void foo() { while(1) { while(2) {} } }", "void foo() { if(1) { if(2) {} } }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(while_to_if_with_convert) { BOOST_AUTO_TEST_CASE(if_to_for) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { if(i < 10) { sum += i; } }", "void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }"); + runner.RunDispatcher({{"void foo() { if(i < 10) { sum += i; } }", "void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(if_to_for) { BOOST_AUTO_TEST_CASE(for_to_if) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }", "void foo() { if(i < 10) { sum += i; } }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }", "void foo() { if(i < 10) { sum += i; } }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -265,7 +265,7 @@ BOOST_AUTO_TEST_CASE(for_to_if) { BOOST_AUTO_TEST_CASE(while_to_for) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { while(i < 10) { sum += i; } }", "void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }"); + runner.RunDispatcher({{"void foo() { while(i < 10) { sum += i; } }", "void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -315,7 +315,7 @@ BOOST_AUTO_TEST_CASE(while_to_for) { BOOST_AUTO_TEST_CASE(for_to_while) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }", "void foo() { while(i < 10) { sum += i; } }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 10; ++i) { sum += i; } }", "void foo() { while(i < 10) { sum += i; } }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testControl.cpp b/test/suite/testControl.cpp index 1909c0f..670097b 100644 --- a/test/suite/testControl.cpp +++ b/test/suite/testControl.cpp @@ -24,7 +24,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_common_control) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; 1; ++i) {} }", "void foo() { for(int i = 0; 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; 1; ++i) {} }", "void foo() { for(int i = 0; 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE(block_common_control) { BOOST_AUTO_TEST_CASE(block_change_control) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 1; i < 2; ++j) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 1; i < 2; ++j) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(block_change_control) { BOOST_AUTO_TEST_CASE(block_expr_init_control_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -150,7 +150,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_common) { BOOST_AUTO_TEST_CASE(block_expr_init_control_minor_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(i = 1; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(i = 1; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_minor_change) { BOOST_AUTO_TEST_CASE(block_expr_init_control_replace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(j = 1; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(j = 1; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_replace) { BOOST_AUTO_TEST_CASE(block_expr_init_control_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -276,7 +276,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_insert) { BOOST_AUTO_TEST_CASE(block_expr_init_control_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -318,7 +318,7 @@ BOOST_AUTO_TEST_CASE(block_expr_init_control_delete) { BOOST_AUTO_TEST_CASE(block_decl_init_control_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -360,7 +360,7 @@ BOOST_AUTO_TEST_CASE(block_decl_init_control_insert) { BOOST_AUTO_TEST_CASE(block_decl_init_control_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -402,7 +402,7 @@ BOOST_AUTO_TEST_CASE(block_decl_init_control_delete) { BOOST_AUTO_TEST_CASE(block_init_control_decl_to_expr) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -446,7 +446,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_decl_to_expr) { BOOST_AUTO_TEST_CASE(block_init_control_expr_to_decl) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -490,7 +490,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_expr_to_decl) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -534,7 +534,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int j = 1; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(int j = 1; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -578,7 +578,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_front) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -622,7 +622,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_back) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_middle) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0, k = 2; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1, k = 2; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0, k = 2; i < 1; ++i) {} }", "void foo() { for(int i = 0, j = 1, k = 2; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -668,7 +668,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_insert_middle) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(int j = 1; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(int j = 1; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -712,7 +712,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_front) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -757,7 +757,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_back) { BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_middle) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0, j = 1, k = 2; i < 1; ++i) {} }", "void foo() { for(int i = 0, k = 2; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0, j = 1, k = 2; i < 1; ++i) {} }", "void foo() { for(int i = 0, k = 2; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -804,7 +804,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_decl_delete_middle) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -848,7 +848,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(j = 1; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(j = 1; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -892,7 +892,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_front) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(i = 0; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -936,7 +936,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_back) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_middle) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(i = 0, k = 2; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1, k = 2; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(i = 0, k = 2; i < 1; ++i) {} }", "void foo() { for(i = 0, j = 1, k = 2; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -982,7 +982,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_insert_middle) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(j = 1; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(j = 1; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1026,7 +1026,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_front) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(i = 0, j = 1; i < 1; ++i) {} }", "void foo() { for(i = 0; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1070,7 +1070,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_back) { BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_middle) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(i = 0, j = 1, k = 2; i < 1; ++i) {} }", "void foo() { for(i = 0, k = 2; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(i = 0, j = 1, k = 2; i < 1; ++i) {} }", "void foo() { for(i = 0, k = 2; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1117,7 +1117,7 @@ BOOST_AUTO_TEST_CASE(block_init_control_multi_expr_delete_middle) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, --j) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 1; ++i, --j) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1161,7 +1161,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 1; --j) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 1; --j) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1205,7 +1205,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_front) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 1; ++i) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1249,7 +1249,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_back) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_middle) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, k /= 2) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j, k /= 2) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 1; ++i, k /= 2) {} }", "void foo() { for(int i = 0; i < 1; ++i, --j, k /= 2) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1295,7 +1295,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_insert_middle) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, --j) {} }", "void foo() { for(int i = 0; i < 1; --j) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 1; ++i, --j) {} }", "void foo() { for(int i = 0; i < 1; --j) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1339,7 +1339,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_front) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, --j) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 1; ++i, --j) {} }", "void foo() { for(int i = 0; i < 1; ++i) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1383,7 +1383,7 @@ BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_back) { BOOST_AUTO_TEST_CASE(block_incr_control_multi_expr_delete_middle) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(int i = 0; i < 1; ++i, --j, k /= 2) {} }", "void foo() { for(int i = 0; i < 1; ++i, k /= 2) {} }"); + runner.RunDispatcher({{"void foo() { for(int i = 0; i < 1; ++i, --j, k /= 2) {} }", "void foo() { for(int i = 0; i < 1; ++i, k /= 2) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testDecl.cpp b/test/suite/testDecl.cpp index f4998aa..00744bd 100644 --- a/test/suite/testDecl.cpp +++ b/test/suite/testDecl.cpp @@ -24,7 +24,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(decl_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a = 0;", "type a = 0;"); + runner.RunDispatcher({{"type a = 0;", "type a = 0;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(decl_common) { BOOST_AUTO_TEST_CASE(decl_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("", "type a = 0;"); + runner.RunDispatcher({{"", "type a = 0;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(decl_insert) { BOOST_AUTO_TEST_CASE(decl_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a = 0;", ""); + runner.RunDispatcher({{"type a = 0;", ""}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(decl_delete) { BOOST_AUTO_TEST_CASE(name_rename) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a = 0;", "type b = 0;"); + runner.RunDispatcher({{"type a = 0;", "type b = 0;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -161,7 +161,7 @@ BOOST_AUTO_TEST_CASE(name_rename) { BOOST_AUTO_TEST_CASE(type_rename) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("foo a;", "bar a;"); + runner.RunDispatcher({{"foo a;", "bar a;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(type_rename) { BOOST_AUTO_TEST_CASE(type_rename_two) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("foo a;", "foo* a;"); + runner.RunDispatcher({{"foo a;", "foo* a;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -227,7 +227,7 @@ BOOST_AUTO_TEST_CASE(type_rename_two) { BOOST_AUTO_TEST_CASE(decl_init_literal_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a = 0;", "type a = 1;"); + runner.RunDispatcher({{"type a = 0;", "type a = 1;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -268,7 +268,7 @@ BOOST_AUTO_TEST_CASE(decl_init_literal_change) { BOOST_AUTO_TEST_CASE(init_literal_change_2) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a(0);", "type a = 1;"); + runner.RunDispatcher({{"type a(0);", "type a = 1;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -312,7 +312,7 @@ BOOST_AUTO_TEST_CASE(init_literal_change_2) { BOOST_AUTO_TEST_CASE(init_literal_change_3) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a{0};", "type a = 1;"); + runner.RunDispatcher({{"type a{0};", "type a = 1;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -356,7 +356,7 @@ BOOST_AUTO_TEST_CASE(init_literal_change_3) { BOOST_AUTO_TEST_CASE(name_only_match) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type* a(0);", "typePtr a = 1;"); + runner.RunDispatcher({{"type* a(0);", "typePtr a = 1;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -404,7 +404,7 @@ BOOST_AUTO_TEST_CASE(name_only_match) { BOOST_AUTO_TEST_CASE(comma_separated_decl) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a = 0, b = 1, c = 2;", "type a = 0, c = 2, d = 3;"); + runner.RunDispatcher({{"type a = 0, b = 1, c = 2;", "type a = 0, c = 2, d = 3;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -499,7 +499,7 @@ BOOST_AUTO_TEST_CASE(comma_separated_decl) { BOOST_AUTO_TEST_CASE(decl_compound_name_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("std::string str = \"\";", "std::string str = \"\";"); + runner.RunDispatcher({{"std::string str = \"\";", "std::string str = \"\";"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -575,7 +575,7 @@ BOOST_AUTO_TEST_CASE(decl_compound_name_common) { BOOST_AUTO_TEST_CASE(decl_compound_name_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("std::string str = \"\";", "std::wstring str = \"\";"); + runner.RunDispatcher({{"std::string str = \"\";", "std::wstring str = \"\";"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -651,7 +651,7 @@ BOOST_AUTO_TEST_CASE(decl_compound_name_change) { BOOST_AUTO_TEST_CASE(decl_simple_to_complex_name) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("string str = \"\";", "std::string str = \"\";"); + runner.RunDispatcher({{"string str = \"\";", "std::string str = \"\";"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -728,7 +728,7 @@ BOOST_AUTO_TEST_CASE(decl_simple_to_complex_name) { BOOST_AUTO_TEST_CASE(decl_add_specifier) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a = 0;", "const type a = 0;"); + runner.RunDispatcher({{"type a = 0;", "const type a = 0;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -771,7 +771,7 @@ BOOST_AUTO_TEST_CASE(decl_add_specifier) { BOOST_AUTO_TEST_CASE(decl_remove_specifier) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("const type a = 0;", "type a = 0;"); + runner.RunDispatcher({{"const type a = 0;", "type a = 0;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -814,7 +814,7 @@ BOOST_AUTO_TEST_CASE(decl_remove_specifier) { BOOST_AUTO_TEST_CASE(decl_change_specifier) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("static type a = 0;", "const type a = 0;"); + runner.RunDispatcher({{"static type a = 0;", "const type a = 0;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -862,7 +862,7 @@ BOOST_AUTO_TEST_CASE(decl_change_specifier) { BOOST_AUTO_TEST_CASE(decl_modifier_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type* a;", "type& a;"); + runner.RunDispatcher({{"type* a;", "type& a;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -898,7 +898,7 @@ BOOST_AUTO_TEST_CASE(decl_modifier_change) { BOOST_AUTO_TEST_CASE(decl_template_argument_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a;", "type a;"); + runner.RunDispatcher({{"type a;", "type a;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -945,7 +945,7 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_common) { BOOST_AUTO_TEST_CASE(decl_template_argument_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a;", "type a;"); + runner.RunDispatcher({{"type a;", "type a;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -992,7 +992,7 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_insert) { BOOST_AUTO_TEST_CASE(decl_template_argument_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a;", "type a;"); + runner.RunDispatcher({{"type a;", "type a;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1039,7 +1039,7 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_delete) { BOOST_AUTO_TEST_CASE(decl_template_argument_insert_arg) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a;", "type a;"); + runner.RunDispatcher({{"type a;", "type a;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1088,7 +1088,7 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_insert_arg) { BOOST_AUTO_TEST_CASE(decl_template_argument_delete_arg) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a;", "type a;"); + runner.RunDispatcher({{"type a;", "type a;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1137,7 +1137,7 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_delete_arg) { BOOST_AUTO_TEST_CASE(decl_template_argument_change_arg) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("type a;", "type a;"); + runner.RunDispatcher({{"type a;", "type a;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); @@ -1207,7 +1207,7 @@ BOOST_AUTO_TEST_CASE(decl_template_argument_change_arg) { BOOST_AUTO_TEST_CASE(decl_template_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template type a = 0;", "template type a = 0;"); + runner.RunDispatcher({{"template type a = 0;", "template type a = 0;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 1); BOOST_TEST(runner.GetFunctionInfo().size() == 0); diff --git a/test/suite/testDeclStmt.cpp b/test/suite/testDeclStmt.cpp index e5e8331..8c3cc94 100644 --- a/test/suite/testDeclStmt.cpp +++ b/test/suite/testDeclStmt.cpp @@ -22,7 +22,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_common_decl_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { int i; }", "void foo() { int i; }"); + runner.RunDispatcher({{"void foo() { int i; }", "void foo() { int i; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(block_common_decl_stmt) { BOOST_AUTO_TEST_CASE(block_insert_decl_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { foo bar; }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { foo bar; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(block_insert_decl_stmt) { BOOST_AUTO_TEST_CASE(block_delete_decl_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { foo bar; }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { foo bar; }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(block_delete_decl_stmt) { BOOST_AUTO_TEST_CASE(block_replace_decl_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { foo f; }", "void foo() { bar b; }"); + runner.RunDispatcher({{"void foo() { foo f; }", "void foo() { bar b; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testDo.cpp b/test/suite/testDo.cpp index 93ddcc0..5601dd4 100644 --- a/test/suite/testDo.cpp +++ b/test/suite/testDo.cpp @@ -24,7 +24,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_change_common_do) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { do {} while(1); }", "void foo() { do {} while(1); }"); + runner.RunDispatcher({{"void foo() { do {} while(1); }", "void foo() { do {} while(1); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_do) { BOOST_AUTO_TEST_CASE(block_insert_do) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { do {} while(1);"); + runner.RunDispatcher({{"void foo() {}", "void foo() { do {} while(1);"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(block_insert_do) { BOOST_AUTO_TEST_CASE(block_delete_do) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { do {} while(1);", "void foo() {}"); + runner.RunDispatcher({{"void foo() { do {} while(1);", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(block_delete_do) { BOOST_AUTO_TEST_CASE(block_replace_do) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { do { a; } while(1); }", "void foo() { do { b; } while(2); }"); + runner.RunDispatcher({{"void foo() { do { a; } while(1); }", "void foo() { do { b; } while(2); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testExprConvert.cpp b/test/suite/testExprConvert.cpp index c3cafc3..fb51bd8 100644 --- a/test/suite/testExprConvert.cpp +++ b/test/suite/testExprConvert.cpp @@ -26,7 +26,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(decl_to_expr) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { int i = 0; }", "void foo() { 0; }"); + runner.RunDispatcher({{"void foo() { int i = 0; }", "void foo() { 0; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE(decl_to_expr) { BOOST_AUTO_TEST_CASE(expr_to_decl) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { 0; }", "void foo() { int i = 0; }"); + runner.RunDispatcher({{"void foo() { 0; }", "void foo() { int i = 0; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE(expr_to_decl) { BOOST_AUTO_TEST_CASE(expr_to_return) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { 0; }", "void foo() { return 0; }"); + runner.RunDispatcher({{"void foo() { 0; }", "void foo() { return 0; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(expr_to_return) { BOOST_AUTO_TEST_CASE(return_to_expr) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { return 0; }", "void foo() { 0; }"); + runner.RunDispatcher({{"void foo() { return 0; }", "void foo() { 0; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -184,7 +184,7 @@ BOOST_AUTO_TEST_CASE(return_to_expr) { BOOST_AUTO_TEST_CASE(decl_to_return) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { int i = 0; }", "void foo() { return 0; }"); + runner.RunDispatcher({{"void foo() { int i = 0; }", "void foo() { return 0; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -227,7 +227,7 @@ BOOST_AUTO_TEST_CASE(decl_to_return) { BOOST_AUTO_TEST_CASE(return_to_decl) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { return 0; }", "void foo() { int i = 0; }"); + runner.RunDispatcher({{"void foo() { return 0; }", "void foo() { int i = 0; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testExprStmt.cpp b/test/suite/testExprStmt.cpp index 472e08e..747b2a5 100644 --- a/test/suite/testExprStmt.cpp +++ b/test/suite/testExprStmt.cpp @@ -22,7 +22,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_change_common_expr_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { a; }", "void foo() { a; }"); + runner.RunDispatcher({{"void foo() { a; }", "void foo() { a; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_expr_stmt) { BOOST_AUTO_TEST_CASE(block_insert_expr_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { a; }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { a; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(block_insert_expr_stmt) { BOOST_AUTO_TEST_CASE(block_delete_expr_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { a; }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { a; }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(block_delete_expr_stmt) { BOOST_AUTO_TEST_CASE(block_change_expr_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { a - b; }", "void foo() { a + b; }"); + runner.RunDispatcher({{"void foo() { a - b; }", "void foo() { a + b; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(block_change_expr_stmt) { BOOST_AUTO_TEST_CASE(block_replace_expr_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { a; }", "void foo() { b; }"); + runner.RunDispatcher({{"void foo() { a; }", "void foo() { b; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testFor.cpp b/test/suite/testFor.cpp index 20bb7da..556936a 100644 --- a/test/suite/testFor.cpp +++ b/test/suite/testFor.cpp @@ -25,7 +25,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_common_for) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(; 1; ) {} }", "void foo() { for(; 1; ) {} }"); + runner.RunDispatcher({{"void foo() { for(; 1; ) {} }", "void foo() { for(; 1; ) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(block_common_for) { BOOST_AUTO_TEST_CASE(block_insert_for) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { for(; 1; ) {} }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { for(; 1; ) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE(block_insert_for) { BOOST_AUTO_TEST_CASE(block_delete_for) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { for(; 1; ) {} }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { for(; 1; ) {} }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testFunction.cpp b/test/suite/testFunction.cpp index 1978a6a..f601640 100644 --- a/test/suite/testFunction.cpp +++ b/test/suite/testFunction.cpp @@ -19,22 +19,10 @@ // Define test data namespace data = boost::unit_test; -BOOST_AUTO_TEST_CASE(function_foo) { - - srcDispatch::DispatchRunner runner; - runner.RunDispatcher("#include \n#include \n\nclass Person {\nprivate:\n std::string name_;\n int age_;\n\npublic:\n // Constructor\n Person(const std::string& NAME, int AGE): name_(NAME), age_(AGE) {}\n\n // Getter\n std::string getName() const {\n return name_;\n }\n\n // Setter\n void setName(const std::string& newName) {\n name_ = newName;\n }\n\n // Method\n void sayHello() const {\n std::cout << \"Hi, my name is \" << name_ << \" and I am \" << age_ << \" years old.\n\";\n }\n", "#include \n#include \n\nclass Person {\nprivate:\n std::string name_;\n int age_;\n\npublic:\n // Constructor\n Person(const std::string& NAME, int AGE): name_(NAME), age_(AGE) {}\n\n // Getter\n std::string getName() const {\n return name_;\n }\n\n // Setter\n void setName(const std::string& newName) {\n name_ = newName;\n }\n\n // Method\n void sayHello() const {\n std::cout << \"Hi, my name is \" << name_ << \" and I am \" << age_ << \" years old.\n\";\n }\n"); - - BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); - BOOST_TEST(runner.GetFunctionInfo().size() == 0); - BOOST_TEST(runner.GetClassInfo().size() == 1); - - std::cerr << "HERE: " << __FILE__ << ' ' << __FUNCTION__ << ' ' << __LINE__ << ' ' << runner.GetClassInfo().at(0)->constructors.at(0) << '\n'; -} - BOOST_AUTO_TEST_CASE(function_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() {}"); + runner.RunDispatcher({{"void foo() {}", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -75,7 +63,7 @@ BOOST_AUTO_TEST_CASE(function_common) { BOOST_AUTO_TEST_CASE(function_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("", "void foo() {}"); + runner.RunDispatcher({{"", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -116,7 +104,7 @@ BOOST_AUTO_TEST_CASE(function_insert) { BOOST_AUTO_TEST_CASE(function_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", ""); + runner.RunDispatcher({{"void foo() {}", ""}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -157,7 +145,7 @@ BOOST_AUTO_TEST_CASE(function_delete) { BOOST_AUTO_TEST_CASE(function_name_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void bar() {}"); + runner.RunDispatcher({{"void foo() {}", "void bar() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -199,7 +187,7 @@ BOOST_AUTO_TEST_CASE(function_name_change) { BOOST_AUTO_TEST_CASE(function_return_type_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "int foo() {}"); + runner.RunDispatcher({{"void foo() {}", "int foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -241,7 +229,7 @@ BOOST_AUTO_TEST_CASE(function_return_type_change) { BOOST_AUTO_TEST_CASE(function_add_parameter) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo(int i) {}"); + runner.RunDispatcher({{"void foo() {}", "void foo(int i) {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -291,7 +279,7 @@ BOOST_AUTO_TEST_CASE(function_add_parameter) { BOOST_AUTO_TEST_CASE(function_remove_parameter) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo(double d) {}", "void foo() {}"); + runner.RunDispatcher({{"void foo(double d) {}", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -340,7 +328,7 @@ BOOST_AUTO_TEST_CASE(function_remove_parameter) { BOOST_AUTO_TEST_CASE(function_parameter_type_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo(double d) {}", "void foo(int d) {}"); + runner.RunDispatcher({{"void foo(double d) {}", "void foo(int d) {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -388,7 +376,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_type_change) { BOOST_AUTO_TEST_CASE(function_parameter_name_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo(double d) {}", "void foo(double num) {}"); + runner.RunDispatcher({{"void foo(double d) {}", "void foo(double num) {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -437,7 +425,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_name_change) { BOOST_AUTO_TEST_CASE(function_parameter_multi_change) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo(int i, double d) {}", "void foo(double d, long l) {}"); + runner.RunDispatcher({{"void foo(int i, double d) {}", "void foo(double d, long l) {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -505,7 +493,7 @@ BOOST_AUTO_TEST_CASE(function_parameter_multi_change) { BOOST_AUTO_TEST_CASE(function_decl_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo();", "void foo();"); + runner.RunDispatcher({{"void foo();", "void foo();"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -546,7 +534,7 @@ BOOST_AUTO_TEST_CASE(function_decl_common) { BOOST_AUTO_TEST_CASE(function_specifier_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo();", "void foo() const;"); + runner.RunDispatcher({{"void foo();", "void foo() const;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -589,7 +577,7 @@ BOOST_AUTO_TEST_CASE(function_specifier_insert) { BOOST_AUTO_TEST_CASE(function_specifier_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() const;", "void foo();"); + runner.RunDispatcher({{"void foo() const;", "void foo();"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -632,7 +620,7 @@ BOOST_AUTO_TEST_CASE(function_specifier_delete) { BOOST_AUTO_TEST_CASE(function_pure_virtual_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo();", "void foo() = 0;"); + runner.RunDispatcher({{"void foo();", "void foo() = 0;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -676,7 +664,7 @@ BOOST_AUTO_TEST_CASE(function_pure_virtual_insert) { BOOST_AUTO_TEST_CASE(function_pure_virtual_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() = 0;", "void foo();"); + runner.RunDispatcher({{"void foo() = 0;", "void foo();"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -721,7 +709,7 @@ BOOST_AUTO_TEST_CASE(function_pure_virtual_delete) { BOOST_AUTO_TEST_CASE(function_pure_delete_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo();", "void foo() = delete;"); + runner.RunDispatcher({{"void foo();", "void foo() = delete;"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -764,7 +752,7 @@ BOOST_AUTO_TEST_CASE(function_pure_delete_insert) { BOOST_AUTO_TEST_CASE(function_pure_delete_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() = delete;", "void foo();"); + runner.RunDispatcher({{"void foo() = delete;", "void foo();"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -807,7 +795,7 @@ BOOST_AUTO_TEST_CASE(function_pure_delete_delete) { BOOST_AUTO_TEST_CASE(function_block_insert_expr_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { a; }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { a; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -866,7 +854,7 @@ BOOST_AUTO_TEST_CASE(function_block_insert_expr_stmt) { BOOST_AUTO_TEST_CASE(function_operator_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("bool operator==() {}", "bool operator==() {}"); + runner.RunDispatcher({{"bool operator==() {}", "bool operator==() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -907,7 +895,7 @@ BOOST_AUTO_TEST_CASE(function_operator_common) { BOOST_AUTO_TEST_CASE(function_operator_common_decl) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("bool operator==();", "bool operator==();"); + runner.RunDispatcher({{"bool operator==();", "bool operator==();"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -946,7 +934,7 @@ BOOST_AUTO_TEST_CASE(function_operator_common_decl) { BOOST_AUTO_TEST_CASE(function_operator_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("", "bool operator==() {}"); + runner.RunDispatcher({{"", "bool operator==() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -987,7 +975,7 @@ BOOST_AUTO_TEST_CASE(function_operator_insert) { BOOST_AUTO_TEST_CASE(function_operator_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("bool operator==() {}", ""); + runner.RunDispatcher({{"bool operator==() {}", ""}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1028,7 +1016,7 @@ BOOST_AUTO_TEST_CASE(function_operator_delete) { BOOST_AUTO_TEST_CASE(function_operator_type) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("operator bool() {}", "operator bool() {}"); + runner.RunDispatcher({{"operator bool() {}", "operator bool() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1065,7 +1053,7 @@ BOOST_AUTO_TEST_CASE(function_operator_type) { BOOST_AUTO_TEST_CASE(function_template_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + runner.RunDispatcher({{"template void foo() {}", "template void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1108,7 +1096,7 @@ BOOST_AUTO_TEST_CASE(function_template_common) { BOOST_AUTO_TEST_CASE(function_template_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "template void foo() {}"); + runner.RunDispatcher({{"void foo() {}", "template void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -1151,7 +1139,7 @@ BOOST_AUTO_TEST_CASE(function_template_insert) { BOOST_AUTO_TEST_CASE(function_template_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void foo() {}", "void foo() {}"); + runner.RunDispatcher({{"template void foo() {}", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testGoto.cpp b/test/suite/testGoto.cpp index 45981b6..4398115 100644 --- a/test/suite/testGoto.cpp +++ b/test/suite/testGoto.cpp @@ -25,7 +25,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_change_common_break) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { break; }", "void foo() { break; }"); + runner.RunDispatcher({{"void foo() { break; }", "void foo() { break; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_break) { BOOST_AUTO_TEST_CASE(block_change_insert_break) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { break; }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { break; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(block_change_insert_break) { BOOST_AUTO_TEST_CASE(block_change_delete_break) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { break; }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { break; }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(block_change_delete_break) { BOOST_AUTO_TEST_CASE(block_change_common_continue) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { continue; }", "void foo() { continue; }"); + runner.RunDispatcher({{"void foo() { continue; }", "void foo() { continue; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_continue) { BOOST_AUTO_TEST_CASE(block_change_insert_continue) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { continue; }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { continue; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE(block_change_insert_continue) { BOOST_AUTO_TEST_CASE(block_change_delete_continue) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { continue; }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { continue; }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -187,7 +187,7 @@ BOOST_AUTO_TEST_CASE(block_change_delete_continue) { BOOST_AUTO_TEST_CASE(block_change_common_goto) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { goto; }", "void foo() { goto; }"); + runner.RunDispatcher({{"void foo() { goto; }", "void foo() { goto; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -214,7 +214,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_goto) { BOOST_AUTO_TEST_CASE(block_change_insert_goto) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { goto; }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { goto; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -241,7 +241,7 @@ BOOST_AUTO_TEST_CASE(block_change_insert_goto) { BOOST_AUTO_TEST_CASE(block_change_delete_goto) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { goto; }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { goto; }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -268,7 +268,7 @@ BOOST_AUTO_TEST_CASE(block_change_delete_goto) { BOOST_AUTO_TEST_CASE(block_change_common_label_goto) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { goto foo; }", "void foo() { goto foo; }"); + runner.RunDispatcher({{"void foo() { goto foo; }", "void foo() { goto foo; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -296,7 +296,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_label_goto) { BOOST_AUTO_TEST_CASE(block_change_rename_label_goto) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { goto foo; }", "void foo() { goto bar; }"); + runner.RunDispatcher({{"void foo() { goto foo; }", "void foo() { goto bar; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testIfStmt.cpp b/test/suite/testIfStmt.cpp index 771cd93..cde6a29 100644 --- a/test/suite/testIfStmt.cpp +++ b/test/suite/testIfStmt.cpp @@ -27,7 +27,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_change_common_if_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { if(1) {} }"); + runner.RunDispatcher({{"void foo() { if(1) {} }", "void foo() { if(1) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -50,7 +50,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_if_stmt) { BOOST_AUTO_TEST_CASE(block_insert_if_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { if(1) {} }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { if(1) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(block_insert_if_stmt) { BOOST_AUTO_TEST_CASE(block_delete_if_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { if(1) {} }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { if(1) {} }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -108,7 +108,7 @@ BOOST_AUTO_TEST_CASE(block_delete_if_stmt) { BOOST_AUTO_TEST_CASE(block_change_condition_if_stmt) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { if(2) {} }"); + runner.RunDispatcher({{"void foo() { if(1) {} }", "void foo() { if(2) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE(block_change_condition_if_stmt) { BOOST_AUTO_TEST_CASE(block_common_elseif) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { if(1) {} else if(2) {} }", "void foo() { if(1) {} else if(2) {} }"); + runner.RunDispatcher({{"void foo() { if(1) {} else if(2) {} }", "void foo() { if(1) {} else if(2) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -172,7 +172,7 @@ BOOST_AUTO_TEST_CASE(block_common_elseif) { BOOST_AUTO_TEST_CASE(block_insert_elseif_whole) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { if(1) {} else if(2) {} }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { if(1) {} else if(2) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(block_insert_elseif_whole) { BOOST_AUTO_TEST_CASE(block_delete_elseif_whole) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {if(1) {} else if(2) {} }", "void foo() { }"); + runner.RunDispatcher({{"void foo() {if(1) {} else if(2) {} }", "void foo() { }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(block_delete_elseif_whole) { BOOST_AUTO_TEST_CASE(block_insert_elseif) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { if(1) {} else if(2) {} }"); + runner.RunDispatcher({{"void foo() { if(1) {} }", "void foo() { if(1) {} else if(2) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE(block_insert_elseif) { BOOST_AUTO_TEST_CASE(block_delete_elseif) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { if(1) {} else if(2) {} }", "void foo() { if(1) {} }"); + runner.RunDispatcher({{"void foo() { if(1) {} else if(2) {} }", "void foo() { if(1) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -312,7 +312,7 @@ BOOST_AUTO_TEST_CASE(block_delete_elseif) { BOOST_AUTO_TEST_CASE(block_common_else) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { if(1) {} else {} }", "void foo() { if(1) {} else {} }"); + runner.RunDispatcher({{"void foo() { if(1) {} else {} }", "void foo() { if(1) {} else {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -345,7 +345,7 @@ BOOST_AUTO_TEST_CASE(block_common_else) { BOOST_AUTO_TEST_CASE(block_insert_else_whole) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { if(1) {} else {} }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { if(1) {} else {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -378,7 +378,7 @@ BOOST_AUTO_TEST_CASE(block_insert_else_whole) { BOOST_AUTO_TEST_CASE(block_delete_else_whole) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {if(1) {} else {} }", "void foo() { }"); + runner.RunDispatcher({{"void foo() {if(1) {} else {} }", "void foo() { }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -412,7 +412,7 @@ BOOST_AUTO_TEST_CASE(block_delete_else_whole) { BOOST_AUTO_TEST_CASE(block_insert_else) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { if(1) {} }", "void foo() { if(1) {} else {} }"); + runner.RunDispatcher({{"void foo() { if(1) {} }", "void foo() { if(1) {} else {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -446,7 +446,7 @@ BOOST_AUTO_TEST_CASE(block_insert_else) { BOOST_AUTO_TEST_CASE(block_delete_else) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { if(1) {} else {} }", "void foo() { if(1) {} }"); + runner.RunDispatcher({{"void foo() { if(1) {} else {} }", "void foo() { if(1) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testLabel.cpp b/test/suite/testLabel.cpp index 1b0b614..2463b4d 100644 --- a/test/suite/testLabel.cpp +++ b/test/suite/testLabel.cpp @@ -22,7 +22,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_common_label) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { label: }", "void foo() { label: }"); + runner.RunDispatcher({{"void foo() { label: }", "void foo() { label: }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -46,7 +46,7 @@ BOOST_AUTO_TEST_CASE(block_common_label) { BOOST_AUTO_TEST_CASE(block_insert_label) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { label: }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { label: }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(block_insert_label) { BOOST_AUTO_TEST_CASE(block_delete_label) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { label: }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { label: }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE(block_delete_label) { BOOST_AUTO_TEST_CASE(block_replace_label) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { foo: }", "void foo() { bar: }"); + runner.RunDispatcher({{"void foo() { foo: }", "void foo() { bar: }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testReturn.cpp b/test/suite/testReturn.cpp index 3247891..c154dbb 100644 --- a/test/suite/testReturn.cpp +++ b/test/suite/testReturn.cpp @@ -22,7 +22,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_change_common_return) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { return 0; }", "void foo() { return 0; }"); + runner.RunDispatcher({{"void foo() { return 0; }", "void foo() { return 0; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_return) { BOOST_AUTO_TEST_CASE(block_insert_return) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { return a; }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { return a; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(block_insert_return) { BOOST_AUTO_TEST_CASE(block_delete_return) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { return a; }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { return a; }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(block_delete_return) { BOOST_AUTO_TEST_CASE(block_change_return) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { return a - b; }", "void foo() { return a + b; }"); + runner.RunDispatcher({{"void foo() { return a - b; }", "void foo() { return a + b; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(block_change_return) { BOOST_AUTO_TEST_CASE(block_change_return_expr) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { return a; }", "void foo() { return b; }"); + runner.RunDispatcher({{"void foo() { return a; }", "void foo() { return b; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -174,7 +174,7 @@ BOOST_AUTO_TEST_CASE(block_change_return_expr) { BOOST_AUTO_TEST_CASE(block_change_whole_return) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { return 0; }", "void foo() { return a; }"); + runner.RunDispatcher({{"void foo() { return 0; }", "void foo() { return a; }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testSwitch.cpp b/test/suite/testSwitch.cpp index acc294b..267492d 100644 --- a/test/suite/testSwitch.cpp +++ b/test/suite/testSwitch.cpp @@ -25,7 +25,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_change_common_switch) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { switch(1) {} }", "void foo() { switch(1) {} }"); + runner.RunDispatcher({{"void foo() { switch(1) {} }", "void foo() { switch(1) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_switch) { BOOST_AUTO_TEST_CASE(block_insert_switch) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { switch(1) {}"); + runner.RunDispatcher({{"void foo() {}", "void foo() { switch(1) {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(block_insert_switch) { BOOST_AUTO_TEST_CASE(block_delete_switch) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { switch(1) {}", "void foo() {}"); + runner.RunDispatcher({{"void foo() { switch(1) {}", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(block_delete_switch) { BOOST_AUTO_TEST_CASE(block_replace_switch) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { switch(1) { default: a; } }", "void foo() { switch(2) { default: b; } }"); + runner.RunDispatcher({{"void foo() { switch(1) { default: a; } }", "void foo() { switch(2) { default: b; } }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testTemplate.cpp b/test/suite/testTemplate.cpp index 0094026..b1c5bae 100644 --- a/test/suite/testTemplate.cpp +++ b/test/suite/testTemplate.cpp @@ -22,7 +22,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(template_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + runner.RunDispatcher({{"template void foo() {}", "template void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(template_common) { BOOST_AUTO_TEST_CASE(template_insert_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void func() {}", "template template void func() {}"); + runner.RunDispatcher({{"template void func() {}", "template template void func() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(template_insert_front) { BOOST_AUTO_TEST_CASE(template_insert_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void func() {}", "template template void func() {}"); + runner.RunDispatcher({{"template void func() {}", "template template void func() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -87,7 +87,7 @@ BOOST_AUTO_TEST_CASE(template_insert_back) { BOOST_AUTO_TEST_CASE(template_delete_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template template void func() {}", "template void func() {}"); + runner.RunDispatcher({{"template template void func() {}", "template void func() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -110,7 +110,7 @@ BOOST_AUTO_TEST_CASE(template_delete_front) { BOOST_AUTO_TEST_CASE(template_delete_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template template void func() {}", "template void func() {}"); + runner.RunDispatcher({{"template template void func() {}", "template void func() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -133,7 +133,7 @@ BOOST_AUTO_TEST_CASE(template_delete_back) { BOOST_AUTO_TEST_CASE(template_insert_parameter_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + runner.RunDispatcher({{"template void foo() {}", "template void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE(template_insert_parameter_front) { BOOST_AUTO_TEST_CASE(template_insert_parameter_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + runner.RunDispatcher({{"template void foo() {}", "template void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -177,7 +177,7 @@ BOOST_AUTO_TEST_CASE(template_insert_parameter_back) { BOOST_AUTO_TEST_CASE(template_delete_parameter_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + runner.RunDispatcher({{"template void foo() {}", "template void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -199,7 +199,7 @@ BOOST_AUTO_TEST_CASE(template_delete_parameter_front) { BOOST_AUTO_TEST_CASE(template_delete_parameter_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + runner.RunDispatcher({{"template void foo() {}", "template void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(template_delete_parameter_back) { BOOST_AUTO_TEST_CASE(template_modify_parameter_type) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + runner.RunDispatcher({{"template void foo() {}", "template void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -247,7 +247,7 @@ BOOST_AUTO_TEST_CASE(template_modify_parameter_type) { BOOST_AUTO_TEST_CASE(template_modify_parameter_name) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + runner.RunDispatcher({{"template void foo() {}", "template void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -273,7 +273,7 @@ BOOST_AUTO_TEST_CASE(template_modify_parameter_name) { BOOST_AUTO_TEST_CASE(template_modify_parameter_init) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + runner.RunDispatcher({{"template void foo() {}", "template void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -299,7 +299,7 @@ BOOST_AUTO_TEST_CASE(template_modify_parameter_init) { BOOST_AUTO_TEST_CASE(template_common_int) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + runner.RunDispatcher({{"template void foo() {}", "template void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -318,7 +318,7 @@ BOOST_AUTO_TEST_CASE(template_common_int) { BOOST_AUTO_TEST_CASE(template_common_int_insert_init) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("template void foo() {}", "template void foo() {}"); + runner.RunDispatcher({{"template void foo() {}", "template void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testThrow.cpp b/test/suite/testThrow.cpp index 0589e8b..87a89ab 100644 --- a/test/suite/testThrow.cpp +++ b/test/suite/testThrow.cpp @@ -22,7 +22,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_change_common_throw) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { throw std::string(); }", "void foo() { throw std::string(); }"); + runner.RunDispatcher({{"void foo() { throw std::string(); }", "void foo() { throw std::string(); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -45,7 +45,7 @@ BOOST_AUTO_TEST_CASE(block_change_common_throw) { BOOST_AUTO_TEST_CASE(block_insert_throw) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { throw Exception(); }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { throw Exception(); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(block_insert_throw) { BOOST_AUTO_TEST_CASE(block_delete_throw) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { throw Exception(); }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { throw Exception(); }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(block_delete_throw) { BOOST_AUTO_TEST_CASE(block_change_throw) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { throw std::string(); }", "void foo() { throw Exception(); }"); + runner.RunDispatcher({{"void foo() { throw std::string(); }", "void foo() { throw Exception(); }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testTry.cpp b/test/suite/testTry.cpp index 65541ba..2b1738d 100644 --- a/test/suite/testTry.cpp +++ b/test/suite/testTry.cpp @@ -25,7 +25,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(try_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} }", "void foo() { try {} }"); + runner.RunDispatcher({{"void foo() { try {} }", "void foo() { try {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(try_common) { BOOST_AUTO_TEST_CASE(try_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { try {} }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { try {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(try_insert) { BOOST_AUTO_TEST_CASE(try_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} }", "void foo() {}"); + runner.RunDispatcher({{"void foo() { try {} }", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(try_delete) { BOOST_AUTO_TEST_CASE(catch_common) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} catch() {} }", "void foo() { try {} catch() {} }"); + runner.RunDispatcher({{"void foo() { try {} catch() {} }", "void foo() { try {} catch() {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE(catch_common) { BOOST_AUTO_TEST_CASE(catch_insert) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} }", "void foo() { try {} catch() {} }"); + runner.RunDispatcher({{"void foo() { try {} }", "void foo() { try {} catch() {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE(catch_insert) { BOOST_AUTO_TEST_CASE(catch_delete) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} catch() {} }", "void foo() { try {} }"); + runner.RunDispatcher({{"void foo() { try {} catch() {} }", "void foo() { try {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(catch_delete) { BOOST_AUTO_TEST_CASE(catch_common_param) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch(Exception e) {} }"); + runner.RunDispatcher({{"void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch(Exception e) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(catch_common_param) { BOOST_AUTO_TEST_CASE(catch_insert_param) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} catch() {} }", "void foo() { try {} catch(Exception e) {} }"); + runner.RunDispatcher({{"void foo() { try {} catch() {} }", "void foo() { try {} catch(Exception e) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE(catch_insert_param) { BOOST_AUTO_TEST_CASE(catch_delete_param) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch() {} }"); + runner.RunDispatcher({{"void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch() {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -316,7 +316,7 @@ BOOST_AUTO_TEST_CASE(catch_delete_param) { BOOST_AUTO_TEST_CASE(catch_common_param_insert_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch(foo bar, Exception e) {} }"); + runner.RunDispatcher({{"void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch(foo bar, Exception e) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -355,7 +355,7 @@ BOOST_AUTO_TEST_CASE(catch_common_param_insert_front) { BOOST_AUTO_TEST_CASE(catch_common_param_insert_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch(Exception e, foo bar) {} }"); + runner.RunDispatcher({{"void foo() { try {} catch(Exception e) {} }", "void foo() { try {} catch(Exception e, foo bar) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -394,7 +394,7 @@ BOOST_AUTO_TEST_CASE(catch_common_param_insert_back) { BOOST_AUTO_TEST_CASE(catch_common_param_delete_front) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} catch(foo bar, Exception e) {} }", "void foo() { try {} catch(Exception e) {} }"); + runner.RunDispatcher({{"void foo() { try {} catch(foo bar, Exception e) {} }", "void foo() { try {} catch(Exception e) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -433,7 +433,7 @@ BOOST_AUTO_TEST_CASE(catch_common_param_delete_front) { BOOST_AUTO_TEST_CASE(catch_common_param_delete_back) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} catch(Exception e, foo bar) {} }", "void foo() { try {} catch(Exception e) {} }"); + runner.RunDispatcher({{"void foo() { try {} catch(Exception e, foo bar) {} }", "void foo() { try {} catch(Exception e) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -472,7 +472,7 @@ BOOST_AUTO_TEST_CASE(catch_common_param_delete_back) { BOOST_AUTO_TEST_CASE(catch_common_param_replace) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { try {} catch(std::string str) {} }", "void foo() { try {} catch(Exception e) {} }"); + runner.RunDispatcher({{"void foo() { try {} catch(std::string str) {} }", "void foo() { try {} catch(Exception e) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/suite/testWhile.cpp b/test/suite/testWhile.cpp index ac0eee1..e4b84e2 100644 --- a/test/suite/testWhile.cpp +++ b/test/suite/testWhile.cpp @@ -24,7 +24,7 @@ namespace data = boost::unit_test; BOOST_AUTO_TEST_CASE(block_common_while) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { while(1) {} }", "void foo() { while(1) {} }"); + runner.RunDispatcher({{"void foo() { while(1) {} }", "void foo() { while(1) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE(block_common_while) { BOOST_AUTO_TEST_CASE(block_insert_while) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() {}", "void foo() { while(1) {} }"); + runner.RunDispatcher({{"void foo() {}", "void foo() { while(1) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(block_insert_while) { BOOST_AUTO_TEST_CASE(block_delete_while) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { while(1) {}", "void foo() {}"); + runner.RunDispatcher({{"void foo() { while(1) {}", "void foo() {}"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(block_delete_while) { BOOST_AUTO_TEST_CASE(block_change_condition_expr_while) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { while(1) {}", "void foo() { while(2) {} }"); + runner.RunDispatcher({{"void foo() { while(1) {}", "void foo() { while(2) {} }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(block_change_condition_expr_while) { BOOST_AUTO_TEST_CASE(block_replace_while) { srcDispatch::DispatchRunner runner; - runner.RunDispatcher("void foo() { while(1) { a; }", "void foo() { while(2) { b; } }"); + runner.RunDispatcher({{"void foo() { while(1) { a; }", "void foo() { while(2) { b; } }"}}); BOOST_TEST(runner.GetDeclStmtInfo().size() == 0); BOOST_TEST(runner.GetFunctionInfo().size() == 1); diff --git a/test/util/DispatchRunner.hpp b/test/util/DispatchRunner.hpp index 3c460ba..9b7c670 100644 --- a/test/util/DispatchRunner.hpp +++ b/test/util/DispatchRunner.hpp @@ -105,20 +105,6 @@ class DispatchRunner : public srcDispatch::PolicyListener { void NotifyWrite(const srcDispatch::PolicyDispatcher* policy [[maybe_unused]], srcDispatch::srcSAXEventContext& ctx [[maybe_unused]]) override {} - - void RunDispatcher(const std::string& original, const std::string& modified) { - - std::string srcDiffStr = srcDiff(original, modified); - try { - srcSAXController control(srcDiffStr); - srcDispatch::srcDispatcher dispatch(this); - control.parse(&dispatch); //Start parsing - } catch(SAXError error) { - std::cerr << error.message; - exit(1); - } - } - void RunDispatcher(const std::vector& sourcePairs) { std::string srcDiffStr; From 01f71a342d3b5dedb672115a7f9f60f675e299a7 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Sun, 29 Jun 2025 12:38:34 +0900 Subject: [PATCH 138/149] Add filesystem include to dispatch runner --- test/util/DispatchRunner.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/util/DispatchRunner.hpp b/test/util/DispatchRunner.hpp index 9b7c670..2d35c99 100644 --- a/test/util/DispatchRunner.hpp +++ b/test/util/DispatchRunner.hpp @@ -18,6 +18,7 @@ #include #include +#include namespace srcDispatch { From 60a6f9510f75ab5b163818fb960d2f3aa6243835 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 30 Jun 2025 10:55:51 +0900 Subject: [PATCH 139/149] Add == operator overloads --- src/policy_classes/DeltaElement.hpp | 10 ++++------ src/policy_classes/DeltaElement.tcc | 30 ++++++++++++++++++++++++----- src/policy_classes/TypePolicy.hpp | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/policy_classes/DeltaElement.hpp b/src/policy_classes/DeltaElement.hpp index b4c137b..c8ebb94 100644 --- a/src/policy_classes/DeltaElement.hpp +++ b/src/policy_classes/DeltaElement.hpp @@ -61,6 +61,10 @@ class DeltaElement { const auto operator->() const; auto operator->(); + operator bool() const; + bool operator==(const DeltaElement& that); + bool operator==(const type& that); + srcDispatch::DiffOperation GetOperation() const; void SetOperation(srcDispatch::DiffOperation operation); @@ -73,12 +77,6 @@ class DeltaElement { void Append(srcDispatch::DiffOperation operation, const std::string& str); void Clear(); - operator bool() const; - - - std::string GetOriginalStr() const; - std::string GetModifiedStr() const; - template std::string ToString(srcDispatch::DiffOperation operation = srcDispatch::NONE) const; }; diff --git a/src/policy_classes/DeltaElement.tcc b/src/policy_classes/DeltaElement.tcc index 8ec1add..19e316c 100644 --- a/src/policy_classes/DeltaElement.tcc +++ b/src/policy_classes/DeltaElement.tcc @@ -182,6 +182,31 @@ auto DeltaElement::operator->() { } } +template +DeltaElement::operator bool() const { + return operation != srcDispatch::NONE; +} + +template +bool DeltaElement::operator==(const DeltaElement& that) { + if(this->operation != that.operation) return false; + if(this->HasOriginal() != that.HasOriginal()) return false; + if(this->HasModified() != that.HasModified()) return false; + if(this->HasOriginal() && this->original != that.original) return false; + if(this->HasModified() && this->modified != that.modified) return false; + + return true; +} + +template +bool DeltaElement::operator==(const type& that) { + if(!*this) return false; + + return GetElement() == that; +} + + + template srcDispatch::DiffOperation DeltaElement::GetOperation() const { return operation; @@ -283,11 +308,6 @@ void DeltaElement::Clear() { modified = std::optional(); } -template -DeltaElement::operator bool() const { - return operation != srcDispatch::NONE; -} - template template std::string DeltaElement::ToString(srcDispatch::DiffOperation operation) const { diff --git a/src/policy_classes/TypePolicy.hpp b/src/policy_classes/TypePolicy.hpp index b342914..ad23859 100644 --- a/src/policy_classes/TypePolicy.hpp +++ b/src/policy_classes/TypePolicy.hpp @@ -21,7 +21,7 @@ namespace srcDispatch { class NamePolicy; struct TypeData { - enum TypeType { TYPENAME, POINTER, REFERENCE, RVALUE, SPECIFIER, NONE }; + enum TypeType : int { TYPENAME, POINTER, REFERENCE, RVALUE, SPECIFIER, NONE }; unsigned int lineNumber; std::vector, DeltaElement>> types; From a73a34877f58af71bb5205ef3d565fa437799109 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 30 Jun 2025 11:07:04 +0900 Subject: [PATCH 140/149] Add support for two-way comparison --- src/policy_classes/DeltaElement.hpp | 1 + src/policy_classes/DeltaElement.tcc | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/policy_classes/DeltaElement.hpp b/src/policy_classes/DeltaElement.hpp index c8ebb94..b076e81 100644 --- a/src/policy_classes/DeltaElement.hpp +++ b/src/policy_classes/DeltaElement.hpp @@ -64,6 +64,7 @@ class DeltaElement { operator bool() const; bool operator==(const DeltaElement& that); bool operator==(const type& that); + friend bool operator==(const type& lhs, const DeltaElement& rhs); srcDispatch::DiffOperation GetOperation() const; void SetOperation(srcDispatch::DiffOperation operation); diff --git a/src/policy_classes/DeltaElement.tcc b/src/policy_classes/DeltaElement.tcc index 19e316c..4ffa9ca 100644 --- a/src/policy_classes/DeltaElement.tcc +++ b/src/policy_classes/DeltaElement.tcc @@ -200,12 +200,13 @@ bool DeltaElement::operator==(const DeltaElement& that) { template bool DeltaElement::operator==(const type& that) { - if(!*this) return false; - - return GetElement() == that; + return *this == DeltaElement(that); } - +template +bool operator==(const type& lhs, const DeltaElement& rhs) { + return DeltaElement(lhs) == rhs; +} template srcDispatch::DiffOperation DeltaElement::GetOperation() const { From 70ef615d36534797d2cd17681fc18c1a6ecaeaed Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Mon, 30 Jun 2025 11:33:26 +0900 Subject: [PATCH 141/149] Make comparisons const --- src/policy_classes/DeltaElement.hpp | 8 +++++--- src/policy_classes/DeltaElement.tcc | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/policy_classes/DeltaElement.hpp b/src/policy_classes/DeltaElement.hpp index b076e81..04a8688 100644 --- a/src/policy_classes/DeltaElement.hpp +++ b/src/policy_classes/DeltaElement.hpp @@ -62,9 +62,11 @@ class DeltaElement { auto operator->(); operator bool() const; - bool operator==(const DeltaElement& that); - bool operator==(const type& that); - friend bool operator==(const type& lhs, const DeltaElement& rhs); + bool operator==(const DeltaElement& that) const; + bool operator==(const type& that) const; + + template + friend bool operator==(const compare_type& lhs, const DeltaElement& rhs); srcDispatch::DiffOperation GetOperation() const; void SetOperation(srcDispatch::DiffOperation operation); diff --git a/src/policy_classes/DeltaElement.tcc b/src/policy_classes/DeltaElement.tcc index 4ffa9ca..afeebf6 100644 --- a/src/policy_classes/DeltaElement.tcc +++ b/src/policy_classes/DeltaElement.tcc @@ -188,7 +188,7 @@ DeltaElement::operator bool() const { } template -bool DeltaElement::operator==(const DeltaElement& that) { +bool DeltaElement::operator==(const DeltaElement& that) const { if(this->operation != that.operation) return false; if(this->HasOriginal() != that.HasOriginal()) return false; if(this->HasModified() != that.HasModified()) return false; @@ -199,13 +199,13 @@ bool DeltaElement::operator==(const DeltaElement& that) { } template -bool DeltaElement::operator==(const type& that) { +bool DeltaElement::operator==(const type& that) const { return *this == DeltaElement(that); } template bool operator==(const type& lhs, const DeltaElement& rhs) { - return DeltaElement(lhs) == rhs; + return rhs == lhs; } template From e85ab9c52a356292a74712f9d82cd8acd8fe069d Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 2 Jul 2025 11:08:06 +0900 Subject: [PATCH 142/149] Put an assert that names has something --- src/policy_classes/NamePolicy.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/policy_classes/NamePolicy.cpp b/src/policy_classes/NamePolicy.cpp index be194a4..bb202f8 100644 --- a/src/policy_classes/NamePolicy.cpp +++ b/src/policy_classes/NamePolicy.cpp @@ -19,6 +19,7 @@ namespace srcDispatch { if(name) return name.ToString(); // Not sure how safe GetElement use is + assert(names.size()); assert(names.back().GetElement().type() == typeid(std::shared_ptr)); return names.back().ToString>(); } From fe6d36cac71ebd0dd44436f2178df16c429b9e5d Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 2 Jul 2025 11:11:40 +0900 Subject: [PATCH 143/149] Change assert to throwing an exception --- src/policy_classes/NamePolicy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/policy_classes/NamePolicy.cpp b/src/policy_classes/NamePolicy.cpp index bb202f8..4aebf3f 100644 --- a/src/policy_classes/NamePolicy.cpp +++ b/src/policy_classes/NamePolicy.cpp @@ -17,9 +17,9 @@ namespace srcDispatch { std::string NameData::SimpleName() const { if(name) return name.ToString(); + if(names.empty()) throw std::logic_error("NameData is empty"); // Not sure how safe GetElement use is - assert(names.size()); assert(names.back().GetElement().type() == typeid(std::shared_ptr)); return names.back().ToString>(); } From 90c2b64ca4f78b479296efc80e872f3f6daca215 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 2 Jul 2025 15:44:48 +0900 Subject: [PATCH 144/149] Update so all data has start/end line and change to guard-clause on policy start --- src/policy_classes/BlockPolicy.cpp | 5 +- src/policy_classes/CallPolicy.cpp | 18 ++--- src/policy_classes/CallPolicy.hpp | 4 +- src/policy_classes/CasePolicy.hpp | 4 ++ src/policy_classes/CatchPolicy.hpp | 16 ++--- src/policy_classes/ClassPolicy.hpp | 7 +- src/policy_classes/ConditionPolicy.hpp | 18 +++-- src/policy_classes/ConditionalPolicy.hpp | 16 ++--- src/policy_classes/ControlPolicy.hpp | 19 ++--- src/policy_classes/DeclPolicy.hpp | 10 +-- src/policy_classes/DeclStmtPolicy.hpp | 15 ++-- src/policy_classes/ExprStmtPolicy.hpp | 3 + src/policy_classes/ExprTypePolicy.hpp | 12 ++-- src/policy_classes/ExpressionPolicy.cpp | 22 +++--- src/policy_classes/ExpressionPolicy.hpp | 4 +- src/policy_classes/ForPolicy.hpp | 16 ++--- src/policy_classes/FunctionPolicy.hpp | 70 ++++++++++--------- src/policy_classes/GenericArgumentsPolicy.cpp | 16 +++-- src/policy_classes/GenericArgumentsPolicy.hpp | 4 +- src/policy_classes/GenericPolicy.cpp | 13 ++-- src/policy_classes/GenericPolicy.hpp | 4 +- src/policy_classes/GotoPolicy.hpp | 32 +++++---- src/policy_classes/IfStmtPolicy.hpp | 18 ++--- src/policy_classes/IncrPolicy.hpp | 16 +++-- src/policy_classes/InitPolicy.hpp | 15 ++-- src/policy_classes/LabelPolicy.hpp | 16 +++-- src/policy_classes/LiteralPolicy.hpp | 15 ++-- src/policy_classes/NamePolicy.cpp | 7 +- src/policy_classes/NamePolicy.hpp | 4 +- src/policy_classes/OperatorPolicy.hpp | 15 ++-- src/policy_classes/ReturnPolicy.hpp | 4 ++ src/policy_classes/ThrowPolicy.hpp | 4 ++ src/policy_classes/TryPolicy.hpp | 16 ++--- src/policy_classes/TypePolicy.cpp | 21 +++--- src/policy_classes/TypePolicy.hpp | 4 +- src/policy_classes/UnitPolicy.hpp | 5 ++ 36 files changed, 287 insertions(+), 201 deletions(-) diff --git a/src/policy_classes/BlockPolicy.cpp b/src/policy_classes/BlockPolicy.cpp index b257997..9428d9f 100644 --- a/src/policy_classes/BlockPolicy.cpp +++ b/src/policy_classes/BlockPolicy.cpp @@ -107,13 +107,12 @@ namespace srcDispatch { void BlockPolicy::CollectBlockHandlers() { using namespace srcDispatch; - openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) - { + openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { if(!depth) { depth = ctx.depth; data = BlockData{}; data.startLineNumber = ctx.startLineNumber; - data.endLineNumber = ctx.endLineNumber; + data.endLineNumber = ctx.endLineNumber; } else { if(!blockPolicy) blockPolicy = make_unique_policy({this}); diff --git a/src/policy_classes/CallPolicy.cpp b/src/policy_classes/CallPolicy.cpp index 50de00f..e4b2e1a 100644 --- a/src/policy_classes/CallPolicy.cpp +++ b/src/policy_classes/CallPolicy.cpp @@ -43,7 +43,8 @@ namespace srcDispatch { std::shared_ptr CallData::copyAs(srcDispatch::DiffOperation operation) const { std::shared_ptr data = std::make_shared(); - data->lineNumber = lineNumber; + data->startLineNumber = startLineNumber; + data->endLineNumber = endLineNumber; data->name = name.GetElement()->copyAs(operation); @@ -75,13 +76,14 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy openEventMap[ParserState::call] = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = CallData{}; - data.lineNumber = ctx.startLineNumber; - CollectNameHandlers(); - CollectCallArgumentHandlers(); - } + if(depth) return; + + depth = ctx.depth; + data = CallData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectNameHandlers(); + CollectCallArgumentHandlers(); }; // end of policy diff --git a/src/policy_classes/CallPolicy.hpp b/src/policy_classes/CallPolicy.hpp index 263a2d3..54d34eb 100644 --- a/src/policy_classes/CallPolicy.hpp +++ b/src/policy_classes/CallPolicy.hpp @@ -37,7 +37,9 @@ namespace srcDispatch { struct CallData { - unsigned int lineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; + DeltaElement> name; std::vector>> arguments; // expressions diff --git a/src/policy_classes/CasePolicy.hpp b/src/policy_classes/CasePolicy.hpp index 1e75fda..00cd59d 100644 --- a/src/policy_classes/CasePolicy.hpp +++ b/src/policy_classes/CasePolicy.hpp @@ -23,6 +23,10 @@ namespace srcDispatch { struct CaseData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + DeltaElement> expr; template diff --git a/src/policy_classes/CatchPolicy.hpp b/src/policy_classes/CatchPolicy.hpp index b379f5e..9fd108c 100644 --- a/src/policy_classes/CatchPolicy.hpp +++ b/src/policy_classes/CatchPolicy.hpp @@ -74,14 +74,14 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[ParserState::catchstmt] = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = CatchData{}; - data.startLineNumber = ctx.startLineNumber; - data.endLineNumber = ctx.endLineNumber; - CollectParametersHandlers(); - CollectBlockHandlers(); - } + if(depth) return; + + depth = ctx.depth; + data = CatchData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectParametersHandlers(); + CollectBlockHandlers(); }; // end of policy diff --git a/src/policy_classes/ClassPolicy.hpp b/src/policy_classes/ClassPolicy.hpp index 58d0993..6f8765c 100644 --- a/src/policy_classes/ClassPolicy.hpp +++ b/src/policy_classes/ClassPolicy.hpp @@ -34,7 +34,8 @@ namespace srcDispatch { std::vector namespaces; - unsigned int lineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; std::string language; std::string filename; @@ -147,10 +148,12 @@ namespace srcDispatch { // start of policy std::function startPolicy = [this](srcSAXEventContext& ctx) { if(!depth) { + depth = ctx.depth; data = ClassData{}; data.namespaces = ctx.currentNamespaces; - data.lineNumber = ctx.startLineNumber; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); if(stereotype_attr_itr != ctx.attributes.end()) { std::istringstream stereostring(stereotype_attr_itr->second); diff --git a/src/policy_classes/ConditionPolicy.hpp b/src/policy_classes/ConditionPolicy.hpp index d0f8d30..9b42224 100644 --- a/src/policy_classes/ConditionPolicy.hpp +++ b/src/policy_classes/ConditionPolicy.hpp @@ -24,6 +24,10 @@ namespace srcDispatch { struct ConditionData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + std::vector> conditions; template @@ -109,12 +113,14 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if (!depth) { - depth = ctx.depth; - data = ConditionData{}; - CollectExpressionHandlers(); - CollectDeclPolicyHandlers(); - } + if (depth) return; + + depth = ctx.depth; + data = ConditionData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectExpressionHandlers(); + CollectDeclPolicyHandlers(); }; // end of policy diff --git a/src/policy_classes/ConditionalPolicy.hpp b/src/policy_classes/ConditionalPolicy.hpp index 27000fd..78ceff6 100644 --- a/src/policy_classes/ConditionalPolicy.hpp +++ b/src/policy_classes/ConditionalPolicy.hpp @@ -65,14 +65,14 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[DispatchEvent] = [this](srcSAXEventContext& ctx) { - if (!depth) { - depth = ctx.depth; - data = ConditionalData{}; - data.startLineNumber = ctx.startLineNumber; - data.endLineNumber = ctx.endLineNumber; - CollectConditionHandlers(); - CollectBlockHandlers(); - } + if (depth) return; + + depth = ctx.depth; + data = ConditionalData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectConditionHandlers(); + CollectBlockHandlers(); }; // end of policy diff --git a/src/policy_classes/ControlPolicy.hpp b/src/policy_classes/ControlPolicy.hpp index 4fa3c73..f164358 100644 --- a/src/policy_classes/ControlPolicy.hpp +++ b/src/policy_classes/ControlPolicy.hpp @@ -27,7 +27,8 @@ namespace srcDispatch { struct ControlData { - unsigned int lineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; DeltaElement> init; DeltaElement> condition; @@ -105,13 +106,15 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { - if (!depth) { - depth = ctx.depth; - data = ControlData{}; - CollectInitHandlers(); - CollectConditionHandlers(); - CollectIncrHandlers(); - } + if (depth) return; + + depth = ctx.depth; + data = ControlData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectInitHandlers(); + CollectConditionHandlers(); + CollectIncrHandlers(); }; // end of policy diff --git a/src/policy_classes/DeclPolicy.hpp b/src/policy_classes/DeclPolicy.hpp index f140196..4c090ba 100644 --- a/src/policy_classes/DeclPolicy.hpp +++ b/src/policy_classes/DeclPolicy.hpp @@ -26,7 +26,8 @@ namespace srcDispatch { struct DeclData { - unsigned int lineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; std::vector>> generics; DeltaElement accessSpecifier; @@ -152,13 +153,12 @@ namespace srcDispatch { // start of policy std::function startDecl = [this](srcSAXEventContext &ctx) { - if(depth) { - return; - } + if(depth) return; depth = ctx.depth; data = DeclData{}; - data.lineNumber = ctx.startLineNumber; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; CollectGenericHandlers(); CollectSpecifiersHandlers(); diff --git a/src/policy_classes/DeclStmtPolicy.hpp b/src/policy_classes/DeclStmtPolicy.hpp index f9a21e1..344fe77 100644 --- a/src/policy_classes/DeclStmtPolicy.hpp +++ b/src/policy_classes/DeclStmtPolicy.hpp @@ -21,7 +21,8 @@ namespace srcDispatch { struct DeclStmtData { - unsigned int lineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; std::vector>> decls; @@ -82,11 +83,13 @@ namespace srcDispatch { // start of policy openEventMap[ParserState::declstmt] = [this](srcSAXEventContext &ctx) { - if (!depth) { - depth = ctx.depth; - data = DeclStmtData{}; - CollectDeclHandlers(ctx); - } + if (depth) return; + + depth = ctx.depth; + data = DeclStmtData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectDeclHandlers(ctx); }; // end of policy diff --git a/src/policy_classes/ExprStmtPolicy.hpp b/src/policy_classes/ExprStmtPolicy.hpp index 8e4b5be..b29945d 100644 --- a/src/policy_classes/ExprStmtPolicy.hpp +++ b/src/policy_classes/ExprStmtPolicy.hpp @@ -23,6 +23,9 @@ namespace srcDispatch { struct ExprStmtData { + unsigned int startLineNumber; + unsigned int endLineNumber; + DeltaElement> expr; template diff --git a/src/policy_classes/ExprTypePolicy.hpp b/src/policy_classes/ExprTypePolicy.hpp index 8045a50..1dc7548 100644 --- a/src/policy_classes/ExprTypePolicy.hpp +++ b/src/policy_classes/ExprTypePolicy.hpp @@ -60,11 +60,13 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy openEventMap[DispatchEvent] = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = ExprTypeData{}; - CollectExpressionHandlers(); - } + if(depth) return; + + depth = ctx.depth; + data = ExprTypeData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectExpressionHandlers(); }; // end of policy diff --git a/src/policy_classes/ExpressionPolicy.cpp b/src/policy_classes/ExpressionPolicy.cpp index e25373c..ccfd0c3 100644 --- a/src/policy_classes/ExpressionPolicy.cpp +++ b/src/policy_classes/ExpressionPolicy.cpp @@ -43,7 +43,8 @@ namespace srcDispatch { std::shared_ptr ExpressionData::copyAs(srcDispatch::DiffOperation operation) const { std::shared_ptr data = std::make_shared(); - data->lineNumber = lineNumber; + data->startLineNumber = startLineNumber; + data->endLineNumber = endLineNumber; for (const DeltaElement& item : expr) { DeltaElement exprAny; @@ -87,15 +88,16 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy std::function expressionStart = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = ExpressionData{}; - data.lineNumber = ctx.startLineNumber; - CollectNameHandlers(); - CollectCallHandlers(); - CollectOperatorHandlers(); - CollectLiteralHandlers(); - } + if(depth) return; + + depth = ctx.depth; + data = ExpressionData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectNameHandlers(); + CollectCallHandlers(); + CollectOperatorHandlers(); + CollectLiteralHandlers(); }; // end of policy diff --git a/src/policy_classes/ExpressionPolicy.hpp b/src/policy_classes/ExpressionPolicy.hpp index 620d03f..5e524ae 100644 --- a/src/policy_classes/ExpressionPolicy.hpp +++ b/src/policy_classes/ExpressionPolicy.hpp @@ -37,7 +37,9 @@ namespace srcDispatch { struct ExpressionData { - unsigned int lineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; + std::vector> expr; std::shared_ptr copyAs(srcDispatch::DiffOperation operation) const; diff --git a/src/policy_classes/ForPolicy.hpp b/src/policy_classes/ForPolicy.hpp index 3ca7147..688be07 100644 --- a/src/policy_classes/ForPolicy.hpp +++ b/src/policy_classes/ForPolicy.hpp @@ -83,14 +83,14 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[ParserState::forstmt] = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = ForData{}; - data.startLineNumber = ctx.startLineNumber; - data.endLineNumber = ctx.endLineNumber; - CollectControlHandlers(); - CollectBlockHandlers(); - } + if(depth) return; + + depth = ctx.depth; + data = ForData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectControlHandlers(); + CollectBlockHandlers(); }; // end of policy diff --git a/src/policy_classes/FunctionPolicy.hpp b/src/policy_classes/FunctionPolicy.hpp index ddac37a..a23a283 100644 --- a/src/policy_classes/FunctionPolicy.hpp +++ b/src/policy_classes/FunctionPolicy.hpp @@ -36,7 +36,9 @@ namespace srcDispatch { // std::vector> namespaces; std::vector namespaces; - unsigned int lineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; + std::string language; std::string filename; @@ -183,41 +185,43 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy std::function startFunction = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = FunctionData{}; - data.namespaces = ctx.currentNamespaces; - data.lineNumber = ctx.startLineNumber; - data.language = ctx.currentFileLanguage; - data.filename = ctx.currentFilePath; - std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); - if(stereotype_attr_itr != ctx.attributes.end()) { - std::istringstream stereostring(stereotype_attr_itr->second); - data.stereotypes = std::set(std::istream_iterator(stereostring), std::istream_iterator()); - } - if(ctx.currentTag == "function" || ctx.currentTag == "function_decl") { - if(ctx.isOperator) { - data.type.Update(ctx.diffStack.back().operation, FunctionData::OPERATOR); - } else { - data.type.Update(ctx.diffStack.back().operation, FunctionData::FUNCTION); - } - } else if(ctx.currentTag == "constructor" || ctx.currentTag == "constructor_decl") { - data.type.Update(ctx.diffStack.back().operation, FunctionData::CONSTRUCTOR); - } else if(ctx.currentTag == "destructor" || ctx.currentTag == "destructor_decl") { - data.type.Update(ctx.diffStack.back().operation, FunctionData::DESTRUCTOR); + if(depth) return; + + depth = ctx.depth; + data = FunctionData{}; + data.namespaces = ctx.currentNamespaces; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + data.language = ctx.currentFileLanguage; + data.filename = ctx.currentFilePath; + + std::map::const_iterator stereotype_attr_itr = ctx.attributes.find("stereotype"); + if(stereotype_attr_itr != ctx.attributes.end()) { + std::istringstream stereostring(stereotype_attr_itr->second); + data.stereotypes = std::set(std::istream_iterator(stereostring), std::istream_iterator()); + } + if(ctx.currentTag == "function" || ctx.currentTag == "function_decl") { + if(ctx.isOperator) { + data.type.Update(ctx.diffStack.back().operation, FunctionData::OPERATOR); + } else { + data.type.Update(ctx.diffStack.back().operation, FunctionData::FUNCTION); } + } else if(ctx.currentTag == "constructor" || ctx.currentTag == "constructor_decl") { + data.type.Update(ctx.diffStack.back().operation, FunctionData::CONSTRUCTOR); + } else if(ctx.currentTag == "destructor" || ctx.currentTag == "destructor_decl") { + data.type.Update(ctx.diffStack.back().operation, FunctionData::DESTRUCTOR); + } - data.isDecl.Update(ctx.diffStack.back().operation, ctx.currentTag == "function_decl" || ctx.currentTag == "constructor_decl" || ctx.currentTag == "destructor_decl"); + data.isDecl.Update(ctx.diffStack.back().operation, ctx.currentTag == "function_decl" || ctx.currentTag == "constructor_decl" || ctx.currentTag == "destructor_decl"); - CollectXMLAttributeHandlers(); - CollectGenericHandlers(); - CollectTypeHandlers(); - CollectNameHandlers(); - CollectParameterHandlers(); - CollectCallHandlers(); - CollectOtherHandlers(); - CollectBlockHandlers(); - } + CollectXMLAttributeHandlers(); + CollectGenericHandlers(); + CollectTypeHandlers(); + CollectNameHandlers(); + CollectParameterHandlers(); + CollectCallHandlers(); + CollectOtherHandlers(); + CollectBlockHandlers(); }; // end of policy diff --git a/src/policy_classes/GenericArgumentsPolicy.cpp b/src/policy_classes/GenericArgumentsPolicy.cpp index 1242800..094125b 100644 --- a/src/policy_classes/GenericArgumentsPolicy.cpp +++ b/src/policy_classes/GenericArgumentsPolicy.cpp @@ -47,7 +47,8 @@ namespace srcDispatch { std::shared_ptr GenericArgumentsData::copyAs(srcDispatch::DiffOperation operation) const { std::shared_ptr data = std::make_shared(); - data->lineNumber = lineNumber; + data->startLineNumber = startLineNumber; + data->endLineNumber = endLineNumber; for (const DeltaElement>& argument : arguments) { data->arguments.emplace_back(DeltaElement(operation, argument.GetElement()->copyAs(operation))); @@ -82,12 +83,13 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy openEventMap[ParserState::genericargumentlist] = [this](srcSAXEventContext &ctx) { - if(!depth) { - depth = ctx.depth; - data = GenericArgumentsData{}; - data.lineNumber = ctx.startLineNumber; - CollectArgumentHandler(); - } + if(depth) return; + + depth = ctx.depth; + data = GenericArgumentsData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectArgumentHandler(); }; // end of policy diff --git a/src/policy_classes/GenericArgumentsPolicy.hpp b/src/policy_classes/GenericArgumentsPolicy.hpp index d700ebf..603f8aa 100644 --- a/src/policy_classes/GenericArgumentsPolicy.hpp +++ b/src/policy_classes/GenericArgumentsPolicy.hpp @@ -22,7 +22,9 @@ namespace srcDispatch { struct GenericArgumentsData { - unsigned int lineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; + std::vector>> arguments; std::shared_ptr copyAs(srcDispatch::DiffOperation operation) const; diff --git a/src/policy_classes/GenericPolicy.cpp b/src/policy_classes/GenericPolicy.cpp index c27f5b2..d4d7407 100644 --- a/src/policy_classes/GenericPolicy.cpp +++ b/src/policy_classes/GenericPolicy.cpp @@ -71,12 +71,13 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy openEventMap[ParserState::templates] = [this](srcSAXEventContext &ctx) { - if(!depth) { - depth = ctx.depth; - data = GenericData{}; - data.lineNumber = ctx.startLineNumber; - CollectParameterHandlers(); - } + if(depth) return; + + depth = ctx.depth; + data = GenericData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectParameterHandlers(); }; // end of policy diff --git a/src/policy_classes/GenericPolicy.hpp b/src/policy_classes/GenericPolicy.hpp index f594da3..0223f7e 100644 --- a/src/policy_classes/GenericPolicy.hpp +++ b/src/policy_classes/GenericPolicy.hpp @@ -27,7 +27,9 @@ namespace srcDispatch { struct GenericData { - unsigned int lineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; + std::vector>> parameters; template diff --git a/src/policy_classes/GotoPolicy.hpp b/src/policy_classes/GotoPolicy.hpp index 198f460..3c6618b 100644 --- a/src/policy_classes/GotoPolicy.hpp +++ b/src/policy_classes/GotoPolicy.hpp @@ -26,7 +26,8 @@ namespace srcDispatch { struct GotoData { enum GotoType { GOTO, BREAK, CONTINUE }; - unsigned int lineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; DeltaElement type; DeltaElement> label; @@ -70,21 +71,22 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy std::function startGoto = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = GotoData{}; - data.lineNumber = ctx.startLineNumber; - - if(ctx.currentTag == "break") { - data.type.Update(ctx.diffStack.back().operation, GotoData::BREAK); - } else if(ctx.currentTag == "continue") { - data.type.Update(ctx.diffStack.back().operation, GotoData::CONTINUE); - } else { - data.type.Update(ctx.diffStack.back().operation, GotoData::GOTO); - } - - CollectLabelHandlers(); + if(depth) return; + + depth = ctx.depth; + data = GotoData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + + if(ctx.currentTag == "break") { + data.type.Update(ctx.diffStack.back().operation, GotoData::BREAK); + } else if(ctx.currentTag == "continue") { + data.type.Update(ctx.diffStack.back().operation, GotoData::CONTINUE); + } else { + data.type.Update(ctx.diffStack.back().operation, GotoData::GOTO); } + + CollectLabelHandlers(); }; // end of policy diff --git a/src/policy_classes/IfStmtPolicy.hpp b/src/policy_classes/IfStmtPolicy.hpp index 3f84d9a..d074931 100644 --- a/src/policy_classes/IfStmtPolicy.hpp +++ b/src/policy_classes/IfStmtPolicy.hpp @@ -88,15 +88,15 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[ParserState::ifgroup] = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = IfStmtData{}; - data.startLineNumber = ctx.startLineNumber; - data.endLineNumber = ctx.endLineNumber; - CollectIfHandlers(); - CollectElseIfHandlers(); - CollectElseHandlers(); - } + if(depth) return; + + depth = ctx.depth; + data = IfStmtData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectIfHandlers(); + CollectElseIfHandlers(); + CollectElseHandlers(); }; // end of policy diff --git a/src/policy_classes/IncrPolicy.hpp b/src/policy_classes/IncrPolicy.hpp index 091bbd0..1d3459d 100644 --- a/src/policy_classes/IncrPolicy.hpp +++ b/src/policy_classes/IncrPolicy.hpp @@ -26,6 +26,8 @@ namespace srcDispatch { struct IncrData { unsigned int startLineNumber; + unsigned int endLineNumber; + std::vector>> exprs; template @@ -90,12 +92,14 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = IncrData{}; - data.startLineNumber = ctx.startLineNumber; - CollectExpressionHandlers(); - } + if(depth) return; + + depth = ctx.depth; + data = IncrData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectExpressionHandlers(); + }; // end of policy diff --git a/src/policy_classes/InitPolicy.hpp b/src/policy_classes/InitPolicy.hpp index 3064195..e0860d5 100644 --- a/src/policy_classes/InitPolicy.hpp +++ b/src/policy_classes/InitPolicy.hpp @@ -26,6 +26,8 @@ namespace srcDispatch { struct InitData { unsigned int startLineNumber; + unsigned int endLineNumber; + std::vector> inits; template @@ -109,12 +111,13 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = InitData{}; - data.startLineNumber = ctx.startLineNumber; - CollectExpressionHandlers(); - } + if(depth) return; + + depth = ctx.depth; + data = InitData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectExpressionHandlers(); }; // end of policy diff --git a/src/policy_classes/LabelPolicy.hpp b/src/policy_classes/LabelPolicy.hpp index d87cf86..d23fdcf 100644 --- a/src/policy_classes/LabelPolicy.hpp +++ b/src/policy_classes/LabelPolicy.hpp @@ -24,6 +24,10 @@ namespace srcDispatch { struct LabelData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + DeltaElement> name; template @@ -71,11 +75,13 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy openEventMap[ParserState::label] = [this](srcSAXEventContext &ctx) { - if(!depth) { - depth = ctx.depth; - data = LabelData{}; - CollectNameHandlers(); - } + if(depth) return; + + depth = ctx.depth; + data = LabelData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectNameHandlers(); }; // end of policy diff --git a/src/policy_classes/LiteralPolicy.hpp b/src/policy_classes/LiteralPolicy.hpp index 9cb6d4f..c207b8e 100644 --- a/src/policy_classes/LiteralPolicy.hpp +++ b/src/policy_classes/LiteralPolicy.hpp @@ -23,6 +23,8 @@ namespace srcDispatch { struct LiteralData { unsigned int startLineNumber; + unsigned int endLineNumber; + DeltaElement literal; std::shared_ptr copyAs(srcDispatch::DiffOperation operation) const { @@ -65,12 +67,13 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[ParserState::literal] = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = LiteralData{}; - data.startLineNumber = ctx.startLineNumber; - CollectTokenHandlers(); - } + if(depth) return; + + depth = ctx.depth; + data = LiteralData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectTokenHandlers(); }; // end of policy diff --git a/src/policy_classes/NamePolicy.cpp b/src/policy_classes/NamePolicy.cpp index 4aebf3f..dde6713 100644 --- a/src/policy_classes/NamePolicy.cpp +++ b/src/policy_classes/NamePolicy.cpp @@ -57,7 +57,9 @@ namespace srcDispatch { std::shared_ptr NameData::copyAs(srcDispatch::DiffOperation operation) const { std::shared_ptr data = std::make_shared(); - data->lineNumber = lineNumber; + data->startLineNumber = startLineNumber; + data->endLineNumber = endLineNumber; + if(name) { data->name = DeltaElement(operation, name.GetElement()); } @@ -109,7 +111,8 @@ namespace srcDispatch { if(!depth) { depth = ctx.depth; data = NameData{}; - data.lineNumber = ctx.startLineNumber; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; CollectOperatorsHandlers(); CollectGenericArgumentsHandlers(); CollectArrayIndicesHandlers(); diff --git a/src/policy_classes/NamePolicy.hpp b/src/policy_classes/NamePolicy.hpp index 4eb74b7..4f8bd8d 100644 --- a/src/policy_classes/NamePolicy.hpp +++ b/src/policy_classes/NamePolicy.hpp @@ -29,7 +29,9 @@ namespace srcDispatch { struct NameData { - unsigned int lineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; + DeltaElement name; std::vector> names; DeltaElement> templateArgumentList; diff --git a/src/policy_classes/OperatorPolicy.hpp b/src/policy_classes/OperatorPolicy.hpp index 756c901..0279c23 100644 --- a/src/policy_classes/OperatorPolicy.hpp +++ b/src/policy_classes/OperatorPolicy.hpp @@ -23,6 +23,8 @@ namespace srcDispatch { struct OperatorData { unsigned int startLineNumber; + unsigned int endLineNumber; + DeltaElement op; std::shared_ptr copyAs(srcDispatch::DiffOperation operation) const { @@ -65,12 +67,13 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[ParserState::op] = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = OperatorData{}; - data.startLineNumber = ctx.startLineNumber; - CollectTokenHandlers(); - } + if(depth) return; + + depth = ctx.depth; + data = OperatorData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectTokenHandlers(); }; // end of policy diff --git a/src/policy_classes/ReturnPolicy.hpp b/src/policy_classes/ReturnPolicy.hpp index 361d3de..3c8d799 100644 --- a/src/policy_classes/ReturnPolicy.hpp +++ b/src/policy_classes/ReturnPolicy.hpp @@ -23,6 +23,10 @@ namespace srcDispatch { struct ReturnData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + DeltaElement> expr; template diff --git a/src/policy_classes/ThrowPolicy.hpp b/src/policy_classes/ThrowPolicy.hpp index 031fcdf..0e86c4b 100644 --- a/src/policy_classes/ThrowPolicy.hpp +++ b/src/policy_classes/ThrowPolicy.hpp @@ -23,6 +23,10 @@ namespace srcDispatch { struct ThrowData { + + unsigned int startLineNumber; + unsigned int endLineNumber; + DeltaElement> expr; template diff --git a/src/policy_classes/TryPolicy.hpp b/src/policy_classes/TryPolicy.hpp index 1c47deb..889362f 100644 --- a/src/policy_classes/TryPolicy.hpp +++ b/src/policy_classes/TryPolicy.hpp @@ -74,14 +74,14 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[ParserState::trystmt] = [this](srcSAXEventContext &ctx) { - if (!depth) { - depth = ctx.depth; - data = TryData{}; - data.startLineNumber = ctx.startLineNumber; - data.endLineNumber = ctx.endLineNumber; - CollectBlockHandlers(); - CollectCatchHandlers(); - } + if (depth) return; + + depth = ctx.depth; + data = TryData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectBlockHandlers(); + CollectCatchHandlers(); }; // end of policy diff --git a/src/policy_classes/TypePolicy.cpp b/src/policy_classes/TypePolicy.cpp index ae8ddfa..e982742 100644 --- a/src/policy_classes/TypePolicy.cpp +++ b/src/policy_classes/TypePolicy.cpp @@ -46,7 +46,9 @@ namespace srcDispatch { std::shared_ptr TypeData::copyAs(srcDispatch::DiffOperation operation) const { std::shared_ptr data = std::make_shared(); - data->lineNumber = lineNumber; + data->startLineNumber = startLineNumber; + data->endLineNumber = endLineNumber; + for(const std::pair, DeltaElement>& type : types) { DeltaElement typeAny; if(type.second.GetElement() == TypeData::SPECIFIER) { @@ -80,14 +82,15 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy openEventMap[ParserState::type] = [this](srcSAXEventContext& ctx) { - if(!depth) { - depth = ctx.depth; - data = TypeData{}; - data.lineNumber = ctx.startLineNumber; - CollectNamesHandler(); - CollectModifersHandler(); - CollectSpecifiersHandler(); - } + if(depth) return; + + depth = ctx.depth; + data = TypeData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; + CollectNamesHandler(); + CollectModifersHandler(); + CollectSpecifiersHandler(); }; // end of policy diff --git a/src/policy_classes/TypePolicy.hpp b/src/policy_classes/TypePolicy.hpp index ad23859..82bbb04 100644 --- a/src/policy_classes/TypePolicy.hpp +++ b/src/policy_classes/TypePolicy.hpp @@ -23,7 +23,9 @@ namespace srcDispatch { struct TypeData { enum TypeType : int { TYPENAME, POINTER, REFERENCE, RVALUE, SPECIFIER, NONE }; - unsigned int lineNumber; + unsigned int startLineNumber; + unsigned int endLineNumber; + std::vector, DeltaElement>> types; std::shared_ptr copyAs(srcDispatch::DiffOperation operation) const; diff --git a/src/policy_classes/UnitPolicy.hpp b/src/policy_classes/UnitPolicy.hpp index c9c10bb..a5b9666 100644 --- a/src/policy_classes/UnitPolicy.hpp +++ b/src/policy_classes/UnitPolicy.hpp @@ -32,6 +32,9 @@ namespace srcDispatch { struct UnitData { + unsigned int startLineNumber; + unsigned int endLineNumber; + std::vector>> classInfo; std::vector>> functionInfo; std::vector>> declStmtInfo; @@ -87,6 +90,8 @@ namespace srcDispatch { if (unitDepth == MAX_DEPTH && (ctx.isArchive || ctx.depth > 0)) { unitDepth = ctx.depth; data = UnitData{}; + data.startLineNumber = ctx.startLineNumber; + data.endLineNumber = ctx.endLineNumber; } }; From babeb200a7bfb5f7049008310d750dd541a2d748 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Wed, 2 Jul 2025 15:48:06 +0900 Subject: [PATCH 145/149] Remove space between if and ( (normalizing) --- src/policy_classes/BlockPolicy.cpp | 2 +- src/policy_classes/ConditionPolicy.hpp | 22 +++++++++++----------- src/policy_classes/ConditionalPolicy.hpp | 12 ++++++------ src/policy_classes/ControlPolicy.hpp | 24 ++++++++++++------------ src/policy_classes/DeclStmtPolicy.hpp | 12 ++++++------ src/policy_classes/TryPolicy.hpp | 16 ++++++++-------- src/policy_classes/UnitPolicy.hpp | 10 +++++----- 7 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/policy_classes/BlockPolicy.cpp b/src/policy_classes/BlockPolicy.cpp index 9428d9f..ef64d6b 100644 --- a/src/policy_classes/BlockPolicy.cpp +++ b/src/policy_classes/BlockPolicy.cpp @@ -324,7 +324,7 @@ namespace srcDispatch { std::function startClassPolicy = [this](srcSAXEventContext& ctx) { if(!depth) return; - if (!classPolicy) { + if(!classPolicy) { classPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(classPolicy.get()); diff --git a/src/policy_classes/ConditionPolicy.hpp b/src/policy_classes/ConditionPolicy.hpp index 9b42224..fb6e2fb 100644 --- a/src/policy_classes/ConditionPolicy.hpp +++ b/src/policy_classes/ConditionPolicy.hpp @@ -42,13 +42,13 @@ namespace srcDispatch { bool outputRaw = condition.IsOfOperation(operation); if(outputRaw) { - if (printComma) { + if(printComma) { str += ", "; } printComma = true; } - if (condition.GetElement().type() == typeid(std::shared_ptr)) { + if(condition.GetElement().type() == typeid(std::shared_ptr)) { str += condition.ToString>(operation); } else { str += condition.ToString>(operation); @@ -84,16 +84,16 @@ namespace srcDispatch { std::any DataInner() const override { return std::make_shared(data); } virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(ExpressionPolicy) == typeid(*policy)) { + if(typeid(ExpressionPolicy) == typeid(*policy)) { if(data.conditions.size() && ctx.diffStack.back().isReplace && data.conditions.back().GetElement().type() == typeid(std::shared_ptr)) { data.conditions.back().Update(ctx.diffStack.back().operation, policy->Data()); } else { data.conditions.emplace_back(ctx.diffStack.back().operation, policy->Data()); } - } else if (typeid(DeclPolicy) == typeid(*policy)) { + } else if(typeid(DeclPolicy) == typeid(*policy)) { // not sure how safe GetElement is here std::shared_ptr decl = policy->Data(); - if (data.conditions.size() && decl->type->types.empty() + if(data.conditions.size() && decl->type->types.empty() && data.conditions.back().GetElement().type() == typeid(std::shared_ptr)) { decl->type = std::any_cast>(data.conditions.back().GetElement())->type; decl->isStatic = std::any_cast>(data.conditions.back().GetElement())->isStatic; @@ -113,7 +113,7 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if (depth) return; + if(depth) return; depth = ctx.depth; data = ConditionData{}; @@ -125,7 +125,7 @@ namespace srcDispatch { // end of policy closeEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if (!depth || depth != ctx.depth) return; + if(!depth || depth != ctx.depth) return; depth = 0; NotifyAll(ctx); @@ -136,9 +136,9 @@ namespace srcDispatch { void CollectExpressionHandlers() { using namespace srcDispatch; openEventMap[ParserState::expr] = [this](srcSAXEventContext& ctx) { - if (!depth) return; + if(!depth) return; - if (!exprPolicy) { + if(!exprPolicy) { exprPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(exprPolicy.get()); @@ -148,9 +148,9 @@ namespace srcDispatch { void CollectDeclPolicyHandlers() { using namespace srcDispatch; openEventMap[ParserState::decl] = [this](srcSAXEventContext& ctx) { - if (!depth) return; + if(!depth) return; - if (!declPolicy) { + if(!declPolicy) { declPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(declPolicy.get()); diff --git a/src/policy_classes/ConditionalPolicy.hpp b/src/policy_classes/ConditionalPolicy.hpp index 78ceff6..7a4274c 100644 --- a/src/policy_classes/ConditionalPolicy.hpp +++ b/src/policy_classes/ConditionalPolicy.hpp @@ -47,9 +47,9 @@ namespace srcDispatch { std::any DataInner() const override { return std::make_shared(data); } void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(ConditionPolicy) == typeid(*policy)) { + if(typeid(ConditionPolicy) == typeid(*policy)) { data.condition = DeltaElement(ctx.diffStack.back().operation, policy->Data()); - } else if (typeid(BlockPolicy) == typeid(*policy)) { + } else if(typeid(BlockPolicy) == typeid(*policy)) { data.block = DeltaElement(ctx.diffStack.back().operation, policy->Data()); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); @@ -65,7 +65,7 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[DispatchEvent] = [this](srcSAXEventContext& ctx) { - if (depth) return; + if(depth) return; depth = ctx.depth; data = ConditionalData{}; @@ -77,7 +77,7 @@ namespace srcDispatch { // end of policy closeEventMap[DispatchEvent] = [this](srcSAXEventContext& ctx) { - if (!depth || depth != ctx.depth) return ; + if(!depth || depth != ctx.depth) return ; depth = 0; NotifyAll(ctx); @@ -90,7 +90,7 @@ namespace srcDispatch { openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { if(!depth) return; - if (!conditionPolicy) { + if(!conditionPolicy) { conditionPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(conditionPolicy.get()); @@ -102,7 +102,7 @@ namespace srcDispatch { openEventMap[ParserState::block] = [this](srcSAXEventContext& ctx) { if(!depth) return; - if (!blockPolicy) { + if(!blockPolicy) { blockPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); diff --git a/src/policy_classes/ControlPolicy.hpp b/src/policy_classes/ControlPolicy.hpp index f164358..5c9bdac 100644 --- a/src/policy_classes/ControlPolicy.hpp +++ b/src/policy_classes/ControlPolicy.hpp @@ -41,7 +41,7 @@ namespace srcDispatch { std::string str = init.ToString(operation); - if (condition) { + if(condition) { if(condition.IsOfOperation(operation)) { str += "; "; } @@ -86,11 +86,11 @@ namespace srcDispatch { virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { using namespace srcDispatch; - if (typeid(InitPolicy) == typeid(*policy)) { + if(typeid(InitPolicy) == typeid(*policy)) { data.init.Update(ctx.diffStack.back().operation, policy->Data()); - } else if (typeid(ConditionPolicy) == typeid(*policy)) { + } else if(typeid(ConditionPolicy) == typeid(*policy)) { data.condition = DeltaElement(ctx.diffStack.back().operation, policy->Data()); - } else if (typeid(IncrPolicy) == typeid(*policy)) { + } else if(typeid(IncrPolicy) == typeid(*policy)) { data.incr.Update(ctx.diffStack.back().operation, policy->Data()); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); @@ -106,7 +106,7 @@ namespace srcDispatch { using namespace srcDispatch; // start of policy openEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { - if (depth) return; + if(depth) return; depth = ctx.depth; data = ControlData{}; @@ -119,7 +119,7 @@ namespace srcDispatch { // end of policy closeEventMap[ParserState::control] = [this](srcSAXEventContext& ctx) { - if (!depth || depth != ctx.depth) + if(!depth || depth != ctx.depth) depth = 0; NotifyAll(ctx); @@ -130,9 +130,9 @@ namespace srcDispatch { void CollectInitHandlers() { using namespace srcDispatch; openEventMap[ParserState::init] = [this](srcSAXEventContext& ctx) { - if (!depth) return; + if(!depth) return; - if (!initPolicy) { + if(!initPolicy) { initPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(initPolicy.get()); @@ -142,9 +142,9 @@ namespace srcDispatch { void CollectConditionHandlers() { using namespace srcDispatch; openEventMap[ParserState::condition] = [this](srcSAXEventContext& ctx) { - if (!depth) return; + if(!depth) return; - if (!conditionPolicy) { + if(!conditionPolicy) { conditionPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(conditionPolicy.get()); @@ -154,9 +154,9 @@ namespace srcDispatch { void CollectIncrHandlers() { using namespace srcDispatch; openEventMap[ParserState::incr] = [this](srcSAXEventContext& ctx) { - if (!depth) return; + if(!depth) return; - if (!incrPolicy) { + if(!incrPolicy) { incrPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(incrPolicy.get()); diff --git a/src/policy_classes/DeclStmtPolicy.hpp b/src/policy_classes/DeclStmtPolicy.hpp index 344fe77..5bd9ffe 100644 --- a/src/policy_classes/DeclStmtPolicy.hpp +++ b/src/policy_classes/DeclStmtPolicy.hpp @@ -60,11 +60,11 @@ namespace srcDispatch { std::any DataInner() const override { return std::make_shared(data); } virtual void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) override { - if (typeid(DeclPolicy) == typeid(*policy)) { + if(typeid(DeclPolicy) == typeid(*policy)) { // not sure how safe GetElement is here srcDispatch::DiffOperation operation = ctx.diffStack.back().operation; DeltaElement> decl(operation, policy->Data()); - if (data.decls.size() && decl.GetElement()->type->types.empty()) { + if(data.decls.size() && decl.GetElement()->type->types.empty()) { decl.GetElement()->type = data.decls.back().GetElement()->type; decl.GetElement()->isStatic = data.decls.back().GetElement()->isStatic; } @@ -83,7 +83,7 @@ namespace srcDispatch { // start of policy openEventMap[ParserState::declstmt] = [this](srcSAXEventContext &ctx) { - if (depth) return; + if(depth) return; depth = ctx.depth; data = DeclStmtData{}; @@ -94,7 +94,7 @@ namespace srcDispatch { // end of policy closeEventMap[ParserState::declstmt] = [this](srcSAXEventContext &ctx) { - if (!depth || depth != ctx.depth) return; + if(!depth || depth != ctx.depth) return; depth = 0; NotifyAll(ctx); @@ -107,9 +107,9 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[ParserState::decl] = [this](srcSAXEventContext &ctx) { - if (!depth) return; + if(!depth) return; - if (!declPolicy) { + if(!declPolicy) { declPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(declPolicy.get()); diff --git a/src/policy_classes/TryPolicy.hpp b/src/policy_classes/TryPolicy.hpp index 889362f..29a7ad6 100644 --- a/src/policy_classes/TryPolicy.hpp +++ b/src/policy_classes/TryPolicy.hpp @@ -56,9 +56,9 @@ namespace srcDispatch { std::any DataInner() const { return std::make_shared(data); } void Notify(const PolicyDispatcher* policy, const srcDispatch::srcSAXEventContext& ctx) { - if (typeid(BlockPolicy) == typeid(*policy)) { + if(typeid(BlockPolicy) == typeid(*policy)) { data.block.Update(ctx.diffStack.back().operation, policy->Data()); - } else if (typeid(CatchPolicy) == typeid(*policy)) { + } else if(typeid(CatchPolicy) == typeid(*policy)) { data.clauses.push_back(DeltaElement(ctx.diffStack.back().operation, policy->Data())); } else { throw srcDispatch::PolicyError(std::string("Unhandled Policy '") + typeid(*policy).name() + '\''); @@ -74,7 +74,7 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[ParserState::trystmt] = [this](srcSAXEventContext &ctx) { - if (depth) return; + if(depth) return; depth = ctx.depth; data = TryData{}; @@ -86,7 +86,7 @@ namespace srcDispatch { // end of policy closeEventMap[ParserState::trystmt] = [this](srcSAXEventContext &ctx) { - if (!depth || depth != ctx.depth) return; + if(!depth || depth != ctx.depth) return; depth = 0; NotifyAll(ctx); @@ -97,9 +97,9 @@ namespace srcDispatch { void CollectBlockHandlers() { using namespace srcDispatch; openEventMap[ParserState::block] = [this](srcSAXEventContext &ctx) { - if (!depth) return; + if(!depth) return; - if (!blockPolicy) { + if(!blockPolicy) { blockPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(blockPolicy.get()); @@ -109,9 +109,9 @@ namespace srcDispatch { void CollectCatchHandlers() { using namespace srcDispatch; openEventMap[ParserState::catchstmt] = [this](srcSAXEventContext &ctx) { - if (!depth) return; + if(!depth) return; - if (!catchPolicy) { + if(!catchPolicy) { catchPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(catchPolicy.get()); diff --git a/src/policy_classes/UnitPolicy.hpp b/src/policy_classes/UnitPolicy.hpp index a5b9666..85a5e96 100644 --- a/src/policy_classes/UnitPolicy.hpp +++ b/src/policy_classes/UnitPolicy.hpp @@ -87,7 +87,7 @@ namespace srcDispatch { using namespace srcDispatch; openEventMap[ParserState::unit] = [this](srcSAXEventContext& ctx) { - if (unitDepth == MAX_DEPTH && (ctx.isArchive || ctx.depth > 0)) { + if(unitDepth == MAX_DEPTH && (ctx.isArchive || ctx.depth > 0)) { unitDepth = ctx.depth; data = UnitData{}; data.startLineNumber = ctx.startLineNumber; @@ -96,7 +96,7 @@ namespace srcDispatch { }; closeEventMap[ParserState::unit] = [this](srcSAXEventContext& ctx) { - if (unitDepth != ctx.depth) return; + if(unitDepth != ctx.depth) return; unitDepth = MAX_DEPTH; NotifyAll(ctx); @@ -106,7 +106,7 @@ namespace srcDispatch { std::function startClassPolicy = [this](srcSAXEventContext& ctx) { if(depth == MAX_DEPTH) return; - if (!classPolicy) { + if(!classPolicy) { classPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(classPolicy.get()); @@ -125,7 +125,7 @@ namespace srcDispatch { std::function startFunction = [this](srcSAXEventContext& ctx) { if(depth == MAX_DEPTH) return; - if (!functionPolicy) { + if(!functionPolicy) { functionPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(functionPolicy.get()); @@ -151,7 +151,7 @@ namespace srcDispatch { openEventMap[ParserState::declstmt] = [this](srcSAXEventContext& ctx) { if(depth == MAX_DEPTH) return; - if (!declStmtPolicy) { + if(!declStmtPolicy) { declStmtPolicy = make_unique_policy({this}); } ctx.dispatcher->AddListenerDispatch(declStmtPolicy.get()); From 8da568c69b80db85f583d013e1f5b35b9e9bd0da Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 4 Jul 2025 11:18:29 +0900 Subject: [PATCH 146/149] Add handling for versioned attributes --- src/policy_classes/DeltaElement.tcc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/policy_classes/DeltaElement.tcc b/src/policy_classes/DeltaElement.tcc index afeebf6..afa55b1 100644 --- a/src/policy_classes/DeltaElement.tcc +++ b/src/policy_classes/DeltaElement.tcc @@ -58,6 +58,25 @@ DeltaElement::DeltaElement() template DeltaElement::DeltaElement(const type& element) : original(element), modified(), operation(srcDispatch::COMMON) { + + static const char ATTR_SEPARATOR = '|'; + if constexpr (std::is_same_v || std::is_same_v>) { + std::string str = ValueConst(element).value; + std::size_t pos = str.find(ATTR_SEPARATOR); + if(pos != std::string::npos) { + std::size_t length = element.size(); + operation = pos == 0? srcDispatch::INSERT : (pos == (length - 1)? srcDispatch::DELETE : srcDispatch::CHANGE); + + original.reset(); + if(operation == srcDispatch::DELETE || operation == srcDispatch::CHANGE) { + original = str.substr(0, pos); + } + + if(operation == srcDispatch::INSERT || operation == srcDispatch::CHANGE) { + modified = str.substr(pos + 1, length - (pos + 1)); + } + } + } } template From 6264f3a65bb40eb63addd3e1dc0d87488ba46c18 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 4 Jul 2025 12:30:24 +0900 Subject: [PATCH 147/149] Handle versioned pos info --- src/dispatcher/srcDispatchUtilities.hpp | 19 ++++--------- src/dispatcher/srcDispatcher.hpp | 23 ++++++++++++--- src/policy_classes/BlockPolicy.hpp | 4 +-- src/policy_classes/CallPolicy.hpp | 4 +-- src/policy_classes/CasePolicy.hpp | 4 +-- src/policy_classes/CatchPolicy.hpp | 4 +-- src/policy_classes/ClassPolicy.hpp | 4 +-- src/policy_classes/ConditionPolicy.hpp | 4 +-- src/policy_classes/ControlPolicy.hpp | 4 +-- src/policy_classes/DeclPolicy.hpp | 4 +-- src/policy_classes/DeclStmtPolicy.hpp | 4 +-- src/policy_classes/DeltaElement.hpp | 2 +- src/policy_classes/Diff.hpp | 28 +++++++++++++++++++ src/policy_classes/DoPolicy.hpp | 4 +-- src/policy_classes/ElseIfPolicy.hpp | 4 +-- src/policy_classes/ElsePolicy.hpp | 4 +-- src/policy_classes/ExprStmtPolicy.hpp | 4 +-- src/policy_classes/ExpressionPolicy.hpp | 4 +-- src/policy_classes/ForPolicy.hpp | 4 +-- src/policy_classes/FunctionPolicy.hpp | 4 +-- src/policy_classes/GenericArgumentsPolicy.hpp | 4 +-- src/policy_classes/GenericPolicy.hpp | 4 +-- src/policy_classes/GotoPolicy.hpp | 4 +-- src/policy_classes/IfPolicy.hpp | 4 +-- src/policy_classes/IfStmtPolicy.hpp | 4 +-- src/policy_classes/IncrPolicy.hpp | 4 +-- src/policy_classes/InitPolicy.hpp | 4 +-- src/policy_classes/LabelPolicy.hpp | 4 +-- src/policy_classes/LiteralPolicy.hpp | 4 +-- src/policy_classes/NamePolicy.hpp | 4 +-- src/policy_classes/OperatorPolicy.hpp | 4 +-- src/policy_classes/ReturnPolicy.hpp | 4 +-- src/policy_classes/SwitchPolicy.hpp | 4 +-- src/policy_classes/ThrowPolicy.hpp | 4 +-- src/policy_classes/TryPolicy.hpp | 4 +-- src/policy_classes/TypePolicy.hpp | 4 +-- src/policy_classes/UnitPolicy.hpp | 4 +-- src/policy_classes/WhilePolicy.hpp | 4 +-- 38 files changed, 121 insertions(+), 87 deletions(-) create mode 100644 src/policy_classes/Diff.hpp diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 31b9106..7811dec 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -31,6 +31,9 @@ #include #include +#include +#include + #include #include @@ -60,18 +63,6 @@ namespace srcDispatch { // do not put anything after these xmlattribute, tokenstring, empty, MAXENUMVALUE = empty}; - enum DiffOperation { COMMON, DELETE, INSERT, CHANGE, NONE }; - struct Diff { - Diff(DiffOperation operation, size_t depth = 0, bool isReplace = false, bool isConvert = false) - : operation(operation), depth(depth), isReplace(isReplace), isConvert(isConvert) {} - - DiffOperation operation; - size_t depth; - bool isReplace; - bool isConvert; - }; - - class srcSAXEventContext { public: srcSAXEventContext() = delete; @@ -104,8 +95,8 @@ namespace srcDispatch { const std::vector& elementStack; std::vector diffStack; std::vector genericDepth; - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector triggerField; std::string currentFilePath, currentFileName, currentFileLanguage, currentsrcMLRevision, currentTag, currentToken, currentAttributeName, currentAttributeValue, diff --git a/src/dispatcher/srcDispatcher.hpp b/src/dispatcher/srcDispatcher.hpp index ac54fa3..a3b09c0 100644 --- a/src/dispatcher/srcDispatcher.hpp +++ b/src/dispatcher/srcDispatcher.hpp @@ -868,6 +868,23 @@ namespace srcDispatch { ctx.currentsrcMLRevision = std::string(attributes[0].value); } } + + + static DeltaElement parseLineAttr(const char* attrValue) { + DeltaElement posAttr(attrValue); + + DeltaElement lineNumber(posAttr.GetOperation()); + if(posAttr.HasOriginal()) { + int length = posAttr.GetOriginal().find(':'); + lineNumber.SetOriginal(std::stoi(posAttr.GetOriginal().substr(0, length))); + } + + if(posAttr.HasModified()) { + int length = posAttr.GetModified().find(':'); + lineNumber.SetModified(std::stoi(posAttr.GetModified().substr(0, length))); + } + return lineNumber; + } /** * startElementNs * @param localname the name of the element tag @@ -948,11 +965,9 @@ namespace srcDispatch { std::string attributeName = srcSAXHandler::get_qualified_name(attributes[pos].localname, attributes[pos].prefix); if(strcmp(attributes[pos].localname, "start") == 0) { - int length = ::index(attributes[pos].value, ':') - attributes[pos].value; - ctx.startLineNumber = std::stoi(std::string(attributes[pos].value, length)); + ctx.startLineNumber = parseLineAttr(attributes[pos].value); } else if(strcmp(attributes[pos].localname, "end") == 0) { - int length = ::index(attributes[pos].value, ':') - attributes[pos].value; - ctx.endLineNumber = std::stoi(std::string(attributes[pos].value, length)); + ctx.endLineNumber = parseLineAttr(attributes[pos].value); } std::string attributeValue = attributes[pos].value; diff --git a/src/policy_classes/BlockPolicy.hpp b/src/policy_classes/BlockPolicy.hpp index efc1bf6..4721d4f 100644 --- a/src/policy_classes/BlockPolicy.hpp +++ b/src/policy_classes/BlockPolicy.hpp @@ -43,8 +43,8 @@ namespace srcDispatch { struct BlockData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector> statements; std::vector>> localClasses; diff --git a/src/policy_classes/CallPolicy.hpp b/src/policy_classes/CallPolicy.hpp index 54d34eb..d95372c 100644 --- a/src/policy_classes/CallPolicy.hpp +++ b/src/policy_classes/CallPolicy.hpp @@ -37,8 +37,8 @@ namespace srcDispatch { struct CallData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> name; std::vector>> arguments; // expressions diff --git a/src/policy_classes/CasePolicy.hpp b/src/policy_classes/CasePolicy.hpp index 00cd59d..8b0ebfd 100644 --- a/src/policy_classes/CasePolicy.hpp +++ b/src/policy_classes/CasePolicy.hpp @@ -24,8 +24,8 @@ namespace srcDispatch { struct CaseData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> expr; diff --git a/src/policy_classes/CatchPolicy.hpp b/src/policy_classes/CatchPolicy.hpp index 9fd108c..f6b8c63 100644 --- a/src/policy_classes/CatchPolicy.hpp +++ b/src/policy_classes/CatchPolicy.hpp @@ -26,8 +26,8 @@ namespace srcDispatch { struct CatchData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector>> parameters; DeltaElement> block; diff --git a/src/policy_classes/ClassPolicy.hpp b/src/policy_classes/ClassPolicy.hpp index 6f8765c..5b9e444 100644 --- a/src/policy_classes/ClassPolicy.hpp +++ b/src/policy_classes/ClassPolicy.hpp @@ -34,8 +34,8 @@ namespace srcDispatch { std::vector namespaces; - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::string language; std::string filename; diff --git a/src/policy_classes/ConditionPolicy.hpp b/src/policy_classes/ConditionPolicy.hpp index fb6e2fb..d7a83fd 100644 --- a/src/policy_classes/ConditionPolicy.hpp +++ b/src/policy_classes/ConditionPolicy.hpp @@ -25,8 +25,8 @@ namespace srcDispatch { struct ConditionData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector> conditions; diff --git a/src/policy_classes/ControlPolicy.hpp b/src/policy_classes/ControlPolicy.hpp index 5c9bdac..d38b540 100644 --- a/src/policy_classes/ControlPolicy.hpp +++ b/src/policy_classes/ControlPolicy.hpp @@ -27,8 +27,8 @@ namespace srcDispatch { struct ControlData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> init; DeltaElement> condition; diff --git a/src/policy_classes/DeclPolicy.hpp b/src/policy_classes/DeclPolicy.hpp index 4c090ba..70f3c2b 100644 --- a/src/policy_classes/DeclPolicy.hpp +++ b/src/policy_classes/DeclPolicy.hpp @@ -26,8 +26,8 @@ namespace srcDispatch { struct DeclData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector>> generics; DeltaElement accessSpecifier; diff --git a/src/policy_classes/DeclStmtPolicy.hpp b/src/policy_classes/DeclStmtPolicy.hpp index 5bd9ffe..75ddd7a 100644 --- a/src/policy_classes/DeclStmtPolicy.hpp +++ b/src/policy_classes/DeclStmtPolicy.hpp @@ -21,8 +21,8 @@ namespace srcDispatch { struct DeclStmtData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector>> decls; diff --git a/src/policy_classes/DeltaElement.hpp b/src/policy_classes/DeltaElement.hpp index 04a8688..07df39c 100644 --- a/src/policy_classes/DeltaElement.hpp +++ b/src/policy_classes/DeltaElement.hpp @@ -10,7 +10,7 @@ #ifndef INCLUDED_DELTA_ELEMENT_HPP #define INCLUDED_DELTA_ELEMENT_HPP -#include +#include #include #include diff --git a/src/policy_classes/Diff.hpp b/src/policy_classes/Diff.hpp new file mode 100644 index 0000000..eb0bebe --- /dev/null +++ b/src/policy_classes/Diff.hpp @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-3.0-only +/** + * @file Diff.hpp + * + * @copyright Copyright (C) 2025-2025 srcML, LLC. (www.srcML.org) + * + * This file is part of the srcML Infrastructure. + */ + +#ifndef INCLUDED_DIFF_HPP +#define INCLUDED_DIFF_HPP + +namespace srcDispatch { + +enum DiffOperation { COMMON, DELETE, INSERT, CHANGE, NONE }; +struct Diff { + Diff(DiffOperation operation, size_t depth = 0, bool isReplace = false, bool isConvert = false) + : operation(operation), depth(depth), isReplace(isReplace), isConvert(isConvert) {} + + DiffOperation operation; + size_t depth; + bool isReplace; + bool isConvert; +}; + +} + +#endif diff --git a/src/policy_classes/DoPolicy.hpp b/src/policy_classes/DoPolicy.hpp index 47484b4..045c493 100644 --- a/src/policy_classes/DoPolicy.hpp +++ b/src/policy_classes/DoPolicy.hpp @@ -22,8 +22,8 @@ namespace srcDispatch { struct DoData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> condition; DeltaElement> block; diff --git a/src/policy_classes/ElseIfPolicy.hpp b/src/policy_classes/ElseIfPolicy.hpp index 2e1b66f..363467e 100644 --- a/src/policy_classes/ElseIfPolicy.hpp +++ b/src/policy_classes/ElseIfPolicy.hpp @@ -22,8 +22,8 @@ namespace srcDispatch { struct ElseIfData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> condition; DeltaElement> block; diff --git a/src/policy_classes/ElsePolicy.hpp b/src/policy_classes/ElsePolicy.hpp index 02e1c6a..b159bf5 100644 --- a/src/policy_classes/ElsePolicy.hpp +++ b/src/policy_classes/ElsePolicy.hpp @@ -22,8 +22,8 @@ namespace srcDispatch { struct ElseData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> condition; DeltaElement> block; diff --git a/src/policy_classes/ExprStmtPolicy.hpp b/src/policy_classes/ExprStmtPolicy.hpp index b29945d..03291df 100644 --- a/src/policy_classes/ExprStmtPolicy.hpp +++ b/src/policy_classes/ExprStmtPolicy.hpp @@ -23,8 +23,8 @@ namespace srcDispatch { struct ExprStmtData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> expr; diff --git a/src/policy_classes/ExpressionPolicy.hpp b/src/policy_classes/ExpressionPolicy.hpp index 5e524ae..b16cd19 100644 --- a/src/policy_classes/ExpressionPolicy.hpp +++ b/src/policy_classes/ExpressionPolicy.hpp @@ -37,8 +37,8 @@ namespace srcDispatch { struct ExpressionData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector> expr; diff --git a/src/policy_classes/ForPolicy.hpp b/src/policy_classes/ForPolicy.hpp index 688be07..ea8032e 100644 --- a/src/policy_classes/ForPolicy.hpp +++ b/src/policy_classes/ForPolicy.hpp @@ -28,8 +28,8 @@ namespace srcDispatch { struct ForData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> control; DeltaElement> block; diff --git a/src/policy_classes/FunctionPolicy.hpp b/src/policy_classes/FunctionPolicy.hpp index a23a283..42603c7 100644 --- a/src/policy_classes/FunctionPolicy.hpp +++ b/src/policy_classes/FunctionPolicy.hpp @@ -36,8 +36,8 @@ namespace srcDispatch { // std::vector> namespaces; std::vector namespaces; - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::string language; std::string filename; diff --git a/src/policy_classes/GenericArgumentsPolicy.hpp b/src/policy_classes/GenericArgumentsPolicy.hpp index 603f8aa..8da3646 100644 --- a/src/policy_classes/GenericArgumentsPolicy.hpp +++ b/src/policy_classes/GenericArgumentsPolicy.hpp @@ -22,8 +22,8 @@ namespace srcDispatch { struct GenericArgumentsData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector>> arguments; diff --git a/src/policy_classes/GenericPolicy.hpp b/src/policy_classes/GenericPolicy.hpp index 0223f7e..acb20c2 100644 --- a/src/policy_classes/GenericPolicy.hpp +++ b/src/policy_classes/GenericPolicy.hpp @@ -27,8 +27,8 @@ namespace srcDispatch { struct GenericData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector>> parameters; diff --git a/src/policy_classes/GotoPolicy.hpp b/src/policy_classes/GotoPolicy.hpp index 3c6618b..58e7c22 100644 --- a/src/policy_classes/GotoPolicy.hpp +++ b/src/policy_classes/GotoPolicy.hpp @@ -26,8 +26,8 @@ namespace srcDispatch { struct GotoData { enum GotoType { GOTO, BREAK, CONTINUE }; - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement type; DeltaElement> label; diff --git a/src/policy_classes/IfPolicy.hpp b/src/policy_classes/IfPolicy.hpp index a956f93..89885c1 100644 --- a/src/policy_classes/IfPolicy.hpp +++ b/src/policy_classes/IfPolicy.hpp @@ -22,8 +22,8 @@ namespace srcDispatch { struct IfData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> condition; DeltaElement> block; diff --git a/src/policy_classes/IfStmtPolicy.hpp b/src/policy_classes/IfStmtPolicy.hpp index d074931..f771d47 100644 --- a/src/policy_classes/IfStmtPolicy.hpp +++ b/src/policy_classes/IfStmtPolicy.hpp @@ -26,8 +26,8 @@ namespace srcDispatch { struct IfStmtData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector> clauses; diff --git a/src/policy_classes/IncrPolicy.hpp b/src/policy_classes/IncrPolicy.hpp index 1d3459d..5978498 100644 --- a/src/policy_classes/IncrPolicy.hpp +++ b/src/policy_classes/IncrPolicy.hpp @@ -25,8 +25,8 @@ namespace srcDispatch { struct IncrData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector>> exprs; diff --git a/src/policy_classes/InitPolicy.hpp b/src/policy_classes/InitPolicy.hpp index e0860d5..7d66c0f 100644 --- a/src/policy_classes/InitPolicy.hpp +++ b/src/policy_classes/InitPolicy.hpp @@ -25,8 +25,8 @@ namespace srcDispatch { struct InitData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector> inits; diff --git a/src/policy_classes/LabelPolicy.hpp b/src/policy_classes/LabelPolicy.hpp index d23fdcf..44c5171 100644 --- a/src/policy_classes/LabelPolicy.hpp +++ b/src/policy_classes/LabelPolicy.hpp @@ -25,8 +25,8 @@ namespace srcDispatch { struct LabelData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> name; diff --git a/src/policy_classes/LiteralPolicy.hpp b/src/policy_classes/LiteralPolicy.hpp index c207b8e..d6a8721 100644 --- a/src/policy_classes/LiteralPolicy.hpp +++ b/src/policy_classes/LiteralPolicy.hpp @@ -22,8 +22,8 @@ namespace srcDispatch { struct LiteralData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement literal; diff --git a/src/policy_classes/NamePolicy.hpp b/src/policy_classes/NamePolicy.hpp index 4f8bd8d..4047f44 100644 --- a/src/policy_classes/NamePolicy.hpp +++ b/src/policy_classes/NamePolicy.hpp @@ -29,8 +29,8 @@ namespace srcDispatch { struct NameData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement name; std::vector> names; diff --git a/src/policy_classes/OperatorPolicy.hpp b/src/policy_classes/OperatorPolicy.hpp index 0279c23..f509b1e 100644 --- a/src/policy_classes/OperatorPolicy.hpp +++ b/src/policy_classes/OperatorPolicy.hpp @@ -22,8 +22,8 @@ namespace srcDispatch { struct OperatorData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement op; diff --git a/src/policy_classes/ReturnPolicy.hpp b/src/policy_classes/ReturnPolicy.hpp index 3c8d799..1bbb4e7 100644 --- a/src/policy_classes/ReturnPolicy.hpp +++ b/src/policy_classes/ReturnPolicy.hpp @@ -24,8 +24,8 @@ namespace srcDispatch { struct ReturnData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> expr; diff --git a/src/policy_classes/SwitchPolicy.hpp b/src/policy_classes/SwitchPolicy.hpp index 9121d39..910479a 100644 --- a/src/policy_classes/SwitchPolicy.hpp +++ b/src/policy_classes/SwitchPolicy.hpp @@ -22,8 +22,8 @@ namespace srcDispatch { struct SwitchData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> condition; DeltaElement> block; diff --git a/src/policy_classes/ThrowPolicy.hpp b/src/policy_classes/ThrowPolicy.hpp index 0e86c4b..0206288 100644 --- a/src/policy_classes/ThrowPolicy.hpp +++ b/src/policy_classes/ThrowPolicy.hpp @@ -24,8 +24,8 @@ namespace srcDispatch { struct ThrowData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> expr; diff --git a/src/policy_classes/TryPolicy.hpp b/src/policy_classes/TryPolicy.hpp index 29a7ad6..5538387 100644 --- a/src/policy_classes/TryPolicy.hpp +++ b/src/policy_classes/TryPolicy.hpp @@ -26,8 +26,8 @@ namespace srcDispatch { struct TryData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> block; std::vector> clauses; diff --git a/src/policy_classes/TypePolicy.hpp b/src/policy_classes/TypePolicy.hpp index 82bbb04..1900a14 100644 --- a/src/policy_classes/TypePolicy.hpp +++ b/src/policy_classes/TypePolicy.hpp @@ -23,8 +23,8 @@ namespace srcDispatch { struct TypeData { enum TypeType : int { TYPENAME, POINTER, REFERENCE, RVALUE, SPECIFIER, NONE }; - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector, DeltaElement>> types; diff --git a/src/policy_classes/UnitPolicy.hpp b/src/policy_classes/UnitPolicy.hpp index 85a5e96..5e361d8 100644 --- a/src/policy_classes/UnitPolicy.hpp +++ b/src/policy_classes/UnitPolicy.hpp @@ -32,8 +32,8 @@ namespace srcDispatch { struct UnitData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; std::vector>> classInfo; std::vector>> functionInfo; diff --git a/src/policy_classes/WhilePolicy.hpp b/src/policy_classes/WhilePolicy.hpp index 809a327..f7da257 100644 --- a/src/policy_classes/WhilePolicy.hpp +++ b/src/policy_classes/WhilePolicy.hpp @@ -22,8 +22,8 @@ namespace srcDispatch { struct WhileData { - unsigned int startLineNumber; - unsigned int endLineNumber; + DeltaElement startLineNumber; + DeltaElement endLineNumber; DeltaElement> condition; DeltaElement> block; From 28719de3d9f69b54f0c928aa2f523cfc2ede9837 Mon Sep 17 00:00:00 2001 From: "Michael J. Decker, Ph.D." Date: Fri, 4 Jul 2025 15:11:18 +0900 Subject: [PATCH 148/149] Remove warnings and fix style issues --- src/dispatcher/srcDispatchUtilities.hpp | 58 +++++++++++----------- src/policy_classes/ConvertPlexerPolicy.hpp | 13 +++-- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/dispatcher/srcDispatchUtilities.hpp b/src/dispatcher/srcDispatchUtilities.hpp index 7811dec..5cd6510 100644 --- a/src/dispatcher/srcDispatchUtilities.hpp +++ b/src/dispatcher/srcDispatchUtilities.hpp @@ -81,8 +81,8 @@ namespace srcDispatch { isOperator(false), endArchive(false) {} - ~srcSAXEventContext(){ - if(writer){ + ~srcSAXEventContext() { + if(writer) { xmlBufferFree(archiveBuffer); xmlFreeTextWriter(writer); } @@ -160,58 +160,58 @@ namespace srcDispatch { xmlTextWriterWriteString(writer, (const xmlChar *)text); } } - inline bool And(const std::vector vec) const{ - for(auto field : vec){ + inline bool And(const std::vector vec) const { + for(auto field : vec) { if(triggerField[field]) continue; else return false; } return true; } - inline bool Nand(const std::vector vec) const{ - for(auto field : vec){ + inline bool Nand(const std::vector vec) const { + for(auto field : vec) { if(triggerField[field]) return false; else continue; } return true; } - inline bool Or(const std::vector vec) const{ - for(auto field : vec){ + inline bool Or(const std::vector vec) const { + for(auto field : vec) { if(triggerField[field]) return true; else continue; } return false; } - inline bool Nor(const std::vector vec) const{ - for(auto field : vec){ + inline bool Nor(const std::vector vec) const { + for(auto field : vec) { if(triggerField[field]) return false; else continue; } return true; } - inline bool IsEqualTo(const ParserState lhs, const ParserState rhs) const{ + inline bool IsEqualTo(const ParserState lhs, const ParserState rhs) const { return triggerField[lhs] == triggerField[rhs] ? true : false; } - inline bool IsGreaterThan(const ParserState lhs, const ParserState rhs) const{ + inline bool IsGreaterThan(const ParserState lhs, const ParserState rhs) const { return triggerField[lhs] > triggerField[rhs] ? true : false; } - inline bool IsGreaterThanOrEqualTo(const ParserState lhs, const ParserState rhs) const{ + inline bool IsGreaterThanOrEqualTo(const ParserState lhs, const ParserState rhs) const { return triggerField[lhs] >= triggerField[rhs] ? true : false; } - inline bool IsLessThan(const ParserState lhs, const ParserState rhs) const{ + inline bool IsLessThan(const ParserState lhs, const ParserState rhs) const { return triggerField[lhs] < triggerField[rhs] ? true : false; } - inline bool IsLessThanOrEqualTo(const ParserState lhs, const ParserState rhs) const{ + inline bool IsLessThanOrEqualTo(const ParserState lhs, const ParserState rhs) const { return triggerField[lhs] <= triggerField[rhs] ? true : false; } - inline bool IsOpen(const ParserState field) const{ + inline bool IsOpen(const ParserState field) const { if(triggerField[field]) return true; else return false; } - inline bool IsClosed(const ParserState field) const{ + inline bool IsClosed(const ParserState field) const { if(triggerField[field]) return false; else return true; } - inline unsigned int NumCurrentlyOpen(const ParserState field){ + inline unsigned int NumCurrentlyOpen(const ParserState field) { return triggerField[field]; } }; @@ -230,7 +230,7 @@ namespace srcDispatch { public: - EventListener() : depth(0), dispatched(false){ + EventListener() : depth(0), dispatched(false) { DefaultEventHandlers(); } @@ -248,11 +248,11 @@ namespace srcDispatch { dispatched = true; - switch(estate){ + switch(estate) { case srcDispatch::ElementState::open: { auto event = openEventMap.find(pstate); - if(event != openEventMap.end()){ + if(event != openEventMap.end()) { event->second(ctx); } break; @@ -260,7 +260,7 @@ namespace srcDispatch { case srcDispatch::ElementState::close: { auto event = closeEventMap.find(pstate); - if(event != closeEventMap.end()){ + if(event != closeEventMap.end()) { event->second(ctx); } break; @@ -303,7 +303,7 @@ namespace srcDispatch { virtual void RemoveListener(EventListener* l) = 0; virtual void RemoveListenerDispatch(EventListener* listener) = 0; virtual void RemoveListenerNoDispatch(EventListener* listener) = 0; - xmlBufferPtr GetXmlBuffer(){return ctx.archiveBuffer;} + xmlBufferPtr GetXmlBuffer() {return ctx.archiveBuffer;} protected: srcSAXEventContext ctx; std::list elementListeners; @@ -348,14 +348,14 @@ namespace srcDispatch { virtual void Notify(const PolicyDispatcher* policy, const srcSAXEventContext& ctx) = 0; virtual void NotifyWrite(const PolicyDispatcher* policy, srcSAXEventContext& ctx) = 0; }; - class PolicyDispatcher{ + class PolicyDispatcher { public: - PolicyDispatcher(std::initializer_list listeners) : policyListeners(listeners){} + PolicyDispatcher(std::initializer_list listeners) : policyListeners(listeners) {} virtual ~PolicyDispatcher() {} - virtual void AddListener(PolicyListener* listener){ + virtual void AddListener(PolicyListener* listener) { policyListeners.push_back(listener); } - virtual void RemoveListener(PolicyListener* listener){ + virtual void RemoveListener(PolicyListener* listener) { policyListeners.erase(std::find(policyListeners.begin(), policyListeners.end(), listener)); } @@ -369,10 +369,10 @@ namespace srcDispatch { virtual std::any DataInner() const = 0; //TODO: These may not need to be synchronous or even called in the same method (i.e., notifyall) virtual void NotifyAll(/*const*/ srcSAXEventContext& ctx) { - for(std::list::iterator listener = policyListeners.begin(); listener != policyListeners.end(); ++listener){ + for(std::list::iterator listener = policyListeners.begin(); listener != policyListeners.end(); ++listener) { (*listener)->Notify(this, ctx); } - for(std::list::iterator listener = policyListeners.begin(); listener != policyListeners.end(); ++listener){ + for(std::list::iterator listener = policyListeners.begin(); listener != policyListeners.end(); ++listener) { (*listener)->NotifyWrite(this, ctx); } diff --git a/src/policy_classes/ConvertPlexerPolicy.hpp b/src/policy_classes/ConvertPlexerPolicy.hpp index 394100e..d4de843 100644 --- a/src/policy_classes/ConvertPlexerPolicy.hpp +++ b/src/policy_classes/ConvertPlexerPolicy.hpp @@ -46,13 +46,12 @@ namespace srcDispatch { protected: ConvertData data; - std::stack dispatcherStack; + std::stack dispatcherStack; + std::stack dispatchingState; std::unique_ptr originalPolicy; std::unique_ptr modifiedPolicy; - std::stack dispatchingState; - std::stack originalPolicyStack; std::stack modifiedPolicyStack; public: @@ -80,6 +79,14 @@ namespace srcDispatch { dispatcherStack.top()->GetContext().dispatcher = currentDispatcher; } + virtual void AddListener(PolicyListener* listener) override { + PolicyDispatcher::AddListener(listener); + } + + virtual void RemoveListener(PolicyListener* listener) override { + PolicyDispatcher::RemoveListener(listener); + } + virtual void AddListener(EventListener* listener) override { #ifdef CONVERT_DEBUG std::cerr << "ADD: " << std::string(index * 4, ' ') << index << ' ' << __LINE__ << ' ' << dispatchingState.top() << '\n'; From 97a27adebf8bbc0b285e44ed8856a74717519cb2 Mon Sep 17 00:00:00 2001 From: jsipahio Date: Fri, 11 Jul 2025 14:24:41 -0400 Subject: [PATCH 149/149] Corresponds to issue 39. Added vector for class specifiers and a visibility field --- src/policy_classes/ClassPolicy.hpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/policy_classes/ClassPolicy.hpp b/src/policy_classes/ClassPolicy.hpp index 5b9e444..223b83c 100644 --- a/src/policy_classes/ClassPolicy.hpp +++ b/src/policy_classes/ClassPolicy.hpp @@ -47,6 +47,7 @@ namespace srcDispatch { DeltaElement type; DeltaElement> name; std::vector>> parents; + DeltaElement visibility; std::vector>> fields; std::vector>> constructors; @@ -56,6 +57,8 @@ namespace srcDispatch { std::vector>> methods; std::vector>> innerClasses; + std::vector>> specifiers; + DeltaElement isAbstract; }; @@ -168,6 +171,7 @@ namespace srcDispatch { CollectNameHandlers(); CollectSuperHanders(); CollectBlockHanders(); + CollectSpecifierHandlers(); } else { if(ctx.diffStack.back().isConvert && ctx.diffStack.back().operation == srcDispatch::INSERT) { @@ -342,6 +346,25 @@ namespace srcDispatch { NopCloseEvents({ParserState::block}); }; } + + void CollectSpecifierHandlers() { + using namespace srcDispatch; + closeEventMap[ParserState::tokenstring] = [this](srcSAXEventContext& ctx) { + if (!depth) return; + + if (ctx.And({ParserState::specifier})) { + if (ctx.currentToken == "public") { + data.visibility.Update(ctx.diffStack.back().operation, AccessSpecifier::PUBLIC); + } else if (ctx.currentToken == "private") { + data.visibility.Update(ctx.diffStack.back().operation, AccessSpecifier::PRIVATE); + } else if (ctx.currentToken == "protected") { + data.visibility.Update(ctx.diffStack.back().operation, AccessSpecifier::PROTECTED); + } else { + data.specifiers.emplace_back(ctx.diffStack.back().operation, std::make_shared(ctx.currentToken)); + } + } + }; + } }; }