From 1de0486989afc5edbc991fd1e68bbbd614d02426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Tue, 30 May 2017 18:13:31 +0200 Subject: [PATCH] Removed unnecessary namespace identifiers. --- include/anthem/ASTUtils.h | 14 ++++----- include/anthem/ASTVisitors.h | 47 +++++++++++++--------------- src/anthem/ASTCopy.cpp | 16 +++++----- src/anthem/ASTUtils.cpp | 60 ++++++++++++++++++------------------ 4 files changed, 67 insertions(+), 70 deletions(-) diff --git a/include/anthem/ASTUtils.h b/include/anthem/ASTUtils.h index d9d0af6..2bc4042 100644 --- a/include/anthem/ASTUtils.h +++ b/include/anthem/ASTUtils.h @@ -20,14 +20,14 @@ namespace ast class VariableStack { public: - using Layer = ast::VariableDeclarationPointers *; + using Layer = VariableDeclarationPointers *; public: void push(Layer layer); void pop(); - std::experimental::optional findUserVariableDeclaration(const char *variableName) const; - bool contains(const ast::VariableDeclaration &variableDeclaration) const; + std::experimental::optional findUserVariableDeclaration(const char *variableName) const; + bool contains(const VariableDeclaration &variableDeclaration) const; private: std::vector m_layers; @@ -35,11 +35,11 @@ class VariableStack //////////////////////////////////////////////////////////////////////////////////////////////////// -std::vector collectFreeVariables(ast::Formula &formula); -std::vector collectFreeVariables(ast::Formula &formula, ast::VariableStack &variableStack); +std::vector collectFreeVariables(Formula &formula); +std::vector collectFreeVariables(Formula &formula, VariableStack &variableStack); -bool matches(const ast::Predicate &lhs, const ast::Predicate &rhs); -void collectPredicates(const ast::Formula &formula, std::vector &predicates); +bool matches(const Predicate &lhs, const Predicate &rhs); +void collectPredicates(const Formula &formula, std::vector &predicates); //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/include/anthem/ASTVisitors.h b/include/anthem/ASTVisitors.h index bdca776..f651741 100644 --- a/include/anthem/ASTVisitors.h +++ b/include/anthem/ASTVisitors.h @@ -5,6 +5,8 @@ namespace anthem { +namespace ast +{ //////////////////////////////////////////////////////////////////////////////////////////////////// // @@ -12,16 +14,11 @@ namespace anthem // //////////////////////////////////////////////////////////////////////////////////////////////////// -namespace ast -{ - -//////////////////////////////////////////////////////////////////////////////////////////////////// - template struct RecursiveFormulaVisitor { template - void visit(ast::And &and_, ast::Formula &formula, Arguments &&... arguments) + void visit(And &and_, Formula &formula, Arguments &&... arguments) { for (auto &argument : and_.arguments) argument.accept(*this, argument, std::forward(arguments)...); @@ -30,7 +27,7 @@ struct RecursiveFormulaVisitor } template - void visit(ast::Biconditional &biconditional, ast::Formula &formula, Arguments &&... arguments) + void visit(Biconditional &biconditional, Formula &formula, Arguments &&... arguments) { biconditional.left.accept(*this, biconditional.left, std::forward(arguments)...); biconditional.right.accept(*this, biconditional.right, std::forward(arguments)...); @@ -39,19 +36,19 @@ struct RecursiveFormulaVisitor } template - void visit(ast::Boolean &boolean, ast::Formula &formula, Arguments &&... arguments) + void visit(Boolean &boolean, Formula &formula, Arguments &&... arguments) { return T::accept(boolean, formula, std::forward(arguments)...); } template - void visit(ast::Comparison &comparison, ast::Formula &formula, Arguments &&... arguments) + void visit(Comparison &comparison, Formula &formula, Arguments &&... arguments) { return T::accept(comparison, formula, std::forward(arguments)...); } template - void visit(ast::Exists &exists, ast::Formula &formula, Arguments &&... arguments) + void visit(Exists &exists, Formula &formula, Arguments &&... arguments) { exists.argument.accept(*this, exists.argument, std::forward(arguments)...); @@ -59,7 +56,7 @@ struct RecursiveFormulaVisitor } template - void visit(ast::ForAll &forAll, ast::Formula &formula, Arguments &&... arguments) + void visit(ForAll &forAll, Formula &formula, Arguments &&... arguments) { forAll.argument.accept(*this, forAll.argument, std::forward(arguments)...); @@ -67,7 +64,7 @@ struct RecursiveFormulaVisitor } template - void visit(ast::Implies &implies, ast::Formula &formula, Arguments &&... arguments) + void visit(Implies &implies, Formula &formula, Arguments &&... arguments) { implies.antecedent.accept(*this, implies.antecedent, std::forward(arguments)...); implies.consequent.accept(*this, implies.consequent, std::forward(arguments)...); @@ -76,13 +73,13 @@ struct RecursiveFormulaVisitor } template - void visit(ast::In &in, ast::Formula &formula, Arguments &&... arguments) + void visit(In &in, Formula &formula, Arguments &&... arguments) { return T::accept(in, formula, std::forward(arguments)...); } template - void visit(ast::Not ¬_, ast::Formula &formula, Arguments &&... arguments) + void visit(Not ¬_, Formula &formula, Arguments &&... arguments) { not_.argument.accept(*this, not_.argument, std::forward(arguments)...); @@ -90,7 +87,7 @@ struct RecursiveFormulaVisitor } template - void visit(ast::Or &or_, ast::Formula &formula, Arguments &&... arguments) + void visit(Or &or_, Formula &formula, Arguments &&... arguments) { for (auto &argument : or_.arguments) argument.accept(*this, argument, std::forward(arguments)...); @@ -99,7 +96,7 @@ struct RecursiveFormulaVisitor } template - void visit(ast::Predicate &predicate, ast::Formula &formula, Arguments &&... arguments) + void visit(Predicate &predicate, Formula &formula, Arguments &&... arguments) { return T::accept(predicate, formula, std::forward(arguments)...); } @@ -112,7 +109,7 @@ struct RecursiveTermVisitor { // TODO: return type is incorrect template - void visit(ast::BinaryOperation &binaryOperation, ast::Term &term, Arguments &&... arguments) + void visit(BinaryOperation &binaryOperation, Term &term, Arguments &&... arguments) { binaryOperation.left.accept(*this, binaryOperation.left, std::forward(arguments)...); binaryOperation.right.accept(*this, binaryOperation.left, std::forward(arguments)...); @@ -121,19 +118,19 @@ struct RecursiveTermVisitor } template - void visit(ast::Boolean &boolean, ast::Term &term, Arguments &&... arguments) + void visit(Boolean &boolean, Term &term, Arguments &&... arguments) { return T::accept(boolean, term, std::forward(arguments)...); } template - void visit(ast::Constant &constant, ast::Term &term, Arguments &&... arguments) + void visit(Constant &constant, Term &term, Arguments &&... arguments) { return T::accept(constant, term, std::forward(arguments)...); } template - void visit(ast::Function &function, ast::Term &term, Arguments &&... arguments) + void visit(Function &function, Term &term, Arguments &&... arguments) { for (auto &argument : function.arguments) argument.accept(*this, argument, std::forward(arguments)...); @@ -142,13 +139,13 @@ struct RecursiveTermVisitor } template - void visit(ast::Integer &integer, ast::Term &term, Arguments &&... arguments) + void visit(Integer &integer, Term &term, Arguments &&... arguments) { return T::accept(integer, term, std::forward(arguments)...); } template - void visit(ast::Interval &interval, ast::Term &term, Arguments &&... arguments) + void visit(Interval &interval, Term &term, Arguments &&... arguments) { interval.from.accept(*this, interval.from, std::forward(arguments)...); interval.to.accept(*this, interval.to, std::forward(arguments)...); @@ -157,19 +154,19 @@ struct RecursiveTermVisitor } template - void visit(ast::SpecialInteger &specialInteger, ast::Term &term, Arguments &&... arguments) + void visit(SpecialInteger &specialInteger, Term &term, Arguments &&... arguments) { return T::accept(specialInteger, term, std::forward(arguments)...); } template - void visit(ast::String &string, ast::Term &term, Arguments &&... arguments) + void visit(String &string, Term &term, Arguments &&... arguments) { return T::accept(string, term, std::forward(arguments)...); } template - void visit(ast::Variable &variable, ast::Term &term, Arguments &&... arguments) + void visit(Variable &variable, Term &term, Arguments &&... arguments) { return T::accept(variable, term, std::forward(arguments)...); } diff --git a/src/anthem/ASTCopy.cpp b/src/anthem/ASTCopy.cpp index 79dcff5..8be5da7 100644 --- a/src/anthem/ASTCopy.cpp +++ b/src/anthem/ASTCopy.cpp @@ -21,9 +21,9 @@ namespace ast //////////////////////////////////////////////////////////////////////////////////////////////////// // Replaces all occurrences of a variable in a given term with another term -struct ReplaceVariableInTermVisitor : public ast::RecursiveTermVisitor +struct ReplaceVariableInTermVisitor : public RecursiveTermVisitor { - static void accept(ast::Variable &variable, ast::Term &, const ast::VariableDeclaration *original, ast::VariableDeclaration *replacement) + static void accept(Variable &variable, Term &, const VariableDeclaration *original, VariableDeclaration *replacement) { if (variable.declaration == original) variable.declaration = replacement; @@ -31,7 +31,7 @@ struct ReplaceVariableInTermVisitor : public ast::RecursiveTermVisitor - static void accept(T &, ast::Term &, const ast::VariableDeclaration *, ast::VariableDeclaration *) + static void accept(T &, Term &, const VariableDeclaration *, VariableDeclaration *) { } }; @@ -39,21 +39,21 @@ struct ReplaceVariableInTermVisitor : public ast::RecursiveTermVisitor +struct ReplaceVariableInFormulaVisitor : public RecursiveFormulaVisitor { - static void accept(ast::Comparison &comparison, ast::Formula &, const ast::VariableDeclaration *original, ast::VariableDeclaration *replacement) + static void accept(Comparison &comparison, Formula &, const VariableDeclaration *original, VariableDeclaration *replacement) { comparison.left.accept(ReplaceVariableInTermVisitor(), comparison.left, original, replacement); comparison.right.accept(ReplaceVariableInTermVisitor(), comparison.right, original, replacement); } - static void accept(ast::In &in, ast::Formula &, const ast::VariableDeclaration *original, ast::VariableDeclaration *replacement) + static void accept(In &in, Formula &, const VariableDeclaration *original, VariableDeclaration *replacement) { in.element.accept(ReplaceVariableInTermVisitor(), in.element, original, replacement); in.set.accept(ReplaceVariableInTermVisitor(), in.set, original, replacement); } - static void accept(ast::Predicate &predicate, ast::Formula &, const ast::VariableDeclaration *original, ast::VariableDeclaration *replacement) + static void accept(Predicate &predicate, Formula &, const VariableDeclaration *original, VariableDeclaration *replacement) { for (auto &argument : predicate.arguments) argument.accept(ReplaceVariableInTermVisitor(), argument, original, replacement); @@ -61,7 +61,7 @@ struct ReplaceVariableInFormulaVisitor : public ast::RecursiveFormulaVisitor - static void accept(T &, ast::Formula &, const ast::VariableDeclaration *, ast::VariableDeclaration *) + static void accept(T &, Formula &, const VariableDeclaration *, VariableDeclaration *) { } }; diff --git a/src/anthem/ASTUtils.cpp b/src/anthem/ASTUtils.cpp index 0cc7c86..2faed08 100644 --- a/src/anthem/ASTUtils.cpp +++ b/src/anthem/ASTUtils.cpp @@ -27,7 +27,7 @@ void VariableStack::pop() //////////////////////////////////////////////////////////////////////////////////////////////////// -std::experimental::optional VariableStack::findUserVariableDeclaration(const char *variableName) const +std::experimental::optional VariableStack::findUserVariableDeclaration(const char *variableName) const { const auto variableDeclarationMatches = [&variableName](const auto &variableDeclaration) @@ -50,7 +50,7 @@ std::experimental::optional VariableStack::findUserV //////////////////////////////////////////////////////////////////////////////////////////////////// -bool VariableStack::contains(const ast::VariableDeclaration &variableDeclaration) const +bool VariableStack::contains(const VariableDeclaration &variableDeclaration) const { const auto variableDeclarationMatches = [&variableDeclaration](const auto &other) @@ -75,66 +75,66 @@ struct CollectFreeVariablesVisitor // Formulas //////////////////////////////////////////////////////////////////////////////////////////////// - void visit(ast::And &and_, VariableStack &variableStack, std::vector &freeVariables) + void visit(And &and_, VariableStack &variableStack, std::vector &freeVariables) { for (auto &argument : and_.arguments) argument.accept(*this, variableStack, freeVariables); } - void visit(ast::Biconditional &biconditional, VariableStack &variableStack, std::vector &freeVariables) + void visit(Biconditional &biconditional, VariableStack &variableStack, std::vector &freeVariables) { biconditional.left.accept(*this, variableStack, freeVariables); biconditional.right.accept(*this, variableStack, freeVariables); } - void visit(ast::Boolean &, VariableStack &, std::vector &) + void visit(Boolean &, VariableStack &, std::vector &) { } - void visit(ast::Comparison &comparison, VariableStack &variableStack, std::vector &freeVariables) + void visit(Comparison &comparison, VariableStack &variableStack, std::vector &freeVariables) { comparison.left.accept(*this, variableStack, freeVariables); comparison.right.accept(*this, variableStack, freeVariables); } - void visit(ast::Exists &exists, VariableStack &variableStack, std::vector &freeVariables) + void visit(Exists &exists, VariableStack &variableStack, std::vector &freeVariables) { variableStack.push(&exists.variables); exists.argument.accept(*this, variableStack, freeVariables); variableStack.pop(); } - void visit(ast::ForAll &forAll, VariableStack &variableStack, std::vector &freeVariables) + void visit(ForAll &forAll, VariableStack &variableStack, std::vector &freeVariables) { variableStack.push(&forAll.variables); forAll.argument.accept(*this, variableStack, freeVariables); variableStack.pop(); } - void visit(ast::Implies &implies, VariableStack &variableStack, std::vector &freeVariables) + void visit(Implies &implies, VariableStack &variableStack, std::vector &freeVariables) { implies.antecedent.accept(*this, variableStack, freeVariables); implies.consequent.accept(*this, variableStack, freeVariables); } - void visit(ast::In &in, VariableStack &variableStack, std::vector &freeVariables) + void visit(In &in, VariableStack &variableStack, std::vector &freeVariables) { in.element.accept(*this, variableStack, freeVariables); in.set.accept(*this, variableStack, freeVariables); } - void visit(ast::Not ¬_, VariableStack &variableStack, std::vector &freeVariables) + void visit(Not ¬_, VariableStack &variableStack, std::vector &freeVariables) { not_.argument.accept(*this, variableStack, freeVariables); } - void visit(ast::Or &or_, VariableStack &variableStack, std::vector &freeVariables) + void visit(Or &or_, VariableStack &variableStack, std::vector &freeVariables) { for (auto &argument : or_.arguments) argument.accept(*this, variableStack, freeVariables); } - void visit(ast::Predicate &predicate, VariableStack &variableStack, std::vector &freeVariables) + void visit(Predicate &predicate, VariableStack &variableStack, std::vector &freeVariables) { for (auto &argument : predicate.arguments) argument.accept(*this, variableStack, freeVariables); @@ -144,41 +144,41 @@ struct CollectFreeVariablesVisitor // Terms //////////////////////////////////////////////////////////////////////////////////////////////// - void visit(ast::BinaryOperation &binaryOperation, VariableStack &variableStack, std::vector &freeVariables) + void visit(BinaryOperation &binaryOperation, VariableStack &variableStack, std::vector &freeVariables) { binaryOperation.left.accept(*this, variableStack, freeVariables); binaryOperation.right.accept(*this, variableStack, freeVariables); } - void visit(ast::Constant &, VariableStack &, std::vector &) + void visit(Constant &, VariableStack &, std::vector &) { } - void visit(ast::Function &function, VariableStack &variableStack, std::vector &freeVariables) + void visit(Function &function, VariableStack &variableStack, std::vector &freeVariables) { for (auto &argument : function.arguments) argument.accept(*this, variableStack, freeVariables); } - void visit(ast::Integer &, VariableStack &, std::vector &) + void visit(Integer &, VariableStack &, std::vector &) { } - void visit(ast::Interval &interval, VariableStack &variableStack, std::vector &freeVariables) + void visit(Interval &interval, VariableStack &variableStack, std::vector &freeVariables) { interval.from.accept(*this, variableStack, freeVariables); interval.to.accept(*this, variableStack, freeVariables); } - void visit(ast::SpecialInteger &, VariableStack &, std::vector &) + void visit(SpecialInteger &, VariableStack &, std::vector &) { } - void visit(ast::String &, VariableStack &, std::vector &) + void visit(String &, VariableStack &, std::vector &) { } - void visit(ast::Variable &variable, VariableStack &variableStack, std::vector &freeVariables) + void visit(Variable &variable, VariableStack &variableStack, std::vector &freeVariables) { if (variableStack.contains(*variable.declaration)) return; @@ -192,17 +192,17 @@ struct CollectFreeVariablesVisitor //////////////////////////////////////////////////////////////////////////////////////////////////// -std::vector collectFreeVariables(ast::Formula &formula) +std::vector collectFreeVariables(Formula &formula) { - ast::VariableStack variableStack; + VariableStack variableStack; return collectFreeVariables(formula, variableStack); } //////////////////////////////////////////////////////////////////////////////////////////////////// -std::vector collectFreeVariables(ast::Formula &formula, ast::VariableStack &variableStack) +std::vector collectFreeVariables(Formula &formula, VariableStack &variableStack) { - std::vector freeVariables; + std::vector freeVariables; formula.accept(CollectFreeVariablesVisitor(), variableStack, freeVariables); @@ -213,7 +213,7 @@ std::vector collectFreeVariables(ast::Formula &formu struct CollectPredicatesVisitor : public RecursiveFormulaVisitor { - static void accept(const ast::Predicate &predicate, const ast::Formula &, std::vector &predicates) + static void accept(const Predicate &predicate, const Formula &, std::vector &predicates) { const auto predicateMatches = [&predicate](const auto *otherPredicate) @@ -227,14 +227,14 @@ struct CollectPredicatesVisitor : public RecursiveFormulaVisitor - static void accept(const T &, const ast::Formula &, std::vector &) + static void accept(const T &, const Formula &, std::vector &) { } }; //////////////////////////////////////////////////////////////////////////////////////////////////// -bool matches(const ast::Predicate &lhs, const ast::Predicate &rhs) +bool matches(const Predicate &lhs, const Predicate &rhs) { return (lhs.name == rhs.name && lhs.arity() == rhs.arity()); } @@ -242,9 +242,9 @@ bool matches(const ast::Predicate &lhs, const ast::Predicate &rhs) //////////////////////////////////////////////////////////////////////////////////////////////////// // TODO: remove const_cast -void collectPredicates(const ast::Formula &formula, std::vector &predicates) +void collectPredicates(const Formula &formula, std::vector &predicates) { - auto &formulaMutable = const_cast(formula); + auto &formulaMutable = const_cast(formula); formulaMutable.accept(CollectPredicatesVisitor(), formulaMutable, predicates); }