diff --git a/OMCompiler/Parser/MetaModelicaJuliaLayer.c b/OMCompiler/Parser/MetaModelicaJuliaLayer.c index 4dcc5148b53..a09e80c3ba7 100644 --- a/OMCompiler/Parser/MetaModelicaJuliaLayer.c +++ b/OMCompiler/Parser/MetaModelicaJuliaLayer.c @@ -27,7 +27,7 @@ void OpenModelica_initMetaModelicaJuliaLayer() assert((omc_jl_listEmpty = jl_get_function(MetaModelicaModule, "listEmpty"))); assert((omc_jl_isDerCref = jl_get_function(parserModule, "isDerCref"))); assert((omc_jl_tuple2 = jl_get_function(jl_base_module, "tuple"))); - assert((omc_jl_nil = jl_call0(jl_get_function(ListDefModule, "nil")))); + assert((omc_jl_nil = jl_get_global(ListDefModule, jl_symbol("nil")))); } void c_add_source_message( diff --git a/OMCompiler/Parser/MetaModelicaJuliaLayer.h b/OMCompiler/Parser/MetaModelicaJuliaLayer.h index 06cbf6cf570..f064fd02cc3 100644 --- a/OMCompiler/Parser/MetaModelicaJuliaLayer.h +++ b/OMCompiler/Parser/MetaModelicaJuliaLayer.h @@ -3,6 +3,8 @@ #include +#define jl_debug_println(X) jl_call1(jl_get_function(jl_base_module, "show"), (X)); + /* Note: These values may be garbage collected away? Call this before each file is parsed? */ void OpenModelica_initMetaModelicaJuliaLayer(); @@ -85,6 +87,4 @@ static inline jl_value_t* or_nil(jl_value_t *value) { return value ? value : mmc_mk_nil(); } -#define jl_debug_println(X) jl_call1(jl_get_function(jl_base_module, "show"), (X)); - #endif diff --git a/OMCompiler/Parser/Modelica.g b/OMCompiler/Parser/Modelica.g index 51a06ab2a50..08e2d0131d6 100644 --- a/OMCompiler/Parser/Modelica.g +++ b/OMCompiler/Parser/Modelica.g @@ -39,7 +39,16 @@ import MetaModelica_Lexer; /* Makes all tokens defined, imported in OptiMo_Lexer //import ParModelica_Lexer; /* Makes all tokens defined, except the ones specific to MetaModelica */ //import OptiMo_Lexer; /* Makes all tokens defined */ +scope omc{ + int numPushed; +} + @includes { + + #if defined(_WIN32) + #include + #endif + #define false 0 #define true 1 #define token_to_scon(tok) mmc_mk_scon((char*)tok->getText(tok)->chars) @@ -123,11 +132,23 @@ goto rule ## func ## Ex; }} #define isCall(X) (MMC_GETHDR(X) == MMC_STRUCTHDR(2+1, Absyn__CALL_3dBOX2)) #define isNotNil(X) (MMC_NILHDR != MMC_GETHDR(X)) #define mmc_mk_cons_typed(T,head,tail) mmc_mk_cons(head,tail) + #define OM_PUSHZ1(A) (A) = NULL; + #define OM_PUSHZ2(A,B) (A) = NULL; (B) = NULL; + #define OM_PUSHZ3(A,B,C) (A) = NULL; (B) = NULL; (C) = NULL; + #define OM_PUSHZ4(A,B,C,D) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; + #define OM_PUSHZ5(A,B,C,D,E) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; + #define OM_PUSHZ6(A,B,C,D,E,F) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; (F) = NULL; + #define OM_PUSHZ7(A,B,C,D,E,F,G) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; (F) = NULL; (G) = NULL; + #define OM_PUSHZ8(A,B,C,D,E,F,G,H) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; (F) = NULL; (G) = NULL; (H) = NULL; + #define OM_PUSHZ9(A,B,C,D,E,F,G,H,I) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; (F) = NULL; (G) = NULL; (H) = NULL; (I) = NULL; + #define OM_PUSHZ10(A,B,C,D,E,F,G,H,I,J) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; (F) = NULL; (G) = NULL; (H) = NULL; (I) = NULL; (J) = NULL; + #define OM_PUSHZ11(A,B,C,D,E,F,G,H,I,J,K) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; (F) = NULL; (G) = NULL; (H) = NULL; (I) = NULL; (J) = NULL; (K) = NULL; + #define OM_POP(NN) /* nothing */ #else /* Julia */ - #define PARSER_INFO(start) ((void*) SourceInfo__SOURCEINFO(mmc_mk_scon("dummyFile"), MMC_TRUE, mmc_mk_icon(start->line), mmc_mk_icon(start->line == 1 ? start->charPosition+2 : start->charPosition+1), mmc_mk_icon(LT(1)->line), mmc_mk_icon(LT(1)->charPosition+1), mmc_mk_rcon(0.0))) + #define PARSER_INFO(start) ((void*) SourceInfo__SOURCEINFO(ModelicaParser_filename_OMC, mmc_mk_bcon(ModelicaParser_readonly), mmc_mk_icon(start->line), mmc_mk_icon(start->line == 1 ? start->charPosition+2 : start->charPosition+1), mmc_mk_icon(LT(1)->line), mmc_mk_icon(LT(1)->charPosition+1), mmc_mk_rcon(0.0))) #define isCref(X) jl_typeis(X, Absyn_Exp_CREF_type) #define isPath(X) jl_typeis(X, Absyn_TypeSpec_TPATH_type) #define isComplex(X) jl_typeis(X, Absyn_TypeSpec_TCOMPLEX_type) @@ -138,6 +159,36 @@ goto rule ## func ## Ex; }} #define GlobalScript__IALG(X) NULL #define GlobalScript__IEXP(X, Y) NULL #define GlobalScript__ISTMTS(X, Y) NULL + + #define JL_GC_PUSH7(arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ + void *__gc_stkf[] = {(void*)15, jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6, arg7}; \ + jl_pgcstack = (jl_gcframe_t*)__gc_stkf; + #define JL_GC_PUSH8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \ + void *__gc_stkf[] = {(void*)17, jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8}; \ + jl_pgcstack = (jl_gcframe_t*)__gc_stkf; + #define JL_GC_PUSH9(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) \ + void *__gc_stkf[] = {(void*)19, jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9}; \ + jl_pgcstack = (jl_gcframe_t*)__gc_stkf; + #define JL_GC_PUSH10(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) \ + void *__gc_stkf[] = {(void*)21, jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10}; \ + jl_pgcstack = (jl_gcframe_t*)__gc_stkf; + #define JL_GC_PUSH11(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) \ + void *__gc_stkf[] = {(void*)23, jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11}; \ + jl_pgcstack = (jl_gcframe_t*)__gc_stkf; + + #define OM_PUSHZ1(A) (A) = NULL; JL_GC_PUSH1(&(A)); ctx->pModelicaParser_omcTop->numPushed+=1; + #define OM_PUSHZ2(A,B) (A) = NULL; (B) = NULL; JL_GC_PUSH2(&(A),&(B)); ctx->pModelicaParser_omcTop->numPushed+=2; + #define OM_PUSHZ3(A,B,C) (A) = NULL; (B) = NULL; (C) = NULL; JL_GC_PUSH3(&(A),&(B),&(C)); ctx->pModelicaParser_omcTop->numPushed+=3; + #define OM_PUSHZ4(A,B,C,D) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; JL_GC_PUSH4(&(A),&(B),&(C),&(D)); ctx->pModelicaParser_omcTop->numPushed+=4; + #define OM_PUSHZ5(A,B,C,D,E) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; JL_GC_PUSH5(&(A),&(B),&(C),&(D),&(E)); ctx->pModelicaParser_omcTop->numPushed+=5; + #define OM_PUSHZ6(A,B,C,D,E,F) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; (F) = NULL; JL_GC_PUSH6(&(A),&(B),&(C),&(D),&(E),&(F)); ctx->pModelicaParser_omcTop->numPushed+=6; + #define OM_PUSHZ7(A,B,C,D,E,F,G) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; (F) = NULL; (G) = NULL; JL_GC_PUSH7(&(A),&(B),&(C),&(D),&(E),&(F),&(G)); ctx->pModelicaParser_omcTop->numPushed+=7; + #define OM_PUSHZ8(A,B,C,D,E,F,G,H) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; (F) = NULL; (G) = NULL; (H) = NULL; JL_GC_PUSH8(&(A),&(B),&(C),&(D),&(E),&(F),&(G),&(H)); ctx->pModelicaParser_omcTop->numPushed+=8; + #define OM_PUSHZ9(A,B,C,D,E,F,G,H,I) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; (F) = NULL; (G) = NULL; (H) = NULL; (I) = NULL; JL_GC_PUSH9(&(A),&(B),&(C),&(D),&(E),&(F),&(G),&(H),&(I)); ctx->pModelicaParser_omcTop->numPushed+=9; + #define OM_PUSHZ10(A,B,C,D,E,F,G,H,I,J) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; (F) = NULL; (G) = NULL; (H) = NULL; (I) = NULL; (J) = NULL; JL_GC_PUSH10(&(A),&(B),&(C),&(D),&(E),&(F),&(G),&(H),&(I),&(J)); ctx->pModelicaParser_omcTop->numPushed+=10; + #define OM_PUSHZ11(A,B,C,D,E,F,G,H,I,J,K) (A) = NULL; (B) = NULL; (C) = NULL; (D) = NULL; (E) = NULL; (F) = NULL; (G) = NULL; (H) = NULL; (I) = NULL; (J) = NULL; (K) = NULL; JL_GC_PUSH11(&(A),&(B),&(C),&(D),&(E),&(F),&(G),&(H),&(I),&(J),&(K)); ctx->pModelicaParser_omcTop->numPushed+=11; + #define OM_POP(NN) ctx->pModelicaParser_omcTop->numPushed=ctx->pModelicaParser_omcTop->numPushed-NN; JL_GC_POP(); + #endif } @@ -163,7 +214,7 @@ goto rule ## func ## Ex; }} *------------------------------------------------------------------*/ stored_definition returns [void* ast] -@init{ within = NULL; cl = NULL; } : +@init{ $omc::numPushed; OM_PUSHZ2(within, cl); } : BOM? (within=within_clause SEMICOLON)? cl=class_definition_list? EOF @@ -171,27 +222,31 @@ stored_definition returns [void* ast] ast = Absyn__PROGRAM(or_nil(cl), within ? within : Absyn__TOP); } ; + finally{ OM_POP(2); } within_clause returns [void* ast] -@init{ name = NULL; } : - WITHIN (name=name_path)? {ast = name ? Absyn__WITHIN(name) : Absyn__TOP;} +@init{ OM_PUSHZ1(name); } : + WITHIN (name=name_path)? {ast = name ? Absyn__WITHIN(name) : Absyn__TOP; } ; + finally{ OM_POP(1); } class_definition_list returns [void* ast] -@init{ f = NULL; cd.ast = NULL; cl = NULL; } : +@init{ f = NULL; OM_PUSHZ2(cd.ast, cl); } : ((f=FINAL)? cd=class_definition[f != NULL] SEMICOLON) cl=class_definition_list? { ast = mmc_mk_cons_typed(Absyn_Class, cd.ast, or_nil(cl)); } ; + finally{ OM_POP(2); } class_definition [int final] returns [void* ast] -@init{ e = 0; p = 0; ct = 0; cs.ast = 0; } : +@init{ e = 0; p = 0; OM_PUSHZ4(ct, cs.ast, $cs.name, $ast); } : ((e=ENCAPSULATED)? (p=PARTIAL)? ct=class_type cs=class_specifier) { $ast = Absyn__CLASS($cs.name, mmc_mk_bcon(p), mmc_mk_bcon(final), mmc_mk_bcon(e), ct, $cs.ast, PARSER_INFO($start)); } ; + finally{ OM_POP(4); } class_type returns [void* ast] @init{ e = 0; pur = 0; impur = 0; opr = 0; prl = 0; ker = 0; r = 0; } : @@ -220,13 +275,14 @@ class_type returns [void* ast] } ) ; + identifier returns [char* str] : ( id=IDENT | id=DER | id=CODE | id=EQUALITY | id=INITIAL ) { str = (char*)$id.text->chars; } ; class_specifier returns [void* ast, void* name] -@init{ s1 = 0; mod = 0; cmt = 0; s2 = 0; comp.ast = 0; comp.ann = 0; spec.ast = 0; } : +@init{ s1 = 0; s2 = 0; OM_PUSHZ5(mod, cmt, comp.ast, comp.ann, spec.ast); } : ( s1=identifier spec=class_specifier2 { modelicaParserAssert($spec.s2 == NULL || !strcmp(s1,$spec.s2), "The identifier at start and end are different", class_specifier, $start->line, $start->charPosition+1, LT(1)->line, LT(1)->charPosition); @@ -241,11 +297,11 @@ class_specifier returns [void* ast, void* name] } ) ; + finally{ OM_POP(5); } class_specifier2 returns [void* ast, const char *s2] @init { - $s2 = 0; ids = 0; gt = 0; cmtStr = 0; cmt = 0; c.ast = 0; c.ann = 0; - na = 0; rp = 0; attr = 0; path.ast = 0; cm = 0; cs = 0; ts.ast = 0; + $s2 = 0; gt = 0; rp = 0; OM_PUSHZ11(ids, cmtStr, cmt, c.ast, c.ann, na, attr, path.ast, cm, cs, ts.ast); } : ( (lt=LESS ids=ident_list gt=GREATER)? cmtStr=string_comment c=composition id=END_IDENT @@ -272,51 +328,58 @@ class_specifier2 returns [void* ast, const char *s2] | EQUALS cs=overloading { $ast=cs; } | SUBTYPEOF ts=type_specifier { - $ast = Absyn__DERIVED(Absyn__TCOMPLEX(Absyn__IDENT(mmc_mk_scon("polymorphic")),mmc_mk_cons($ts.ast,mmc_mk_nil()),mmc_mk_nil()), + $ast = Absyn__DERIVED(Absyn__TCOMPLEX(Absyn__IDENT(mmc_mk_scon("polymorphic")),mmc_mk_cons_typed(Absyn_TypeSpec, $ts.ast, mmc_mk_nil()),mmc_mk_nil()), Absyn__ATTR(MMC_FALSE,MMC_FALSE,Absyn__NON_5fPARALLEL,Absyn__VAR,Absyn__BIDIR,Absyn__NONFIELD,mmc_mk_nil()),mmc_mk_nil(),mmc_mk_none()); } ) ; +finally{ OM_POP(11); } pder returns [void* ast] -@init { func = 0; var_lst = 0; cmt = 0; } : +@init { OM_PUSHZ3(func, var_lst, cmt); } : DER LPAR func=name_path COMMA var_lst=ident_list RPAR cmt=comment { ast = Absyn__PDER(func, var_lst, mmc_mk_some_or_none(cmt)); } ; + finally{ OM_POP(3); } ident_list returns [void* ast] -@init { i = 0; il = 0; } : +@init { i = 0; OM_PUSHZ1(il); } : i=IDENT (COMMA il=ident_list)? { ast = mmc_mk_cons(token_to_scon(i), or_nil(il)); } ; + finally{ OM_POP(1); } overloading returns [void* ast] -@init { nl = 0; cmt = 0; } : +@init { OM_PUSHZ2(nl, cmt); } : OVERLOAD LPAR nl=name_list RPAR cmt=comment { ast = Absyn__OVERLOAD(nl, mmc_mk_some_or_none(cmt)); } ; + finally{ OM_POP(2); } -base_prefix returns [void* ast] : - tp=type_prefix {ast = Absyn__ATTR(tp.flow, tp.stream, tp.parallelism, tp.variability, tp.direction, tp.field, mmc_mk_nil());} +base_prefix returns [void* ast] +@init { OM_PUSHZ7(tp.flow, tp.stream, tp.parallelism, tp.variability, tp.direction, tp.field, ast); } : + tp=type_prefix { ast = Absyn__ATTR(tp.flow, tp.stream, tp.parallelism, tp.variability, tp.direction, tp.field, mmc_mk_nil()); } ; + finally{ OM_POP(7); } name_list returns [void* ast] -@init { n = 0; nl = 0; } : +@init { OM_PUSHZ2(n, nl); } : n=name_path (COMMA nl=name_list)? { ast = mmc_mk_cons_typed(Absyn_Path, n, or_nil(nl)); } ; + finally{ OM_POP(2); } enumeration returns [void* ast] -@init { el = 0; c = 0; cmt = 0; } : +@init { c = 0; OM_PUSHZ2(el, cmt); } : ENUMERATION LPAR (el=enum_list | c=COLON ) RPAR cmt=comment { if (c) { @@ -326,28 +389,32 @@ enumeration returns [void* ast] } } ; + finally{ OM_POP(2); } enum_list returns [void* ast] -@init { e = 0; el = 0; } : +@init { OM_PUSHZ2(e, el); } : e=enumeration_literal ( COMMA el=enum_list )? { ast = mmc_mk_cons_typed(Absyn_EnumLiteral, e, or_nil(el)); } ; + finally{ OM_POP(2); } enumeration_literal returns [void* ast] -@init { i1 = 0; c1 = 0; } : +@init { i1 = 0; OM_PUSHZ1(c1); } : i1=IDENT c1=comment { ast = Absyn__ENUMLITERAL(token_to_scon(i1),mmc_mk_some_or_none(c1)); } ; + finally{ OM_POP(1); } composition returns [void* ast, void* ann] -@init { $ann = mmc_mk_nil(); el = 0; els = 0; a = 0; } : +@init { OM_PUSHZ4($ann, el, els, a); $ann = mmc_mk_nil(); } : el=element_list[&$ann] els=composition2[&$ann] (a=annotation SEMICOLON)? { $ast = mmc_mk_cons_typed(Absyn_ClassPart, Absyn__PUBLIC(el), els); $ann = a ? mmc_mk_cons_typed(Absyn_Annotation, a, $ann) : $ann; } ; + finally{ OM_POP(4); } composition2 [void **ann] returns [void* ast] -@init { ext = 0; el = 0; } : +@init { OM_PUSHZ2(ext, el); } : ( ext=external_clause? { ast = or_nil(ext); } | ( el=public_element_list[ann] | el=protected_element_list[ann] @@ -356,12 +423,13 @@ composition2 [void **ann] returns [void* ast] | el=equation_clause[ann] | el=constraint_clause[ann] | el=algorithm_clause[ann] - ) els=composition2[ann] {ast = mmc_mk_cons(el,els);} + ) els=composition2[ann] {ast = mmc_mk_cons_typed(Absyn_ClassPart, el, els); } ) ; + finally{ OM_POP(2); } external_clause returns [void* ast] -@init { retexp.ast = 0; lang = 0; funcname = 0; expl = 0; ann1 = 0;} : +@init { OM_PUSHZ4(retexp.ast, lang, expl, ann1); funcname = 0; } : EXTERNAL ( lang=language_specification )? ( ( retexp=component_reference EQUALS )? @@ -374,24 +442,28 @@ external_clause returns [void* ast] mmc_mk_some_or_none(retexp.ast), or_nil(expl), mmc_mk_some_or_none(ann1)); - ast = mmc_mk_cons(Absyn__EXTERNAL(ast, mmc_mk_none()), mmc_mk_nil()); + ast = mmc_mk_cons_typed(Absyn_ClassPart, Absyn__EXTERNAL(ast, mmc_mk_none()), mmc_mk_nil()); } ; + finally{ OM_POP(4); } external_annotation returns [void* ast] -@init { ann = 0; } : +@init { OM_PUSHZ1(ann); } : ann=annotation SEMICOLON { ast = ann; } ; + finally{ OM_POP(1); } public_element_list [void **ann] returns [void* ast] -@init { es = 0; } : +@init { OM_PUSHZ1(es); } : PUBLIC es=element_list[ann] { ast = Absyn__PUBLIC(es); } ; + finally{ OM_POP(1); } protected_element_list [void **ann] returns [void* ast] -@init { es = 0; } : - PROTECTED es=element_list[ann] {ast = Absyn__PROTECTED(es);} +@init { OM_PUSHZ1(es); } : + PROTECTED es=element_list[ann] {ast = Absyn__PROTECTED(es); } ; + finally{ OM_POP(1); } language_specification returns [void* ast] : id=STRING {ast = token_to_scon(id);} @@ -400,20 +472,19 @@ language_specification returns [void* ast] : element_list [void **ann] returns [void* ast] @init { int first = 0, last = 0; - e.ast = 0; + OM_PUSHZ3(e.ast, ast, a); ast = mmc_mk_nil(); last = LT(1)->getTokenIndex(LT(1)); - a = 0; for (;omc_first_commentget(INPUT,omc_first_comment); if (tok->getChannel(tok) == HIDDEN && (tok->type == LINE_COMMENT || tok->type == ML_COMMENT)) { - ast = mmc_mk_cons(Absyn__LEXER_5fCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),ast); + ast = mmc_mk_cons_typed(Absyn_ElementItem, Absyn__LEXER_5fCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),ast); } } } : (( - ( e=element {ast=mmc_mk_cons(Absyn__ELEMENTITEM(e.ast), ast);} - | ( { ann && (ModelicaParser_langStd < 31 || 1) }? a=annotation {*ann = mmc_mk_cons(a, *ann);} ) + ( e=element {ast=mmc_mk_cons_typed(Absyn_ElementItem, Absyn__ELEMENTITEM(e.ast), ast);} + | ( { ann && (ModelicaParser_langStd < 31 || 1) }? a=annotation {*ann = mmc_mk_cons_typed(Absyn_Annotation, a, *ann);} ) ) ) SEMICOLON { @@ -421,7 +492,7 @@ element_list [void **ann] returns [void* ast] for (;omc_first_commentget(INPUT,omc_first_comment); if (tok->getChannel(tok) == HIDDEN && (tok->type == LINE_COMMENT || tok->type == ML_COMMENT)) { - ast = mmc_mk_cons(Absyn__LEXER_5fCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),ast); + ast = mmc_mk_cons_typed(Absyn_ElementItem, Absyn__LEXER_5fCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)), ast); } } } @@ -433,10 +504,11 @@ element_list [void **ann] returns [void* ast] } } ; + finally{ OM_POP(3); } element returns [void* ast] -@declarations { void *final = 0, *innerouter = 0, *redecl = 0; } -@init { cc = 0; f = 0; i = 0; o = 0; r = 0; $ast = 0; cdef.ast = 0; constr = 0; } +@declarations { void *final = 0, *innerouter = 0; } +@init { f = 0; i = 0; o = 0; r = 0; OM_PUSHZ9(cc, $ast, cdef.ast, constr, final, innerouter, ic, ec, du); } : ic=import_clause { $ast = Absyn__ELEMENT(MMC_FALSE,mmc_mk_none(),Absyn__NOT_5fINNER_5fOUTER, ic, PARSER_INFO($start), mmc_mk_none()); } | ec=extends_clause { $ast = Absyn__ELEMENT(MMC_FALSE,mmc_mk_none(),Absyn__NOT_5fINNER_5fOUTER, ec, PARSER_INFO($start),mmc_mk_none()); } @@ -468,35 +540,40 @@ element returns [void* ast] modelicaParserAssert(0, "Found the start of a connect equation but expected an element (are you missing the equation keyword?)", element, $start->line, $start->charPosition+1, LT(1)->line, LT(1)->charPosition); } ; + finally{ OM_POP(9); } import_clause returns [void* ast] -@init { cmt = 0; im = 0; imp = 0; } : +@init { im = 0; OM_PUSHZ2(cmt, imp); } : im=IMPORT (imp=explicit_import_name | imp=implicit_import_name) cmt=comment { ast = Absyn__IMPORT(imp, mmc_mk_some_or_none(cmt), PARSER_INFO($im)); } ; + finally{ OM_POP(2); } defineunit_clause returns [void* ast] -@init { id = 0; na = 0; } : +@init { id = 0; OM_PUSHZ1(na); } : DEFINEUNIT id=IDENT (LPAR na=named_arguments RPAR)? { ast = Absyn__DEFINEUNIT(token_to_scon(id),or_nil(na)); } ; + finally{ OM_POP(1); } explicit_import_name returns [void* ast] -@init { id = 0; p = 0; } : - (id=IDENT|id=CODE) EQUALS p=name_path {ast = Absyn__NAMED_5fIMPORT(token_to_scon(id),p);} +@init { id = 0; OM_PUSHZ1(p); } : + (id=IDENT|id=CODE) EQUALS p=name_path {ast = Absyn__NAMED_5fIMPORT(token_to_scon(id),p); } ; + finally{ OM_POP(1); } implicit_import_name returns [void* ast] -@init { np.lst = 0; np.ast = 0; np.unqual = 0; } : +@init { OM_PUSHZ2(np.lst, np.ast); np.unqual = 0; } : np=name_path_star { ast = np.lst ? Absyn__GROUP_5fIMPORT(np.ast, np.lst) : np.unqual ? Absyn__UNQUAL_5fIMPORT(np.ast) : Absyn__QUAL_5fIMPORT(np.ast); } -; + ; + finally{ OM_POP(2); } /* * 2.2.3 Extends @@ -505,23 +582,26 @@ implicit_import_name returns [void* ast] // Note that this is a minor modification of the standard by // allowing the comment. extends_clause returns [void* ast] -@init { path = 0; mod = 0; ann = 0; } : +@init { OM_PUSHZ3(path, mod, ann); } : EXTENDS path=name_path (mod=class_modification)? (ann=annotation)? { ast = Absyn__EXTENDS(path,or_nil(mod),mmc_mk_some_or_none(ann)); } ; + finally{ OM_POP(3); } constraining_clause_comment returns [void* ast] -@init { constr = 0; cmt = 0; } : +@init { OM_PUSHZ2(constr, cmt); } : constr=constraining_clause cmt=comment { $ast = Absyn__CONSTRAINCLASS(constr, mmc_mk_some_or_none(cmt)); } ; + finally{ OM_POP(2); } constraining_clause returns [void* ast] -@init { np = 0; mod = 0; } : +@init { OM_PUSHZ2(np, mod); } : EXTENDS np=name_path (mod=class_modification)? { ast = Absyn__EXTENDS(np,or_nil(mod),mmc_mk_none()); } | CONSTRAINEDBY np=name_path (mod=class_modification)? { ast = Absyn__EXTENDS(np,or_nil(mod),mmc_mk_none()); } ; + finally{ OM_POP(2); } /* * 2.2.4 Component clause @@ -529,7 +609,7 @@ constraining_clause returns [void* ast] component_clause returns [void* ast] @declarations { void *arr = 0, *ar_option = 0; } -@init { path.ast = 0; clst = 0; ast = 0; } : +@init { OM_PUSHZ11(path.ast, clst, ast, arr, ar_option, tp.flow, tp.stream, tp.parallelism, tp.variability, tp.direction, tp.field); } : tp=type_prefix path=type_specifier clst=component_list { // Take the last (array subscripts) from type and move it to ATTR @@ -542,7 +622,8 @@ component_clause returns [void* ast] #else /* Are these things OK? */ ar_option = jl_data_ptr($path.ast)[1]; - jl_data_ptr($path.ast)[1] = jl_nothing; + jl_data_ptr($path.ast)[1] = jl_nothing; /* TODO! FIXME! I think we need a write barrier here, see jl_gc_wb */ + jl_gc_wb($path.ast, jl_nothing); #endif } else if (isComplex($path.ast)) @@ -554,7 +635,8 @@ component_clause returns [void* ast] #else /* Are these things OK? */ ar_option = jl_data_ptr($path.ast)[2]; - jl_data_ptr($path.ast)[2] = jl_nothing; + jl_data_ptr($path.ast)[2] = jl_nothing; /* TODO! FIXME! I think we need a write barrier here, see jl_gc_wb */ + jl_gc_wb($path.ast, jl_nothing); #endif } else @@ -584,7 +666,7 @@ component_clause returns [void* ast] } else // is SOME(arr) { - arr = jl_data_ptr(ar_option)[0]; + arr = jl_data_ptr(ar_option)[0]; /* TODO! FIXME! I think we need a write barrier here, see jl_gc_wb */ } } #endif @@ -592,9 +674,10 @@ component_clause returns [void* ast] ast = Absyn__COMPONENTS(Absyn__ATTR(tp.flow, tp.stream, tp.parallelism, tp.variability, tp.direction, tp.field, arr), $path.ast, clst); } ; + finally{ OM_POP(11); } type_prefix returns [void* flow, void* stream, void* parallelism, void* variability, void* direction, void* field] -@init { fl = 0; st = 0; srd = 0; glb = 0; di = 0; pa = 0; co = 0; in = 0; out = 0; fi = 0; nofi = 0;} : +@init { fl = 0; st = 0; srd = 0; glb = 0; di = 0; pa = 0; co = 0; in = 0; out = 0; fi = 0; nofi = 0; OM_PUSHZ6($flow, $stream, $parallelism, $variability, $direction, $field); } : (fl=FLOW|st=STREAM)? (srd=T_LOCAL|glb=T_GLOBAL)? (di=DISCRETE|pa=PARAMETER|co=CONSTANT)? in=T_INPUT? out=T_OUTPUT? (fi=FIELD|nofi=NONFIELD)? { $flow = mmc_mk_bcon(fl); @@ -610,9 +693,10 @@ type_prefix returns [void* flow, void* stream, void* parallelism, void* variabil $field = fi ? Absyn__FIELD : nofi ? Absyn__NONFIELD : Absyn__NONFIELD; } ; + finally{ OM_POP(6); } type_specifier returns [void* ast] -@init { ts = 0; as = 0; } : +@init { OM_PUSHZ3(np, ts, as); } : np=name_path (lt=LESS ts=type_specifier_list gt=GREATER)? (as=array_subscripts)? { @@ -625,43 +709,50 @@ type_specifier returns [void* ast] } } ; + finally{ OM_POP(3); } type_specifier_list returns [void* ast] -@init { np2 = 0; } : - np1=type_specifier ( COMMA np2=type_specifier_list )? { ast = mmc_mk_cons($np1.ast,or_nil(np2)); } +@init { OM_PUSHZ3($np1.ast, np2, ast); } : + np1=type_specifier ( COMMA np2=type_specifier_list )? { ast = mmc_mk_cons_typed(Absyn_TypeSpec, $np1.ast, or_nil(np2)); } ; + finally{ OM_POP(3); } component_list returns [void* ast] -@init { c = 0; cs = 0; } : - c=component_declaration (COMMA cs=component_list)? {ast = mmc_mk_cons(c, or_nil(cs));} +@init { OM_PUSHZ2(c, cs); } : + c=component_declaration (COMMA cs=component_list)? { ast = mmc_mk_cons_typed(Absyn_ComponentItem, c, or_nil(cs)); } ; + finally{ OM_POP(2); } component_declaration returns [void* ast] -@init { decl = 0; cond = 0; cmt = 0; } : +@init { OM_PUSHZ3(decl, cond, cmt); } : decl=declaration (cond=conditional_attribute)? cmt=comment { ast = Absyn__COMPONENTITEM(decl, mmc_mk_some_or_none(cond), mmc_mk_some_or_none(cmt)); } ; + finally{ OM_POP(3); } -conditional_attribute returns [void* ast] : - IF e=expression[metamodelica_enabled()] {ast = e.ast;} - ; +conditional_attribute returns [void* ast] +@init { OM_PUSHZ1(e.ast); } : + IF e=expression[metamodelica_enabled()] { ast = e.ast; } + ; + finally{ OM_POP(1); } declaration returns [void* ast] -@init { id = 0; as = 0; mod.ast = 0; } : +@init { id = 0; OM_PUSHZ2(as, mod.ast); } : ( id=IDENT | id=OPERATOR ) (as=array_subscripts)? (mod=modification)? { ast = Absyn__COMPONENT(token_to_scon(id), or_nil(as), mmc_mk_some_or_none($mod.ast)); } ; + finally{ OM_POP(2); } /* * 2.2.5 Modification */ modification returns [void* ast] -@init { e.ast = 0; eq = 0; cm = 0; } : +@init { OM_PUSHZ2(e.ast, cm); eq = 0; } : ( cm=class_modification ( eq=EQUALS e=expression[metamodelica_enabled()] )? | eq=EQUALS e=expression[metamodelica_enabled()] | eq=ASSIGN e=expression[metamodelica_enabled()] {c_add_source_message(NULL,2, ErrorType_syntax, ErrorLevel_warning, ":= in modifiers has been deprecated", @@ -672,33 +763,45 @@ modification returns [void* ast] $ast = Absyn__CLASSMOD(or_nil(cm), e.ast ? Absyn__EQMOD(e.ast,PARSER_INFO($eq)) : Absyn__NOMOD); } ; + finally{ OM_POP(2); } class_modification returns [void* ast] -@init { as = 0; ast = 0; } : +@init { OM_PUSHZ2(as, ast); } : LPAR ( as=argument_list )? RPAR { ast = or_nil(as); } ; + finally{ OM_POP(2); } argument_list returns [void* ast] -@init { a = 0; as = 0; } : - a=argument ( COMMA as=argument_list )? { ast = mmc_mk_cons(a, or_nil(as)); } +@init { OM_PUSHZ3(a, as, ast); } : + a=argument ( COMMA as=argument_list )? + { + if (!a) + { + fprintf(stderr, "crap!\n"); + } + ast = mmc_mk_cons_typed(Absyn_ElementArg, a, or_nil(as)); + } ; + finally{ OM_POP(3); } argument returns [void* ast] -@init { em = 0; er.ast = 0; } : +@init { OM_PUSHZ2(em, er.ast); } : ( em=element_modification_or_replaceable { $ast = em; } | er=element_redeclaration { $ast = $er.ast; } ) ; + finally{ OM_POP(2); } element_modification_or_replaceable returns [void* ast] -@init { ast = NULL; em.ast = NULL; e = 0; f = 0; } : +@init { OM_PUSHZ2(ast, em.ast); e = 0; f = 0; } : (e=EACH)? (f=FINAL)? ( em=element_modification[e ? Absyn__EACH : Absyn__NON_5fEACH, mmc_mk_bcon(f)] { ast = $em.ast; } | er=element_replaceable[e != NULL,f != NULL,false] { ast = $er.ast; } ) ; + finally{ OM_POP(2); } element_modification [void *each, void *final] returns [void* ast] -@init { $ast = NULL; mod.ast = 0; cmt = 0; br = 0;} : +@init { OM_PUSHZ4($ast, $mod.ast, cmt, path); br = 0;} : path=name_path2 (br=LBRACK | ((mod=modification)? cmt=string_comment)) { if (br) { @@ -710,9 +813,10 @@ element_modification [void *each, void *final] returns [void* ast] $ast = Absyn__MODIFICATION(final, each, path, mmc_mk_some_or_none($mod.ast), mmc_mk_some_or_none(cmt), PARSER_INFO($start)); } ; + finally{ OM_POP(4); } element_redeclaration returns [void* ast] -@init { $ast = NULL; er.ast = NULL; f = 0; cc = 0; e = 0; cdef.ast = 0; } : +@init { OM_PUSHZ4($ast, er.ast, cc, cdef.ast); f = 0; e = 0; } : REDECLARE (e=EACH)? (f=FINAL)? ( (cdef=class_definition[f != NULL] | cc=component_clause1) | er=element_replaceable[e != NULL,f != NULL, true] ) { @@ -723,9 +827,10 @@ element_redeclaration returns [void* ast] } } ; + finally{ OM_POP(4); } element_replaceable [int each, int final, int redeclare] returns [void* ast] -@init { $ast = NULL; e_spec = 0; cd.ast = 0; constr = 0; } : +@init { OM_PUSHZ4($ast, e_spec, cd.ast, constr); } : REPLACEABLE ( cd=class_definition[final] | e_spec=component_clause1 ) constr=constraining_clause_comment? { $ast = Absyn__REDECLARATION(mmc_mk_bcon(final), make_redeclare_keywords(true,redeclare), @@ -733,63 +838,71 @@ element_replaceable [int each, int final, int redeclare] returns [void* ast] mmc_mk_some_or_none(constr), PARSER_INFO($start)); } ; + finally{ OM_POP(4); } component_clause1 returns [void* ast] -@init { attr = NULL; ts.ast = 0; comp_decl = 0; } : +@init { OM_PUSHZ3(attr, ts.ast, comp_decl); } : attr=base_prefix ts=type_specifier comp_decl=component_declaration1 { - ast = Absyn__COMPONENTS(attr, $ts.ast, mmc_mk_cons(comp_decl, mmc_mk_nil())); + ast = Absyn__COMPONENTS(attr, $ts.ast, mmc_mk_cons_typed(Absyn_ComponentItem, comp_decl, mmc_mk_nil())); } ; + finally{ OM_POP(3); } component_declaration1 returns [void* ast] -@init { decl = 0; cmt = 0; } : +@init { OM_PUSHZ2(decl, cmt); } : decl=declaration cmt=comment { ast = Absyn__COMPONENTITEM(decl, mmc_mk_none(), mmc_mk_some_or_none(cmt)); } ; + finally{ OM_POP(2); } /* * 2.2.6 Equations */ -initial_equation_clause [void **ann] returns [void* ast] : +initial_equation_clause [void **ann] returns [void* ast] +@init { OM_PUSHZ1(es); } : { LA(2)==EQUATION }? INITIAL EQUATION es=equation_annotation_list[ann] { ast = Absyn__INITIALEQUATIONS(es); } ; + finally{ OM_POP(1); } -equation_clause [void **ann] returns [void* ast] : +equation_clause [void **ann] returns [void* ast] +@init { OM_PUSHZ1(es); } : EQUATION es=equation_annotation_list[ann] { ast = Absyn__EQUATIONS(es); } ; + finally{ OM_POP(1); } -constraint_clause [void **ann] returns [void* ast] : +constraint_clause [void **ann] returns [void* ast] +@init { OM_PUSHZ1(cs); } : CONSTRAINT cs=constraint_annotation_list[ann] { ast = Absyn__CONSTRAINTS(cs); } ; + finally{ OM_POP(1); } equation_annotation_list [void **ann] returns [void* ast] @init { int last, haveEq; - ast = mmc_mk_nil(); last = LT(1)->getTokenIndex(LT(1)); - ea = 0; - eq.ast = 0; + OM_PUSHZ3(ea, eq.ast, ast); + ast = mmc_mk_nil(); for (;omc_first_commentget(INPUT,omc_first_comment); if (tok->getChannel(tok) == HIDDEN && (tok->type == LINE_COMMENT || tok->type == ML_COMMENT)) { - ast = mmc_mk_cons(Absyn__EQUATIONITEMCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),ast); + ast = mmc_mk_cons_typed(Absyn_EquationItem, Absyn__EQUATIONITEMCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),ast); } } } : ( { LA(1) != END_IDENT && LA(1) != CONSTRAINT && LA(1) != EQUATION && LA(1) != T_ALGORITHM && LA(1)!=INITIAL && LA(1) != PROTECTED && LA(1) != PUBLIC }? => - ( eq=equation SEMICOLON { ast = mmc_mk_cons(eq.ast,ast); } - | ea=annotation SEMICOLON {*ann = mmc_mk_cons(ea,*ann);} + ( eq=equation SEMICOLON { ast = mmc_mk_cons_typed(Absyn_EquationItem, eq.ast,ast); } + | ea=annotation SEMICOLON {*ann = mmc_mk_cons_typed(Absyn_Annotation, ea, *ann);} ) { last = LT(1)->getTokenIndex(LT(1)); for (;omc_first_commentget(INPUT,omc_first_comment); if (tok->getChannel(tok) == HIDDEN && (tok->type == LINE_COMMENT || tok->type == ML_COMMENT)) { - ast = mmc_mk_cons(Absyn__EQUATIONITEMCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),ast); + ast = mmc_mk_cons_typed(Absyn_EquationItem, Absyn__EQUATIONITEMCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),ast); } } } @@ -801,47 +914,54 @@ equation_annotation_list [void **ann] returns [void* ast] } } ; + finally{ OM_POP(3); } constraint_annotation_list [void **ann] returns [void* ast] -@init { co = 0; c = 0; } +@init { OM_PUSHZ3(co, c, cs); } : - { LA(1) == END_IDENT || LA(1) == CONSTRAINT || LA(1) == EQUATION || LA(1) == T_ALGORITHM || LA(1)==INITIAL || LA(1) == PROTECTED || LA(1) == PUBLIC }? + { LA(1) == END_IDENT || LA(1) == CONSTRAINT || LA(1) == EQUATION || LA(1) == +T_ALGORITHM || LA(1)==INITIAL || LA(1) == PROTECTED || LA(1) == PUBLIC }? { ast = mmc_mk_nil(); } | ( co=constraint SEMICOLON { c = co; } - | c=annotation SEMICOLON { *ann = mmc_mk_cons(c, ann); } - ) cs=constraint_annotation_list[ann] { ast = c ? mmc_mk_cons(c,cs) : cs; } + | c=annotation SEMICOLON { *ann = mmc_mk_cons_typed(Absyn_Annotation, c, *ann); } + ) cs=constraint_annotation_list[ann] { ast = c ? mmc_mk_cons_typed(Absyn_Exp, c, cs) : cs; } ; + finally{ OM_POP(3); } + algorithm_clause [void **ann] returns [void* ast] -@init{ as.ast = 0; } : +@init{ OM_PUSHZ1(as.ast); } : T_ALGORITHM as=algorithm_annotation_list[ann,0] { ast = Absyn__ALGORITHMS(as.ast); } ; + finally{ OM_POP(1); } initial_algorithm_clause [void **ann] returns [void* ast] -@init{ as.ast = 0; } : +@init{ OM_PUSHZ1(as.ast); } : { LA(2)==T_ALGORITHM }? INITIAL T_ALGORITHM as=algorithm_annotation_list[ann,0] { ast = Absyn__INITIALALGORITHMS(as.ast); } ; + finally{ OM_POP(1); } algorithm_annotation_list [void **ann, int matchCase] returns [void* ast] @init { int last,isalg = 0; + OM_PUSHZ3(al.ast, $ast, a); $ast = mmc_mk_nil(); last = LT(1)->getTokenIndex(LT(1)); for (;omc_first_commentget(INPUT,omc_first_comment); if (tok->getChannel(tok) == HIDDEN && (tok->type == LINE_COMMENT || tok->type == ML_COMMENT)) { - $ast = mmc_mk_cons(Absyn__ALGORITHMITEMCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),$ast); + $ast = mmc_mk_cons_typed(Absyn_AlgorithmItem, Absyn__ALGORITHMITEMCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),$ast); } } } : ( { matchCase ? LA(1) != THEN : (LA(1) != END_IDENT && LA(1) != EQUATION && LA(1) != T_ALGORITHM && LA(1)!=INITIAL && LA(1) != PROTECTED && LA(1) != PUBLIC) }?=> - ( al=algorithm SEMICOLON { $ast = mmc_mk_cons(al.ast,$ast); } + ( al=algorithm SEMICOLON { $ast = mmc_mk_cons_typed(Absyn_AlgorithmItem, al.ast,$ast); } | a=annotation SEMICOLON { if (ann) { - *ann = mmc_mk_cons(a,*ann); + *ann = mmc_mk_cons_typed(Absyn_Annotation, a, *ann); } else { ModelicaParser_lexerError = ANTLR3_TRUE; c_add_source_message(NULL, 2, ErrorType_syntax, ErrorLevel_error, "Annotations are not allowed in an algorithm list.", @@ -855,7 +975,7 @@ algorithm_annotation_list [void **ann, int matchCase] returns [void* ast] for (;omc_first_commentget(INPUT,omc_first_comment); if (tok->getChannel(tok) == HIDDEN && (tok->type == LINE_COMMENT || tok->type == ML_COMMENT)) { - $ast = mmc_mk_cons(Absyn__ALGORITHMITEMCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),$ast); + $ast = mmc_mk_cons_typed(Absyn_AlgorithmItem,Absyn__ALGORITHMITEMCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),$ast); } } } @@ -867,9 +987,10 @@ algorithm_annotation_list [void **ann, int matchCase] returns [void* ast] } } ; + finally{ OM_POP(3); } equation returns [void* ast] -@init { cmt = 0; e = 0; e1.ast = 0; e2.ast = 0; eq.ast = 0; ee.ast = 0; } : +@init { OM_PUSHZ6(cmt, e, e1.ast, e2.ast, eq.ast, ee.ast); } : ( ee=equality_or_noretcall_equation { e = ee.ast; } | e=conditional_equation_e | e=for_clause_e @@ -879,7 +1000,9 @@ equation returns [void* ast] | FAILURE LPAR eq=equation RPAR { e = Absyn__EQ_5fFAILURE(eq.ast); } | EQUALITY LPAR e1=expression[metamodelica_enabled()] EQUALS e2=expression[metamodelica_enabled()] RPAR { - e = Absyn__EQ_5fNORETCALL(Absyn__CREF_5fIDENT(mmc_mk_scon("equality"),mmc_mk_nil()),Absyn__FUNCTIONARGS(mmc_mk_cons(e1.ast,mmc_mk_cons(e2.ast,mmc_mk_nil())),mmc_mk_nil())); + e = Absyn__EQ_5fNORETCALL( + Absyn__CREF_5fIDENT(mmc_mk_scon("equality"),mmc_mk_nil()), + Absyn__FUNCTIONARGS(mmc_mk_cons_typed(Absyn_Exp, e1.ast, mmc_mk_cons_typed(Absyn_Exp, e2.ast, mmc_mk_nil())), mmc_mk_nil())); } ) cmt=comment @@ -887,9 +1010,10 @@ equation returns [void* ast] $ast = Absyn__EQUATIONITEM(e, mmc_mk_some_or_none(cmt), PARSER_INFO($start)); } ; + finally{ OM_POP(6); } constraint returns [void* ast] -@init { a = 0; al.ast = 0; e1.ast = 0; e2.ast = 0; cmt = 0; } : +@init { OM_PUSHZ5(a, al.ast, e1.ast, e2.ast, cmt); } : ( a = simple_expr | a=conditional_equation_a | a=for_clause_a @@ -899,10 +1023,12 @@ constraint returns [void* ast] | BREAK { a = Absyn__ALG_5fBREAK; } | RETURN { a = Absyn__ALG_5fRETURN; } | CONTINUE { a = Absyn__ALG_5fCONTINUE; } - | FAILURE LPAR al=algorithm RPAR { a = Absyn__ALG_5fFAILURE(mmc_mk_cons(al.ast,mmc_mk_nil())); } + | FAILURE LPAR al=algorithm RPAR { a = Absyn__ALG_5fFAILURE(mmc_mk_cons_typed(Absyn_AlgorithmItem, al.ast, mmc_mk_nil())); } | EQUALITY LPAR e1=expression[metamodelica_enabled()] ASSIGN e2=expression[metamodelica_enabled()] RPAR { - a = Absyn__ALG_5fNORETCALL(Absyn__CREF_5fIDENT(mmc_mk_scon("equality"),mmc_mk_nil()),Absyn__FUNCTIONARGS(mmc_mk_cons(e1.ast,mmc_mk_cons(e2.ast,mmc_mk_nil())),mmc_mk_nil())); + a = Absyn__ALG_5fNORETCALL( + Absyn__CREF_5fIDENT(mmc_mk_scon("equality"),mmc_mk_nil()), + Absyn__FUNCTIONARGS(mmc_mk_cons_typed(Absyn_Exp, e1.ast, mmc_mk_cons_typed(Absyn_Exp, e2.ast, mmc_mk_nil())), mmc_mk_nil())); } ) cmt=comment @@ -910,10 +1036,11 @@ constraint returns [void* ast] $ast = a; } ; + finally{ OM_POP(5); } algorithm returns [void* ast] -@init { aa.ast = 0; al.ast = 0; a = 0; e1.ast = 0; e2.ast = 0; cmt = 0; } : +@init { OM_PUSHZ6(aa.ast, al.ast, a, e1.ast, e2.ast, cmt); } : ( aa=assign_clause_a { a = aa.ast; } | a=conditional_equation_a | a=for_clause_a @@ -924,10 +1051,13 @@ algorithm returns [void* ast] | BREAK { a = Absyn__ALG_5fBREAK; } | RETURN { a = Absyn__ALG_5fRETURN; } | CONTINUE { a = Absyn__ALG_5fCONTINUE; } - | FAILURE LPAR al=algorithm RPAR { a = Absyn__ALG_5fFAILURE(mmc_mk_cons(al.ast,mmc_mk_nil())); } + | FAILURE LPAR al=algorithm RPAR { a = Absyn__ALG_5fFAILURE(mmc_mk_cons_typed(Absyn_AlgorithmItem, al.ast, mmc_mk_nil())); } | EQUALITY LPAR e1=expression[metamodelica_enabled()] ASSIGN e2=expression[metamodelica_enabled()] RPAR { - a = Absyn__ALG_5fNORETCALL(Absyn__CREF_5fIDENT(mmc_mk_scon("equality"),mmc_mk_nil()),Absyn__FUNCTIONARGS(mmc_mk_cons(e1.ast,mmc_mk_cons(e2.ast,mmc_mk_nil())),mmc_mk_nil())); + a = Absyn__ALG_5fNORETCALL( + Absyn__CREF_5fIDENT(mmc_mk_scon("equality"),mmc_mk_nil()), + Absyn__FUNCTIONARGS(mmc_mk_cons_typed(Absyn_Exp, e1.ast,mmc_mk_cons_typed(Absyn_Exp, e2.ast, mmc_mk_nil())), + mmc_mk_nil())); } ) cmt=comment @@ -935,10 +1065,11 @@ algorithm returns [void* ast] $ast = Absyn__ALGORITHMITEM(a, mmc_mk_some_or_none(cmt), PARSER_INFO($start)); } ; + finally{ OM_POP(6); } assign_clause_a returns [void* ast] @declarations { char *s1 = 0; } -@init { e1 = 0; eq = 0; e2.ast = 0; } : +@init { OM_PUSHZ2(e1, e2.ast); eq = 0; } : /* MetaModelica allows pattern matching on arbitrary expressions in algorithm sections... */ e1=simple_expression ( (ASSIGN|eq=EQUALS) e2=expression[metamodelica_enabled()] @@ -968,15 +1099,16 @@ assign_clause_a returns [void* ast] struct mmc_struct *p = (struct mmc_struct*)MMC_UNTAGPTR(e1); $ast = Absyn__ALG_5fNORETCALL(p->data[0+UNBOX_OFFSET],p->data[1+UNBOX_OFFSET]); #else - $ast = Absyn__ALG_5fNORETCALL(jl_data_ptr(e1)[0],jl_data_ptr(e1)[1]); + $ast = Absyn__ALG_5fNORETCALL(jl_data_ptr(e1)[0],jl_data_ptr(e1)[1]); /* TODO! FIXME! I think we need a write barrier here, see jl_gc_wb */ #endif } } ) ; + finally{ OM_POP(2); } equality_or_noretcall_equation returns [void* ast] -@init { ass = 0; e1 = 0; ass = 0; e2.ast = 0; cr.ast = 0;} : +@init { OM_PUSHZ3(e1, e2.ast, cr.ast); ass = 0; } : e1=simple_expression ( (EQUALS | ass=ASSIGN) e2=expression[metamodelica_enabled()] (INDOMAIN cr=component_reference2)? { @@ -989,7 +1121,6 @@ equality_or_noretcall_equation returns [void* ast] } | {LA(1) != EQUALS && LA(1) != ASSIGN}? /* It has to be a CALL */ { - modelicaParserAssert(isCall(e1),"A singleton expression in an equation section is required to be a function call", equality_or_noretcall_equation, $start->line, $start->charPosition+1, LT(1)->line, LT(1)->charPosition); { #if !defined(OMJULIA) @@ -1002,171 +1133,196 @@ equality_or_noretcall_equation returns [void* ast] } ) ; + finally{ OM_POP(3); } conditional_equation_e returns [void* ast] -@init { i = 0; else_b = 0; then_b = 0; else_if_b = 0; } : +@init { i = 0; OM_PUSHZ4(e.ast, then_b, else_b, else_if_b); } : IF e=expression[metamodelica_enabled()] THEN then_b=equation_list else_if_b=equation_elseif_list? ( ELSE else_b=equation_list )? (i=END_IF|t=END_IDENT|t=END_FOR|t=END_WHEN) { modelicaParserAssert(i,else_b ? "Expected 'end if'; did you use a nested 'else if' instead of 'elseif'?" : "Expected 'end if'",conditional_equation_e,t->line, t->charPosition+1, LT(1)->line, LT(1)->charPosition+1); ast = Absyn__EQ_5fIF(e.ast, then_b, or_nil(else_if_b), or_nil(else_b)); } ; + finally{ OM_POP(4); } conditional_equation_a returns [void* ast] -@init { i = 0; else_b = 0; else_if_b = 0; } : +@init { i = 0; OM_PUSHZ4(e.ast, then_b, else_b, else_if_b); } : IF e=expression[metamodelica_enabled()] THEN then_b=algorithm_list else_if_b=algorithm_elseif_list? ( ELSE else_b=algorithm_list )? (i=END_IF|t=END_IDENT|t=END_FOR|t=END_WHEN|t=END_WHILE) { modelicaParserAssert(i,else_b ? "Expected 'end if'; did you use a nested 'else if' instead of 'elseif'?" : "Expected 'end if'",conditional_equation_a,t->line, t->charPosition+1, LT(1)->line, LT(1)->charPosition+1); ast = Absyn__ALG_5fIF(e.ast, then_b, or_nil(else_if_b), or_nil(else_b)); } ; + finally{ OM_POP(4); } for_clause_e returns [void* ast] -@init { is = 0; es = 0; } : +@init { OM_PUSHZ2(is, es); } : FOR is=for_indices LOOP es=equation_list END_FOR { ast = Absyn__EQ_5fFOR(is,es); } ; + finally{ OM_POP(2); } for_clause_a returns [void* ast] -@init { is = 0; as = 0; } : +@init { OM_PUSHZ2(is, as); } : FOR is=for_indices LOOP as=algorithm_list END_FOR { ast = Absyn__ALG_5fFOR(is,as); } ; + finally{ OM_POP(2); } parfor_clause_e returns [void* ast] -@init { is = 0; es = 0; } : - PARFOR is=for_indices LOOP es=equation_list END_PARFOR { ast = Absyn__EQ_5fFOR(is,es); } +@init { OM_PUSHZ2(is, es); } : + PARFOR is=for_indices LOOP es=equation_list END_PARFOR { ast = Absyn__EQ_5fFOR(is, es); } ; + finally{ OM_POP(2); } parfor_clause_a returns [void* ast] -@init { is = 0; as = 0; } : - PARFOR is=for_indices LOOP as=algorithm_list END_PARFOR { ast = Absyn__ALG_5fPARFOR(is,as); } +@init { OM_PUSHZ2(is, as); } : + PARFOR is=for_indices LOOP as=algorithm_list END_PARFOR { ast = Absyn__ALG_5fPARFOR(is, as); } ; + finally{ OM_POP(2); } while_clause returns [void* ast] -@init { e.ast = 0; as = 0; } : - WHILE e=expression[metamodelica_enabled()] LOOP as=algorithm_list END_WHILE { ast = Absyn__ALG_5fWHILE(e.ast,as); } +@init { OM_PUSHZ2(e.ast, as); } : + WHILE e=expression[metamodelica_enabled()] LOOP as=algorithm_list END_WHILE { ast = Absyn__ALG_5fWHILE(e.ast, as); } ; + finally{ OM_POP(2); } try_clause returns [void* ast] -@init { as1 = 0; as2 = 0; } : +@init { OM_PUSHZ2(as1, as2); } : TRY as1=algorithm_list ELSE as2=algorithm_list END_TRY { ast = Absyn__ALG_5fTRY(as1,as2); } ; + finally{ OM_POP(2); } when_clause_e returns [void* ast] -@init{ es = 0; body = 0; es = 0; } : +@init{ OM_PUSHZ3(e.ast, body, es); } : WHEN e=expression[metamodelica_enabled()] THEN body=equation_list es=else_when_e_list? END_WHEN { ast = Absyn__EQ_5fWHEN_5fE(e.ast,body,or_nil(es)); } ; + finally{ OM_POP(3); } else_when_e_list returns [void* ast] -@init{ es = 0; e = 0;} : - e=else_when_e es=else_when_e_list? { ast = mmc_mk_cons(e,or_nil(es)); } +@init{ OM_PUSHZ2(es, e); } : + e=else_when_e es=else_when_e_list? { ast = mmc_mk_cons(e, or_nil(es)); /* TODO: This will need some casting to make sure e is always Absyn.Exp */ } ; + finally{ OM_POP(2); } else_when_e returns [void* ast] -@init{ es = 0; es = 0; } : +@init{ OM_PUSHZ2(e.ast, es); } : ELSEWHEN e=expression[metamodelica_enabled()] THEN es=equation_list { ast = mmc_mk_tuple2(e.ast,es); } ; + finally{ OM_POP(2); } when_clause_a returns [void* ast] -@init{ e.ast = 0; body = 0; es = 0; } : +@init{ OM_PUSHZ3(e.ast, body, es); } : WHEN e=expression[metamodelica_enabled()] THEN body=algorithm_list es=else_when_a_list? END_WHEN { ast = Absyn__ALG_5fWHEN_5fA(e.ast,body,or_nil(es)); } ; + finally{ OM_POP(3); } else_when_a_list returns [void* ast] -@init{ e = 0; es = 0; } : - e=else_when_a es=else_when_a_list? { ast = mmc_mk_cons(e,or_nil(es)); } +@init{ OM_PUSHZ2(e, es); } : + e=else_when_a es=else_when_a_list? { ast = mmc_mk_cons(e,or_nil(es)); /* TODO: This will need some casting to make sure e is always Absyn.Exp */ } ; + finally{ OM_POP(2); } else_when_a returns [void* ast] -@init{ e.ast = 0; as = 0; } : +@init{ OM_PUSHZ2(e.ast, as); } : ELSEWHEN e=expression[metamodelica_enabled()] THEN as=algorithm_list { ast = mmc_mk_tuple2(e.ast,as); } ; + finally{ OM_POP(2); } equation_elseif_list returns [void* ast] -@init{ e = 0; es = 0; } : - e=equation_elseif es=equation_elseif_list? { ast = mmc_mk_cons(e,or_nil(es)); } +@init{ OM_PUSHZ2(e, es); } : + e=equation_elseif es=equation_elseif_list? { ast = mmc_mk_cons(e,or_nil(es)); /* TODO: This will need some casting to make sure e is always Absyn.Exp */ } ; + finally{ OM_POP(2); } equation_elseif returns [void* ast] -@init{ e.ast = 0; es = 0; } : - ELSEIF e=expression[metamodelica_enabled()] THEN es=equation_list { ast = mmc_mk_tuple2(e.ast,es); } +@init{ OM_PUSHZ2(e.ast, es); } : + ELSEIF e=expression[metamodelica_enabled()] THEN es=equation_list { ast = mmc_mk_tuple2(e.ast, es); } ; + finally{ OM_POP(2); } algorithm_elseif_list returns [void* ast] -@init{ a = 0; as = 0; } : - a=algorithm_elseif as=algorithm_elseif_list? { ast = mmc_mk_cons(a,or_nil(as)); } +@init{ OM_PUSHZ2(a, as); } : + a=algorithm_elseif as=algorithm_elseif_list? { ast = mmc_mk_cons(a,or_nil(as)); /* TODO: This will need some casting to make sure e is always Absyn.Exp */ } ; + finally{ OM_POP(2); } algorithm_elseif returns [void* ast] -@init{ e.ast = 0; as = 0; } : +@init{ OM_PUSHZ2(e.ast, as); } : ELSEIF e=expression[metamodelica_enabled()] THEN as=algorithm_list { ast = mmc_mk_tuple2(e.ast,as); } ; + finally{ OM_POP(2); } equation_list_then returns [void* ast] -@init{ e.ast = 0; es = 0; } : - { LA(1) == THEN }? {ast = mmc_mk_nil();} - | (e=equation SEMICOLON es=equation_list_then) { ast = mmc_mk_cons(e.ast,es); } +@init{ OM_PUSHZ2(e.ast, es); } : + { LA(1) == THEN }? { ast = mmc_mk_nil(); } + | (e=equation SEMICOLON es=equation_list_then) { ast = mmc_mk_cons_typed(Absyn_Equation, e.ast, es); } ; + finally{ OM_POP(2); } equation_list returns [void* ast] @init { + OM_PUSHZ3(ast, e.ast, es); int first = 0, last = 0; - e.ast = 0; - es = 0; first = omc_first_comment; last = LT(1)->getTokenIndex(LT(1)); omc_first_comment = last; } : {LA(1) != END_IDENT || LA(1) != END_IF || LA(1) != END_WHEN || LA(1) != END_FOR}? { - ast = mmc_mk_nil(); + ast = mmc_mk_nil(); for (;firstget(INPUT,last-1); if (tok->getChannel(tok) == HIDDEN && (tok->type == LINE_COMMENT || tok->type == ML_COMMENT)) { - ast = mmc_mk_cons(Absyn__EQUATIONITEMCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),ast); + ast = mmc_mk_cons_typed(Absyn_EquationItem, Absyn__EQUATIONITEMCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),ast); } } } | ( e=equation SEMICOLON es=equation_list ) { ast = es; - ast = mmc_mk_cons(e.ast,ast); + ast = mmc_mk_cons_typed(Absyn_EquationItem, e.ast,ast); for (;firstget(INPUT,last-1); if (tok->getChannel(tok) == HIDDEN && (tok->type == LINE_COMMENT || tok->type == ML_COMMENT)) { - ast = mmc_mk_cons(Absyn__EQUATIONITEMCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),ast); + ast = mmc_mk_cons_typed(Absyn_EquationItem, Absyn__EQUATIONITEMCOMMENT(mmc_mk_scon((char*)tok->getText(tok)->chars)),ast); } } } ; + finally{ OM_POP(3); } algorithm_list returns [void* ast] -@init { a.ast = 0; as = 0; } : +@init { OM_PUSHZ2(a.ast, as); } : {LA(1) != END_IDENT || LA(1) != END_IF || LA(1) != END_WHEN || LA(1) != END_FOR || LA(1) != END_WHILE}? { ast = mmc_mk_nil(); } - | a=algorithm SEMICOLON as=algorithm_list { ast = mmc_mk_cons(a.ast,as); } + | a=algorithm SEMICOLON as=algorithm_list { ast = mmc_mk_cons_typed(Absyn_AlgorithmItem, a.ast, as); } ; + finally{ OM_POP(2); } -connect_clause returns [void* ast] : +connect_clause returns [void* ast] +@init{ OM_PUSHZ2(cr1.ast, cr2.ast); } : CONNECT LPAR cr1=component_reference COMMA cr2=component_reference RPAR { ast = Absyn__EQ_5fCONNECT(cr1.ast,cr2.ast); } ; + finally{ OM_POP(2); } /* adrpo: 2010-10-11, replaced commented-out part with the rule above which is conform to the grammar in the Modelica specification! -connect_clause returns [void* ast] : - CONNECT LPAR cr1=connector_ref COMMA cr2=connector_ref RPAR {ast = Absyn__EQ_5fCONNECT(cr1,cr2);} +connect_clause returns [void* ast] +@init{ OM_PUSHZ2(cr1, cr2); } : + CONNECT LPAR cr1=connector_ref COMMA cr2=connector_ref RPAR { ast = Absyn__EQ_5fCONNECT(cr1,cr2); } ; + finally{ OM_POP(2); } connector_ref returns [void* ast] -@init{ as = 0; cr2 = 0; } : +@init{ OM_PUSHZ2(as, cr2); } : id=IDENT ( as=array_subscripts )? ( DOT cr2=connector_ref_2 )? { if (cr2) @@ -1175,17 +1331,21 @@ connector_ref returns [void* ast] ast = Absyn__CREF_5fIDENT(token_to_scon(id),or_nil(as)); } ; + finally{ OM_POP(2); } connector_ref_2 returns [void* ast] -@init{ id = 0; as = 0; } : - id=IDENT ( as=array_subscripts )? {ast = Absyn__CREF_5fIDENT(token_to_scon(id),or_nil(as));} +@init{ id = 0; OM_PUSHZ1(as); } : + id=IDENT ( as=array_subscripts )? { ast = Absyn__CREF_5fIDENT(token_to_scon(id),or_nil(as)); } ; + finally{ OM_POP(1); } + */ /* * 2.2.7 Expressions */ -expression[int allowPartEvalFunc] returns [void* ast] : +expression[int allowPartEvalFunc] returns [void* ast] +@init { OM_PUSHZ1(e); } : ( e=if_expression { $ast = e; } | e=simple_expression { $ast = e; } | e=code_expression { $ast = e; } @@ -1200,53 +1360,60 @@ expression[int allowPartEvalFunc] returns [void* ast] : } ) ; + finally{ OM_POP(1); } part_eval_function_expression returns [void* ast] -@init { cr.ast = 0; args = 0; } : +@init { OM_PUSHZ2(cr.ast, args); } : FUNCTION cr=component_reference LPAR (args=named_arguments)? RPAR { ast = Absyn__PARTEVALFUNCTION(cr.ast, Absyn__FUNCTIONARGS(mmc_mk_nil(), or_nil(args))); } ; + finally{ OM_POP(2); } if_expression returns [void* ast] -@init{ cond.ast = 0; e1.ast = 0; es = 0; e2.ast = 0; } : +@init{ OM_PUSHZ4(cond.ast, e1.ast, es, e2.ast); } : IF cond=expression[metamodelica_enabled()] THEN e1=expression[metamodelica_enabled()] es=elseif_expression_list? ELSE e2=expression[metamodelica_enabled()] { ast = Absyn__IFEXP(cond.ast,e1.ast,e2.ast,or_nil(es)); } ; + finally{ OM_POP(4); } elseif_expression_list returns [void* ast] -@init{ e = 0; es = 0; } : - e=elseif_expression es=elseif_expression_list? { ast = mmc_mk_cons(e,or_nil(es)); } +@init{ OM_PUSHZ2(e, es); } : + e=elseif_expression es=elseif_expression_list? { ast = mmc_mk_cons(e,or_nil(es)); /* TODO: Need the tuple to have Absyn.Exp */ } ; + finally{ OM_POP(2); } elseif_expression returns [void* ast] -@init { e1.ast = 0; e2.ast = 0; } : +@init { OM_PUSHZ2(e1.ast, e2.ast); } : ELSEIF e1=expression[metamodelica_enabled()] THEN e2=expression[metamodelica_enabled()] { ast = mmc_mk_tuple2(e1.ast,e2.ast); } ; + finally{ OM_POP(2); } for_indices returns [void* ast] -@init{ i = 0; is = 0; } : - i=for_index (COMMA is=for_indices)? { ast = mmc_mk_cons(i, or_nil(is)); } +@init{ OM_PUSHZ2(i, is); } : + i=for_index (COMMA is=for_indices)? { ast = mmc_mk_cons_typed(Absyn_ForIterator, i, or_nil(is)); } ; + finally{ OM_POP(2); } for_index returns [void* ast] -@init{ i = 0; e.ast = 0; guard.ast = 0; } : +@init{ i = 0; OM_PUSHZ2(e.ast, guard.ast); } : (i=IDENT (((IF|GUARD) guard=expression[metamodelica_enabled()])? T_IN e=expression[metamodelica_enabled()])? { ast = Absyn__ITERATOR(token_to_scon(i),mmc_mk_some_or_none(guard.ast),mmc_mk_some_or_none(e.ast)); } ) ; + finally{ OM_POP(2); } simple_expression returns [void* ast] -@init{ e1 = 0; e2 = 0; i = 0; e = 0; } : - e1=simple_expr { ast = e; } (COLONCOLON e2=simple_expression)? +@init{ OM_PUSHZ4(e, e1, e2, ast); i = 0; } : + e1=simple_expr (COLONCOLON e2=simple_expression)? { if (e2) - ast = Absyn__CONS(e1,e2); + ast = Absyn__CONS(e1, e2); else ast = e1; } @@ -1255,9 +1422,10 @@ simple_expression returns [void* ast] ast = Absyn__AS(token_to_scon(i),e); } ; + finally{ OM_POP(4); } simple_expr returns [void* ast] -@init{ e1 = 0; e2 = 0; e3 = 0; } : +@init{ OM_PUSHZ3(e1, e2, e3); } : e1=logical_expression ( COLON e2=logical_expression ( COLON e3=logical_expression )? )? { if (e3) @@ -1268,25 +1436,29 @@ simple_expr returns [void* ast] ast = e1; } ; + finally{ OM_POP(3); } logical_expression returns [void* ast] -@init{ e1 = 0; e2 = 0; } : +@init{ OM_PUSHZ3(e1, e2, ast); } : e1=logical_term { ast = e1; } ( T_OR e2=logical_term { ast = Absyn__LBINARY(ast,Absyn__OR,e2); } )* ; + finally{ OM_POP(3); } logical_term returns [void* ast] -@init{ e2 = 0; } : +@init{ OM_PUSHZ3(e1, e2, ast); } : e1=logical_factor { ast = e1; } ( T_AND e2=logical_factor { ast = Absyn__LBINARY(ast,Absyn__AND,e2); } )* ; + finally{ OM_POP(3); } logical_factor returns [void* ast] -@init{ n = 0; e = 0; } : +@init{ n = 0; OM_PUSHZ1(e); } : ( n=T_NOT )? e=relation { ast = n ? Absyn__LUNARY(Absyn__NOT, e) : e; } ; + finally{ OM_POP(1); } relation returns [void* ast] @declarations { void* op = NULL; } -@init { e1 = 0; e2 = 0; } : +@init { OM_PUSHZ4(e1, e2, op, ast); } : e1=arithmetic_expression ( ( LESS {op = Absyn__LESS;} | LESSEQ {op = Absyn__LESSEQ;} | GREATER {op = Absyn__GREATER;} | GREATEREQ {op = Absyn__GREATEREQ;} @@ -1296,17 +1468,20 @@ relation returns [void* ast] ast = e2 ? Absyn__RELATION(e1,op,e2) : e1; } ; + finally{ OM_POP(4); } arithmetic_expression returns [void* ast] @declarations { void* op = NULL; } -@init { e1 = 0; e2 = 0; } : +@init { OM_PUSHZ3(e1, e2, op); } : e1=unary_arithmetic_expression { ast = e1; } ( ( PLUS {op=Absyn__ADD;} | MINUS {op=Absyn__SUB;} | PLUS_EW {op=Absyn__ADD_5fEW;} | MINUS_EW {op=Absyn__SUB_5fEW;} ) e2=term { ast = Absyn__BINARY(ast,op,e2); } )* ; + finally{ OM_POP(3); } -unary_arithmetic_expression returns [void* ast] : +unary_arithmetic_expression returns [void* ast] +@init { OM_PUSHZ2(t, ast); } : ( PLUS t=term { ast = Absyn__UNARY(Absyn__UPLUS,t); } | MINUS t=term { ast = Absyn__UNARY(Absyn__UMINUS,t); } | PLUS_EW t=term { ast = Absyn__UNARY(Absyn__UPLUS_5fEW,t); } @@ -1314,28 +1489,31 @@ unary_arithmetic_expression returns [void* ast] : | t=term { ast = t; } ) ; + finally{ OM_POP(2); } term returns [void* ast] @declarations { void* op = NULL; } -@init { e1 = 0; e2 = 0; } : +@init { OM_PUSHZ4(e1, e2, op, ast); } : e1=factor { ast = e1; } ( ( STAR {op=Absyn__MUL;} | SLASH {op=Absyn__DIV;} | STAR_EW {op=Absyn__MUL_5fEW;} | SLASH_EW {op=Absyn__DIV_5fEW;} ) e2=factor { ast = Absyn__BINARY(ast,op,e2); } )* ; + finally{ OM_POP(4); } factor returns [void* ast] -@init{ e1.ast = 0; pw = 0; e2.ast = 0; } : +@init{ OM_PUSHZ2(e1.ast, e2.ast); pw = 0; } : e1=primary ( ( pw=POWER | pw=POWER_EW ) e2=primary )? { ast = pw ? Absyn__BINARY(e1.ast, $pw.type == POWER ? Absyn__POW : Absyn__POW_5fEW, e2.ast) : e1.ast; } ; + finally{ OM_POP(2); } primary returns [void* ast] @declarations { int tupleExpressionIsTuple = 0; } -@init { v = 0; ptr.ast = 0; el = 0; for_or_el.ast = 0; for_or_el.isFor = 0; } : +@init { v = 0; for_or_el.isFor = 0; OM_PUSHZ3(ptr.ast, el, for_or_el.ast) } : ( v=UNSIGNED_INTEGER { char* chars = (char*)$v.text->chars; @@ -1423,14 +1601,16 @@ primary returns [void* ast] | T_END { $ast = Absyn__END; } ) ; + finally{ OM_POP(3); } matrix_expression_list returns [void* ast] -@init{ e1 = 0; e2 = 0; } : +@init{ OM_PUSHZ2(e1, e2); } : e1=expression_list (SEMICOLON e2=matrix_expression_list)? { ast = mmc_mk_cons(e1, or_nil(e2)); } ; + finally{ OM_POP(2); } component_reference__function_call returns [void* ast] -@init{ cr.ast = 0; fc = 0; i = 0; e.ast = 0; } : +@init{ OM_PUSHZ3(cr.ast, fc, e.ast); i = 0; } : cr=component_reference ( fc=function_call (DOT e=expression[metamodelica_enabled()])? )? { if (fc != NULL) { $ast = Absyn__CALL(cr.ast, fc); @@ -1446,30 +1626,35 @@ component_reference__function_call returns [void* ast] $ast = Absyn__CALL(Absyn__CREF_5fIDENT(mmc_mk_scon("initial"), mmc_mk_nil()),Absyn__FUNCTIONARGS(mmc_mk_nil(),mmc_mk_nil())); } ; + finally{ OM_POP(3); } -name_path_end returns [void* ast] : +name_path_end returns [void* ast] +@init{ OM_PUSHZ1(np); } : np=name_path EOF { $ast = np; } ; + finally{ OM_POP(1); } name_path returns [void* ast] -@init{ dot = 0; np = 0; } : +@init{ dot = 0; OM_PUSHZ1(np); } : (dot=DOT)? np=name_path2 { ast = dot ? Absyn__FULLYQUALIFIED(np) : np; } ; + finally{ OM_POP(1); } name_path2 returns [void* ast] -@init{ id = 0; p = 0; } : +@init{ id = 0; OM_PUSHZ1(p); } : { LA(2) != DOT }? (id=IDENT|id=CODE) { ast = Absyn__IDENT(token_to_scon(id)); } | (id=IDENT | id=CODE) DOT p=name_path2 { ast = Absyn__QUALIFIED(token_to_scon(id),p); } ; + finally{ OM_POP(1); } name_path_star returns [void* ast, int unqual, void* lst] -@init{ id = 0; uq = 0; mlst = 0; p.ast = 0; p.lst = 0; } : +@init{ id = 0; uq = 0; OM_PUSHZ5(mlst, p.ast, p.lst, $lst, $ast); } : { LA(2) != DOT || LA(3) == LBRACE }? (id=IDENT|id=CODE) ( uq=STAR_EW | DOT LBRACE mlst=name_path_group RBRACE )? { $ast = Absyn__IDENT(token_to_scon(id)); @@ -1483,37 +1668,42 @@ name_path_star returns [void* ast, int unqual, void* lst] $lst = p.lst; } ; + finally{ OM_POP(5); } name_path_group returns [void* ast] -@init{ id1 = 0; id2 = 0; rest = 0; } : +@init{ id1 = 0; id2 = 0; OM_PUSHZ1(rest); } : (id1=IDENT|id1=CODE) (EQUALS (id2=IDENT|id2=CODE))? (COMMA rest=name_path_group)? { - $ast = mmc_mk_cons(id2 ? Absyn__GROUP_5fIMPORT_5fRENAME(token_to_scon(id1),token_to_scon(id2)) : + $ast = mmc_mk_cons_typed(Absyn_Import, id2 ? Absyn__GROUP_5fIMPORT_5fRENAME(token_to_scon(id1),token_to_scon(id2)) : Absyn__GROUP_5fIMPORT_5fNAME(token_to_scon(id1)), or_nil(rest)); } ; + finally{ OM_POP(1); } -component_reference_end returns [void* ast] : +component_reference_end returns [void* ast] +@init{ OM_PUSHZ1(cr.ast); } : cr=component_reference EOF { $ast = cr.ast; } ; + finally{ OM_POP(1); } component_reference returns [void* ast, int isNone] -@init{ cr.ast = 0; dot = 0; cr.isNone = 0; } : +@init{ OM_PUSHZ1(cr.ast); dot = 0; cr.isNone = 0; } : (dot=DOT)? cr=component_reference2 { $ast = dot ? Absyn__CREF_5fFULLYQUALIFIED(cr.ast) : cr.ast; $isNone = cr.isNone; } - | ALLWILD {$ast = Absyn__ALLWILD; $isNone = false;} - | WILD {$ast = Absyn__WILD; $isNone = false;} + | ALLWILD { $ast = Absyn__ALLWILD; $isNone = false; } + | WILD { $ast = Absyn__WILD; $isNone = false; } ; + finally{ OM_POP(1); } component_reference2 returns [void* ast, int isNone] -@init { id = 0; cr.ast = 0; arr = 0; } : +@init { id = 0; OM_PUSHZ2(cr.ast, arr); } : (id=IDENT | id=OPERATOR) ( arr=array_subscripts )? ( DOT cr=component_reference2 )? { if (cr.ast) { @@ -1526,14 +1716,16 @@ component_reference2 returns [void* ast, int isNone] } } ; + finally{ OM_POP(2); } function_call returns [void* ast] -@init { fa = 0; } : +@init { OM_PUSHZ1(fa); } : LPAR fa=function_arguments RPAR { ast = fa; } ; + finally{ OM_POP(1); } function_arguments returns [void* ast] -@init{ for_or_el.ast = 0; for_or_el.isFor = 0; namel = 0; } : +@init{ OM_PUSHZ2(for_or_el.ast, namel); for_or_el.isFor = 0; } : for_or_el=for_or_expression_list (namel=named_arguments)? { if (for_or_el.isFor) @@ -1542,9 +1734,10 @@ function_arguments returns [void* ast] ast = Absyn__FUNCTIONARGS(for_or_el.ast, or_nil(namel)); } ; + finally{ OM_POP(2); } for_or_expression_list returns [void* ast, int isFor] -@init{ e.ast = 0; el = 0; forind = 0; } : +@init{ OM_PUSHZ3(e.ast, el, forind); } : ( {LA(1)==IDENT || (LA(1)==OPERATOR && LA(2) == EQUALS) || LA(1) == RPAR || LA(1) == RBRACE}? { $ast = mmc_mk_nil(); $isFor = 0; } | ( e=expression[1] ( (COMMA el=for_or_expression_list2) @@ -1553,35 +1746,39 @@ for_or_expression_list returns [void* ast, int isFor] ) { if (el != NULL) { - $ast = mmc_mk_cons(e.ast,el); + $ast = mmc_mk_cons_typed(Absyn_Exp, e.ast, el); } else if (forind != NULL) { $ast = Absyn__FOR_5fITER_5fFARG(e.ast, threaded ? Absyn__THREAD : Absyn__COMBINE, forind); } else { - $ast = mmc_mk_cons(e.ast, mmc_mk_nil()); + $ast = mmc_mk_cons_typed(Absyn_Exp, e.ast, mmc_mk_nil()); } $isFor = forind != 0; } ) ; + finally{ OM_POP(3); } for_or_expression_list2 returns [void* ast] -@init{ e.ast = 0; el = 0; } : +@init{ OM_PUSHZ2(e.ast, el); } : {LA(2) == EQUALS}? { ast = mmc_mk_nil(); } | e=expression[1] (COMMA el=for_or_expression_list2)? { ast = mmc_mk_cons_typed(Absyn_Exp, e.ast, or_nil(el)); } ; + finally{ OM_POP(2); } named_arguments returns [void* ast] -@init{ a = 0; as = 0; } : - a=named_argument (COMMA as=named_arguments)? { ast = mmc_mk_cons(a, or_nil(as)); } +@init{ OM_PUSHZ2(a, as); } : + a=named_argument (COMMA as=named_arguments)? { ast = mmc_mk_cons_typed(Absyn_NamedArg, a, or_nil(as)); } ; + finally{ OM_POP(2); } named_argument returns [void* ast] -@init{ id = 0; e.ast = 0; } : +@init{ id = 0; OM_PUSHZ1(e.ast); } : ( id=IDENT | id=OPERATOR) EQUALS e=expression[1] { ast = Absyn__NAMEDARG(token_to_scon(id),e.ast); } ; + finally{ OM_POP(1); } output_expression_list [int* isTuple] returns [void* ast] -@init{ el = 0; e1.ast = 0; } : +@init{ OM_PUSHZ2(el, e1.ast); } : ( RPAR { ast = mmc_mk_nil(); @@ -1589,51 +1786,56 @@ output_expression_list [int* isTuple] returns [void* ast] } | COMMA {*isTuple = true;} el=output_expression_list[isTuple] { - $ast = mmc_mk_cons(Absyn__CREF(Absyn__WILD), el); + $ast = mmc_mk_cons_typed(Absyn_Exp, Absyn__CREF(Absyn__WILD), el); } | e1=expression[metamodelica_enabled()] ( COMMA {*isTuple = true;} el=output_expression_list[isTuple] { if (isNotNil(el)) { - ast = mmc_mk_cons(e1.ast, el); + ast = mmc_mk_cons_typed(Absyn_Exp, e1.ast, el); } else { - ast = mmc_mk_cons(e1.ast, mmc_mk_cons(Absyn__CREF(Absyn__WILD), el)); + ast = mmc_mk_cons_typed(Absyn_Exp, e1.ast, mmc_mk_cons_typed(Absyn_Exp, Absyn__CREF(Absyn__WILD), el)); } } | RPAR { - ast = *isTuple ? mmc_mk_cons(e1.ast, mmc_mk_nil()) : e1.ast; + ast = *isTuple ? mmc_mk_cons_typed(Absyn_Exp, e1.ast, mmc_mk_nil()) : e1.ast; } ) ) ; + finally{ OM_POP(2); } expression_list returns [void* ast] -@init { e1.ast = 0; el = 0; } : - e1=expression[metamodelica_enabled()] (COMMA el=expression_list)? { ast = (el == NULL ? mmc_mk_cons(e1.ast,mmc_mk_nil()) : mmc_mk_cons(e1.ast,el)); } +@init { OM_PUSHZ2(e1.ast, el); } : + e1=expression[metamodelica_enabled()] (COMMA el=expression_list)? { ast = (el == NULL ? mmc_mk_cons_typed(Absyn_Exp, e1.ast, mmc_mk_nil()) : mmc_mk_cons_typed(Absyn_Exp, e1.ast, el)); } ; + finally{ OM_POP(2); } array_subscripts returns [void* ast] -@init{ sl = 0; } : +@init{ OM_PUSHZ1(sl); } : LBRACK sl=subscript_list RBRACK { ast = sl; } ; + finally{ OM_POP(1); } subscript_list returns [void* ast] -@init{ s1 = 0; s2 = 0; } : - s1=subscript ( COMMA s2=subscript_list )? { ast = mmc_mk_cons(s1, or_nil(s2)); } +@init{ OM_PUSHZ2(s1, s2); } : + s1=subscript ( COMMA s2=subscript_list )? { ast = mmc_mk_cons_typed(Absyn_Subscript, s1, or_nil(s2)); } ; + finally{ OM_POP(2); } subscript returns [void* ast] -@init{ e.ast = 0; } : +@init{ OM_PUSHZ1(e.ast); } : e=expression[metamodelica_enabled()] { ast = Absyn__SUBSCRIPT(e.ast); } | COLON { ast = Absyn__NOSUB; } ; + finally{ OM_POP(1); } comment returns [void* ast] -@init{ cmt = 0; ann = 0; ast = 0; } : +@init{ OM_PUSHZ3(cmt, ann, ast); } : (cmt=string_comment (ann=annotation)?) { if (cmt || ann) { @@ -1641,6 +1843,7 @@ comment returns [void* ast] } } ; + finally{ OM_POP(3); } string_comment returns [void* ast] @declarations { pANTLR3_STRING t1; } @@ -1651,9 +1854,10 @@ string_comment returns [void* ast] ; annotation returns [void* ast] -@init{ cmod = 0; } : +@init{ OM_PUSHZ1(cmod); } : T_ANNOTATION cmod=class_modification { ast = Absyn__ANNOTATION(cmod); } ; + finally{ OM_POP(1); } /* Code quotation mechanism */ @@ -1695,7 +1899,7 @@ code_equation_clause returns [void* ast] @init{ e.ast = 0; as = 0; } : ( e=equation SEMICOLON as=code_equation_clause? { - ast = mmc_mk_cons(e.ast,or_nil(as)); + ast = mmc_mk_cons_typed(Absyn_EquationItem, e.ast, or_nil(as)); } ) ; @@ -1704,7 +1908,7 @@ code_constraint_clause returns [void* ast] @init{ e.ast = 0; as = 0; } : e=equation SEMICOLON as=code_constraint_clause? { - ast = mmc_mk_cons(e.ast,or_nil(as)); + ast = mmc_mk_cons_typed(Absyn_EquationItem, e.ast,or_nil(as)); } ; @@ -1712,7 +1916,7 @@ code_algorithm_clause returns [void* ast] @init{ al.ast = 0; as = 0; } : al=algorithm SEMICOLON as=code_algorithm_clause? { - ast = mmc_mk_cons(al.ast,or_nil(as)); + ast = mmc_mk_cons_typed(Absyn_AlgorithmItem, al.ast, or_nil(as)); } ; @@ -1760,7 +1964,7 @@ interactive_stmt returns [void* ast] interactive_stmt_list returns [void* ast] @init { a.ast = 0; $ast = mmc_mk_nil(); void *val; } : - a=top_algorithm {$ast = mmc_mk_cons(a.ast, $ast);} (SEMICOLON a=top_algorithm {$ast = mmc_mk_cons(a.ast, $ast);})* + a=top_algorithm {$ast = mmc_mk_cons_typed(Absyn_Algorithm, a.ast, $ast);} (SEMICOLON a=top_algorithm {$ast = mmc_mk_cons_typed(Absyn_AlgorithmItem, a.ast, $ast);})* { /* We build the list using iteration instead of recursion to save * stack space, so we need to reverse the result. */ @@ -1799,7 +2003,7 @@ cases returns [void* ast] @init{ c.ast = 0; cs.ast = 0; } : c=onecase cs=cases2 { - $ast = mmc_mk_cons(c.ast,cs.ast); + $ast = mmc_mk_cons_typed(Absyn_Case, c.ast, cs.ast); } ; @@ -1813,14 +2017,14 @@ cases2 returns [void* ast] ModelicaParser_readonly, ModelicaParser_filename_C_testsuiteFriendly); if ($th) $el = $th; if (exp.ast) { - $ast = mmc_mk_cons(Absyn__ELSE(or_nil(es),eqs ? Absyn__EQUATIONS(eqs) : (al ? Absyn__ALGORITHMS(algs.ast) : Absyn__EQUATIONS(mmc_mk_nil())),exp.ast,PARSER_INFO($el),mmc_mk_some_or_none(cmt),PARSER_INFO($start)),mmc_mk_nil()); + $ast = mmc_mk_cons_typed(Absyn_Case, Absyn__ELSE(or_nil(es),eqs ? Absyn__EQUATIONS(eqs) : (al ? Absyn__ALGORITHMS(algs.ast) : Absyn__EQUATIONS(mmc_mk_nil())),exp.ast,PARSER_INFO($el),mmc_mk_some_or_none(cmt),PARSER_INFO($start)),mmc_mk_nil()); } else { $ast = mmc_mk_nil(); } } | c=onecase cs=cases2 { - $ast = mmc_mk_cons(c.ast, cs.ast); + $ast = mmc_mk_cons_typed(Absyn_Case, c.ast, cs.ast); } ) ; diff --git a/OMCompiler/Parser/ModelicaParserCommon.h b/OMCompiler/Parser/ModelicaParserCommon.h index 05edf6668be..9d6079206b2 100644 --- a/OMCompiler/Parser/ModelicaParserCommon.h +++ b/OMCompiler/Parser/ModelicaParserCommon.h @@ -47,7 +47,8 @@ extern "C" { #define DLLDirection __declspec(dllexport) #else #define DLLDirection /* nothing */ -#endif +#endif + #include #endif diff --git a/OMCompiler/Parser/Parser_jl.c b/OMCompiler/Parser/Parser_jl.c index 57719e88eae..2f40855a0ae 100644 --- a/OMCompiler/Parser/Parser_jl.c +++ b/OMCompiler/Parser/Parser_jl.c @@ -30,6 +30,11 @@ /* Include standard headers before we do odd things with the __cplusplus define */ +#if defined(_WIN32) +#include +#undef PURE +#endif + #include #include #include @@ -37,11 +42,6 @@ #define bool int -#if defined(_WIN32) -#include -#undef PURE -#endif - #include #include #include @@ -274,7 +274,7 @@ static void* parseStream(pANTLR3_INPUT_STREAM input) void* lxr = 0; void* res = NULL; - jl_gc_enable(0); + jl_gc_enable(1); OpenModelica_initMetaModelicaJuliaLayer(); OpenModelica_initAbsynReferences(); @@ -296,6 +296,9 @@ static void* parseStream(pANTLR3_INPUT_STREAM input) // Finally, now that we have our lexer constructed, create the parser psr = ModelicaParserNew(tstream); // ModelicaParserNew is generated by ANTLR3 + psr->pModelicaParser_omcTop = psr->pModelicaParser_omcPush(psr); + psr->pModelicaParser_omcTop->numPushed = 0; + if (tstream == NULL) { fprintf(stderr, "Out of memory trying to allocate parser\n"); fflush(stderr); exit(ANTLR3_ERR_NOMEM); } psr->pParser->rec->displayRecognitionError = handleParseError; @@ -308,6 +311,10 @@ static void* parseStream(pANTLR3_INPUT_STREAM input) res = jl_nothing; } + for (int i = 0; i < psr->pModelicaParser_omcTop->numPushed; i++) { + JL_GC_POP(); + } + psr->free(psr); psr = (pModelicaParser) NULL; tstream->free(tstream); @@ -332,11 +339,12 @@ DLLDirection jl_value_t* parseFile(jl_value_t *fileName) pthread_once(&parser_once_create_key,make_key); pthread_setspecific(modelicaParserKey,&members); - jl_gc_enable(0); + jl_gc_enable(1); members.encoding = "UTF-8"; members.filename_C = fileName; members.filename_C_testsuiteFriendly = fileName; + members.filename_OMC = fileName; members.flags = 0; members.readonly = 1; omc_first_comment = 0;