Skip to content

Commit c394c66

Browse files
committed
Fix pass type parsing
1 parent 2f6c9f9 commit c394c66

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

src/parser/functionParser.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ Node *Parser::parseFunction() {
2929
advance();
3030
}
3131

32-
if ((currentToken->type == TokenType::BYREF && !byRef)
33-
|| (currentToken->type == TokenType::BYVAL && byRef)
32+
if (currentToken->type == TokenType::BYREF
33+
|| currentToken->type == TokenType::BYVAL
3434
) {
35-
for (int i = 0; i < passTypeCount; i++)
36-
parameterPassTypes.push_back(byRef);
37-
byRef = !byRef;
38-
passTypeCount = 1;
35+
TokenType currentType = byRef ? TokenType::BYREF : TokenType::BYVAL;
36+
if (currentType != currentToken->type) {
37+
parameterPassTypes.reserve(passTypeCount);
38+
for (int i = 0; i < passTypeCount; i++)
39+
parameterPassTypes.push_back(byRef);
40+
byRef = !byRef;
41+
passTypeCount = 1;
42+
} else {
43+
passTypeCount++;
44+
}
3945
advance();
4046
} else {
4147
passTypeCount++;
@@ -60,13 +66,15 @@ Node *Parser::parseFunction() {
6066
advance();
6167

6268
parameterNames.emplace_back(paramName);
69+
parameterTypes.reserve(typeCount);
6370
for (int i = 0; i < typeCount; i++) {
6471
parameterTypes.emplace_back(type);
6572
}
6673
typeCount = 1;
6774
}
6875
if (typeCount != 1) throw PSC::ExpectedTokenError(*currentToken, "data type");
6976
if (passTypeCount > 0) {
77+
parameterPassTypes.reserve(passTypeCount);
7078
for (int i = 0; i < passTypeCount; i++)
7179
parameterPassTypes.push_back(byRef);
7280
}

src/parser/procedureParser.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,19 @@ Node *Parser::parseProcedure() {
6161
advance();
6262
}
6363

64-
if ((currentToken->type == TokenType::BYREF && !byRef)
65-
|| (currentToken->type == TokenType::BYVAL && byRef)
64+
if (currentToken->type == TokenType::BYREF
65+
|| currentToken->type == TokenType::BYVAL
6666
) {
67-
for (int i = 0; i < passTypeCount; i++)
68-
parameterPassTypes.push_back(byRef);
69-
byRef = !byRef;
70-
passTypeCount = 1;
67+
TokenType currentType = byRef ? TokenType::BYREF : TokenType::BYVAL;
68+
if (currentType != currentToken->type) {
69+
parameterPassTypes.reserve(passTypeCount);
70+
for (int i = 0; i < passTypeCount; i++)
71+
parameterPassTypes.push_back(byRef);
72+
byRef = !byRef;
73+
passTypeCount = 1;
74+
} else {
75+
passTypeCount++;
76+
}
7177
advance();
7278
} else {
7379
passTypeCount++;
@@ -92,13 +98,15 @@ Node *Parser::parseProcedure() {
9298
advance();
9399

94100
parameterNames.emplace_back(paramName);
101+
parameterTypes.reserve(typeCount);
95102
for (int i = 0; i < typeCount; i++) {
96103
parameterTypes.emplace_back(type);
97104
}
98105
typeCount = 1;
99106
}
100107
if (typeCount != 1) throw PSC::ExpectedTokenError(*currentToken, "data type");
101108
if (passTypeCount > 0) {
109+
parameterPassTypes.reserve(passTypeCount);
102110
for (int i = 0; i < passTypeCount; i++)
103111
parameterPassTypes.push_back(byRef);
104112
}

0 commit comments

Comments
 (0)