Fixed issue with TypeMod.
This commit is contained in:
parent
f5baed48a9
commit
ad8a0ce1b4
|
@ -345,7 +345,7 @@ namespace MalachScript::Parser {
|
||||||
if (!ParseType((const ParsedStatement*&)parameter.GetTypeStatement(), currentToken)) {
|
if (!ParseType((const ParsedStatement*&)parameter.GetTypeStatement(), currentToken)) {
|
||||||
LogError(Diagnostics::DiagnosticType::UnexpectedToken, currentToken->GetSpan());
|
LogError(Diagnostics::DiagnosticType::UnexpectedToken, currentToken->GetSpan());
|
||||||
}
|
}
|
||||||
ParseTypeMod(parameter.GetTypeMod());
|
ParseTypeMod(parameter.GetTypeMod(), currentToken);
|
||||||
ParseIdentifier(parameter.GetIdentifier(), currentToken);
|
ParseIdentifier(parameter.GetIdentifier(), currentToken);
|
||||||
PROGRESS_TOKEN(currentToken);
|
PROGRESS_TOKEN(currentToken);
|
||||||
if (currentToken->GetKind() != LexTokenKind::CommaSymbol) {
|
if (currentToken->GetKind() != LexTokenKind::CommaSymbol) {
|
||||||
|
@ -402,23 +402,23 @@ namespace MalachScript::Parser {
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool Parser::ParseTypeMod(TypeMod& typeMod) {
|
bool Parser::ParseTypeMod(TypeMod& typeMod, const LexToken*& currentToken) {
|
||||||
if (_currentToken->GetKind() != LexTokenKind::AmpersandSymbol) {
|
if (currentToken->GetKind() != LexTokenKind::AmpersandSymbol) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PROGRESS_TOKEN(_currentToken);
|
PROGRESS_TOKEN(currentToken);
|
||||||
switch (_currentToken->GetKind()) {
|
switch (currentToken->GetKind()) {
|
||||||
case LexTokenKind::InKeyword:
|
case LexTokenKind::InKeyword:
|
||||||
typeMod = TypeMod::RefIn;
|
typeMod = TypeMod::RefIn;
|
||||||
PROGRESS_TOKEN(_currentToken);
|
PROGRESS_TOKEN(currentToken);
|
||||||
return true;
|
return true;
|
||||||
case LexTokenKind::OutKeyword:
|
case LexTokenKind::OutKeyword:
|
||||||
typeMod = TypeMod::RefOut;
|
typeMod = TypeMod::RefOut;
|
||||||
PROGRESS_TOKEN(_currentToken);
|
PROGRESS_TOKEN(currentToken);
|
||||||
return true;
|
return true;
|
||||||
case LexTokenKind::InoutKeyword:
|
case LexTokenKind::InoutKeyword:
|
||||||
typeMod = TypeMod::RefInOut;
|
typeMod = TypeMod::RefInOut;
|
||||||
PROGRESS_TOKEN(_currentToken);
|
PROGRESS_TOKEN(currentToken);
|
||||||
return true;
|
return true;
|
||||||
default: typeMod = TypeMod::RefInOut; return true;
|
default: typeMod = TypeMod::RefInOut; return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace MalachScript::Parser {
|
||||||
bool ParseType(const ParsedStatement*& out, const LexToken*& currentToken);
|
bool ParseType(const ParsedStatement*& out, const LexToken*& currentToken);
|
||||||
bool ParseScope(std::vector<Identifier>& out, const LexToken*& currentToken);
|
bool ParseScope(std::vector<Identifier>& out, const LexToken*& currentToken);
|
||||||
bool ParseParamList(const ParsedStatement*& out, const LexToken*& currentToken);
|
bool ParseParamList(const ParsedStatement*& out, const LexToken*& currentToken);
|
||||||
bool ParseTypeMod(TypeMod& typeMod);
|
bool ParseTypeMod(TypeMod& typeMod, const LexToken*& currentToken);
|
||||||
bool ParseDataType(Identifier& out, const LexToken*& currentToken);
|
bool ParseDataType(Identifier& out, const LexToken*& currentToken);
|
||||||
|
|
||||||
bool ParseVirtProp(const ParsedStatement*& out);
|
bool ParseVirtProp(const ParsedStatement*& out);
|
||||||
|
|
|
@ -153,3 +153,74 @@ PARSER_TEST("Parse scoped function with parameters without body.",
|
||||||
CHECK(funcStat->GetFuncAttr() == MalachScript::FuncAttr::None);
|
CHECK(funcStat->GetFuncAttr() == MalachScript::FuncAttr::None);
|
||||||
CHECK(funcStat->GetStatBlock() == nullptr);
|
CHECK(funcStat->GetStatBlock() == nullptr);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
PARSER_TEST("Parse scoped function with reference parameters without body.",
|
||||||
|
PARSER_TEST_TOKENS(new Parser::IdentifierToken(TextSpan(0, 0), u8"foo"),
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::ColonColonSymbol>(TextSpan(0, 0)),
|
||||||
|
new Parser::IdentifierToken(TextSpan(0, 0), u8"bar"),
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::ColonColonSymbol>(TextSpan(0, 0)),
|
||||||
|
new Parser::IdentifierToken(TextSpan(0, 0), u8"baz"),
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||||
|
new Parser::IdentifierToken(TextSpan(0, 0), u8"foobar"),
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::OpenParenthesisSymbol>(TextSpan(0, 0)),
|
||||||
|
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::IntKeyword>(TextSpan(0, 0)),
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::AmpersandSymbol>(TextSpan(0, 0)),
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::InKeyword>(TextSpan(0, 0)),
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||||
|
new Parser::IdentifierToken(TextSpan(0, 0), u8"par1"),
|
||||||
|
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::CommaSymbol>(TextSpan(0, 0)),
|
||||||
|
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::BoolKeyword>(TextSpan(0, 0)),
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::AmpersandSymbol>(TextSpan(0, 0)),
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::OutKeyword>(TextSpan(0, 0)),
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::Whitespace>(TextSpan(0, 0)),
|
||||||
|
new Parser::IdentifierToken(TextSpan(0, 0), u8"par2"),
|
||||||
|
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::CloseParenthesisSymbol>(TextSpan(0, 0)),
|
||||||
|
new Parser::LexTokenImpl<Parser::LexTokenKind::SemicolonSymbol>(TextSpan(0, 0))),
|
||||||
|
{
|
||||||
|
REQUIRE(script->GetStatements().size() == 1);
|
||||||
|
REQUIRE(script->GetStatements()[0].get()->GetKind() == Parser::ParsedStatementKind::Func);
|
||||||
|
auto funcStat = (const MalachScript::Parser::ParsedFuncStatement*)script->GetStatements()[0].get();
|
||||||
|
CHECK_FALSE(funcStat->IsShared());
|
||||||
|
CHECK_FALSE(funcStat->IsExternal());
|
||||||
|
CHECK(funcStat->GetAccess() == MalachScript::AccessModifier::Public);
|
||||||
|
auto type = (const MalachScript::Parser::ParsedTypeStatement*)funcStat->GetTypeStatement().get();
|
||||||
|
CHECK_FALSE(type->IsConst());
|
||||||
|
CHECK_FALSE(type->IsArray());
|
||||||
|
CHECK_FALSE(type->IsHandle());
|
||||||
|
auto& id = type->GetScopedIdentifier();
|
||||||
|
CHECK(id.GetIdentifier().GetString() == u8"baz");
|
||||||
|
CHECK(id.GetScope()[1].GetString() == u8"bar");
|
||||||
|
CHECK(id.GetScope()[0].GetString() == u8"foo");
|
||||||
|
CHECK_FALSE(funcStat->ReturnsReference());
|
||||||
|
CHECK(funcStat->GetIdentifier().GetString() == u8"foobar");
|
||||||
|
auto paramList = (const MalachScript::Parser::ParsedParamListStatement*)funcStat->GetParamList().get();
|
||||||
|
CHECK(paramList->GetParameters().size() == 2);
|
||||||
|
|
||||||
|
auto& par1 = paramList->GetParameters()[0];
|
||||||
|
CHECK_FALSE(par1.GetTypeStatement()->IsConst());
|
||||||
|
CHECK_FALSE(par1.GetTypeStatement()->IsArray());
|
||||||
|
CHECK_FALSE(par1.GetTypeStatement()->IsHandle());
|
||||||
|
auto& par1TypeId = par1.GetTypeStatement()->GetScopedIdentifier();
|
||||||
|
CHECK(par1TypeId.GetIdentifier().GetString() == u8"int");
|
||||||
|
CHECK(par1.GetTypeMod() == TypeMod::RefIn);
|
||||||
|
CHECK(par1.GetIdentifier().GetString() == u8"par1");
|
||||||
|
CHECK(par1.GetDefaultExpression() == nullptr);
|
||||||
|
|
||||||
|
auto& par2 = paramList->GetParameters()[1];
|
||||||
|
CHECK_FALSE(par2.GetTypeStatement()->IsConst());
|
||||||
|
CHECK_FALSE(par2.GetTypeStatement()->IsArray());
|
||||||
|
CHECK_FALSE(par2.GetTypeStatement()->IsHandle());
|
||||||
|
auto& par2TypeId = par2.GetTypeStatement()->GetScopedIdentifier();
|
||||||
|
CHECK(par2TypeId.GetIdentifier().GetString() == u8"bool");
|
||||||
|
CHECK(par2.GetTypeMod() == TypeMod::RefOut);
|
||||||
|
CHECK(par2.GetIdentifier().GetString() == u8"par2");
|
||||||
|
CHECK(par2.GetDefaultExpression() == nullptr);
|
||||||
|
|
||||||
|
CHECK_FALSE(funcStat->IsConst());
|
||||||
|
CHECK(funcStat->GetFuncAttr() == MalachScript::FuncAttr::None);
|
||||||
|
CHECK(funcStat->GetStatBlock() == nullptr);
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue