protected override void VisitReference(ReferenceNode referenceNode) { base.VisitReference(referenceNode); Symbol symbol = referenceNode.Symbol; if (symbol != null) { if (_currentExpressionTypes.Count > 0) { SymbolTypePair currentExpressionType = _currentExpressionTypes.Peek(); if (currentExpressionType != null) { SymbolType asType = currentExpressionType.BuiltinType; if (asType == SymbolType.Func || (asType == SymbolType.Int && symbol.BuiltinType != SymbolType.Int)) { referenceNode.DoCastToInt = true; } } } else { if (_isInsideCondition && symbol.BuiltinType != SymbolType.Int) { referenceNode.DoCastToInt = true; } } if (symbol is FunctionSymbol) { referenceNode.BuiltinType = SymbolType.Func; return; } if (symbol.BuiltinType == SymbolType.Uninitialized && symbol is NestableSymbol tmpSymbol && tmpSymbol.ComplexType is ClassSymbol) { symbol.BuiltinType = SymbolType.Instance; } referenceNode.BuiltinType = symbol.BuiltinType; if (symbol is NestableSymbol nestableSymbol) { referenceNode.ComplexType = nestableSymbol.ComplexType; } } }
private bool IsInsideFloatExpression() { if (_currentExpressionTypes.Count > 0) { SymbolTypePair currentExpressionType = _currentExpressionTypes.Peek(); if (currentExpressionType != null) { SymbolType asType = currentExpressionType.BuiltinType; if (asType == SymbolType.Float) { return(true); } } } return(false); }
protected override void VisitReturnStatement(ReturnStatementNode node) { ASTNode parentBlockNode = node.GetFirstSignificantAncestorNode(); FunctionDefinitionNode functionDefinitionNode = (FunctionDefinitionNode)parentBlockNode; SymbolTypePair functionType = GetSymbolTypePairFromSymbol(functionDefinitionNode.Symbol); /* * if (functionDefinitionNode.Symbol.BuiltinType == SymbolType.Float) * { * _isInsideFloatExpression = true; * } */ _currentExpressionTypes.Push(functionType); base.VisitReturnStatement(node); _currentExpressionTypes.Pop(); //_isInsideFloatExpression = false; }
protected override void VisitAssignment(AssignmentNode node) { Visit(node.LeftSideNode); SymbolTypePair assignmentType = GetSymbolTypePairFromSymbol(node.LeftSideNode.Symbol); /* * if (node.LeftSideNode.BuiltinType == SymbolType.Float) * { * _isInsideFloatExpression = true; * } */ _currentExpressionTypes.Push(assignmentType); Visit(node.RightSideNode); _currentExpressionTypes.Pop(); //_isInsideFloatExpression = false; /* * IncompatibleTypeAssignmentError * TODO check assignment types compability */ }
protected override void VisitFunctionCall(FunctionCallNode node) { if (node.FunctionReferenceNode.Symbol != null) { FunctionDefinitionNode functionDefinitionNode; ASTNode declarationNode = node.FunctionReferenceNode.Symbol.Node; if (declarationNode is FunctionDefinitionNode) { functionDefinitionNode = (FunctionDefinitionNode)node.FunctionReferenceNode.Symbol.Node; } else { node.Annotations.Add(new SymbolIsNotAFunctionError(node.FunctionReferenceNode.Name, declarationNode.Location)); return; } Symbol symbol = functionDefinitionNode.Symbol; if (symbol != null) { node.BuiltinType = symbol.BuiltinType; if (symbol is NestableSymbol nestableSymbol) { node.ComplexType = nestableSymbol.ComplexType; } } string identifier = functionDefinitionNode.NameNode.Value; List <ParameterDeclarationNode> parameterNodes = functionDefinitionNode.ParameterNodes; List <ExpressionNode> argumentNodes = node.ArgumentNodes; int parametersCount = parameterNodes.Count; int argumentsCount = argumentNodes.Count; if (parametersCount != argumentsCount) { node.Annotations.Add(new ArgumentsCountDoesNotMatchError(identifier, parametersCount, argumentsCount, functionDefinitionNode.NameNode.Location)); } int iterationsCount = Math.Min(parametersCount, argumentsCount); for (int i = 0; i < iterationsCount; i++) { ParameterDeclarationNode parameterNode = parameterNodes[i]; SymbolTypePair parameterType = GetSymbolTypePairFromSymbol(parameterNode.Symbol); ExpressionNode argumentNode = argumentNodes[i]; /* * if (parameterType.BuiltinType == SymbolType.Float) * { * _isInsideFloatExpression = true; * } */ _currentExpressionTypes.Push(parameterType); Visit(argumentNode); _currentExpressionTypes.Pop(); //_isInsideFloatExpression = false; SymbolTypePair argumentType = GetSymbolTypePairFromExpressionNode(argumentNode); //Console.Write("x"); } } }