Ejemplo n.º 1
0
 public void Insert(string name, AstType type, string fileAndLine)
 {
     if (table.TryGetValue(name, out AstType definedType))
     {
         if (definedType != type)
         {
             ErrorReporter.ErrorFL("Duplicite type definition. Type {0} defined twice, first as {1} but then as {2}", fileAndLine, name, definedType, type);
         }
         return; // if there already is the same type under the same name, just ignore it => uniqueness
     }
     table[name] = type;
 }
        public override object VisitExternalFunctionDefinition([NotNull] functionalParser.ExternalFunctionDefinitionContext context)
        {
            var predicate = ((string, string[], Ty))Visit(context.predicate());

            if (predicate.Item2.Length != 0)
            {
                ErrorReporter.ErrorFL("An external function cannot be generic", FileAndLine(context));
            }

            FunctionType functionPredicate;

            if (predicate.Item3.Type.Is <FunctionType>())
            {
                functionPredicate = predicate.Item3.Type.As <FunctionType>();
            }
            else
            {
                // If the predicate is not a function type make it into one (e.g. main :: Int)
                functionPredicate = new FunctionType(new Ty[] { predicate.Item3 });
            }

            return(new FunctionNode(predicate.Item1, functionPredicate, FileAndLine(context)));
        }
Ejemplo n.º 3
0
 public void ReportError(string format, params object[] args)
 => ErrorReporter.ErrorFL(format, FileAndLine, args);