Пример #1
0
        private TyperVisitor(TyperResult result_box,
                             Dictionary <BRAQParser.Var_stmtContext, ParserRuleContext> assignment_points,
                             List <OwnMethodInfo> user_functions)
        {
            this.result_box         = result_box;
            type_dict               = result_box.type_dict;
            var_to_local_def        = result_box.var_to_def;
            local_def_to_assignment = assignment_points;
            this.user_functions     = user_functions;
            locals_type             = result_box.local_types;

            #region typecombos_reading
            this.TypeAllowances = File.ReadAllText("binary_typing.txt")
                                  .Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
                                  .Select(x => x.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
                                  .Select(x =>
                                          new TypeHelper(Type.GetType(x[0]), Type.GetType(x[2]), x[1], Type.GetType(x[4]))
                                          ).ToList()

                                  .Concat <TypeHelper>(



                File.ReadAllText("unary_typing.txt")
                .Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(x => x.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
                .Select(x =>
                        new TypeHelper(null, Type.GetType(x[0]), x[1], Type.GetType(x[3]))
                        ).ToList()



                ).ToList();
            #endregion
        }
Пример #2
0
        solveTypes(BRAQParser.ProgramContext context,
                   Dictionary <BRAQParser.Function_def_stmtContext, AssignCheckVisitor.AssignCheckResult> step1_result,
                   List <Type> imported_names)
        {
            var answ           = new Dictionary <BRAQParser.Function_def_stmtContext, TyperResult>();
            var user_functions = new List <OwnMethodInfo>();

            //function signatures
            foreach (var fdef in step1_result)
            {
                var tr = new TyperResult(fdef.Value.token_to_def, fdef.Value.token_to_arg.Keys.ToList());

                tr.methodInfo = new OwnMethodInfo(
                    fdef.Key.id_name.Text,
                    fdef.Key.typed_id().Select(x => new Pair <string, Type>(x.id_name.Text, string_to_type(x.type_name.Text, imported_names))).ToList(),
                    fdef.Key.of_type != null ? string_to_type(fdef.Key.of_type.Text, imported_names): typeof(void),
                    fdef.Key
                    );

                user_functions.Add(tr.methodInfo);

                tr.argtypes = tr.methodInfo.arguments.ToDictionary(x => x.a, x => x.b);

                tr.argvars = fdef.Value.token_to_arg.Keys.ToList();

                answ[fdef.Key] = tr;
            }

            foreach (var fdef in step1_result)
            {
                var v = new TyperVisitor(answ[fdef.Key], fdef.Value.def_to_assign, user_functions);
                v.imported_names = imported_names;
                fdef.Key.Accept(v);
            }

            return(answ);
        }