Skip to content

Commit

Permalink
fixed MatchAlias Test
Browse files Browse the repository at this point in the history
  • Loading branch information
LostbBlizzard committed Aug 24, 2024
1 parent 69abcbc commit 559e679
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 78 deletions.
7 changes: 7 additions & 0 deletions UCodeLang/UCodeLang/Compilation/Front/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ GotNodeType Parser::GetAlias(const Token* AliasName, GenericValuesNode&& AliasGe

r = GetType(Func->_ReturnType);
}
else if (FirtToken->Type == TokenType::KeyWord_match)
{
out._AliasType = AliasType::Match;
auto ex = new MatchExpression();
out._Node.reset(ex);
r = GetMatchExpression(*ex);
}
else
{
r = GetType(out._Type, false, false);
Expand Down
10 changes: 10 additions & 0 deletions UCodeLang/UCodeLang/Compilation/Front/SystematicAnalysis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,13 @@ class SystematicAnalysis
size_t errcount = 0;
};

struct DoBinaryOpContext
{
const RawEvaluatedObject* Op1 = nullptr;
const RawEvaluatedObject* Op2 = nullptr;
TokenType type = TokenType::Null;
RawEvaluatedObject* OpOut = nullptr;
};
//Members
CompilationErrors* _ErrorsOutput = nullptr;
CompilationSettings* _Settings = nullptr;
Expand Down Expand Up @@ -2093,6 +2100,9 @@ class SystematicAnalysis
bool Eval_Evaluate(EvaluatedEx& Out, const BinaryExpressionNode& node);
bool Eval_Evaluate(EvaluatedEx& Out, const CastNode& node);
bool Eval_Evaluate(EvaluatedEx& Out, const ReadVariableNode& nod);
bool Eval_Evaluate(EvaluatedEx& Out, const MatchExpression& nod,bool runmatchcheck = true);
bool Eval_MatchArm(const TypeSymbol& MatchItem, const EvaluatedEx& Item, MatchArm& Arm, const ExpressionNodeType& ArmEx);
void DoBinaryOpContextWith(TypeSymbol type,const DoBinaryOpContext& context);
bool Eval_Evaluate_t(EvaluatedEx& Out, const Node* node, GetValueMode Mode);
bool Eval_Evaluate(EvaluatedEx& Out, const ExpressionNodeType& node, GetValueMode Mode);
bool Eval_EvaluatePostfixOperator(EvaluatedEx& Out, TokenType Op);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ void SystematicAnalysis::OnAliasNode(const AliasNode& node)

V->Context = Save_SymbolContextRemoveOneScopeName();
}
else if (node._AliasType == AliasType::Match)
{
const MatchExpression* ex = MatchExpression::As(node._Node.get());

_LookingForTypes.push(TypesEnum::Var);
_GetExpressionMode.push(GetValueMode::Read);

OnMatchExpression(*ex);

_GetExpressionMode.pop();
_LookingForTypes.pop();
}
else
{

Expand Down Expand Up @@ -103,10 +115,53 @@ void SystematicAnalysis::OnAliasNode(const AliasNode& node)
{
if (!Isgeneric_t)
{
if (node._AliasType == AliasType::Type)
if (node._AliasType == AliasType::Type || node._AliasType == AliasType::Match)
{
Syb.PassState = PassType::FixedTypes;
Type_ConvertAndValidateType(node._Type, Syb.VarType, NodeSyb_t::Any);

if (node._AliasType == AliasType::Type)
{
Type_ConvertAndValidateType(node._Type, Syb.VarType, NodeSyb_t::Any);
}
else
{
const MatchExpression* ex = MatchExpression::As(node._Node.get());

_LookingForTypes.push(TypesEnum::Var);
_GetExpressionMode.push(GetValueMode::Read);

OnMatchExpression(*ex);

_GetExpressionMode.pop();
_LookingForTypes.pop();

auto outputtype = _LastExpressionType;
if (!outputtype.IsTypeInfo() && !outputtype.IsNull())
{
LogError(ErrorCodes::InValidType, "Match must return 'typeinfo' type", NeverNullptr(ex->_Token));
}

if (outputtype.IsTypeInfo())
{
EvaluatedEx evalout = Eval_MakeEx(outputtype);
bool itworked = Eval_Evaluate(evalout, *ex, false);

if (itworked)
{
const TypeSymbol* EvalTypeSymbol = Eval_Get_ObjectAs<TypeSymbol>(evalout);

TypeSymbol val = *EvalTypeSymbol;
val._TypeInfo = TypeInfoPrimitive::Null;

Syb.VarType = val;
}
else
{
Syb.VarType = TypesEnum::Null;
}
}

}

bool ispublic = node._Access == AccessModifierType::Public;
if (node.IsExport && ispublic)
Expand All @@ -119,7 +174,7 @@ void SystematicAnalysis::OnAliasNode(const AliasNode& node)
}
else
{
AliasNode_Func* node_ = (AliasNode_Func*)node._Node.get();
const AliasNode_Func* node_ = (AliasNode_Func*)node._Node.get();
FuncPtrInfo* nodeinfo_ = (FuncPtrInfo*)Syb.Info.get();

auto& GenericList = node.Generic;
Expand Down Expand Up @@ -158,7 +213,7 @@ void SystematicAnalysis::OnAliasNode(const AliasNode& node)
{
if (!Isgeneric_t)
{
if (node._AliasType == AliasType::Type)
if (node._AliasType == AliasType::Type || node._AliasType == AliasType::Match)
{
auto& V = _Lib.Get_Assembly().AddAlias((String)ClassName, RemoveSymboolFuncOverloadMangling(_Table._Scope.ThisScope));
V.Type = Assembly_ConvertToType(Syb.VarType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ void SystematicAnalysis::OnExpressionNode(const BinaryExpressionNode& node)



_BinaryExpressionNode_Datas.AddValue(Symbol_GetSymbolID(node), V);
if (!_BinaryExpressionNode_Datas.HasValue(Symbol_GetSymbolID(node)))
{
_BinaryExpressionNode_Datas.AddValue(Symbol_GetSymbolID(node), V);
}


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ void SystematicAnalysis::OnMatchExpression(const MatchExpression& node)

MatchExpressionData V;

bool haserror = false;
for (auto& Item : node._Arms)
{
_Table.AddScope(ScopeName + std::to_string(ScopeCounter));
Expand All @@ -774,10 +775,25 @@ void SystematicAnalysis::OnMatchExpression(const MatchExpression& node)

if (!Type_CanBeImplicitConverted(AssignmentType, MatchAssignmentType))
{
const NeverNullPtr<Token> token = _LastLookedAtToken.value();
LogError_CantCastImplicitTypes(token, MatchAssignmentType, AssignmentType, false);
bool next = true;
//TODO make sure this only happens in an AlasNode.
if (MatchAssignmentType.IsTypeInfo() && AssignmentType.IsTypeInfo())
{
next = false;
}

if (next)
{
const NeverNullPtr<Token> token = _LastLookedAtToken.value();
LogError_CantCastImplicitTypes(token, MatchAssignmentType, AssignmentType, false);
haserror = true;
}
}

if (AssignmentType.IsNull())
{
haserror = true;
}

_Table.RemoveScope();

Expand Down Expand Up @@ -822,7 +838,14 @@ void SystematicAnalysis::OnMatchExpression(const MatchExpression& node)
V._MatchAssignmentType = MatchAssignmentType;
_MatchExpressionDatas.AddValue(Symbol_GetSymbolID(node), std::move(V));

_LastExpressionType = MatchAssignmentType;
if (haserror)
{
_LastExpressionType = TypesEnum::Null;
}
else
{
_LastExpressionType = MatchAssignmentType;
}
}
else if (_PassType == PassType::BuidCode)
{
Expand Down
Loading

0 comments on commit 559e679

Please sign in to comment.