sledorze / Parsex

Packrat Parser combinators for Haxe
21 stars 5 forks source link

Duplicate "_and" functions defined in compiled C++ files. #7

Closed SethSR closed 9 years ago

SethSR commented 9 years ago

Testing with a single file: Main.hx

import com.mindrocks.text.Parser;
class Main {
  static public function main() {
    trace ('Hello world');
  }
}

When I compile with: "haxe -lib Parsex -main Main.hx -cpp bin", I get the following:

include\Parsers.h(84) : error C2535: 'Dynamic Parsers_obj::_and(Dynamic,Dynamic)' : member function already defined or declared
include\Parsers.h(78) : see declaration of 'Parsers_obj::_and'
include\Parsers.h(85) : error C2535: 'Dynamic Parsers_obj::_and_dyn(void)' : member function already defined or declared
include\Parsers.h(79) : see declaration of 'Parsers_obj::_and_dyn'
./src/Parsers.cpp(1032) : error C2084: function 'Dynamic Parsers_obj::_and(Dynamic,Dynamic)' already has a body

include\Parsers.h(78) : see previous definition of '_and'
./src/Parsers.cpp(1041) : error C2084: function 'Dynamic __Parsers_obj_and(const Dynamic &,const Dynamic &)' already has a body
./src/Parsers.cpp(1019) : see previous definition of '__Parsers_obj_and'
./src/Parsers.cpp(1041) : error C2084: function 'Dynamic Parsers_obj::_and_dyn(void)' already has a body
include\Parsers.h(79) : see previous definition of '_and_dyn'
sledorze commented 9 years ago

Hummm... This appears to be a cpp target issue. Which Haxe version are you using?

Using the last Haxe stable version I have a different output

Error: ./src/haxe/Log.cpp:57:20: error: use of undeclared identifier '_g1'; did you mean '_g'?
                                cpp::ArrayBase _g1 = infos->__Field(HX_HCSTRING("customParams","\xd7","\x51","\x18","\xed"), hx::paccDynamic );         HX_STACK_VAR(_g1,"_g1");
                                               ^~~
                                               _g
./src/haxe/Log.cpp:55:9: note: '_g' declared here
                                int _g = (int)0;                HX_STACK_VAR(_g,"_g");
                                    ^
./src/haxe/Log.cpp:57:5: error: no member named 'ArrayBase' in namespace 'cpp'; did you mean 'hx::ArrayBase'?
                                cpp::ArrayBase _g1 = infos->__Field(HX_HCSTRING("customParams","\xd7","\x51","\x18","\xed"), hx::paccDynamic );         HX_STACK_VAR(_g1,"_g1");
                                ^~~~~
/usr/lib/haxe/lib/hxcpp/3,2,37/include/Array.h:71:37: note: 'hx::ArrayBase' declared here
class HXCPP_EXTERN_CLASS_ATTRIBUTES ArrayBase : public hx::Object
                                    ^
./src/haxe/Log.cpp:61:24: error: use of undeclared identifier '_g1'; did you mean '_g'?
                                        bool tmp2 = (_g < _g1->__Field(HX_HCSTRING("length","\xe6","\x94","\x07","\x9f"), hx::paccDynamic ));           HX_STACK_VAR(tmp2,"tmp2");
                                                          ^~~
                                                          _g
./src/haxe/Log.cpp:55:9: note: '_g' declared here
                                int _g = (int)0;                HX_STACK_VAR(_g,"_g");
                                    ^
./src/haxe/Log.cpp:61:29: error: member reference type 'int' is not a pointer
                                        bool tmp2 = (_g < _g1->__Field(HX_HCSTRING("length","\xe6","\x94","\x07","\x9f"), hx::paccDynamic ));           HX_STACK_VAR(tmp2,"tmp2");
                                                          ~~~  ^
./src/haxe/Log.cpp:70:21: error: use of undeclared identifier '_g1'; did you mean '_g'?
                                        Dynamic tmp4 = _g1->__GetItem(_g);              HX_STACK_VAR(tmp4,"tmp4");
                                                       ^~~
                                                       _g
./src/haxe/Log.cpp:55:9: note: '_g' declared here
                                int _g = (int)0;                HX_STACK_VAR(_g,"_g");
                                    ^
./src/haxe/Log.cpp:70:26: error: member reference type 'int' is not a pointer
                                        Dynamic tmp4 = _g1->__GetItem(_g);              HX
sledorze commented 9 years ago

Ok, upgrading to latest hxcpp I have something more in line with your report.

Error: In file included from ./src/Parsers.cpp:7:
include/Parsers.h:85:18: error: class member cannot be redeclared
                static Dynamic _and( Dynamic p1,Dynamic p2);
                               ^
include/Parsers.h:79:18: note: previous declaration is here
                static Dynamic _and( Dynamic p1,Dynamic p2);
                               ^
include/Parsers.h:86:18: error: class member cannot be redeclared
                static Dynamic _and_dyn();
                               ^
include/Parsers.h:80:18: note: previous declaration is here
                static Dynamic _and_dyn();
                               ^
./src/Parsers.cpp:1548:22: error: redefinition of '_and'
Dynamic Parsers_obj::_and( Dynamic p1,Dynamic p2){
                     ^
./src/Parsers.cpp:1516:22: note: previous definition is here
Dynamic Parsers_obj::_and( Dynamic p1,Dynamic p2){
                     ^
./src/Parsers.cpp:1565:1: error: redefinition of '__Parsers_obj_and'
STATIC_HX_DEFINE_DYNAMIC_FUNC2(Parsers_obj,_and,return )
^
/usr/lib/haxe/lib/hxcpp/3,2,94/include/hx/Macros.h:392:11: note: expanded from macro 'STATIC_HX_DEFINE_DYNAMIC_FUNC2'
          STATIC_HX_DEFINE_DYNAMIC_FUNC(class,2,func,ret,HX_ARR_LIST2,HX_DYNAMIC_ARG_LIST2,HX_ARG_LIST2)
          ^
/usr/lib/haxe/lib/hxcpp/3,2,94/include/hx/Macros.h:361:9: note: expanded from macro 'STATIC_HX_DEFINE_DYNAMIC_FUNC'
Dynamic __##class##func(dynamic_arg_list) \
        ^
<scratch space>:177:1: note: expanded from here
__Parsers_obj_and

...
sledorze commented 9 years ago

Ok the name collision comes from improper cpp source file generation.

See the haxe 'and' function line 400 has cpp function name '_and'

Dynamic Parsers_obj::_and( Dynamic p1,Dynamic p2){
    HX_STACK_FRAME("Parsers","and",0x155073fd,"Parsers.and","com/mindrocks/text/Parser.hx",400,0xcffee55e)
    HX_STACK_ARG(p1,"p1")
    HX_STACK_ARG(p2,"p2")

And the haxe '_and' function line 405 has also cpp function name '_and'

Dynamic Parsers_obj::_and( Dynamic p1,Dynamic p2){
    HX_STACK_FRAME("Parsers","_and",0x8fb8c7f2,"Parsers._and","com/mindrocks/text/Parser.hx",405,0xcffee55e)
    HX_STACK_ARG(p1,"p1")
    HX_STACK_ARG(p2,"p2")

I'll modify generated code name for that function.

sledorze commented 9 years ago

CPP generation issue reported here HaxeFoundation/haxe#4246

SethSR commented 9 years ago

Hmm, it seems like I'm still getting the same error. I tried downloading Parsex from Haxelib, and implementing your fix directly, but @:native("__and") didn't seem to have any effect...