Skip to content
Snippets Groups Projects
Commit f9105219 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

introspection in cli

parent 3ef26b44
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -52,6 +52,7 @@ public: ...@@ -52,6 +52,7 @@ public:
std::cout << "" << std::endl; std::cout << "" << std::endl;
std::cout << "command quit: quits the processor." << std::endl; std::cout << "command quit: quits the processor." << std::endl;
std::cout << "command help: shows this help." << std::endl; std::cout << "command help: shows this help." << std::endl;
std::cout << "command introspect: prints available algorithms and algorithm overloads." << std::endl;
std::cout << "command execute: executes statements" << std::endl; std::cout << "command execute: executes statements" << std::endl;
std::cout << "" << std::endl; std::cout << "" << std::endl;
std::cout << "for details use help of individual command" << std::endl; std::cout << "for details use help of individual command" << std::endl;
......
#ifndef _CLI_INTROSPECTION_COMMAND_H_
#define _CLI_INTROSPECTION_COMMAND_H_
#include <command/Command.h>
#include <environment/Environment.h>
namespace cli {
class IntrospectionCommand : public Command {
std::string m_algorithm;
public:
IntrospectionCommand ( std::string algorithm ) : m_algorithm ( std::move ( algorithm ) ) {
}
virtual Command::Result run ( Environment & ) const override {
if ( m_algorithm == "" ) {
abstraction::Registry::listAlgorithms ( );
} else {
abstraction::Registry::listAlgorithmOverloads ( m_algorithm );
}
return Command::Result::OK;
}
};
} /* namespace cli */
#endif /* _CLI_INTROSPECTION_COMMAND_H_ */
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <command/ExecuteCommand.h> #include <command/ExecuteCommand.h>
#include <command/QuitCommand.h> #include <command/QuitCommand.h>
#include <command/HelpCommand.h> #include <command/HelpCommand.h>
#include <command/IntrospectionCommand.h>
   
#include <primitive/Integer.h> #include <primitive/Integer.h>
#include <primitive/String.h> #include <primitive/String.h>
...@@ -166,7 +167,7 @@ void Parser::result ( std::shared_ptr < StatementList > & list ) { ...@@ -166,7 +167,7 @@ void Parser::result ( std::shared_ptr < StatementList > & list ) {
} }
} }
   
std::string Parser::help_parameter ( ) { std::string Parser::optional_identifier ( ) {
if ( check ( cli::Lexer::TokenType::IDENTIFIER ) ) { if ( check ( cli::Lexer::TokenType::IDENTIFIER ) ) {
return matchIdentifier ( ); return matchIdentifier ( );
} else { } else {
...@@ -187,9 +188,14 @@ std::unique_ptr < Command > Parser::parse ( ) { ...@@ -187,9 +188,14 @@ std::unique_ptr < Command > Parser::parse ( ) {
return std::make_unique < QuitCommand > ( ); return std::make_unique < QuitCommand > ( );
} else if ( check_nonreserved_kw ( "help" ) ) { } else if ( check_nonreserved_kw ( "help" ) ) {
match_nonreserved_kw ( "help" ); match_nonreserved_kw ( "help" );
std::string command = help_parameter ( ); std::string command = optional_identifier ( );
match ( cli::Lexer::TokenType::END ); match ( cli::Lexer::TokenType::END );
return std::make_unique < HelpCommand > ( std::move ( command ) ); return std::make_unique < HelpCommand > ( std::move ( command ) );
} else if ( check_nonreserved_kw ( "introspect" ) ) {
match_nonreserved_kw ( "introspect" );
std::string command = optional_identifier ( );
match ( cli::Lexer::TokenType::END );
return std::make_unique < IntrospectionCommand > ( std::move ( command ) );
} else { } else {
throw exception::CommonException ( "Mismatched set while expanding param rule." ); throw exception::CommonException ( "Mismatched set while expanding param rule." );
} }
......
...@@ -84,7 +84,7 @@ public: ...@@ -84,7 +84,7 @@ public:
   
void result ( std::shared_ptr < StatementList > & list ); void result ( std::shared_ptr < StatementList > & list );
   
std::string help_parameter ( ); std::string optional_identifier ( );
   
std::unique_ptr < Command > parse ( ); std::unique_ptr < Command > parse ( );
   
......
...@@ -102,6 +102,24 @@ public: ...@@ -102,6 +102,24 @@ public:
bool normalize; bool normalize;
return getAbstraction ( std::move ( name ), paramTypes, downcast, normalize ); return getAbstraction ( std::move ( name ), paramTypes, downcast, normalize );
} }
static void listOverloads ( const std::string & algorithm ) {
auto group = getEntries ( ).find ( algorithm );
if ( group == getEntries ( ).end ( ) )
throw exception::CommonException ( "Entry " + algorithm + " not available" );
for ( const std::pair < const std::vector < std::type_index >, std::unique_ptr < Entry > > & overloads : group->second ) {
for ( const std::type_index & param : overloads.first ) {
std::cout << param << " " << std::endl;
}
}
}
static void list ( ) {
for ( const std::pair < const std::string, std::map < std::vector < std::type_index >, std::unique_ptr < Entry > > > & entry : getEntries ( ) ) {
std::cout << entry.first << std::endl;
}
}
}; };
   
} /* namespace abstraction */ } /* namespace abstraction */
......
...@@ -18,6 +18,14 @@ ...@@ -18,6 +18,14 @@
   
namespace abstraction { namespace abstraction {
   
void Registry::listAlgorithmOverloads ( const std::string & algorithm ) {
AlgorithmRegistry::listOverloads ( algorithm );
}
void Registry::listAlgorithms ( ) {
AlgorithmRegistry::list ( );
}
std::shared_ptr < abstraction::OperationAbstraction > Registry::getAlgorithmAbstraction ( std::string name, const std::vector < std::type_index > & paramTypes ) { std::shared_ptr < abstraction::OperationAbstraction > Registry::getAlgorithmAbstraction ( std::string name, const std::vector < std::type_index > & paramTypes ) {
return AlgorithmRegistry::getAbstraction ( std::move ( name ), paramTypes ); return AlgorithmRegistry::getAbstraction ( std::move ( name ), paramTypes );
} }
......
...@@ -14,6 +14,9 @@ namespace abstraction { ...@@ -14,6 +14,9 @@ namespace abstraction {
   
class Registry { class Registry {
public: public:
static void listAlgorithmOverloads ( const std::string & algorithm );
static void listAlgorithms ( );
static std::shared_ptr < abstraction::OperationAbstraction > getAlgorithmAbstraction ( std::string name, const std::vector < std::type_index > & paramTypes ); static std::shared_ptr < abstraction::OperationAbstraction > getAlgorithmAbstraction ( std::string name, const std::vector < std::type_index > & paramTypes );
static std::shared_ptr < abstraction::OperationAbstraction > getAlgorithmAbstraction ( std::string name, const std::vector < std::type_index > & paramTypes, bool & unwrap, bool & normalize ); static std::shared_ptr < abstraction::OperationAbstraction > getAlgorithmAbstraction ( std::string name, const std::vector < std::type_index > & paramTypes, bool & unwrap, bool & normalize );
static std::shared_ptr < abstraction::OperationAbstraction > getCastAbstraction ( std::string target, std::string param ); static std::shared_ptr < abstraction::OperationAbstraction > getCastAbstraction ( std::string target, std::string param );
......
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