Sivelkiria Operating System repository

Commit a57e073f authored by Alexey's avatar Alexey
Browse files

изменено: libs/parsers/interfaceParser.cpp

	изменено:      libs/parsers/interfaceParser.hpp
	изменено:      libs/parsers/parser.cpp
	изменено:      libs/parsers/parser.hpp
	изменено:      libs/parsers/structParser.cpp
	изменено:      libs/parsers/structParser.hpp
	изменено:      libs/programming_languages/cpp/cppGenerator.cpp
	изменено:      libs/programming_languages/cpp/cppGenerator.hpp
	изменено:      libs/programming_languages/cpp/cppInterfaceGenerator.cpp
	изменено:      libs/programming_languages/cpp/cppInterfaceGenerator.hpp
	изменено:      libs/programming_languages/cpp/cppStructGenerator.cpp
	изменено:      libs/programming_languages/cpp/cppStructGenerator.hpp
	изменено:      main.cpp
	изменено:      sdkbuilder.hpp
parent 03ac1015
......@@ -28,7 +28,8 @@ void interfaceParser::parse_permission(
_perm->caller_method= std::string( caller_method );
const char *caller_obj= ptr->Attribute( "caller-object" );
if ( caller_obj != nullptr ) _perm->caller_obj= std::string( caller_obj );
const tinyxml2::XMLElement *rule= ptr->FirstChildElement( "security-permission" );
const tinyxml2::XMLElement *rule=
ptr->FirstChildElement( "security-permission" );
if ( rule != nullptr ) { //если есть вложенные права
if ( _perm->subperm == nullptr ) //если нет вектора подправ
_perm->subperm= new std::vector<permission>; //то создаем его
......@@ -60,10 +61,10 @@ void interfaceParser::parse_method( const tinyxml2::XMLElement *ptr ) {
std::string ret_type=
std::string( ptr->FirstChildElement( "return" )->Attribute( "type" ) );
std::pair<std::string, std::string> *template_pointer= nullptr;
templateHelper *template_pointer= nullptr;
for ( auto it= templates.begin(); it != templates.end();
++it ) // find in templates
if ( it->first == ret_type ) {
if ( it->name() == ret_type ) {
template_pointer= &*it;
break;
}
......@@ -78,21 +79,21 @@ void interfaceParser::parse_method( const tinyxml2::XMLElement *ptr ) {
else
description_methods.back().descr_ret= "";
for ( const tinyxml2::XMLElement *arg= ptr->FirstChildElement( "arg" );
arg != nullptr; arg= arg->NextSiblingElement( "arg" ) )
for ( auto *arg= ptr->FirstChildElement( "arg" ); arg != nullptr;
arg= arg->NextSiblingElement( "arg" ) )
parse_arg( arg );
}
void interfaceParser::parse_arg( const tinyxml2::XMLElement *ptr ) {
methods.back().args.resize( methods.back().args.size() + 1 );
std::vector<std::pair<_arg, std::pair<std::string, std::string> *>>::
reverse_iterator gt= methods.back().args.rbegin();
std::vector<std::pair<_arg, templateHelper *>>::reverse_iterator gt=
methods.back().args.rbegin();
gt->first.mode= std::string( ptr->Attribute( "mode" ) ); // get mode
gt->first.type= std::string( ptr->Attribute( "type" ) ); // get type
gt->second= nullptr;
for ( auto it= templates.begin(); it != templates.end();
++it ) // find in templates
if ( it->first == gt->first.type ) {
if ( it->name() == gt->first.type ) {
gt->second= &*it;
break;
}
......
#pragma once
#include "parser.hpp"
namespace Sivelkiria::sdkBuilder {
namespace Sivelkiria { namespace sdkBuilder {
struct _arg {
std::string mode, type, name, id;
};
struct permission {
std::string default_perm, caller_int, caller_method, caller_obj;
std::vector<permission> *subperm= nullptr;
};
struct method {
//т к массив шиблонов уже не будет меняться, можно смело взять указатель
std::vector<std::pair<_arg, std::pair<std::string, std::string> *>>
args; // 2-е - указатель на шаблон
// if == nullptr => is not template
std::pair<std::string, std::pair<std::string, std::string> *> ret; // return
std::string name;
permission perm;
std::string id; //его можно в int не превращать
std::string minor_since;
};
struct descr_method {
std::string descr_main, descr_ret;
std::vector<std::string> descr_arg;
};
/*\brief class for parse sdk interface from xml
*\date 05.2020
*/
class interfaceParser : public parser {
public:
std::vector<method> methods;
std::vector<descr_method> description_methods;
permission perm;
/*\brief constructor of sdk interface from xml
/*\brief struct for argument
*\date 05.2020
*\param [in] filename
*\return interfaceParser
*/
interfaceParser( const std::string filename );
struct _arg {
std::string mode, type, name, id;
};
private:
/*\brief processing interfaces
/*\brief struct for permission
*\date 05.2020
*\param [in] ptr pointer to root xml element
*\return void
*/
void parse( const tinyxml2::XMLElement *ptr );
/*\brief processing permissions of interface
struct permission {
std::string default_perm, caller_int, caller_method, caller_obj;
std::vector<permission> *subperm= nullptr;
};
/*\brief struct for method
*\date 05.2020
*\param [in] ptr pointer to permission xml element
*\param [out] _perm pointer to permission parser element
*\return void
*/
void
parse_permission( const tinyxml2::XMLElement *ptr, permission *_perm );
/*\brief processing methods
struct method {
//т к массив шиблонов уже не будет меняться, можно смело взять указатель
std::vector<std::pair<_arg, templateHelper *>>
args; // 2-е - указатель на шаблон
// if == nullptr => is not template
std::pair<std::string, templateHelper *> ret; // return
std::string name;
permission perm;
std::string id; //его можно в int не превращать
std::string minor_since;
};
/*\brief struct for description of method
*\date 05.2020
*\param [in] ptr pointer to method xml element
*\return void
*/
void parse_method( const tinyxml2::XMLElement *ptr );
/*\brief processing arguments
struct descr_method {
std::string descr_main, descr_ret;
std::vector<std::string> descr_arg;
};
/*\brief class for parse sdk interface from xml
*\date 05.2020
*\param [in] ptr pointer to argument xml element
*\return void
*/
void parse_arg( const tinyxml2::XMLElement *ptr );
};
}; // namespace Sivelkiria::sdkBuilder
\ No newline at end of file
class interfaceParser : public parser {
public:
std::vector<method> methods;
std::vector<descr_method> description_methods;
permission perm;
/*\brief constructor of sdk interface from xml
*\date 05.2020
*\param [in] filename
*\return interfaceParser
*/
interfaceParser( const std::string filename );
private:
/*\brief processing interfaces
*\date 05.2020
*\param [in] ptr pointer to root xml element
*\return void
*/
void parse( const tinyxml2::XMLElement *ptr );
/*\brief processing permissions of interface
*\date 05.2020
*\param [in] ptr pointer to permission xml element
*\param [out] _perm pointer to permission parser element
*\return void
*/
void parse_permission( const tinyxml2::XMLElement *ptr, permission *_perm );
/*\brief processing methods
*\date 05.2020
*\param [in] ptr pointer to method xml element
*\return void
*/
void parse_method( const tinyxml2::XMLElement *ptr );
/*\brief processing arguments
*\date 05.2020
*\param [in] ptr pointer to argument xml element
*\return void
*/
void parse_arg( const tinyxml2::XMLElement *ptr );
};
}} // namespace Sivelkiria::sdkBuilder
\ No newline at end of file
......@@ -2,6 +2,11 @@
using namespace Sivelkiria::sdkBuilder;
templateHelper::templateHelper( std::string a, std::string b ) {
first= a;
second= b;
}
parser::parser( const std::string filename, tinyxml2::XMLElement **ptr ) {
doc.LoadFile( filename.c_str() );
( *ptr )= doc.FirstChildElement()->FirstChildElement( "Template" );
......@@ -9,15 +14,18 @@ parser::parser( const std::string filename, tinyxml2::XMLElement **ptr ) {
if ( has_template ) parse_templates( ( *ptr ) );
( *ptr )= doc.FirstChildElement();
if ( ( *ptr ) != nullptr ) {
supp_type= std::string( ( *ptr )->Attribute( "support-type" ) );
name= std::string( ( *ptr )->FirstChildElement( "name" )->GetText() );
major= std::string(
( *ptr )->FirstChildElement( "version-major" )->GetText() );
minor= std::string(
( *ptr )->FirstChildElement( "version-minor-max" )->GetText() );
description= std::string( ( *ptr )
->FirstChildElement( "description" )
->GetText() ); // get description
const char *supp= ( *ptr )->Attribute( "support-type" );
if ( supp != nullptr ) supp_type= std::string( supp );
const char *nm= ( *ptr )->FirstChildElement( "name" )->GetText();
if ( nm != nullptr ) name= std::string( nm );
const char *maj= ( *ptr )->FirstChildElement( "version-major" )->GetText();
if ( maj != nullptr ) major= std::string( maj );
const char *minor_max=
( *ptr )->FirstChildElement( "version-minor-max" )->GetText();
if ( minor_max != nullptr ) minor= std::string( minor_max );
const char *descr= ( *ptr )->FirstChildElement( "description" )->GetText();
if ( descr != nullptr )
description= std::string( descr ); // get description
}
}
......@@ -25,14 +33,18 @@ void parser::parse_templates( const tinyxml2::XMLElement *ptr ) {
for ( const tinyxml2::XMLNode *node= ptr->FirstChild(); node != nullptr;
node= node->NextSibling() ) {
const tinyxml2::XMLElement *elem= node->ToElement();
std::pair<std::string, std::string> tmp=
std::pair<std::string, std::string>(
std::string( elem->Attribute( "name" ) ),
std::string( elem->Attribute( "defval" ) ) );
templates.push_back( tmp );
const tinyxml2::XMLNode *tmpnode= node->FirstChild();
description_template_names.push_back(
std::string( tmpnode->ToElement()->GetText() ) ); // description
const char *name= elem->Attribute( "name" );
const char *defval= elem->Attribute( "defval" );
if ( ( name != nullptr ) && ( defval != nullptr ) ) {
templateHelper tmp=
templateHelper( std::string( name ), std::string( defval ) );
templates.push_back( tmp );
}
const tinyxml2::XMLElement *description=
node->FirstChildElement( "description" );
if ( description != nullptr )
description_template_names.push_back(
std::string( description->GetText() ) ); // description
// tmpnode->ToElement()->Attribute(language)
}
}
......@@ -3,40 +3,54 @@
#include <vector>
#include <string>
namespace Sivelkiria::sdkBuilder {
/*\brief class for parse sdk from xml
*\date 05.2020
*/
class parser {
public:
tinyxml2::XMLElement *parse_data= nullptr;
std::string description;
bool has_template;
tinyxml2::XMLDocument doc;
std::vector<std::pair<std::string, std::string>> templates; // name and defval
std::vector<std::string> description_template_names;
std::string supp_type, name, major, minor;
/*\brief constructor of sdk parser from xml
namespace Sivelkiria { namespace sdkBuilder {
/*\brief custumased pair for template data
*\date 05.2020
*\param [in] filename
*\param [out] ptr pointer to root xml element
*\return parser
*/
parser( const std::string filename, tinyxml2::XMLElement **ptr );
class templateHelper {
private:
std::string first;
std::string second;
protected:
/*\brief parse templates
*\date 05.2020
*\param [in] ptr pointer to templates xml element
*\return void
*/
void parse_templates( const tinyxml2::XMLElement *ptr );
/*\brief virtual abstract method for processing different subjects
public:
templateHelper( std::string a, std::string b );
std::string &name() { return first; }
std::string &defval() { return second; }
const std::string &cname() const { return first; }
const std::string &cdefval() const { return second; }
};
/*\brief class for parse sdk from xml
*\date 05.2020
*\param [in] ptr pointer to root xml element
*\return void
*/
virtual void parse( const tinyxml2::XMLElement *ptr )= 0;
};
}; // namespace Sivelkiria::sdkBuilder
class parser {
public:
tinyxml2::XMLElement *parse_data= nullptr;
std::string description;
bool has_template;
tinyxml2::XMLDocument doc;
std::vector<templateHelper> templates; // name and defval
std::vector<std::string> description_template_names;
std::string supp_type, name, major, minor;
/*\brief constructor of sdk parser from xml
*\date 05.2020
*\param [in] filename
*\param [out] ptr pointer to root xml element
*\return parser
*/
parser( const std::string filename, tinyxml2::XMLElement **ptr );
protected:
/*\brief parse templates
*\date 05.2020
*\param [in] ptr pointer to templates xml element
*\return void
*/
void parse_templates( const tinyxml2::XMLElement *ptr );
/*\brief virtual abstract method for processing different subjects
*\date 05.2020
*\param [in] ptr pointer to root xml element
*\return void
*/
virtual void parse( const tinyxml2::XMLElement *ptr )= 0;
};
}} // namespace Sivelkiria::sdkBuilder
\ No newline at end of file
......@@ -9,21 +9,20 @@ structParser::structParser( const std::string filename )
void structParser::parse( const tinyxml2::XMLElement *ptr ) {
// ptr->ToElement()->Attribute("xsi:schemaLocation");
for ( const tinyxml2::XMLElement *field= ptr->FirstChildElement( "field" );
field != nullptr; field= field->NextSiblingElement( "field" ) )
for ( auto *field= ptr->FirstChildElement( "field" ); field != nullptr;
field= field->NextSiblingElement( "field" ) )
parse_field( field );
}
void structParser::parse_field( const tinyxml2::XMLElement *field ) {
fields.resize( fields.size() + 1 );
std::vector<std::pair<_field, std::pair<std::string, std::string> *>>::
reverse_iterator gt= fields.rbegin();
std::vector<std::pair<_field, templateHelper *>>::reverse_iterator gt=
fields.rbegin();
gt->first.type= std::string( field->Attribute( "type" ) ); // get type
gt->second= nullptr;
for ( std::vector<std::pair<std::string, std::string>>::iterator it=
templates.begin();
it != templates.end(); ++it ) // find in templates
if ( it->first == gt->first.type ) {
for ( auto it= templates.begin(); it != templates.end();
++it ) // find in templates
if ( it->name() == gt->first.type ) {
gt->second= &*it;
break;
}
......
#pragma once
#include "parser.hpp"
namespace Sivelkiria::sdkBuilder {
namespace Sivelkiria { namespace sdkBuilder {
struct _field {
std::string type, name, id;
};
/*\brief class for parse sdk struct from xml
*\date 05.2020
*/
class structParser : public parser {
public:
std::vector<std::pair<_field, std::pair<std::string, std::string> *>> fields;
std::vector<std::string> fields_descriptions;
/*\brief constructor of sdk struct from xml
/*\brief struct for field
*\date 05.2020
*\param [in] filename
*\return structParser
*/
structParser( const std::string filename );
struct _field {
std::string type, name, id;
};
private:
/*\brief processing structures
*\date 05.2020
*\param [in] ptr pointer to root xml element
*\return void
*/
void parse( const tinyxml2::XMLElement *ptr );
/*\brief processing filds of structure
/*\brief class for parse sdk struct from xml
*\date 05.2020
*\param [in] field pointer to field xml element
*\return void
*/
void parse_field( const tinyxml2::XMLElement *field );
};
}; // namespace Sivelkiria::sdkBuilder
\ No newline at end of file
class structParser : public parser {
public:
std::vector<std::pair<_field, templateHelper *>> fields;
std::vector<std::string> fields_descriptions;
/*\brief constructor of sdk struct from xml
*\date 05.2020
*\param [in] filename
*\return structParser
*/
structParser( const std::string filename );
private:
/*\brief processing structures
*\date 05.2020
*\param [in] ptr pointer to root xml element
*\return void
*/
void parse( const tinyxml2::XMLElement *ptr );
/*\brief processing filds of structure
*\date 05.2020
*\param [in] field pointer to field xml element
*\return void
*/
void parse_field( const tinyxml2::XMLElement *field );
};
}} // namespace Sivelkiria::sdkBuilder
\ No newline at end of file
......@@ -5,24 +5,25 @@
using namespace Sivelkiria::sdkBuilder;
void cppGenerator::construct(
const std::vector<std::string> &descr_templ,
const std::vector<std::pair<std::string, std::string>> &templ,
const bool &has_template, const std::string type_obj,
const std::string name, const std::string &body ) {
const std::vector<templateHelper> &templ, const bool &has_template,
const std::string type_obj, const std::string name,
const std::string &body ) {
std::ostringstream _templ;
std::ostringstream description_template;
if ( has_template ) {
description_template << "/*";
_templ << "template<";
std::vector<std::string>::const_iterator gt= descr_templ.begin();
auto gt= descr_templ.begin();
for ( auto it= templ.begin(); it != templ.end(); ++it ) {
description_template << std::endl << '*' << it->first;
description_template << " - " << *( gt++ ) << " Default:" << it->second;
_templ << " " << type_obj << " " << it->first << " = " << it->second
description_template << std::endl << '*' << it->cname();
description_template << " - " << *( gt++ )
<< " Default:" << it->cdefval();
_templ << " " << type_obj << " " << it->cname() << " = " << it->cdefval()
<< ',';
}
description_template << std::endl << "*/" << std::endl;
{
long pos = _templ.tellp();
long pos= _templ.tellp();
_templ.seekp( pos - 1 );
}
_templ << ' '; //вставляем вместо последней запятой
......@@ -36,13 +37,13 @@ void cppGenerator::construct_hpp(
const std::string &body, const std::string &name ) {
const std::string filename= build_dir + name + ".hpp";
std::ofstream hpp_file( filename );
hpp_file << "namespace SivDK{\n"
<< "namespace ";
hpp_file << "namespace SivDK{" << std::endl << "namespace ";
if ( type_obj == "class" ) hpp_file << "Interfaces";
else if ( type_obj == "struct" )
hpp_file << "Structures";
else
hpp_file << "Error";
hpp_file << "{\n" << _template << type_obj;
hpp_file << " " << name << body << "};\n};\n};";
hpp_file << "{" << std::endl << _template;
hpp_file << body << "};" << std::endl;
hpp_file << "};" << std::endl << "};";
}
\ No newline at end of file
#pragma once
#include <vector>
#include <string>
#include "../../parsers/parser.hpp"
namespace Sivelkiria::sdkBuilder {
/*\brief class for generate sdk from parser data
*\date 05.2020
*/
class cppGenerator {
protected:
std::string build_dir= "./";
/*\brief write sdk???!!!
*\details wrtite sdk to build_dir folder
namespace Sivelkiria { namespace sdkBuilder {
/*\brief class for generate sdk from parser data
*\date 05.2020
*\param [in] descr_templ all descriptions of templates
*\param [in] templ all templates with default values
*\param [in] has_template flag indicate "is there a template?"
*\param [in] type_obj struct or class
*\param [in] normal_name name with him major and sometimes minor
*\param [in] body body of object
*\return void
*/
void construct(
const std::vector<std::string> &descr_templ,
const std::vector<std::pair<std::string, std::string>> &templ,
const bool &has_template, const std::string type_obj,
const std::string name, const std::string &body );
/*\brief write hpp file???!!!
*\details write to build_dir/objname.hpp
*\date 05.2020
*\param [in] _template template code
*\param [in] type_obj struct or class
*\param [in] body body of object
*\param [in] name name of object
*\return void
*/
void construct_hpp(
const std::string _template, const std::string type_obj,
const std::string &body, const std::string &name );
/*\brief virtual abstract method for write hpp file???!!!
*\date 05.2020
*\param [in] filename
*\param [in] out_dir output dir
*\return void
*/
virtual void
build( const std::string &filename, const std::string out_dir )= 0;
/*
*/
};
}; // namespace Sivelkiria::sdkBuilder
\ No newline at end of file
class cppGenerator {
protected:
std::string build_dir= "./";
/*\brief write sdk???!!!
*\details wrtite sdk to build_dir folder
*\date 05.2020
*\param [in] descr_templ all descriptions of templates
*\param [in] templ all templates with default values
*\param [in] has_template flag indicate "is there a template?"
*\param [in] type_obj struct or class
*\param [in] normal_name name with him major and sometimes minor
*\param [in] body body of object
*\return void
*/
void construct(
const std::vector<std::string> &descr_templ,
const std::vector<templateHelper> &templ, const bool &has_template,
const std::string type_obj, const std::string name,
const std::string &body );
/*\brief write hpp file???!!!
*\details write to build_dir/objname.hpp
*\date 05.2020
*\param [in] _template template code
*\param [in] type_obj struct or class
*\param [in] body body of object
*\param [in] name name of object
*\return void
*/
void construct_hpp(
const std::string _template, const std::string type_obj,
const std::string &body, const std::string &name );
/*\brief virtual abstract method for write hpp file???!!!
*\date 05.2020
*\param [in] filename