Skip to content

Commit

Permalink
Fix pass type parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
SingularityT3 committed Mar 10, 2023
1 parent 2f6c9f9 commit c394c66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
20 changes: 14 additions & 6 deletions src/parser/functionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ Node *Parser::parseFunction() {
advance();
}

if ((currentToken->type == TokenType::BYREF && !byRef)
|| (currentToken->type == TokenType::BYVAL && byRef)
if (currentToken->type == TokenType::BYREF
|| currentToken->type == TokenType::BYVAL
) {
for (int i = 0; i < passTypeCount; i++)
parameterPassTypes.push_back(byRef);
byRef = !byRef;
passTypeCount = 1;
TokenType currentType = byRef ? TokenType::BYREF : TokenType::BYVAL;
if (currentType != currentToken->type) {
parameterPassTypes.reserve(passTypeCount);
for (int i = 0; i < passTypeCount; i++)
parameterPassTypes.push_back(byRef);
byRef = !byRef;
passTypeCount = 1;
} else {
passTypeCount++;
}
advance();
} else {
passTypeCount++;
Expand All @@ -60,13 +66,15 @@ Node *Parser::parseFunction() {
advance();

parameterNames.emplace_back(paramName);
parameterTypes.reserve(typeCount);
for (int i = 0; i < typeCount; i++) {
parameterTypes.emplace_back(type);
}
typeCount = 1;
}
if (typeCount != 1) throw PSC::ExpectedTokenError(*currentToken, "data type");
if (passTypeCount > 0) {
parameterPassTypes.reserve(passTypeCount);
for (int i = 0; i < passTypeCount; i++)
parameterPassTypes.push_back(byRef);
}
Expand Down
20 changes: 14 additions & 6 deletions src/parser/procedureParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@ Node *Parser::parseProcedure() {
advance();
}

if ((currentToken->type == TokenType::BYREF && !byRef)
|| (currentToken->type == TokenType::BYVAL && byRef)
if (currentToken->type == TokenType::BYREF
|| currentToken->type == TokenType::BYVAL
) {
for (int i = 0; i < passTypeCount; i++)
parameterPassTypes.push_back(byRef);
byRef = !byRef;
passTypeCount = 1;
TokenType currentType = byRef ? TokenType::BYREF : TokenType::BYVAL;
if (currentType != currentToken->type) {
parameterPassTypes.reserve(passTypeCount);
for (int i = 0; i < passTypeCount; i++)
parameterPassTypes.push_back(byRef);
byRef = !byRef;
passTypeCount = 1;
} else {
passTypeCount++;
}
advance();
} else {
passTypeCount++;
Expand All @@ -92,13 +98,15 @@ Node *Parser::parseProcedure() {
advance();

parameterNames.emplace_back(paramName);
parameterTypes.reserve(typeCount);
for (int i = 0; i < typeCount; i++) {
parameterTypes.emplace_back(type);
}
typeCount = 1;
}
if (typeCount != 1) throw PSC::ExpectedTokenError(*currentToken, "data type");
if (passTypeCount > 0) {
parameterPassTypes.reserve(passTypeCount);
for (int i = 0; i < passTypeCount; i++)
parameterPassTypes.push_back(byRef);
}
Expand Down

0 comments on commit c394c66

Please sign in to comment.