Esempio n. 1
0
 internal Function(PigeonType returnType, string name, Variable[] parameters, object funcBody)
 {
     Name       = name;
     ReturnType = returnType;
     Parameters = parameters;
     FuncBody   = funcBody;
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
        private void CheckExprType(PigeonParser.ExprContext context, PigeonType expected)
        {
            var actual = Types.Get(context);

            if (actual != expected)
            {
                errorBag.ReportUnexpectedType(context.GetTextSpan(), expected, actual);
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
        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());
        }
Esempio n. 7
0
 private bool Supports(PigeonType type)
 {
     return(resultType == type);
 }
Esempio n. 8
0
 private UnaryOperator(PigeonType type)
 {
     resultType = type;
 }
Esempio n. 9
0
 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);
 }
Esempio n. 10
0
 internal Variable(PigeonType type, string name, bool readOnly)
 {
     Type     = type;
     Name     = name;
     ReadOnly = readOnly;
 }
Esempio n. 11
0
 internal void ReportUnexpectedType(TextSpan textSpan, PigeonType expectedType, PigeonType actualType)
 {
     Report($"Got value of type {actualType.Name} instead of {expectedType.Name}", textSpan);
 }
Esempio n. 12
0
 private bool Supports(PigeonType variableType, PigeonType valueType)
 {
     return(this.variableType == variableType && this.valueType == valueType);
 }
Esempio n. 13
0
 private bool Supports(PigeonType whenTrue, PigeonType whenFalse)
 {
     return(whenTrueType == whenTrue && whenFalseType == whenFalse);
 }
Esempio n. 14
0
 private TernaryOperator(PigeonType whenTrueType, PigeonType whenFalseType, PigeonType resultType)
 {
     this.whenTrueType  = whenTrueType;
     this.whenFalseType = whenFalseType;
     this.resultType    = resultType;
 }
Esempio n. 15
0
 private bool Supports(PigeonType left, PigeonType right)
 {
     return(leftType == left && rightType == right);
 }
Esempio n. 16
0
 private BinaryOperator(PigeonType left, PigeonType right, PigeonType result)
 {
     leftType   = left;
     rightType  = right;
     resultType = result;
 }
Esempio n. 17
0
 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);
 }
Esempio n. 18
0
 internal void Declare(PigeonType type, string name, object value)
 {
     scope.DeclareVariable(type, name, false);
     Assign(name, value);
 }
Esempio n. 19
0
 private AssignmentOperator(PigeonType variableType, PigeonType valueType)
 {
     this.variableType = variableType;
     this.valueType    = valueType;
 }
Esempio n. 20
0
 bool NumberTypes(PigeonType t1, PigeonType t2)
 {
     return((t1 == PigeonType.Int && t2 == PigeonType.Float) || (t1 == PigeonType.Float && t2 == PigeonType.Int));
 }
Esempio n. 21
0
 internal void ReportInvalidTypeUnaryOperator(TextSpan textSpan, string op, PigeonType type)
 {
     Report($"Operator {op} is not defined for type {type.Name}", textSpan);
 }
Esempio n. 22
0
 internal void ReportInvalidTypeTernaryOperator(TextSpan textSpan, PigeonType type1, PigeonType type2)
 {
     Report($"Types {type1.Name} and {type2.Name} are not compatible", textSpan);
 }
Esempio n. 23
0
 public Variable(PigeonType type)
 {
     Type = type;
 }
Esempio n. 24
0
 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);
 }