petergtz / c2c-err-transpiler

This was an attempt to extend the C programming language with advanced error handling constructs, similar to those seen in Rust today. It's a compiler taking a C-like dialect and compiles to pure C.
1 stars 0 forks source link

It's failing to build #1

Open mingodad opened 1 month ago

mingodad commented 1 month ago

While trying to build I'm getting this errors:

 make
bison --verbose --debug -d c2c.ypp
lex c2c.l
clang++ -c -g -I /usr/include/c++/4.5 -I /usr/include/c++/4.5/x86_64-linux-gnu lex.yy.c
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang++ -g -I /usr/include/c++/4.5 -I /usr/include/c++/4.5/x86_64-linux-gnu   -c -o c2c.tab.o c2c.tab.cpp
c2c.ypp:645:36: error: member reference base type 'char' is not a structure or union
                   + (yyvsp[0].str)->eval() + ";"     
                     ~~~~~~~~~~~~~~^ ~~~~
c2c.ypp:650:68: error: member reference type 'std::map<std::__cxx11::basic_string<char>,
      std::__cxx11::basic_string<char>, std::less<std::__cxx11::basic_string<char> >, std::allocator<std::pair<const
      std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > > >::mapped_type' (aka
      'std::__cxx11::basic_string<char>') is not a pointer; did you mean to use '.'?
            if (failable_funcs[call_expressions.back().postfix_expression]->declaration_specifiers.type != "void") {
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
                                                                          .
c2c.ypp:650:70: error: no member named 'declaration_specifiers' in 'std::__cxx11::basic_string<char>'
            if (failable_funcs[call_expressions.back().postfix_expression]->declaration_specifiers.type != "void") {
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ^
3 errors generated.
<builtin>: recipe for target 'c2c.tab.o' failed
make: *** [c2c.tab.o] Error 1

And after this dirty changes I've got it to build but fail the tests:

@@ -638,18 +638,18 @@ expression_statement
            string tmp_result_var = "__tmp_result_var_" + lexical_cast<string>(suffix_index_use);
            string tmp_rc_var = "__tmp_rc_var_" + lexical_cast<string>(suffix_index_use);

            result += failable_funcs[call_expression.postfix_expression] + " " + tmp_result_var + ";\n"
                   + "int " + tmp_rc_var + " = "
                   + call_expression.postfix_expression + "(" + call_expression.argument_expression_list + ", &" + tmp_result_var +");\n"
                   + "if (" + tmp_rc_var + " != 0) {\n"
-                   + $3->eval() + ";"     
+                   + $3 + ";"
                   + "}\n";
            suffix_index_use++;
        }
        result += strdup($1);
-       if (failable_funcs[call_expressions.back().postfix_expression]->declaration_specifiers.type != "void") {
-           yyerror("or_on_error with a compound statement can only be used with a function that is void.");
-       }
+      // if (failable_funcs[call_expressions.back().postfix_expression]->declaration_specifiers.type != "void") {
+      //     yyerror("or_on_error with a compound statement can only be used with a function that is void.");
+      // }
        call_expressions.clear();
        $$ = strdup(result.c_str());
    }

Also I've just added the grammar/lexer to https://mingodad.github.io/parsertl-playground/playground/ an Yacc/Lex compatible online (wasm) editor/tester (select C2c-err-transpiler parser from Examples the click Parse to see a parse tree for the content in Input Source).

mingodad commented 1 month ago

The above post (https://github.com/petergtz/c2c-err-transpiler/issues/1#issuecomment-2363065361) seems to be a scam reported here https://ianspence.com/blog/2024-09/github-email-hijack/ , please delete it.