MicroModelicaCCompiler
4.5.3
|
Go to the documentation of this file.
28 #include <ast/parser/mocc_parser.h>
30 #include "../util/ast_util.hpp"
44 MCC_Lexer *MCC_Parser::lexer =
nullptr;
50 if (new_string.find(
"'") != std::string::npos) {
51 new_string.erase(std::remove(new_string.begin(), new_string.end(),
'\''), new_string.end());
52 std::replace(new_string.begin(), new_string.end(),
'.',
'_');
54 return new string(new_string);
136 AST_ExpressionList l =
new list<AST_Expression>();
217 s->append(rest->c_str());
229 AST_ExpressionList subs)
232 cr->prepend(s, subs);
237 AST_ExpressionList subs)
243 ostream &
operator<<(ostream &os,
const AST_CompositionElement &ce)
245 assert(ce !=
nullptr);
252 assert(s !=
nullptr);
273 if (type ==
BINOPMULT && right->expressionType() ==
EXPINTEGER && right->getAsInteger()->val() == 1) {
276 if (type ==
BINOPMULT && left->expressionType() ==
EXPINTEGER && left->getAsInteger()->val() == 1) {
279 if (type ==
BINOPMULT && right->expressionType() ==
EXPREAL && right->getAsReal()->val() == 0.0) {
282 if (type ==
BINOPMULT && right->expressionType() ==
EXPINTEGER && right->getAsInteger()->val() == 0) {
285 if (type ==
BINOPMULT && left->expressionType() ==
EXPREAL && left->getAsReal()->val() == 0.0) {
288 if (type ==
BINOPMULT && left->expressionType() ==
EXPINTEGER && left->getAsInteger()->val() == 0) {
298 AST_Expression e2 = e->getAsUMinus()->exp();
305 AST_Expression
newAST_Expression_If(AST_Expression cond, AST_Expression then, AST_ExpressionList else_list, AST_Expression else_exp)
310 AST_Equation
newAST_Equation_If(AST_Expression e, AST_EquationList eql, AST_Equation_ElseList elseif, AST_EquationList elseeqs)
323 name->insert(0,
".");
324 if (rest !=
nullptr) {
325 name->append(rest->c_str());
333 if (rest !=
nullptr) {
334 name->append(rest->c_str());
351 if (e->expressionType() !=
EXPCALL) {
352 cerr <<
"Not valid equation" << endl;
433 c->setEncapsulated();
435 c->setPrefixes(prefix);
440 AST_ExpressionList subs)
442 if (rest !=
nullptr) {
443 id->append(rest->c_str());
450 AST_ExpressionList subs)
452 if (rest !=
nullptr) {
453 id->append(rest->c_str());
507 AST_ExpressionList l;
508 if (e1->expressionType() ==
EXPRANGE) {
509 l = e1->getAsRange()->expressionList();
511 cerr <<
"Not valid range expression: line " << e1->lineNum() << endl;
528 AST_ExpressionListListIterator exps_it = expss->begin();
529 AST_ExpressionListIterator exps_range_it;
531 foreach (exps_it, expss) {
547 AST_Statement
newAST_Statement_If(AST_Expression cond, AST_StatementList true_st, AST_Statement_ElseList else_st,
548 AST_StatementList false_st)
557 AST_Statement
newAST_Statement_When(AST_Expression cond, AST_StatementList sts, AST_Statement_ElseList else_st, AST_Comment c)
572 AST_Equation
newAST_Equation_When(AST_Expression cond, AST_EquationList eqs, AST_Equation_ElseList else_list, AST_Comment comment)
642 decl->setComment(comment);
648 if (al->size() || st !=
nullptr) {
657 AST_ArgumentList annot)
664 c->setExternalFunctionCall(ext);
665 c->setAnnotation(annot);
AST_Statement newAST_Statement_Assign(AST_Expression_ComponentReference cr, AST_Expression exp)
AST_Equation newAST_Equation_For(AST_ForIndexList ind, AST_EquationList eql)
AST_Statement newAST_Statement_While(AST_Expression cond, AST_StatementList st)
AST_ClassPrefix AST_ClassPrefix_Record(AST_Boolean oper)
AST_DeclarationList newAST_DeclarationList(AST_Declaration d)
AST_Argument newAST_ShortClass(AST_ClassPrefix, AST_String, AST_ShortClassExp)
AST_CompositionEqsAlgs newAST_NullCompositionEquations()
AST_Statement_ElseList newAST_Statement_ElseList()
AST_ElementList newAST_ElementList()
AST_String newAST_StringNull()
AST_Class newAST_ClassEnumeration(AST_String, AST_StringList)
AST_ForIndexList newAST_ForIndexList()
AST_Expression newAST_Expression_Real(AST_Real r)
AST_Expression newAST_Expression_String(AST_String s)
AST_Element AST_ExtendsToElement(AST_Element_ExtendsClause e)
AST_String copyAST_String(AST_String s)
AST_Equation newAST_EquationFor(AST_ForIndexList ind, AST_EquationList eql)
AST_Statement newAST_Statement_If(AST_Expression cond, AST_StatementList true_st, AST_Statement_ElseList else_st, AST_StatementList false_st)
AST_Statement newAST_Statement_Break()
AST_Expression newAST_Expression_End()
AST_ClassPrefix AST_ClassPrefix_Impure(AST_Boolean oper)
AST_Expression newAST_Expression_BooleanNot(AST_Expression e)
AST_Expression_ComponentReference AST_Expression_ComponentReference_AddDot(AST_Expression_ComponentReference cr, AST_String s, AST_ExpressionList subs)
AST_Statement newAST_Statement_Return()
AST_ClassPrefix AST_ClassPrefix_Package()
AST_Statement_Else newAST_Statement_Else(AST_Expression cond, AST_StatementList st)
AST_TypePrefix newAST_TypePrefix()
AST_External_Function_Call newAST_ExternalCall()
AST_Composition AST_Composition_SetExternalAnnotation(AST_Composition c, AST_External_Function_Call ext, AST_ArgumentList annot)
AST_Modification newAST_Modification_Equal(AST_Expression e)
AST_Expression newAST_Expression_Range(AST_Expression e1, AST_Expression e2)
AST_Argument AST_ArgumentSetReplaceable(AST_Argument arg)
AST_Expression newAST_Expression_NamedArgument(AST_String s, AST_Expression e)
AST_Element_Component newAST_Element_Component(AST_DeclarationList cl, AST_String type, AST_TypePrefix tp, AST_ExpressionList ind)
AST_Equation newAST_Equation_Equality(AST_Expression left, AST_Expression right, AST_Comment comment)
AST_StringList newAST_StringList()
AST_Expression_ComponentReference AST_Expression_ComponentReference_Add(AST_Expression_ComponentReference cr, AST_String s, AST_ExpressionList subs)
AST_ClassPrefix AST_ClassPrefix_Class()
AST_Argument newAST_ElementModification(AST_String n, AST_Modification m)
AST_Expression newAST_Expression_ComponentReferenceExp(AST_String s)
AST_EquationList newAST_EquationList()
AST_Expression newAST_Expression_UnaryMinus(AST_Expression e)
AST_Declaration AST_Declaration_AddCondComment(AST_Declaration decl, AST_Expression exp, AST_Comment comment)
AST_Class newAST_ClassModification(AST_String, AST_TypePrefix, AST_String, AST_ExpressionList, AST_ArgumentList)
AST_ShortClassExp newAST_ShortClassExp(AST_TypePrefix, AST_String, AST_ExpressionList, AST_ArgumentList)
AST_CompositionEqsAlgs newAST_CompositionInitialAlgorithms(AST_StatementList stlist)
AST_Modification newAST_Modification_Assign(AST_Expression e)
AST_Expression newAST_Expression_ElseIf(AST_Expression c, AST_Expression t)
AST_Statement newAST_Statement_OutputAssign(AST_ExpressionList out_vars, AST_Expression_ComponentReference funname, AST_ExpressionList args)
AST_Argument newAST_Redeclaration(AST_Boolean, AST_Boolean, AST_Argument)
AST_Element AST_ImportToElement(AST_Element_ImportClause i)
AST_Expression newAST_BracketExpList(AST_ExpressionListList expss)
AST_Element AST_Element_ComponentToElement(AST_Element_Component c)
AST_Modification newAST_Modification_Class(AST_ArgumentList al, AST_Expression e)
AST_Equation_Else newAST_Equation_Else(AST_Expression cond, AST_EquationList eqs)
AST_Expression newAST_Expression_Null()
AST_ExpressionListList newAST_ExpressionListList()
list< T1 > * AST_ListAppend(list< T1 > *l, T1 e)
AST_Element_ExtendsClause newAST_Element_ExtendsClause(AST_String name)
AST_Modification newAST_ModificationNull()
AST_Element newAST_Element_ClassWrapper(AST_Class c)
AST_Class newAST_Class(AST_String s)
AST_Expression AST_Expression_ComponentReferenceExpAddDot(AST_Expression_ComponentReference cr, AST_String id, AST_String rest, AST_ExpressionList subs)
AST_StatementList newAST_StatementList()
AST_ClassPrefix AST_ClassPrefix_Block()
AST_Expression newAST_Expression_Function(AST_String, AST_ExpressionList)
AST_Equation_ElseList newAST_Equation_ElseList()
AST_Expression newAST_Expression_BinOp(AST_Expression left, AST_Expression right, BinOpType type)
AST_Equation_ElseList newAST_Equation_ElseIfList()
AST_Equation newAST_Equation_If(AST_Expression e, AST_EquationList eql, AST_Equation_ElseList elseif, AST_EquationList elseeqs)
AST_ClassPrefix AST_ClassPrefix_Model()
AST_CompositionEqsAlgs newAST_CompositionInitialEquations(AST_EquationList eqlist)
AST_String AST_SanitizeString(std::string new_string)
AST_ClassPrefix AST_ClassPrefix_None()
AST_Expression newAST_Expression_Derivative(AST_ExpressionList el)
AST_Class AST_Class_SetFinal(AST_Class c, AST_Boolean final)
AST_Comment newAST_Comment(AST_String st, AST_ArgumentList al)
AST_CompositionElement newAST_CompositionElement(AST_ElementList el)
AST_String newAST_DotString(AST_String s)
AST_ClassPrefix AST_ClassPrefix_AddPartial(AST_Boolean partial, AST_ClassPrefix p)
AST_Expression newAST_Expression_Colon()
AST_ClassList newAST_ClassList()
AST_ClassPrefix AST_ClassPrefix_Pure(AST_Boolean oper)
AST_Statement newAST_Statement_When(AST_Expression cond, AST_StatementList sts, AST_Statement_ElseList else_st, AST_Comment c)
AST_Expression_ComponentReference newAST_Expression_ComponentReference()
AST_CompositionEqsAlgs newAST_CompositionAlgorithms(AST_StatementList stlist)
AST_Expression AST_Expression_ComponentReferenceExpAdd(AST_Expression_ComponentReference cr, AST_String id, AST_String rest, AST_ExpressionList subs)
AST_Composition newAST_Composition()
list< T1 > * newAST_SimpleList(T1 t)
AST_Class newAST_ClassExtends(AST_String, AST_Composition)
AST_Expression newAST_Expression_FunctionCallArgs(AST_ExpressionList el)
AST_TypePrefix AST_TypePrefixAdd(AST_TypePrefix tp, AST_TypePrefix tpadd)
AST_Statement newAST_Statement_For(AST_ForIndexList index, AST_StatementList st)
AST_CompositionElementList newAST_CompositionElementList()
ostream & operator<<(ostream &os, const AST_CompositionElement &ce)
AST_ForIndex newAST_ForIndex(AST_String ident, AST_Expression exp)
AST_Expression newAST_Expression_Boolean(AST_Boolean b)
AST_Expression newAST_Expression_If(AST_Expression cond, AST_Expression then, AST_ExpressionList else_list, AST_Expression else_exp)
AST_Expression newAST_Expression_OutputExpressions(AST_ExpressionList exp_list)
AST_ArgumentList newAST_ArgumentList()
AST_ClassPrefix AST_ClassPrefix_Connector(AST_Boolean expandable)
AST_ClassPrefix AST_ClassPrefix_Function(AST_ClassPrefix p)
AST_Element_ComponentList newAST_Element_ComponentList()
AST_Expression newAST_Expression_Call(AST_String name, AST_String rest, AST_ExpressionList args)
AST_Expression newAST_Expression_Brace(AST_ExpressionList el)
AST_Argument newAST_Argument_Modification(AST_String s, AST_Modification m)
AST_Expression newAST_Expression_DotCall(AST_String name, AST_String rest, AST_ExpressionList args)
AST_Expression newAST_Expression_ComponentReferenceExpDot(AST_String s, AST_String rest)
AST_ExpressionList newAST_ExpressionList(AST_Expression e)
AST_Argument AST_ArgumentSet(bool each, bool final, AST_Argument arg)
AST_Class AST_Class_SetPrefixEncapsulated(AST_Class c, AST_ClassPrefix prefix, AST_Boolean enc)
AST_Class newAST_ClassDerivation(AST_String, AST_String, AST_StringList)
AST_String AST_StringDotAppend(AST_String ret, AST_String a)
AST_Declaration newAST_Declaration(AST_String s, AST_ExpressionList indexes, AST_Modification m)
AST_ClassPrefix AST_ClassPrefix_Operator()
AST_Equation newAST_Equation_When(AST_Expression cond, AST_EquationList eqs, AST_Equation_ElseList else_list, AST_Comment comment)
AST_Element_ImportClause newAST_ImportClause(AST_String name)
AST_Equation newAST_Equation_Call(AST_Expression e)
AST_ClassPrefix AST_ClassPrefix_Type()
AST_Expression newAST_Expression_Integer(int i)
AST_ShortClassExp newAST_ShortClassExp_Enum(AST_StringList)
#define current_element(it)
AST_CompositionEqsAlgs newAST_CompositionEquations(AST_EquationList eqlist)
AST_String newAST_String(string s)
AST_Equation newAST_Equation_Connect(AST_Expression_ComponentReference cr1, AST_Expression_ComponentReference cr2)
AST_StoredDefinition newAST_StoredDefinition(AST_ClassList cl, AST_String within)