From: Matthias Braun Date: Fri, 1 Jul 2005 21:26:39 +0000 (+0000) Subject: miniswig supports int, float and string constants now X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=2f9e19ce4e01dc769ae7b2a7129109e0e81a6b5b;p=supertux.git miniswig supports int, float and string constants now SVN-Revision: 2665 --- diff --git a/src/audio/stream_sound_source.hpp b/src/audio/stream_sound_source.hpp index 0c245cd4c..05342eb48 100644 --- a/src/audio/stream_sound_source.hpp +++ b/src/audio/stream_sound_source.hpp @@ -25,8 +25,7 @@ public: void update(); private: - //static const size_t STREAMBUFFERSIZE = 1024 * 500; - static const size_t STREAMBUFFERSIZE = 1024 * 20; + static const size_t STREAMBUFFERSIZE = 1024 * 500; static const size_t STREAMFRAGMENTS = 5; static const size_t STREAMFRAGMENTSIZE = STREAMBUFFERSIZE / STREAMFRAGMENTS; diff --git a/src/gameconfig.cpp b/src/gameconfig.cpp index 1e753b24d..06362dcac 100644 --- a/src/gameconfig.cpp +++ b/src/gameconfig.cpp @@ -23,8 +23,6 @@ #include #include #include -#include -#include #include "lisp/parser.hpp" #include "lisp/lisp.hpp" diff --git a/src/gameconfig.hpp b/src/gameconfig.hpp index d16ebe65b..eb9a32022 100644 --- a/src/gameconfig.hpp +++ b/src/gameconfig.hpp @@ -21,7 +21,8 @@ #include -class Config { +class Config +{ public: Config(); ~Config(); diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 73e5da6fb..90b39e87b 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -458,6 +458,18 @@ WrappedFunction supertux_global_functions[] = { { 0, 0 } }; +WrappedConstant supertux_int_constants[] = { + { 0, 0} +}; + +WrappedConstant supertux_float_constants[] = { + { 0, 0} +}; + +WrappedConstant supertux_string_constants[] = { + { 0, 0} +}; + static WrappedFunction supertux_DisplayEffect_methods[] = { { "fade_out", &DisplayEffect_fade_out_wrapper }, { "fade_in", &DisplayEffect_fade_in_wrapper }, @@ -465,18 +477,54 @@ static WrappedFunction supertux_DisplayEffect_methods[] = { { "is_black", &DisplayEffect_is_black_wrapper }, }; +static WrappedConstant supertux_DisplayEffect_int_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_DisplayEffect_float_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_DisplayEffect_string_consts[] = { + { 0, 0} +}; + static WrappedFunction supertux_Camera_methods[] = { { "shake", &Camera_shake_wrapper }, { "set_pos", &Camera_set_pos_wrapper }, { "set_mode", &Camera_set_mode_wrapper }, }; +static WrappedConstant supertux_Camera_int_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_Camera_float_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_Camera_string_consts[] = { + { 0, 0} +}; + static WrappedFunction supertux_Level_methods[] = { { "finish", &Level_finish_wrapper }, { "spawn", &Level_spawn_wrapper }, { "flip_vertically", &Level_flip_vertically_wrapper }, }; +static WrappedConstant supertux_Level_int_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_Level_float_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_Level_string_consts[] = { + { 0, 0} +}; + static WrappedFunction supertux_ScriptedObject_methods[] = { { "set_animation", &ScriptedObject_set_animation_wrapper }, { "get_animation", &ScriptedObject_get_animation_wrapper }, @@ -492,11 +540,35 @@ static WrappedFunction supertux_ScriptedObject_methods[] = { { "get_name", &ScriptedObject_get_name_wrapper }, }; +static WrappedConstant supertux_ScriptedObject_int_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_ScriptedObject_float_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_ScriptedObject_string_consts[] = { + { 0, 0} +}; + static WrappedFunction supertux_Sound_methods[] = { { "play_music", &Sound_play_music_wrapper }, { "play", &Sound_play_wrapper }, }; +static WrappedConstant supertux_Sound_int_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_Sound_float_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_Sound_string_consts[] = { + { 0, 0} +}; + static WrappedFunction supertux_Text_methods[] = { { "set_text", &Text_set_text_wrapper }, { "set_font", &Text_set_font_wrapper }, @@ -505,6 +577,18 @@ static WrappedFunction supertux_Text_methods[] = { { "set_visible", &Text_set_visible_wrapper }, }; +static WrappedConstant supertux_Text_int_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_Text_float_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_Text_string_consts[] = { + { 0, 0} +}; + static WrappedFunction supertux_Player_methods[] = { { "set_bonus", &Player_set_bonus_wrapper }, { "make_invincible", &Player_make_invincible_wrapper }, @@ -512,14 +596,26 @@ static WrappedFunction supertux_Player_methods[] = { { "add_coins", &Player_add_coins_wrapper }, }; +static WrappedConstant supertux_Player_int_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_Player_float_consts[] = { + { 0, 0} +}; + +WrappedConstant supertux_Player_string_consts[] = { + { 0, 0} +}; + WrappedClass supertux_classes[] = { - { "DisplayEffect", supertux_DisplayEffect_methods }, - { "Camera", supertux_Camera_methods }, - { "Level", supertux_Level_methods }, - { "ScriptedObject", supertux_ScriptedObject_methods }, - { "Sound", supertux_Sound_methods }, - { "Text", supertux_Text_methods }, - { "Player", supertux_Player_methods }, - { 0, 0 } + { "DisplayEffect", supertux_DisplayEffect_methods, supertux_DisplayEffect_int_consts, supertux_DisplayEffect_float_consts, supertux_DisplayEffect_string_consts }, + { "Camera", supertux_Camera_methods, supertux_Camera_int_consts, supertux_Camera_float_consts, supertux_Camera_string_consts }, + { "Level", supertux_Level_methods, supertux_Level_int_consts, supertux_Level_float_consts, supertux_Level_string_consts }, + { "ScriptedObject", supertux_ScriptedObject_methods, supertux_ScriptedObject_int_consts, supertux_ScriptedObject_float_consts, supertux_ScriptedObject_string_consts }, + { "Sound", supertux_Sound_methods, supertux_Sound_int_consts, supertux_Sound_float_consts, supertux_Sound_string_consts }, + { "Text", supertux_Text_methods, supertux_Text_int_consts, supertux_Text_float_consts, supertux_Text_string_consts }, + { "Player", supertux_Player_methods, supertux_Player_int_consts, supertux_Player_float_consts, supertux_Player_string_consts }, + { 0, 0, 0, 0, 0 } }; diff --git a/src/scripting/wrapper.hpp b/src/scripting/wrapper.hpp index 322cfc8fa..dffd5ca2f 100644 --- a/src/scripting/wrapper.hpp +++ b/src/scripting/wrapper.hpp @@ -10,6 +10,18 @@ extern WrappedFunction supertux_global_functions[]; extern WrappedClass supertux_classes[]; +extern WrappedConstant supertux_int_constants[]; +extern WrappedConstant supertux_float_constants[]; +extern WrappedConstant supertux_string_constants[]; + +static inline void register_supertux_wrapper(HSQUIRRELVM v) +{ + register_functions(v, supertux_global_functions); + register_classes(v, supertux_classes); + register_constants(v, supertux_int_constants); + register_constants(v, supertux_float_constants); + register_constants(v, supertux_string_constants); +} #endif diff --git a/src/scripting/wrapper_util.cpp b/src/scripting/wrapper_util.cpp index 5944938eb..b25930f7b 100644 --- a/src/scripting/wrapper_util.cpp +++ b/src/scripting/wrapper_util.cpp @@ -8,17 +8,27 @@ static void register_function(HSQUIRRELVM v, SQFUNCTION func, const char* name) { sq_pushstring(v, name, -1); sq_newclosure(v, func, 0); //create a new function - sq_createslot(v, -3); + if(sq_createslot(v, -3) < 0) { + std::stringstream msg; + msg << "Couldn't register function '" << name << "'"; + throw SquirrelError(v, msg.str()); + } } static void register_class(HSQUIRRELVM v, WrappedClass* wclass) { sq_pushstring(v, wclass->name, -1); sq_newclass(v, false); - for(WrappedFunction* func = wclass->functions; func->name != 0; ++func) { - register_function(v, func->f, func->name); + register_functions(v, wclass->functions); + register_constants(v, wclass->int_consts); + register_constants(v, wclass->float_consts); + register_constants(v, wclass->string_consts); + + if(sq_createslot(v, -3) < 0) { + std::stringstream msg; + msg << "Couldn't register function '" << wclass->name << "'"; + throw SquirrelError(v, msg.str()); } - sq_createslot(v, -3); } void register_functions(HSQUIRRELVM v, WrappedFunction* functions) @@ -39,6 +49,7 @@ void register_classes(HSQUIRRELVM v, WrappedClass* classes) sq_pop(v, 1); } + void print_squirrel_stack(HSQUIRRELVM v) { printf("--------------------------------------------------------------\n"); @@ -89,6 +100,9 @@ void print_squirrel_stack(HSQUIRRELVM v) case OT_USERPOINTER: printf("userpointer"); break; + case OT_THREAD: + printf("thread"); + break; case OT_CLASS: printf("class"); break; @@ -112,7 +126,11 @@ SquirrelError::SquirrelError(HSQUIRRELVM v, const std::string& message) throw() msg << "SQuirrel error: " << message << " ("; const char* lasterr; sq_getlasterror(v); - sq_getstring(v, -1, &lasterr); + if(sq_gettype(v, -1) != OT_STRING) { + lasterr = "no error info"; + } else { + sq_getstring(v, -1, &lasterr); + } sq_pop(v, 1); msg << lasterr << ")"; this->message = msg.str(); diff --git a/src/scripting/wrapper_util.hpp b/src/scripting/wrapper_util.hpp index 63e185d3a..3f24de8a1 100644 --- a/src/scripting/wrapper_util.hpp +++ b/src/scripting/wrapper_util.hpp @@ -3,15 +3,26 @@ #include #include +#include #include struct WrappedFunction { const char* name; SQFUNCTION f; }; + +template +struct WrappedConstant { + const char* name; + T value; +}; + struct WrappedClass { const char* name; WrappedFunction* functions; + WrappedConstant* int_consts; + WrappedConstant* float_consts; + WrappedConstant* string_consts; }; class SquirrelError : public std::exception @@ -28,6 +39,37 @@ private: void register_functions(HSQUIRRELVM v, WrappedFunction* functions); void register_classes(HSQUIRRELVM v, WrappedClass* classes); +static inline void push_value(HSQUIRRELVM v, int val) +{ + sq_pushinteger(v, val); +} + +static inline void push_value(HSQUIRRELVM v, float val) +{ + sq_pushfloat(v, val); +} + +static inline void push_value(HSQUIRRELVM v, const char* str) +{ + sq_pushstring(v, str, -1); +} + +template +void register_constants(HSQUIRRELVM v, WrappedConstant* constants) +{ + sq_pushroottable(v); + for(WrappedConstant* c = constants; *constants->name != 0; ++c) { + sq_pushstring(v, c->name, -1); + push_value(v, c->value); + if(sq_createslot(v, -3) < 0) { + std::stringstream msg; + msg << "Couldn't register int constant '" << c->name << "'"; + throw SquirrelError(v, msg.str()); + } + } + sq_pop(v, 1); +} + void print_squirrel_stack(HSQUIRRELVM v); #endif diff --git a/tools/miniswig/create_wrapper.cpp b/tools/miniswig/create_wrapper.cpp index 1e78d520e..5ba700c7a 100644 --- a/tools/miniswig/create_wrapper.cpp +++ b/tools/miniswig/create_wrapper.cpp @@ -24,6 +24,23 @@ WrapperCreator::create_wrapper(Namespace* ns) << "\n" << "extern WrappedFunction " << modulename << "_global_functions[];\n" << "extern WrappedClass " << modulename << "_classes[];\n" + << "extern WrappedConstant " + << modulename << "_int_constants[];\n" + << "extern WrappedConstant " + << modulename << "_float_constants[];\n" + << "extern WrappedConstant " + << modulename << "_string_constants[];\n" + << "\n" + << "static inline void register_" + << modulename << "_wrapper(HSQUIRRELVM v)\n" + << "{\n" + << " register_functions(v, " + << modulename << "_global_functions);\n" + << " register_classes(v, " << modulename << "_classes);\n" + << " register_constants(v, " << modulename << "_int_constants);\n" + << " register_constants(v, " << modulename << "_float_constants);\n" + << " register_constants(v, "<< modulename << "_string_constants);\n" + << "}\n" << "\n" << "#endif\n" << "\n"; @@ -61,16 +78,8 @@ WrapperCreator::create_wrapper(Namespace* ns) } // create function list... - out << "WrappedFunction " << modulename << "_global_functions[] = {\n"; - for(std::vector::iterator i = ns->functions.begin(); - i != ns->functions.end(); ++i) { - Function* function = *i; - out << ind << "{ \"" << function->name << "\", &" - << function->name << "_wrapper },\n"; - } - out << ind << "{ 0, 0 }\n" - << "};\n" - << "\n"; + create_function_list(ns); + create_const_lists(ns); // create class list... std::ostringstream classlist; @@ -84,9 +93,12 @@ WrapperCreator::create_wrapper(Namespace* ns) continue; classlist << ind << "{ \"" << _class->name << "\", " - << modulename << "_" << _class->name - << "_methods },\n"; - + << modulename << "_" << _class->name << "_methods, " + << modulename << "_" << _class->name << "_int_consts, " + << modulename << "_" << _class->name << "_float_consts, " + << modulename << "_" << _class->name << "_string_consts " + << "},\n"; + out << "static WrappedFunction " << modulename << "_" << _class->name << "_methods[] = {\n"; for(std::vector::iterator i = _class->members.begin(); @@ -103,14 +115,142 @@ WrapperCreator::create_wrapper(Namespace* ns) } out << "};\n" << "\n"; + create_class_const_lists(_class); } - classlist << ind << "{ 0, 0 }\n"; + classlist << ind << "{ 0, 0, 0, 0, 0 }\n"; classlist << "};\n"; out << classlist.str(); out << "\n"; } void +WrapperCreator::create_function_list(Namespace* ns) +{ + out << "WrappedFunction " << modulename << "_global_functions[] = {\n"; + for(std::vector::iterator i = ns->functions.begin(); + i != ns->functions.end(); ++i) { + Function* function = *i; + out << ind << "{ \"" << function->name << "\", &" + << function->name << "_wrapper },\n"; + } + out << ind << "{ 0, 0 }\n" + << "};\n" + << "\n"; +} + +void +WrapperCreator::create_const_lists(Namespace* ns) +{ + out << "WrappedConstant " << modulename << "_int_constants[] = {\n"; + for(std::vector::iterator i = ns->fields.begin(); + i != ns->fields.end(); ++i) { + Field* field = *i; + if(!field->has_const_value + || field->type->atomic_type != &BasicType::INT) + continue; + out << ind << "{ \"" << field->name << "\", " + << field->const_int_value << "},\n"; + } + out << ind << "{ 0, 0}\n"; + out << "};\n"; + out << "\n"; + + out << "WrappedConstant " + << modulename << "_float_constants[] = {\n"; + for(std::vector::iterator i = ns->fields.begin(); + i != ns->fields.end(); ++i) { + Field* field = *i; + if(!field->has_const_value + || field->type->atomic_type != &BasicType::FLOAT) + continue; + out << ind << "{ \"" << field->name << "\", " + << field->const_float_value << "},\n"; + } + out << ind << "{ 0, 0}\n"; + out << "};\n"; + out << "\n"; + + out << "WrappedConstant " + << modulename << "_string_constants[] = {\n"; + for(std::vector::iterator i = ns->fields.begin(); + i != ns->fields.end(); ++i) { + Field* field = *i; + if(!field->has_const_value + || field->type->atomic_type != StringType::instance()) + continue; + out << ind << "{ \"" << field->name << "\", " + << field->const_float_value << "},\n"; + } + out << ind << "{ 0, 0}\n"; + out << "};\n"; + out << "\n"; +} + +void +WrapperCreator::create_class_const_lists(Class* _class) +{ + out << "static WrappedConstant " + << modulename << "_" << _class->name << "_int_consts[] = {\n"; + for(std::vector::iterator i = _class->members.begin(); + i != _class->members.end(); ++i) { + ClassMember* member = *i; + if(member->visibility != ClassMember::PUBLIC) + continue; + Field* field = dynamic_cast (member); + if(!field) + continue; + if(!field->has_const_value + || field->type->atomic_type != &BasicType::INT) + continue; + out << ind << "{ \"" << field->name << "\", " + << field->const_int_value << "},\n"; + } + out << ind << "{ 0, 0}\n"; + out << "};\n"; + out << "\n"; + + out << "WrappedConstant " + << modulename << "_" << _class->name << "_float_consts[] = {\n"; + for(std::vector::iterator i = _class->members.begin(); + i != _class->members.end(); ++i) { + ClassMember* member = *i; + if(member->visibility != ClassMember::PUBLIC) + continue; + Field* field = dynamic_cast (member); + if(!field) + continue; + if(!field->has_const_value + || field->type->atomic_type != &BasicType::FLOAT) + continue; + out << ind << "{ \"" << field->name << "\", " + << field->const_float_value << "},\n"; + } + out << ind << "{ 0, 0}\n"; + out << "};\n"; + out << "\n"; + + out << "WrappedConstant " + << modulename << "_" << _class->name << "_string_consts[] = {\n"; + for(std::vector::iterator i = _class->members.begin(); + i != _class->members.end(); ++i) { + ClassMember* member = *i; + if(member->visibility != ClassMember::PUBLIC) + continue; + Field* field = dynamic_cast (member); + if(!field) + continue; + if(!field->has_const_value + || field->type->atomic_type != StringType::instance()) + continue; + out << ind << "{ \"" << field->name << "\", " + << field->const_float_value << "},\n"; + } + out << ind << "{ 0, 0}\n"; + out << "};\n"; + out << "\n"; +} + +void WrapperCreator::create_function_wrapper(Class* _class, Function* function) { if(function->type == Function::DESTRUCTOR) diff --git a/tools/miniswig/create_wrapper.hpp b/tools/miniswig/create_wrapper.hpp index 97c14df44..06b842204 100644 --- a/tools/miniswig/create_wrapper.hpp +++ b/tools/miniswig/create_wrapper.hpp @@ -19,6 +19,11 @@ public: } void create_wrapper(Namespace* ns); + +private: + void create_function_list(Namespace* ns); + void create_const_lists(Namespace* ns); + void create_class_const_lists(Class* _class); void create_class_wrapper(Class* _class); void create_class_release_hook(Class* _class); void create_function_wrapper(Class* _class, Function* function); diff --git a/tools/miniswig/lexer.ll b/tools/miniswig/lexer.ll index d7f4d4ccb..4cf0850ee 100644 --- a/tools/miniswig/lexer.ll +++ b/tools/miniswig/lexer.ll @@ -78,7 +78,7 @@ int getCurrentLine() class { return T_CLASS; } struct { return T_STRUCT; } static { return T_STATIC; } -virtual { return T_VIRTUAL; } +virtual { } const { return T_CONST; } unsigned { return T_UNSIGNED; } signed { return T_SIGNED; } @@ -112,18 +112,18 @@ namespace { return T_NAMESPACE; } return T_ID; } \:\: { return T_DDCOL; } -[0-9]+ { - yylval->ival = atoi(yytext); - return T_INT; - } -[0-9]*\.[0-9]+(e[0-9]+)? { - yylval->fval = atof(yytext); - return T_FLOAT; - } -\".*\" { - yylval->str = strdup(yytext); - return T_STRING; - } +(0x)?[0-9]+ { + sscanf(yytext, "%i", &(yylval->ival)); + return T_INT; +} +[0-9]*\.[0-9]+(e[0-9]+)? { + sscanf(yytext, "%f", &(yylval->fval)); + return T_FLOAT; +} +\".*\" { + yylval->str = strdup(yytext); + return T_STRING; +} . { return yytext[0]; } %% diff --git a/tools/miniswig/parser.yy b/tools/miniswig/parser.yy index 1aae8ce04..0de8f6c00 100644 --- a/tools/miniswig/parser.yy +++ b/tools/miniswig/parser.yy @@ -15,6 +15,7 @@ float fval; Class* _class; Function* function; + Field* field; Type* type; AtomicType* atomic_type; Namespace* _namespace; @@ -30,8 +31,9 @@ bool search_down = true; Namespace* search_namespace = 0; Namespace* current_namespace = 0; static Class* current_class = 0; -static Function* currentFunction = 0; +static Function* current_function = 0; static Type* current_type = 0; +static Field* current_field = 0; static ClassMember::Visbility current_visibility; class ParseError : public std::exception @@ -67,7 +69,6 @@ private: %token T_CLASS %token T_STRUCT %token T_STATIC -%token T_VIRTUAL %token T_CONST %token T_UNSIGNED %token T_SIGNED @@ -89,6 +90,7 @@ private: %type function_declaration %type constructor_declaration; %type destructor_declaration; +%type field_declaration; %type type %type type_identifier @@ -134,6 +136,8 @@ namespace_member: | function_declaration { current_namespace->functions.push_back($1); } | namespace_declaration + | field_declaration + { current_namespace->fields.push_back($1); } ; class_declaration: @@ -173,7 +177,11 @@ class_body_element: $1->visibility = current_visibility; current_class->members.push_back($1); } - | variable_declaration + | field_declaration + { + $1->visibility = current_visibility; + current_class->members.push_back($1); + } ; visibility_change: @@ -188,58 +196,93 @@ visibility_change: constructor_declaration: T_ID '(' { - currentFunction = new Function(); - currentFunction->type = Function::CONSTRUCTOR; - currentFunction->docu_comment = last_docucomment; + current_function = new Function(); + current_function->type = Function::CONSTRUCTOR; + current_function->docu_comment = last_docucomment; last_docucomment = ""; free($1); } parameter_list ')' ';' { - $$ = currentFunction; + $$ = current_function; } ; destructor_declaration: - maybe_virtual '~' T_ID '(' ')' abstract_declaration ';' + '~' T_ID '(' ')' abstract_declaration ';' { - currentFunction = new Function(); - currentFunction->type = Function::DESTRUCTOR; - currentFunction->docu_comment = last_docucomment; + current_function = new Function(); + current_function->type = Function::DESTRUCTOR; + current_function->docu_comment = last_docucomment; last_docucomment = ""; - free($3); - $$ = currentFunction; + free($2); + $$ = current_function; } ; -maybe_virtual: - /* empty */ - | T_VIRTUAL -; - -variable_declaration: - type T_ID ';' +field_declaration: + type T_ID { - delete $1; + current_field = new Field(); + current_field->type = $1; + current_field->name = $2; free($2); } + maybe_const_initialisation ';' + { + $$ = current_field; + } ; +maybe_const_initialisation: + /* empty */ + | '=' T_INT + { + if(current_field->type->atomic_type == &BasicType::FLOAT) { + current_field->const_float_value = (float) $2; + } else { + current_field->const_int_value = $2; + } + current_field->has_const_value = true; + } + | '=' T_FLOAT + { + current_field->const_float_value = $2; + current_field->has_const_value = true; + } + | '=' T_STRING + { + current_field->const_string_value = $2; + current_field->has_const_value = true; + } +; + function_declaration: - maybe_virtual type T_ID '(' + type T_ID '(' { - currentFunction = new Function(); - currentFunction->type = Function::FUNCTION; - currentFunction->return_type = *($2); + /* + current_function = new Function(); + current_function->type = Function::FUNCTION; + current_function->return_type = *($2); delete $2; - currentFunction->name = $3; + current_function->name = $3; free($3); - currentFunction->docu_comment = last_docucomment; + current_function->docu_comment = last_docucomment; + last_docucomment = ""; + */ + + current_function = new Function(); + current_function->type = Function::FUNCTION; + current_function->return_type = *($1); + delete $1; + current_function->name = $2; + free($2); + current_function->docu_comment = last_docucomment; last_docucomment = ""; } parameter_list ')' abstract_declaration ';' { - $$ = currentFunction; + $$ = current_function; } ; @@ -264,7 +307,7 @@ parameter: Parameter parameter; parameter.type = *($1); delete $1; - currentFunction->parameters.push_back(parameter); + current_function->parameters.push_back(parameter); } | type T_ID { @@ -273,7 +316,7 @@ parameter: delete $1; parameter.name = $2; free($2); - currentFunction->parameters.push_back(parameter); + current_function->parameters.push_back(parameter); } ; diff --git a/tools/miniswig/tree.hpp b/tools/miniswig/tree.hpp index 2e7149c3f..ca0131bcb 100644 --- a/tools/miniswig/tree.hpp +++ b/tools/miniswig/tree.hpp @@ -167,6 +167,25 @@ public: std::vector parameters; }; +class Field : public ClassMember { +public: + Field() + { + has_const_value = false; + } + + Type* type; + std::string docu_comment; + std::string name; + bool has_const_value; + + union { + float const_float_value; + int const_int_value; + }; + std::string const_string_value; +}; + class Class : public AtomicType { public: ~Class() { @@ -243,6 +262,7 @@ public: } std::vector functions; + std::vector fields; std::vector types; std::vector namespaces;