private void WriteCompiledVariable(compiled_variable_definition cvd) { bw.Write(GetCompiledVariable(cvd)); }
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; }
private int GetCompiledVariable(compiled_variable_definition cvd) { ImportedEntity ie = null; if (ext_members.TryGetValue(cvd, out ie)) { return ie.index * ie.GetSize(); } ie = new ImportedEntity(); ie.flag = ImportKind.DotNet; ie.num_unit = GetCompiledTypeReference(cvd.cont_type); //ie.offset = (int)cvd.compiled_field.MetadataToken; ie.offset = GetTokenForNetEntity(cvd.compiled_field); ie.index = imp_entitles.Count; int offset = imp_entitles.Count*ie.GetSize(); imp_entitles.Add(ie); ext_members[cvd] = ie; return offset; }
public static_compiled_variable_reference(compiled_variable_definition var, location loc) : base(var.type, loc) { _var = var; _type = _var.cont_type; }
public SymbolInfo(compiled_variable_definition value) { //_name_information_type=name_information_type.nit_compiled_variable; _sym_info=value; _access_level=get_class_member_access_level(value); _symbol_kind=symbol_kind.sk_none; }
public compiled_variable_reference(compiled_variable_definition var, expression_node obj, location loc) : base(var.type, loc) { _var = var; _obj = obj; }
public static compiled_class_constant_definition ConvertToConstant(compiled_variable_definition cvd) { if (cvd.compiled_field.IsLiteral && cvd.compiled_field.FieldType.IsEnum) return new compiled_class_constant_definition(cvd.compiled_field, new enum_const_node((int)cvd.compiled_field.GetRawConstantValue(), cvd.type, null)); else return null; }
public static compiled_variable_definition GetFieldNode(FieldInfo pi) { compiled_variable_definition cpn = field_nodes[pi] as compiled_variable_definition; if (cpn != null) { if (cpn.type is compiled_type_node) return cpn; if (PascalABCCompiler.TreeConverter.compilation_context.instance != null && PascalABCCompiler.TreeConverter.compilation_context.instance.syntax_tree_visitor.compiled_unit != null && PascalABCCompiler.TreeConverter.compilation_context.instance.converted_namespace != null) { if (cpn.type.type_special_kind == type_special_kind.typed_file && (!PascalABCCompiler.TreeConverter.compilation_context.instance.TypedFiles.ContainsKey(cpn.type.element_type) || PascalABCCompiler.TreeConverter.compilation_context.instance.TypedFiles[cpn.type.element_type] != cpn.type)) { cpn.type = PascalABCCompiler.TreeConverter.compilation_context.instance.create_typed_file_type(cpn.type.element_type,null); return cpn; } else if (cpn.type.type_special_kind == type_special_kind.set_type && (!PascalABCCompiler.TreeConverter.compilation_context.instance.TypedSets.ContainsKey(cpn.type.element_type) || PascalABCCompiler.TreeConverter.compilation_context.instance.TypedSets[cpn.type.element_type] != cpn.type)) { cpn.type = PascalABCCompiler.TreeConverter.compilation_context.instance.create_set_type(cpn.type.element_type,null); return cpn; } else if (cpn.type.type_special_kind == type_special_kind.short_string && (!PascalABCCompiler.TreeConverter.compilation_context.instance.ShortStringTypes.ContainsKey((cpn.type as short_string_type_node).Length) || PascalABCCompiler.TreeConverter.compilation_context.instance.ShortStringTypes[(cpn.type as short_string_type_node).Length] != cpn.type)) { cpn.type = PascalABCCompiler.TreeConverter.compilation_context.instance.create_short_string_type((cpn.type as short_string_type_node).Length,null); return cpn; } } } cpn = new compiled_variable_definition(pi); if (PascalABCCompiler.TreeConverter.compilation_context.instance != null && PascalABCCompiler.TreeConverter.compilation_context.instance.syntax_tree_visitor.compiled_unit != null && PascalABCCompiler.TreeConverter.compilation_context.instance.converted_namespace != null) { object[] attrs = pi.GetCustomAttributes(false); for (int i=0; i<attrs.Length; i++) { Type t = attrs[i].GetType(); if (t.FullName == compiler_string_consts.file_of_attr_name) { object o = t.GetField("Type",BindingFlags.Public|BindingFlags.Instance).GetValue(attrs[i]); type_node tn = null; if (o is Type) t = o as Type; else { t = t.Assembly.GetType(o as string,false); tn = CreatePascalType(t); } if (tn != null) cpn.type = PascalABCCompiler.TreeConverter.compilation_context.instance.create_typed_file_type(tn,null); else cpn.type = PascalABCCompiler.TreeConverter.compilation_context.instance.create_typed_file_type(compiled_type_node.get_type_node(t),null); } else if (t.FullName == compiler_string_consts.set_of_attr_name) { object o = t.GetField("Type",BindingFlags.Public|BindingFlags.Instance).GetValue(attrs[i]); type_node tn = null; if (o is Type) t = o as Type; else { t = t.Assembly.GetType(o as string,false); tn = CreatePascalType(t); } if (tn != null) cpn.type = PascalABCCompiler.TreeConverter.compilation_context.instance.create_set_type(tn,null); else cpn.type = PascalABCCompiler.TreeConverter.compilation_context.instance.create_set_type(compiled_type_node.get_type_node(t),null); } else if (t.FullName == compiler_string_consts.short_string_attr_name) { int len = (int)t.GetField("Length",BindingFlags.Public|BindingFlags.Instance).GetValue(attrs[i]); cpn.type = PascalABCCompiler.TreeConverter.compilation_context.instance.create_short_string_type(len,null); } } } else return cpn; field_nodes[pi] = cpn; return cpn; }
public static_compiled_variable_reference(compiled_variable_definition var,location loc) : base(var.type,loc) { _var=var; _type=_var.cont_type; }
public compiled_variable_reference(compiled_variable_definition var,expression_node obj,location loc) : base(var.type,loc) { _var=var; _obj=obj; }