public void AssertParameters(ExpressionBuilderParams p, EvaluationStatement[] parameters) { if (!FunctionStatementTranspilerBase.ValidateParameters(p.Context, p.Scope, Parameters, parameters, out var exception)) { throw exception; } }
public static TypeDescriptor GetDataType(this EvaluationStatement evaluationStatement, Context context, Scope scope) { switch (evaluationStatement) { case ConstantValueStatement constantValueStatement: { return(constantValueStatement.TypeDescriptor); } case VariableAccessStatement variableAccessStatement: { if (scope.TryGetVariableInfo(variableAccessStatement, out var variableInfo)) { return(variableInfo.TypeDescriptor); } if (scope.TryGetConstantInfo(variableAccessStatement, out var constantInfo)) { return(constantInfo.TypeDescriptor); } if (scope.TryGetPrototypeInfo(variableAccessStatement, out var functionInfo) || scope.TryGetFunctionInfo(variableAccessStatement, out functionInfo)) { return(new TypeDescriptor(DataTypes.Delegate, new TypeDescriptor.LookupInfo(functionInfo.ClassName, functionInfo.Name))); } throw new IdentifierNotFoundCompilerException(variableAccessStatement.VariableName, variableAccessStatement.Info); } case FunctionCallStatement functionCallStatement: { var funcInfo = FunctionStatementTranspilerBase.GetFunctionInfoFromFunctionCall(context, scope, functionCallStatement, out var sourceObjectInfo); if (funcInfo == null) { throw new IdentifierNotFoundCompilerException(functionCallStatement.FunctionName, functionCallStatement.Info); } return(funcInfo.TypeDescriptor); } case BitwiseEvaluationStatement bitwiseEvaluationStatement: { switch (bitwiseEvaluationStatement.Operator) { case BitwiseNotOperator _: { return(bitwiseEvaluationStatement.Right.GetDataType(context, scope)); } case BitwiseAndOperator _: case BitwiseOrOperator _: case XorOperator _: { return(OperateDataTypes( bitwiseEvaluationStatement.Operator, bitwiseEvaluationStatement.Left.GetDataType(context, scope), bitwiseEvaluationStatement.Right.GetDataType(context, scope) )); } } return(TypeDescriptor.Numeric); } case LogicalEvaluationStatement _: //logicalEvaluationStatement { return(TypeDescriptor.Boolean); } case ArithmeticEvaluationStatement arithmeticEvaluationStatement: { switch (arithmeticEvaluationStatement.Operator) { case IncrementOperator _: case DecrementOperator _: case NegativeNumberOperator _: { return((arithmeticEvaluationStatement.Right ?? arithmeticEvaluationStatement.Left) .GetDataType(context, scope)); } case AdditionOperator _: case SubtractionOperator _: case MultiplicationOperator _: case DivisionOperator _: //case ReminderOperator _: case ModulusOperator _: { return(OperateDataTypes( arithmeticEvaluationStatement.Operator, arithmeticEvaluationStatement.Left.GetDataType(context, scope), arithmeticEvaluationStatement.Right.GetDataType(context, scope) )); } } return(TypeDescriptor.Numeric); } case AssignmentStatement assignmentStatement: { return(assignmentStatement.LeftSide.GetDataType(context, scope)); } case TypeCastStatement typeCastStatement: { return(typeCastStatement.TypeDescriptor); } case IndexerAccessStatement indexerAccessStatement: { var type = indexerAccessStatement.Source.GetDataType(context, scope); if (!type.IsArray()) { throw new InvalidStatementStructureCompilerException(indexerAccessStatement, indexerAccessStatement.Info); } //NOTE: multi-dimensional arrays is not supported. return(type ^ DataTypes.Array); } case ArrayStatement arrayStatement: { return(arrayStatement.Type); } default: throw new InvalidOperationException(); } }