Skip to content

Commit

Permalink
[iss-220]
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit ebc2bd8
Author: joaquin.f.fernandez <[email protected]>
Date:   Fri Apr 14 12:04:37 2023 -0300

    Update GT advection quoted file.

commit 45bc3f2
Author: joaquin.f.fernandez <[email protected]>
Date:   Fri Apr 14 11:58:42 2023 -0300

    Added advection_quoted system test.

commit 702244c
Author: joaquin.f.fernandez <[email protected]>
Date:   Fri Apr 14 11:50:21 2023 -0300

    Added quoted string system test.

commit 7cbdf0e
Author: joaquin.f.fernandez <[email protected]>
Date:   Fri Apr 14 11:49:47 2023 -0300

    Sanitize AST strings.

commit 7981832
Author: joaquin.f.fernandez <[email protected]>
Date:   Tue Apr 11 16:54:22 2023 -0300

    Update lexer to allow quoted definitions.
  • Loading branch information
joaquinffernandez committed Apr 14, 2023
1 parent 989335c commit dddb768
Show file tree
Hide file tree
Showing 7 changed files with 467 additions and 18 deletions.
39 changes: 26 additions & 13 deletions src/mmoc/ast/ast_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
******************************************************************************/

#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <iostream>
Expand Down Expand Up @@ -44,28 +45,37 @@ MCC_Lexer *MCC_Parser::lexer = nullptr;

AST_StoredDefinition newAST_StoredDefinition(AST_ClassList cl, AST_String within) { return new AST_StoredDefinition_(cl, within); }

AST_String newAST_String(string s) { return new string(s); }
AST_String AST_SanitizeString(std::string new_string)
{
if (new_string.find("'") != std::string::npos) {
new_string.erase(std::remove(new_string.begin(), new_string.end(), '\''), new_string.end());
std::replace(new_string.begin(), new_string.end(), '.', '_');
}
return new string(new_string);
}

AST_String newAST_String(char *s) { return new string(s); }
AST_String newAST_String(string s) { return AST_SanitizeString(string(s)); }

AST_String newAST_String(const char *s) { return new string(s); }
AST_String newAST_String(char *s) { return AST_SanitizeString(string(s)); }

AST_String newAST_String(const char *s) { return AST_SanitizeString(string(s)); }

AST_String newAST_String(AST_String s)
{
AST_String ret = new string(*s);
AST_String ret = AST_SanitizeString(string(*s));
delete s;
return ret;
}

AST_String copyAST_String(AST_String s)
{
AST_String ret = new string(*s);
AST_String ret = AST_SanitizeString(string(*s));
return ret;
}

AST_String newAST_DotString(AST_String s)
{
AST_String ret = new string(*s);
AST_String ret = AST_SanitizeString(string(*s));
ret->insert(0, ".");
delete s;
return ret;
Expand All @@ -78,7 +88,7 @@ AST_String AST_StringDotAppend(AST_String ret, AST_String a)
}
if (a != nullptr) {
ret->append(".");
ret->append(*a);
ret->append(*AST_SanitizeString(string(*a)));
delete a;
}
return ret;
Expand Down Expand Up @@ -140,7 +150,10 @@ AST_Argument AST_ArgumentSet(bool each, bool final, AST_Argument arg)

AST_EquationList newAST_EquationList() { return new list<AST_Equation>(); }

AST_Equation newAST_Equation_Equality(AST_Expression left, AST_Expression right, AST_Comment comment) { return new AST_Equation_Equality_(left, right, comment); }
AST_Equation newAST_Equation_Equality(AST_Expression left, AST_Expression right, AST_Comment comment)
{
return new AST_Equation_Equality_(left, right, comment);
}

AST_Equation newAST_Equation_Connect(AST_Expression_ComponentReference cr1, AST_Expression_ComponentReference cr2)
{
Expand All @@ -151,7 +164,7 @@ AST_Expression newAST_Expression_Real(AST_Real r) { return new AST_Expression_Re

AST_Expression newAST_Expression_String(AST_String s)
{
AST_Expression_String ret = new AST_Expression_String_(*s);
AST_Expression_String ret = new AST_Expression_String_(*AST_SanitizeString(*s));
delete s;
return ret;
}
Expand All @@ -173,7 +186,7 @@ AST_Element_Component newAST_Element_Component(AST_DeclarationList cl, AST_Strin

AST_Declaration newAST_Declaration(AST_String s, AST_ExpressionList indexes, AST_Modification m)
{
AST_Declaration ret = new AST_Declaration_(*s, indexes, m);
AST_Declaration ret = new AST_Declaration_(*AST_SanitizeString(*s), indexes, m);
delete s;
return ret;
}
Expand All @@ -185,7 +198,7 @@ AST_CompositionElement newAST_CompositionElement(AST_ElementList el) { return ne
AST_Expression newAST_Expression_ComponentReferenceExp(AST_String s)
{
AST_Expression_ComponentReference e = newAST_Expression_ComponentReference();
e->append(s, newAST_ExpressionList());
e->append(AST_SanitizeString(*s), newAST_ExpressionList());
return e;
}

Expand Down Expand Up @@ -223,7 +236,7 @@ AST_Expression_ComponentReference AST_Expression_ComponentReference_AddDot(AST_E
AST_Expression_ComponentReference AST_Expression_ComponentReference_Add(AST_Expression_ComponentReference cr, AST_String s,
AST_ExpressionList subs)
{
cr->append(s, subs);
cr->append(AST_SanitizeString(*s), subs);
return cr;
}

Expand Down Expand Up @@ -517,7 +530,7 @@ AST_Expression newAST_BracketExpList(AST_ExpressionListList expss)
AST_ExpressionList l = newAST_ExpressionList();
foreach (exps_it, expss) {
if (current_element(exps_it)->size()) {
foreach (exps_range_it, current_element(exps_it)){
foreach (exps_range_it, current_element(exps_it)) {
if (current_element(exps_range_it)->expressionType() == EXPRANGE) {
l = AST_ListAppend(l, current_element(exps_range_it));
}
Expand Down
2 changes: 1 addition & 1 deletion src/mmoc/ast/parser/mocc.lex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ DIGIT [0-9]
NUM {DIGIT}*
ID [_a-zA-Z][_a-zA-Z0-9]*
IDNUM [_a-zA-Z0-9][_a-zA-Z0-9]*
QUOTED [0-9a-zA-Z\-_#]*
QUOTED [0-9a-zA-Z\-_#.!$%&()\*+,/:;<>=?@\[\]^{}|~]*

%x str
%x line_comment
Expand Down
Loading

0 comments on commit dddb768

Please sign in to comment.