public override base_function_call copy()
        {
            common_namespace_function_call cnfc_copy = new common_namespace_function_call(this.function_node, this.location);

            cnfc_copy.parameters.AddRange(this.parameters);
            return(cnfc_copy);
        }
Exemple #2
0
        public void create_main_function_as_in_module()
        {
            add_needed_cctors();
            statements_list sl        = new statements_list(loc);
            statements_list intern_sl = new statements_list(loc);
            statements_list sl2       = sl;

            sl = new statements_list(null);
            common_namespace_function_node init_func = new common_namespace_function_node("$_Init_", null, null, common_namespaces[0], null);

            common_namespaces[0].functions.AddElement(init_func);
            namespace_variable init_var = new namespace_variable("$is_init", SystemLibrary.SystemLibrary.bool_type, common_namespaces[0], null);

            common_namespaces[0].variables.AddElement(init_var);
            for (int i = 0; i < units.Count; i++)
            {
                if (units[i].main_function != null)
                {
                    common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc);
                    sl.statements.AddElement(cnfc);
                }
            }

            /*for (int i = units.Count - 1; i >= 0; i--)
             * {
             *  if (units[i].finalization_method != null)
             *  {
             *      common_namespace_function_call cnfc = new common_namespace_function_call(units[i].finalization_method, loc);
             *      sl.statements.AddElement(cnfc);
             *  }
             * }*/
            sl2 = new statements_list(loc);
            basic_function_call bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_assign as basic_function_node, null);

            bfc.parameters.AddElement(new namespace_variable_reference(init_var, null));
            bfc.parameters.AddElement(new bool_const_node(true, null));
            sl.statements.AddElementFirst(bfc);
            bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_not as basic_function_node, null);
            bfc.parameters.AddElement(new namespace_variable_reference(init_var, null));
            sl2.statements.AddElement(new if_node(bfc, sl, null, null));
            init_func.function_code = sl2;
            _init_code = new common_namespace_function_call(init_func, null);
            add_initialization_to_cctors();
        }
Exemple #3
0
        public void create_main_function(string[] used_stand_modules, Dictionary <string, object> config)
        {
            add_needed_cctors();
            common_namespace_function_node temp = _main_function;

            _main_function = new common_namespace_function_node("Main", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null);
            location        loc = temp.loc;
            statements_list sl  = new statements_list(loc);

            _main_function.function_code = sl;
//            if (units[0].MainArgsParameter!=null)
//            {
//                _main_function.parameters.AddElement(units[0].MainArgsParameter);
//                sl.statements.AddElement(units[0].MainArgsAssignExpr);
//            }
//            if (units[0].IsConsoleApplicationVariableAssignExpr!=null)
//            {
//                sl.statements.AddElement(units[0].IsConsoleApplicationVariableAssignExpr);
//            }
            statements_list sl2 = sl;

            sl = new statements_list(null);
            common_namespace_function_node init_func = new common_namespace_function_node("$_Init_", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null);

            ((common_namespace_node)_main_function.comprehensive_namespace).functions.AddElement(init_func);
            namespace_variable init_var = new namespace_variable("$is_init", SystemLibrary.SystemLibrary.bool_type, (common_namespace_node)_main_function.comprehensive_namespace, null);

            ((common_namespace_node)_main_function.comprehensive_namespace).variables.AddElement(init_var);
            if (SystemLibrary.SystemLibInitializer.ConfigVariable != null && SystemLibrary.SystemLibInitializer.ConfigVariable.Found)
            {
                namespace_variable           conf_nv = null;
                compiled_variable_definition conf_cf = null;
                if (SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info is namespace_variable)
                {
                    conf_nv = SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info as namespace_variable;
                }
                else
                {
                    conf_cf = SystemLibrary.SystemLibInitializer.ConfigVariable.sym_info as compiled_variable_definition;
                }
                foreach (string config_var in config.Keys)
                {
                    var config_value           = config[config_var];
                    compiled_function_call cfc = new compiled_function_call(compiled_function_node.get_compiled_method(NetHelper.NetHelper.AddToDictionaryMethod),
                                                                            (conf_nv != null) ? (expression_node) new namespace_variable_reference(conf_nv, null) : (expression_node) new static_compiled_variable_reference(conf_cf, null), null);
                    cfc.parameters.AddElement(new string_const_node(config_var, null));
                    switch (Type.GetTypeCode(config_value.GetType()))
                    {
                    case TypeCode.String:
                        cfc.parameters.AddElement(new string_const_node((string)config_value, null));
                        break;

                    case TypeCode.Int32:
                        cfc.parameters.AddElement(new int_const_node((int)config_value, null));
                        break;

                    case TypeCode.Boolean:
                        cfc.parameters.AddElement(new bool_const_node((bool)config_value, null));
                        break;

                    case TypeCode.Double:
                        cfc.parameters.AddElement(new double_const_node((double)config_value, null));
                        break;

                    default:
                        throw new NotSupportedException("Config value type is nort supported");
                    }
                    sl.statements.AddElement(cfc);
                }
            }
            if (units[0].MainArgsParameter != null)
            {
                _main_function.parameters.AddElement(units[0].MainArgsParameter);
                sl.statements.AddElementFirst(units[0].MainArgsAssignExpr);
            }
            if (units[0].IsConsoleApplicationVariableAssignExpr != null)
            {
                sl.statements.AddElementFirst(units[0].IsConsoleApplicationVariableAssignExpr);
            }
            for (int i = 0; i < units.Count; i++)
            {
                if (units[i].main_function != null)
                {
                    if (units[i].main_function.name != TreeConverter.compiler_string_consts.temp_main_function_name)
                    {
                        common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc);
                        sl.statements.AddElement(cnfc);
                    }
                    else
                    {
                        common_namespace_function_call cnfc = new common_namespace_function_call(units[i].main_function, loc);
                        sl2.statements.AddElement(cnfc);
                    }
                }
            }
            //if (units.Count == 1)
            for (int i = 0; i < used_stand_modules.Length; i++)
            {
                Type t = NetHelper.NetHelper.FindRtlType(used_stand_modules[i] + "." + used_stand_modules[i]);
                if (t == null)
                {
                    continue;
                }
                compiled_type_node           ctn = compiled_type_node.get_type_node(t);
                System.Reflection.MethodInfo mi  = ctn.compiled_type.GetMethod("__InitModule__");
                if (mi == null)
                {
                    continue;
                }
                compiled_static_method_call csmc = new compiled_static_method_call(compiled_function_node.get_compiled_method(mi), null);
                sl.statements.AddElement(csmc);
            }
            for (int i = units.Count - 1; i >= 0; i--)
            {
                if (units[i].finalization_method != null)
                {
                    common_namespace_function_call cnfc = new common_namespace_function_call(units[i].finalization_method, loc);
                    sl2.statements.AddElement(cnfc);
                }
            }
            //if (units.Count == 1)
            for (int i = 0; i < used_stand_modules.Length; i++)
            {
                Type t = NetHelper.NetHelper.FindRtlType(used_stand_modules[i] + "." + used_stand_modules[i]);
                if (t == null)
                {
                    continue;
                }
                compiled_type_node           ctn = compiled_type_node.get_type_node(t);
                System.Reflection.MethodInfo mi  = ctn.compiled_type.GetMethod("__FinalizeModule__");
                if (mi == null)
                {
                    continue;
                }
                compiled_static_method_call csmc = new compiled_static_method_call(compiled_function_node.get_compiled_method(mi), null);
                sl2.statements.AddElement(csmc);
            }
            sl2 = new statements_list(loc);
            basic_function_call bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_assign as basic_function_node, null);

            bfc.parameters.AddElement(new namespace_variable_reference(init_var, null));
            bfc.parameters.AddElement(new bool_const_node(true, null));
            sl.statements.AddElementFirst(bfc);
            bfc = new basic_function_call(SystemLibrary.SystemLibrary.bool_not as basic_function_node, null);
            bfc.parameters.AddElement(new namespace_variable_reference(init_var, null));
            sl2.statements.AddElement(new if_node(bfc, sl, null, null));
            init_func.function_code = sl2;
            sl = new statements_list(null);

            sl.statements.AddElement(new common_namespace_function_call(init_func, null));
            common_namespace_function_node init_variables_func = new common_namespace_function_node("$_InitVariables_", null, null, (common_namespace_node)_main_function.comprehensive_namespace, null);

            init_variables_func.function_code = new statements_list(null);
            ((common_namespace_node)_main_function.comprehensive_namespace).functions.AddElement(init_variables_func);

            sl.statements.AddElement(new common_namespace_function_call(init_variables_func, null));
            _init_code = sl;
        }
Exemple #4
0
 public common_namespace_function_call_as_constant(common_namespace_function_call method_call, location loc)
     :
     base(method_call.type, loc)
 {
     _method_call = method_call;
 }