Poincare: The rules compiler checks for wildcard consistency

Change-Id: I9de57987b10fced3f1e63358b9d0158f97c3db15
This commit is contained in:
Romain Goyet
2016-03-31 18:59:46 +02:00
parent ed2c4cfb59
commit 9125033d90
3 changed files with 7 additions and 1 deletions

View File

@@ -9,6 +9,9 @@ Node::Node(std::string * name, std::vector<Node *> * children) :
if (children == nullptr) {
m_children = new std::vector<Node *>();
}
for (Node * child : *m_children) {
child->m_parent = this;
}
}
Node::~Node() {

View File

@@ -15,9 +15,9 @@ public:
int flatIndexOfChildNamed(std::string name);
protected:
virtual void generateFields(Rule * context, std::string &indentation) = 0;
protected:
std::string * m_name;
std::vector<Node *> * m_children;
Node * m_parent;
};
#endif

View File

@@ -9,12 +9,15 @@ Selector::Selector(Type type, std::string * name, std::vector<Selector *> * chil
}
void Selector::generateFields(Rule * context, std::string &indentation) {
Selector * parent = (Selector *)m_parent;
switch (m_type) {
case Type::Variable:
std::cout << indentation << ".m_match = ExpressionSelector::Match::Any," << std::endl;
break;
case Type::Wildcard:
std::cout << indentation << ".m_match = ExpressionSelector::Match::Wildcard," << std::endl;
// Wildcard should always be the last element of a parent
assert(parent->m_children->back() == this);
break;
case Type::ExpressionType:
std::cout << indentation << ".m_match = ExpressionSelector::Match::TypeAndValue," << std::endl;