public ASTCILNode VisitDynamicMethodCall(ASTDynamicMethodCallNode MethodCall) { var type = MethodCall.InvokeOnExpresion.SemanticCheckResult.Type; if (type is SelfType self) { type = self.ContextType; } var invoke = (ASTCILExpressionNode)MethodCall.InvokeOnExpresion.Accept(this); ASTCILExpressionNode invokeOn = invoke; if (MethodCall.InvokeOnExpresion.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Int || MethodCall.InvokeOnExpresion.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Bool) { invokeOn = new ASTCILBoxingNode(invoke, MethodCall.InvokeOnExpresion.SemanticCheckResult.Type); } var args = new[] { invokeOn } .Concat(MethodCall.Arguments.Select((param, i) => { var exp = (ASTCILExpressionNode)param.Accept(this); ASTCILExpressionNode arg = exp; var coolMethod = compilationUnit.MethodEnvironment.GetMethod(type, MethodCall.MethodName); if (coolMethod.GetParam(i) == compilationUnit.TypeEnvironment.Object && (param.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Int || param.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Bool)) { arg = new ASTCILBoxingNode(exp, param.SemanticCheckResult.Type); } return(arg); })); return(new ASTCILFuncVirtualCallNode(type, MethodCall.MethodName, args)); }
public ASTCILNode VisitStaticMethodCall(ASTStaticMethodCallNode MethodCall) { var invoke = (ASTCILExpressionNode)MethodCall.InvokeOnExpresion.Accept(this); ASTCILExpressionNode invokeOn = invoke; if (MethodCall.InvokeOnExpresion.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Int || MethodCall.InvokeOnExpresion.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Bool) { invokeOn = new ASTCILBoxingNode(invoke, MethodCall.InvokeOnExpresion.SemanticCheckResult.Type); } compilationUnit.TypeEnvironment.GetTypeDefinition(MethodCall.TypeName, null, out var type); return(new ASTCILFuncStaticCallNode( MethodCall.MethodName, type, new[] { invokeOn } .Concat(MethodCall.Arguments.Select((param, i) => { var exp = (ASTCILExpressionNode)param.Accept(this); ASTCILExpressionNode arg = exp; var coolMethod = compilationUnit.MethodEnvironment.GetMethod(type, MethodCall.MethodName); if (coolMethod.GetParam(i) == compilationUnit.TypeEnvironment.Object && (param.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Int || param.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Bool)) { arg = new ASTCILBoxingNode(exp, param.SemanticCheckResult.Type); } return arg; })))); }
public MipsProgram VisitBoxing(ASTCILBoxingNode Boxing) { var result = Boxing.Expression.Accept(this); var label = labelGenerator.GenerateLabelTypeInfo(Boxing.Type.Name); result.SectionCode.Append(MipsGenerationHelper.NewScript().Boxing(label)); return(result); }
public ASTCILNode VisitCase(ASTCaseNode Case) { var exp = (ASTCILExpressionNode)Case.ExpressionCase.Accept(this); if (Case.ExpressionCase.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Int || Case.ExpressionCase.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Bool) { exp = new ASTCILBoxingNode(exp, Case.ExpressionCase.SemanticCheckResult.Type); } return(new ASTCILCaseNode(exp, Case.Cases.Select(x => { compilationUnit.TypeEnvironment.GetTypeDefinition(x.Type.Text, Case.SymbolTable, out var type); return (type, (ASTCILExpressionNode)x.Branch.Accept(this), x.Branch.SymbolTable.GetObject(x.Name.Text)); }))); }
public ASTCILNode VisitOwnMethodCall(ASTOwnMethodCallNode OwnMethodCall) { var self = compilationUnit.TypeEnvironment.GetContextType(OwnMethodCall.SymbolTable); return(new ASTCILFuncVirtualCallNode(self, OwnMethodCall.Method.Text, new[] { new ASTCILSelfNode() } .Concat(OwnMethodCall.Arguments.Select((param, i) => { var exp = (ASTCILExpressionNode)param.Accept(this); ASTCILExpressionNode arg = exp; var coolMethod = compilationUnit.MethodEnvironment.GetMethod(self, OwnMethodCall.MethodName); if (coolMethod.GetParam(i) == compilationUnit.TypeEnvironment.Object && (param.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Int || param.SemanticCheckResult.Type == compilationUnit.TypeEnvironment.Bool)) { arg = new ASTCILBoxingNode(exp, param.SemanticCheckResult.Type); } return arg; })))); }