Ejemplo n.º 1
0
        public override int VisitVar_node(BRAQParser.Var_nodeContext context)
        {
            if (TryResolve(context.id_name, out var var_definition_point))
            {
                if (!assigned[var_definition_point])
                {
                    string msg = $"using unassigned variable {context.id_name.Text}";
                    Console.WriteLine(msg);
                    throw new TypesolvingError();
                }

                declaration[context.id_name] = var_definition_point;
            }
            else if (TryResolveAsArg(context.id_name, out var argumentDefinition))
            {
                token_to_argument[context.id_name] = argumentDefinition;
            }
            else if (PredefsHelper.ResolveType(context.id_name.Text, imported_types) != null)
            {
            }
            else
            {
                Console.WriteLine($"unknown variable {context.id_name.Text} [Line {context.id_name.Line}]");
                throw new UnknownVariableException();
            }



            return(0);
        }
Ejemplo n.º 2
0
        public override Type VisitVar_node(BRAQParser.Var_nodeContext context)
        {
            if (var_to_local_def.ContainsKey(context.id_name))
            {
                var  def_point = var_to_local_def[context.id_name];
                Type t         = locals_type[def_point];
                return(type_dict[context] = t);
            }

            try
            {
                return(type_dict[context] = result_box.argtypes[context.id_name.Text]);
            }
            catch (InvalidOperationException)
            {
            }
            catch (KeyNotFoundException)
            {
            }

            try
            {
                Type t = PredefsHelper.ResolveType(context.id_name.Text, imported_names);
                if (t == null)
                {
                    throw new InvalidOperationException();
                }
                return(type_dict[context] = t);
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine($"unknown variable {context.id_name.Text} [Line {context.id_name.Line}]");
                throw new UnknownVariableException();
            }
        }
Ejemplo n.º 3
0
 private static Type string_to_type(string name, List <Type> imported_names)
 {
     return(PredefsHelper.ResolveType(name, imported_names));
 }