Skip to content

Commit 8580c99

Browse files
author
robertDurst
committed
fix empty list issue and allow direct passing in of lists to udt params
1 parent 0f798e4 commit 8580c99

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

examples/LinkedList.fish

Lines changed: 0 additions & 9 deletions
This file was deleted.

examples/foo.fish

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/intListHandler.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Uat {
33
int size
44
}
55

6-
Ufn {
6+
Ufn{
77
(fun printFoo_(int i)(void){
88
Tree(
99
(| i != own.size | {

examples/test.fish

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import LinkedList : "../examples/LinkedList.fish"
1+
import intListHandler : "../examples/intListHandler.fish"
22

33
start {
4-
4+
dec intListHandler i = new intListHandler { size: 100, list: []}
5+
dec [int] is = []
56
}

src/parser/Parser2.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,13 +745,13 @@ Parser2::parseFunctionInOut(const std::string& name)
745745
outputBuffer +=
746746
", " + builtinTypesTranslator(type) + " " + name;
747747
else
748-
outputBuffer += type + " " + name;
748+
outputBuffer += builtinTypesTranslator(type) + " " + name;
749749
else if (!isUdt)
750750
{
751751
if (outputBuffer != "")
752752
outputBuffer += ", " + builtinTypesTranslator(type);
753753
else
754-
outputBuffer += type;
754+
outputBuffer += builtinTypesTranslator(type);
755755
}
756756

757757
if (type == "void")
@@ -776,7 +776,11 @@ Parser2::parseFunctionInOut(const std::string& name)
776776
// outputs
777777
advanceAndCheckToken(TokenKind::LPAREN); // consume l paren
778778
auto output = parseType();
779+
779780
types += ")" + output;
781+
782+
if (udttable->hasUDT(output))
783+
output = "struct " + output + "*";
780784
advanceAndCheckToken(TokenKind::RPAREN); // consume r paren
781785

782786
if (isUdt)
@@ -1519,6 +1523,7 @@ std::string
15191523
Parser2::parseUDTDec()
15201524
{
15211525
auto udtName = parseIdentifier();
1526+
15221527
targetBuffer +=
15231528
"(struct " + udtName + "*)malloc(sizeof(struct " + udtName + "));\n";
15241529

@@ -1539,9 +1544,18 @@ Parser2::parseUDTDec()
15391544

15401545
advanceAndCheckToken(TokenKind::COLON); // consume ':'
15411546

1547+
std::string temp = decName;
1548+
if (currentToken->value.at(0) == '[')
1549+
{
1550+
decName = decName + "->" + attributeName;
1551+
decType = st->getSymbolType(attributeName);
1552+
}
1553+
15421554
// capture value
15431555
auto type = parsePrimary();
15441556

1557+
decName = temp;
1558+
15451559
if (attributes.size() != 1)
15461560
this->targetBuffer += ";\n";
15471561

@@ -1571,7 +1585,6 @@ Parser2::parseUDTDec()
15711585
"Expected " + std::to_string(st->getSymbols().size()) +
15721586
" keys and received ",
15731587
std::to_string(st->getSymbols().size() - attributes.size()), ".")));
1574-
15751588
return udtName;
15761589
}
15771590

@@ -1637,8 +1650,8 @@ Parser2::parsePrimary()
16371650

16381651
if (methodAccessName == "" ||
16391652
(methodAccessName != "" && type != "void"))
1640-
if (!udttable->hasUDT(symboltable->getSymbolType(type)))
1641-
targetBuffer += builtinTypesTranslator(type);
1653+
// if (!udttable->hasUDT(symboltable->getSymbolType(type)))
1654+
targetBuffer += builtinTypesTranslator(type);
16421655

16431656
return type;
16441657
}
@@ -1833,7 +1846,7 @@ Parser2::parseList()
18331846
advanceAndCheckToken(TokenKind::LIST); // eat list
18341847
auto listVals = determineTypes(parseListValues(v));
18351848

1836-
std::string type = "none";
1849+
std::string type = decType;
18371850

18381851
std::deque<std::string> vals;
18391852
if (listVals.size() != 0)

src/parser/Parser2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Parser2
3838
bool isUdt;
3939
bool inGrouping = false;
4040
std::string decName = "";
41+
std::string decType = "";
4142
int currentTabs = 0;
4243
std::string targetBuffer = "";
4344
std::string methodAccessName = "";

0 commit comments

Comments
 (0)