internal Function(PigeonType returnType, string name, Variable[] parameters, object funcBody) { Name = name; ReturnType = returnType; Parameters = parameters; FuncBody = funcBody; }
internal static bool IsAssignable(string op, PigeonType variableType, PigeonType valueType) { if (operators.TryGetValue(op, out var combinations)) { return(combinations.Any(t => t.Supports(variableType, valueType))); } return(false); }
private void CheckExprType(PigeonParser.ExprContext context, PigeonType expected) { var actual = Types.Get(context); if (actual != expected) { errorBag.ReportUnexpectedType(context.GetTextSpan(), expected, actual); } }
internal static bool TryGetResType(PigeonType whenTrue, PigeonType whenFalse, out PigeonType pigeonType) { pigeonType = PigeonType.Error; TernaryOperator top; if ((top = combinations.FirstOrDefault(t => t.Supports(whenTrue, whenFalse))) != null) { pigeonType = top.resultType; return(true); } return(false); }
internal static bool TryGetResType(string op, PigeonType operandType, out PigeonType pigeonType) { pigeonType = PigeonType.Error; if (operators.TryGetValue(op, out var combinations)) { UnaryOperator uop; if ((uop = combinations.FirstOrDefault(t => t.Supports(operandType))) != null) { pigeonType = uop.resultType; return(true); } } return(false); }
public override void EnterFunctionDecl([NotNull] PigeonParser.FunctionDeclContext context) { var parameters = new List <Variable>(); var returnType = PigeonType.FromName(context.TYPE().GetText()); var parameterCount = context.functionParams()?.ID()?.Length ?? 0; for (var i = 0; i < parameterCount; ++i) { var parameterType = PigeonType.FromName(context.functionParams().TYPE(i).GetText()); var parameterName = context.functionParams().ID(i).GetText(); if (parameters.Any(v => v.Name == parameterName)) { errorBag.ReportDuplicatedArgument(context.functionParams().GetTextSpan(), parameterName); } parameters.Add(new Variable(parameterType, parameterName, false)); } globalScope.DeclareFunction(returnType, context.ID().GetText(), parameters.ToArray(), context.stmtBlock()); }
private bool Supports(PigeonType type) { return(resultType == type); }
private UnaryOperator(PigeonType type) { resultType = type; }
internal void ReportInvalidTypeBinaryOperator(TextSpan textSpan, string op, PigeonType type1, PigeonType type2) { Report($"Operator {op} is not defined for types {type1.Name} and {type2.Name}", textSpan); }
internal Variable(PigeonType type, string name, bool readOnly) { Type = type; Name = name; ReadOnly = readOnly; }
internal void ReportUnexpectedType(TextSpan textSpan, PigeonType expectedType, PigeonType actualType) { Report($"Got value of type {actualType.Name} instead of {expectedType.Name}", textSpan); }
private bool Supports(PigeonType variableType, PigeonType valueType) { return(this.variableType == variableType && this.valueType == valueType); }
private bool Supports(PigeonType whenTrue, PigeonType whenFalse) { return(whenTrueType == whenTrue && whenFalseType == whenFalse); }
private TernaryOperator(PigeonType whenTrueType, PigeonType whenFalseType, PigeonType resultType) { this.whenTrueType = whenTrueType; this.whenFalseType = whenFalseType; this.resultType = resultType; }
private bool Supports(PigeonType left, PigeonType right) { return(leftType == left && rightType == right); }
private BinaryOperator(PigeonType left, PigeonType right, PigeonType result) { leftType = left; rightType = right; resultType = result; }
internal void ReportInvalidArgumentType(TextSpan textSpan, int argCnt, PigeonType expectedType, PigeonType actualType) { Report($"Argument {argCnt} should be of type {expectedType.Name} instead of {actualType.Name}", textSpan); }
internal void Declare(PigeonType type, string name, object value) { scope.DeclareVariable(type, name, false); Assign(name, value); }
private AssignmentOperator(PigeonType variableType, PigeonType valueType) { this.variableType = variableType; this.valueType = valueType; }
bool NumberTypes(PigeonType t1, PigeonType t2) { return((t1 == PigeonType.Int && t2 == PigeonType.Float) || (t1 == PigeonType.Float && t2 == PigeonType.Int)); }
internal void ReportInvalidTypeUnaryOperator(TextSpan textSpan, string op, PigeonType type) { Report($"Operator {op} is not defined for type {type.Name}", textSpan); }
internal void ReportInvalidTypeTernaryOperator(TextSpan textSpan, PigeonType type1, PigeonType type2) { Report($"Types {type1.Name} and {type2.Name} are not compatible", textSpan); }
public Variable(PigeonType type) { Type = type; }
internal void ReportInvalidTypeAssignment(TextSpan textSpan, string variableName, PigeonType variableType, PigeonType valueType) { Report($"Variable '{variableName}' of type {variableType.Name} cannot have value of type {valueType.Name}", textSpan); }