From 7bca3d7e34ca5c2b1e939a001229c04fe6b6bde0 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 2 Jan 2015 12:12:00 +0100 Subject: Added argument validation to parser stack --- src/core/parser/ParserStack.hpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'src/core/parser/ParserStack.hpp') diff --git a/src/core/parser/ParserStack.hpp b/src/core/parser/ParserStack.hpp index 233f4f9..93180b4 100644 --- a/src/core/parser/ParserStack.hpp +++ b/src/core/parser/ParserStack.hpp @@ -38,6 +38,8 @@ #include #include +#include +#include #include "Parser.hpp" @@ -61,9 +63,6 @@ class Handler { private: Rooted node; -protected: - void setNode(Handle node) { this->node = node; } - public: /** * Reference to the ParserContext instance that should be used to resolve @@ -132,7 +131,7 @@ public: virtual void start(const Variant &args) = 0; /** - * Called whenever the command for which this handler + * Called whenever the command for which this handler is defined ends. */ virtual void end() = 0; @@ -153,7 +152,7 @@ public: * * @param handler is a reference at the child Handler instance. */ - virtual void child(std::shared_ptr handler){}; + virtual void child(std::shared_ptr handler); }; /** @@ -212,12 +211,34 @@ struct HandlerDescriptor { */ const bool arbitraryChildren; + /** + * Pointer pointing at a StructType describing the layout of the given when + * a new Handler instance is instantiated. + */ + const Rooted argsType; + + /** + * Constructor of the HandlerDescriptor class. + * + * @param parentStates is a set of states in which a new handler of this + * type may be instantiated. + * @param ctor is a function pointer pointing at a function that + * instantiates the acutal Handler instance. + * @param targetState is the state the ParserStack switches to after + * instantiating an in instance of the described Handler instances. + * @param arbitraryChildren allows the Handler instance to handle any child + * node. + * @param argsType is a struct type describing the arguments that can be + * passed to the Handler or nullptr if no check should be performed. + */ HandlerDescriptor(std::set parentStates, HandlerConstructor ctor, - State targetState, bool arbitraryChildren = false) + State targetState, bool arbitraryChildren = false, + Handle argsType = nullptr) : parentStates(std::move(parentStates)), ctor(ctor), targetState(targetState), - arbitraryChildren(arbitraryChildren) + arbitraryChildren(arbitraryChildren), + argsType(argsType) { } -- cgit v1.2.3