Skip to content
Snippets Groups Projects
Commit 0dd98ed3 authored by vincent  lorrain's avatar vincent lorrain
Browse files

Add doc

parent 666e3950
No related branches found
No related tags found
No related merge requests found
...@@ -83,17 +83,17 @@ struct ConditionalData { ...@@ -83,17 +83,17 @@ struct ConditionalData {
*/ */
template <typename T> template <typename T>
void setValue(const T& newValue) { void setValue(const T& newValue) {
// if (std::is_pointer<T>::value) { //make sure that the old value is free
// throw std::runtime_error("Pointer type not allowed."); deleteValue();
// }
deleteValue(); //the old one
//value = new Value<T>(newValue);
value = std::make_unique<ConditionalValue<T>>(newValue); value = std::make_unique<ConditionalValue<T>>(newValue);
type = &typeid(T); type = &typeid(T);
} }
/** /**
* @brief set a value for vetor * @brief get the actual value
* @details recaste the value to the templaited type and checks that the conversion type is compatible with type
* @tparam the type of the return value
* @return the value
*/ */
template <typename T> template <typename T>
T getValue() const { T getValue() const {
......
...@@ -20,13 +20,21 @@ namespace Aidge{ ...@@ -20,13 +20,21 @@ namespace Aidge{
////////////////////////////// //////////////////////////////
// //
///////////////////////////// /////////////////////////////
/**
* @brief class used to register any lambda function without context,
* it encapsulates the source lambda in a lambda which takes as argument ConditionalData* which are any type.
* @see ConditionalData
*/
class ConditionalRegisterFunction { class ConditionalRegisterFunction {
////////////////////////// //////////////////////////
//Safe recaste //Safe recaste
////////////////////////// //////////////////////////
/**
* @brief recaste the ConditionalData* to the argument type of the lambda
* @tparam T type of the lambda argument
* @see ConditionalData
*/
template <typename T> template <typename T>
T safeCastInput(ConditionalData* data) { T safeCastInput(ConditionalData* data) {
//cnvertion and type cheking //cnvertion and type cheking
...@@ -39,7 +47,11 @@ class ConditionalRegisterFunction { ...@@ -39,7 +47,11 @@ class ConditionalRegisterFunction {
} }
//convert the output of f to a ConditionalData* /**
* @brief recaste the output of the lambda to a ConditionalData*
* @tparam T type of the lambda return
* @see ConditionalData
*/
template <typename T> template <typename T>
ConditionalData* safeCastOutput(T data) { ConditionalData* safeCastOutput(T data) {
...@@ -129,7 +141,7 @@ class ConditionalRegisterFunction { ...@@ -129,7 +141,7 @@ class ConditionalRegisterFunction {
}; };
} }
/** /**
* @brief Converts a function pointer to a ConditionalData*(std::vector<ConditionalData*>). * @brief Converts a function pointer to a ConditionalData*(std::vector<ConditionalData*>).
* @tparam R The return type of the function. * @tparam R The return type of the function.
* @tparam Params The parameter types of the function. * @tparam Params The parameter types of the function.
...@@ -141,6 +153,13 @@ class ConditionalRegisterFunction { ...@@ -141,6 +153,13 @@ class ConditionalRegisterFunction {
return funcPointer(f, std::index_sequence_for<Params...>{}); return funcPointer(f, std::index_sequence_for<Params...>{});
} }
/**
* @brief Converts a std::function to a ConditionalData*(std::vector<ConditionalData*>).
* @tparam R The return type of the function.
* @tparam Params The parameter types of the function.
* @param f The function pointer to convert.
* @return The pointer to the converted function.
*/
template <class R,class... Params> template <class R,class... Params>
auto funcPointer(std::function<R(Params...)> f) { auto funcPointer(std::function<R(Params...)> f) {
return funcPointer(f, std::index_sequence_for<Params...>{}); return funcPointer(f, std::index_sequence_for<Params...>{});
...@@ -187,12 +206,27 @@ class ConditionalRegisterFunction { ...@@ -187,12 +206,27 @@ class ConditionalRegisterFunction {
/////////////////// ///////////////////
//AST tree node //AST tree node
// //////////////// // ////////////////
/**
* @brief this class interprets AST to generate a test on a graph node. For each AST node,
* it generates an interpretation and registers lambda functions that can be used in the test expression.
* there are two lambda control mechanisms:
* - A cpp mechanism which allows any lambda to be inserted into the constructor that use templaite
* - A user mechanism limited to lambda bool(NodePtr)
* @see ConditionalParser use to get the AST
*/
class ConditionalInterpreter class ConditionalInterpreter
{ {
private: private:
/**
* @brief the AST generate by the Parser
* @see ConditionalParser
*/
std::shared_ptr<Aidge::AstConditionalNode> mTree; std::shared_ptr<Aidge::AstConditionalNode> mTree;
/**
* @brief the registery for the lambda fuction
* @see ConditionalRegisterFunction
*/
ConditionalRegisterFunction mLambdaRegiter; ConditionalRegisterFunction mLambdaRegiter;
public: public:
...@@ -206,13 +240,16 @@ class ConditionalInterpreter ...@@ -206,13 +240,16 @@ class ConditionalInterpreter
/** /**
* @brief Test a node depending of the ConditionalExpressions * @brief Test a node depending of the ConditionalExpressions
* @return bool * @details the AST is visit using \ref visit() whith the $ init whit the nodeOp
* @return bool the match node has the initialized expresion
* @see visit() This function uses the visit() function to perform the evaluation.
*/ */
bool test( const NodePtr nodeOp); bool test( const NodePtr nodeOp);
/** /**
* @brief Interface for inserting custom lambda bool(NodePtr) functions in AST interpretation * @brief Interface for inserting custom lambda bool(NodePtr) functions in AST interpretation,
* @param key The key that will be used to call the function in the expression * it will be available in the ConditionalExpressions expretion as : key($)
* @param key The key that will be used to call the function in the expression
* @param f The pointer to function * @param f The pointer to function
*/ */
void insertLambda(const std::string key,std::function<bool(Aidge::NodePtr)> f); void insertLambda(const std::string key,std::function<bool(Aidge::NodePtr)> f);
...@@ -220,7 +257,6 @@ class ConditionalInterpreter ...@@ -220,7 +257,6 @@ class ConditionalInterpreter
///// /////
private: private:
/** /**
* @brief Recursive AST traversal function, using the for interpreting AST nodes function, * @brief Recursive AST traversal function, using the for interpreting AST nodes function,
......
...@@ -26,37 +26,41 @@ namespace Aidge{ ...@@ -26,37 +26,41 @@ namespace Aidge{
/** /**
* @brief enum for all types of token use in the parsing
* 7-5 type * 7-5 type
* 4-0 id * 4-0 id
*/ */
enum class ConditionalTokenTypes enum class ConditionalTokenTypes
{ {
NOT = (1 << 4)+3, NOT = (1 << 4)+3, /**< ! */
AND = (1 << 4)+2, AND = (1 << 4)+2, /**< && */
OR = (1 << 4)+1, OR = (1 << 4)+1, /**< || */
EQ = (1 << 5)+1, EQ = (1 << 5)+1, /**< == */
NEQ = (1 << 5)+2, NEQ = (1 << 5)+2, /**< != */
KEY = (1 << 6) +1 , KEY = (1 << 6) +1 , /**< [A-Za-z][A-Za-z0-9_]* */
INTEGER = (1 << 6) +2 , INTEGER = (1 << 6) +2 , /**< [0-9]+ */
FLOAT = (1 << 6) +3 , FLOAT = (1 << 6) +3 , /**< [0-9]+\.[0-9]* */
STRING = (1 << 6) +4 , STRING = (1 << 6) +4 , /**< \'.*\' */
BOOL = (1 << 6) +5 , BOOL = (1 << 6) +5 , /**< true|false */
NODE = (1 << 6) +6 , //the node ptr NODE = (1 << 6) +6 , /**< \$ */
LAMBDA = (1 << 6) +7 , //the fuction TAG LAMBDA = (1 << 6) +7 , /**< [A-Za-z][A-Za-z0-9_]*\( */
ARGSEP = (1<<7) +1,//sep fuction , ARGSEP = (1<<7) +1, /**< , */
LPAREN = (1<<7) +2, LPAREN = (1<<7) +2, /**< \( */
RPAREN = (1<<7) +3, RPAREN = (1<<7) +3, /**< \) */
STOP = 0, STOP = 0,
}; };
class ConditionalToken
{
/** /**
* @brief token holder * @brief token holder
*/ */
class ConditionalToken
{
public: public:
/** /**
...@@ -67,7 +71,6 @@ public: ...@@ -67,7 +71,6 @@ public:
ConditionalToken(const ConditionalTokenTypes type , const std::string lexeme ); ConditionalToken(const ConditionalTokenTypes type , const std::string lexeme );
/** /**
* @brief get the lexeme * @brief get the lexeme
*
* @return std::string * @return std::string
*/ */
const std::string getLexeme(void); const std::string getLexeme(void);
...@@ -79,14 +82,25 @@ const std::string getLexeme(void); ...@@ -79,14 +82,25 @@ const std::string getLexeme(void);
*/ */
const ConditionalTokenTypes getType(void); const ConditionalTokenTypes getType(void);
/**
* @brief copy the token
* @return deep copy of the token
*/
std::shared_ptr<Aidge::ConditionalToken> copy(); std::shared_ptr<Aidge::ConditionalToken> copy();
std::ostringstream rep(void); std::ostringstream rep(void);
private: private:
/**
* @brief additional information of the token
*/
const std::string mLexeme; const std::string mLexeme;
/**
* @brief type of the token
* @see ConditionalTokenTypes
*/
const ConditionalTokenTypes mType; const ConditionalTokenTypes mType;
}; };
...@@ -101,7 +115,6 @@ ConditionalLexer( const std::string ConditionalExpressions ); ...@@ -101,7 +115,6 @@ ConditionalLexer( const std::string ConditionalExpressions );
/** /**
* @brief Get the next token on the ConditionalExpressions * @brief Get the next token on the ConditionalExpressions
*
* @return ConditionalToken * @return ConditionalToken
*/ */
std::shared_ptr<ConditionalToken> getNextToken(void); std::shared_ptr<ConditionalToken> getNextToken(void);
......
...@@ -18,22 +18,54 @@ const std::map<ConditionalTokenTypes, std::size_t> ConditionalPrec{ ...@@ -18,22 +18,54 @@ const std::map<ConditionalTokenTypes, std::size_t> ConditionalPrec{
class AstConditionalNode; // Forward declaration class AstConditionalNode; // Forward declaration
using ASTNodeCh = std::vector<std::shared_ptr<AstConditionalNode>>; using ASTNodeCh = std::vector<std::shared_ptr<AstConditionalNode>>;
/**
* @brief this class is the node of an AST tree, this
*/
class AstConditionalNode: public std::enable_shared_from_this<AstConditionalNode> class AstConditionalNode: public std::enable_shared_from_this<AstConditionalNode>
{ {
public: public:
AstConditionalNode(std::shared_ptr<ConditionalToken> token,ASTNodeCh child ={}); AstConditionalNode(std::shared_ptr<ConditionalToken> token,ASTNodeCh child ={});
/**
* @brief get the lexeme of the token
* @return the lexeme value
*/
std::string getValue() const; std::string getValue() const;
/**
* @brief get the type of the token
* @return the type
*/
ConditionalTokenTypes getType() const; ConditionalTokenTypes getType() const;
std::string getValue() const;
/**
* @brief get the child of the node
* @return child
*/
const ASTNodeCh& getChilds() const ; const ASTNodeCh& getChilds() const ;
/**
* @brief test if the node is a leaf in the tree
* @return true if a leaf
*/
bool isLeaf() const ; bool isLeaf() const ;
/**
* @brief get the number of child
* @return the number of child
*/
std::size_t nbChild() const; std::size_t nbChild() const;
private: private:
/**
* @brief the token of the node
*/
const std::shared_ptr<ConditionalToken> mToken; const std::shared_ptr<ConditionalToken> mToken;
/**
* @brief list of child
*/
const ASTNodeCh mChild; const ASTNodeCh mChild;
}; };
/**
* @brief this class uses the lexer to create an AST according to a set of gramer rules
*/
class ConditionalParser{ class ConditionalParser{
public: public:
...@@ -53,12 +85,9 @@ class ConditionalParser{ ...@@ -53,12 +85,9 @@ class ConditionalParser{
private: private:
/** /**
* @brief restart at the start of the ConditionalExpressions for LEXER and restart mCurrentToken * @brief restart at the start of the ConditionalExpressions for LEXER and restart mCurrentToken
*
*/ */
void rstParser(void); void rstParser(void);
////////////////// //////////////////
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment