Пример #1
0
 private void CollectInfoNamespaces(common_namespace_node cnn)
 {
     if (!cnn.from_pcu)
     {
         if (cnn.is_main)
         foreach (var_definition_node vdn2 in cnn.variables)
         {
         	if (vdn2 is namespace_variable)
         	{
         		namespace_variable vdn = vdn2 as namespace_variable;
         		VarInfo vi = helper.GetVariable(vdn);
             	if (vi.num_use == 0 && !vdn.is_special_name) warns.Add(new UnusedVariable(vdn.name, vdn.loc));
            	 	if (vi.num_ass > 0 && vi.act_num_use == 0) warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
             //if (vi.num_ass == 0 && vi.act_num_use > 0) helper.AddRealWarning(vdn, warns);
         	}
         	else if (vdn2 is local_block_variable)
         	{
         		local_block_variable vdn = vdn2 as local_block_variable;
         		VarInfo vi = helper.GetVariable(vdn);
             	if (vi.num_use == 0 && !vdn.is_special_name) warns.Add(new UnusedVariable(vdn.name, vdn.loc));
             	if (vi.num_ass > 0 && vi.act_num_use == 0) warns.Add(new AssignWithoutUsing(vdn.name, vi.last_ass_loc));
         	}
         }
         foreach (common_type_node ctn in cnn.types)
             CollectInfoFields(ctn);
     }
 }
Пример #2
0
 private void VisitCommonNamespaceHeader(common_namespace_node cnn)
 {
     if (!cnn.from_pcu)
     {
         foreach (namespace_variable vdn in cnn.variables)
             helper.AddVariable(vdn);
     }
 }
Пример #3
0
        /// <summary>
        /// Клонирует пространство имен.
        /// </summary>
        /// <returns>Копия пространства иен.</returns>
        public common_namespace_node clone()
        {
            common_namespace_node cnn = new common_namespace_node(this._comprehensive_namespace, this._cont_unit,
                                                                  this._name, this._scope, this._loc);

            cnn.merge_with_namespace(this);
            return(cnn);
        }
Пример #4
0
 public common_namespace_event(string name, type_node del_type, common_namespace_node cont_namespace, common_namespace_function_node add_function, common_namespace_function_node remove_function, common_namespace_function_node raise_function,
                               location loc)
 {
     this._name            = name;
     this.del_type         = del_type;
     this._add_function    = add_function;
     this._remove_function = remove_function;
     this._raise_function  = raise_function;
     this._cont_namespace  = cont_namespace;
     this._loc             = loc;
 }
Пример #5
0
 /// <summary>
 /// Добавляет к текущему пространству имен указанное пространство имен.
 /// </summary>
 /// <param name="merge_with">Пространство имен для добавления.</param>
 public void merge_with_namespace(common_namespace_node merge_with)
 {
     _types.AddRange(merge_with._types);
     //ssyy
     _templates.AddRange(merge_with._templates);
     _type_synonyms.AddRange(merge_with._type_synonyms);
     //\ssyy
     _variables.AddRange(merge_with._variables);
     _functions.AddRange(merge_with._functions);
     _constants.AddRange(merge_with._constants);
     _namespaces.AddRange(merge_with._namespaces);
 }
Пример #6
0
        public template_class(SyntaxTree.type_declaration type_decl, string name, common_namespace_node cnn, /*common_type_node ctn,location loc,*/ document doc, using_namespace_list unl)
        {
            _cnn       = cnn;
            _type_decl = type_decl;
            _name      = name;
            _doc       = doc;

            //(ssyy) using - список, по-видимому, можно только копировать, т.к. Николай его периодически чистит.
            _unl = new using_namespace_list();
            foreach (using_namespace un in unl)
            {
                _unl.AddElement(un);
            }
        }
Пример #7
0
        private void VisitCommonNamespaceNode(common_namespace_node cnn)
        {
            if (!cnn.from_pcu)
            {
                foreach (common_type_node ctn in cnn.types)
                    VisitCommonTypeHeader(ctn);

                foreach (common_type_node ctn in cnn.types)
                    VisitCommonType(ctn);

                foreach (common_namespace_function_node cnfn in cnn.functions)
                {
                    VisitCommonNamespaceFunctionNode(cnfn);
                }
            }
        }
Пример #8
0
 public void reset()
 {
     _cmn = null;
     _ctn = null;
     _func_stack.clear();
     var_defs.Clear();
     _main_procedure = null;
     _last_created_function = null;
     _cycles_stack.clear();
     _num_of_for_cycles = 0;
     _fal = SemanticTree.field_access_level.fal_private;
     rec_num = 1;
     var_defs_stack.Clear();
     type_stack.Clear();
     clear_special_local_vars();
     _scope_stack.Clear();
 }
Пример #9
0
        //TODO: Исправить этот метод, так чтобы он работал только с корневыми или со всеми пространствами имен.
        /// <summary>
        /// Просматривает список модулей, и объединяет одни и те-же пространства имен разных модулей.
        /// </summary>
        /// <param name="units">Список модулей.</param>
        /// <returns>Список пространств имен.</returns>
        private static common_namespace_node[] get_units_namespaces(common_unit_node_list units)
        {
            /*System.Collections.Generic.Dictionary<string, common_namespace_node> namespaces =
                new System.Collections.Generic.Dictionary<string, common_namespace_node>(
                SystemLibrary.SystemLibrary.string_comparer);

            foreach (common_unit_node un in units)
            {
                foreach (common_namespace_node cnn in un.namespaces)
                {
                    string full_name = cnn.namespace_full_name;
                    common_namespace_node new_namespace;
                    if (!(namespaces.TryGetValue(full_name,out new_namespace)))
                    {
                        new_namespace = cnn.clone();
                        namespaces[full_name] = new_namespace;
                    }
                    else
                    {
                        new_namespace.merge_with_namespace(cnn);
                    }
                }
            }
            common_namespace_node[] ret = new common_namespace_node[namespaces.Count];
            namespaces.Values.CopyTo(ret, 0);
            return ret;*/
            System.Collections.Hashtable ht = new System.Collections.Hashtable();
            System.Collections.ArrayList al = new System.Collections.ArrayList();
            common_namespace_node main_cnn = null;
            foreach (common_unit_node un in units)
            {
            	foreach (common_namespace_node cnn in un.namespaces)
                {
                    //if (cnn.namespace_full_name != "")
                    //{
                        if (ht[cnn.namespace_name] == null)
                        {
                            al.Add(cnn); ht[cnn.namespace_name] = cnn;
                        }
                        //else
                        //    throw new Errors.CompilerInternalError("MergeNamespaces", new Errors.LocatedError("Dupblicate nammespace name: "+cnn.namespace_name));
                    //}
                    //else main_cnn = cnn;
                }
            }
            int num = 0; if (main_cnn != null) num++;
            common_namespace_node[] namespaces_to_ret = new common_namespace_node[al.Count + num];
            if (main_cnn != null) namespaces_to_ret[0] = main_cnn;
            al.CopyTo(namespaces_to_ret, num);
            return namespaces_to_ret;
            /*System.Collections.Hashtable ht = new System.Collections.Hashtable();
            System.Collections.ArrayList al = new System.Collections.ArrayList();
            foreach (common_unit_node un in units)
            {
                foreach (common_namespace_node cnn in un.namespaces)
                    if (ht[cnn.namespace_name] == null)
                    {
                        al.Add(cnn); 
                        ht[cnn.namespace_name] = cnn;
                    }
            }
            common_namespace_node[] namespaces_to_ret = new common_namespace_node[al.Count];
            al.CopyTo(namespaces_to_ret);
            return namespaces_to_ret;*/
        }
        //\ssyy

        private string GetSynonimName(common_namespace_node cnn, compiled_type_node ctn)
        {
            for (int i = 0; i < cnn.type_synonyms.Count; i++)
            {
                if (cnn.type_synonyms[i].original_type == ctn) return cnn.type_synonyms[i].name;
            }
            return ctn.name;
        }
Пример #11
0
 public wrapped_common_type_node(PCUReader pr, type_node base_type, string name, SemanticTree.type_access_level type_access_level,
     common_namespace_node comprehensive_namespace, SymbolTable.ClassScope cs, location loc,int offset):
     base(base_type, name, type_access_level, comprehensive_namespace,cs,loc) 
 {
     this.pr = pr;
     this.offset = offset;
 }
Пример #12
0
 public template_class(SyntaxTree.type_declaration type_decl, string name,common_namespace_node cnn,/*common_type_node ctn,location loc,*/document doc,using_namespace_list unl)
 {
     _cnn = cnn;
     _type_decl = type_decl;
     _name = name;
     _doc = doc;
     
     //(ssyy) using - список, по-видимому, можно только копировать, т.к. Николай его периодически чистит.
     _unl = new using_namespace_list();
     foreach (using_namespace un in unl)
     {
         _unl.AddElement(un);
     }
 }
Пример #13
0
        //TODO: Исправить этот метод, так чтобы он работал только с корневыми или со всеми пространствами имен.
        /// <summary>
        /// Просматривает список модулей, и объединяет одни и те-же пространства имен разных модулей.
        /// </summary>
        /// <param name="units">Список модулей.</param>
        /// <returns>Список пространств имен.</returns>
        private static common_namespace_node[] get_units_namespaces(common_unit_node_list units)
        {
            /*System.Collections.Generic.Dictionary<string, common_namespace_node> namespaces =
             *  new System.Collections.Generic.Dictionary<string, common_namespace_node>(
             *  SystemLibrary.SystemLibrary.string_comparer);
             *
             * foreach (common_unit_node un in units)
             * {
             *  foreach (common_namespace_node cnn in un.namespaces)
             *  {
             *      string full_name = cnn.namespace_full_name;
             *      common_namespace_node new_namespace;
             *      if (!(namespaces.TryGetValue(full_name,out new_namespace)))
             *      {
             *          new_namespace = cnn.clone();
             *          namespaces[full_name] = new_namespace;
             *      }
             *      else
             *      {
             *          new_namespace.merge_with_namespace(cnn);
             *      }
             *  }
             * }
             * common_namespace_node[] ret = new common_namespace_node[namespaces.Count];
             * namespaces.Values.CopyTo(ret, 0);
             * return ret;*/
            System.Collections.Hashtable ht       = new System.Collections.Hashtable();
            System.Collections.ArrayList al       = new System.Collections.ArrayList();
            common_namespace_node        main_cnn = null;

            foreach (common_unit_node un in units)
            {
                foreach (common_namespace_node cnn in un.namespaces)
                {
                    //if (cnn.namespace_full_name != "")
                    //{
                    if (ht[cnn.namespace_name] == null)
                    {
                        al.Add(cnn); ht[cnn.namespace_name] = cnn;
                    }
                    //else
                    //    throw new Errors.CompilerInternalError("MergeNamespaces", new Errors.LocatedError("Dupblicate nammespace name: "+cnn.namespace_name));
                    //}
                    //else main_cnn = cnn;
                }
            }
            int num = 0; if (main_cnn != null)

            {
                num++;
            }

            common_namespace_node[] namespaces_to_ret = new common_namespace_node[al.Count + num];
            if (main_cnn != null)
            {
                namespaces_to_ret[0] = main_cnn;
            }
            al.CopyTo(namespaces_to_ret, num);
            return(namespaces_to_ret);

            /*System.Collections.Hashtable ht = new System.Collections.Hashtable();
             * System.Collections.ArrayList al = new System.Collections.ArrayList();
             * foreach (common_unit_node un in units)
             * {
             *  foreach (common_namespace_node cnn in un.namespaces)
             *      if (ht[cnn.namespace_name] == null)
             *      {
             *          al.Add(cnn);
             *          ht[cnn.namespace_name] = cnn;
             *      }
             * }
             * common_namespace_node[] namespaces_to_ret = new common_namespace_node[al.Count];
             * al.CopyTo(namespaces_to_ret);
             * return namespaces_to_ret;*/
        }
Пример #14
0
 public void leave_interface_part()
 {
     _cmn = null;
 }
Пример #15
0
 /// <summary>
 /// Конструктор класса.
 /// </summary>
 /// <param name="name">Имя константы.</param>
 /// <param name="cn">Значени константы.</param>
 /// <param name="loc">Расположение определения константы.</param>
 /// <param name="comprehensive_namespace">Пространство имен в котором определена константа.</param>
 public namespace_constant_definition(string name, constant_node cn, location loc, common_namespace_node comprehensive_namespace) :
     base(name, cn, loc)
 {
     _comprehensive_namespace = comprehensive_namespace;
 }
Пример #16
0
 public common_type_node(string name, SemanticTree.type_access_level type_access_level,
     common_namespace_node comprehensive_namespace, SymbolTable.ClassScope cs, location loc)
 {
     _name = name;
     _type_access_level = type_access_level;
     _comprehensive_namespace = comprehensive_namespace;
     defined_in_scope = (comprehensive_namespace == null)?null:comprehensive_namespace.scope;
     //_ref_type = new ref_type_node(this);
     _scope = cs;
     _loc = loc;
 }
Пример #17
0
		public common_namespace_node create_namespace(common_namespace_node comprehensive_namespace,string namespace_name,
            common_unit_node cont_unit,SymbolTable.Scope _scope,location loc)
		{
            SymbolTable.Scope scope;
            if (comprehensive_namespace == null)
            {
                //scope = convertion_data_and_alghoritms.symbol_table.CreateScope(cont_unit.scope);
                scope = _scope;
            }
            else
            {
                scope = convertion_data_and_alghoritms.symbol_table.CreateScope(comprehensive_namespace.scope);
            }
            _cmn = new common_namespace_node(comprehensive_namespace, cont_unit, namespace_name, scope, loc);
			cont_unit.namespaces.AddElement(_cmn);
			_cmn.scope.AddSymbol(namespace_name,new SymbolInfo(_cmn));
			return _cmn;
		}
Пример #18
0
        private static void init_temp_methods_and_consts(common_namespace_node system_namespace,SymbolTable.Scope where_add,
            initialization_properties initialization_properties,location system_unit_location)
        {
            //SymbolTable.Scope sc = system_namespace.scope;
            SymbolTable.Scope sc = where_add;
            namespace_constant_definition _true_constant_definition = new namespace_constant_definition(
                PascalABCCompiler.TreeConverter.compiler_string_consts.true_const_name, SystemLibrary.true_constant, system_unit_location, system_namespace);
            system_namespace.constants.AddElement(_true_constant_definition);

            namespace_constant_definition _false_constant_definition = new namespace_constant_definition(
                PascalABCCompiler.TreeConverter.compiler_string_consts.false_const_name, SystemLibrary.false_constant, system_unit_location, system_namespace);
            system_namespace.constants.AddElement(_false_constant_definition);

            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.true_const_name, new PascalABCCompiler.TreeConverter.SymbolInfo(_true_constant_definition));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.false_const_name, new PascalABCCompiler.TreeConverter.SymbolInfo(_false_constant_definition));
            

            //TODO: Сделано по быстрому. Переделать. Можно просто один раз сериализовать модуль system и не инициализировать его всякий раз подобным образом. Неплохо-бы использовать NetHelper.GetMethod.
            Type tp = typeof(Console);
            compiled_function_node cfn;
            System.Type[] arr = new System.Type[1];
            System.Reflection.MethodInfo mi;

            //TODO: Сделать узел или базовый метод создания и удаления объекта.
            common_namespace_function_node cnfn = new common_namespace_function_node(TreeConverter.compiler_string_consts.new_procedure_name, null, null, system_namespace, null);
            cnfn.parameters.AddElement(new common_parameter("ptr", SystemLibrary.pointer_type, SemanticTree.parameter_type.value, cnfn,
                concrete_parameter_type.cpt_var, null, null));
            cnfn.SpecialFunctionKind = SemanticTree.SpecialFunctionKind.New;
            _NewProcedure = new PascalABCCompiler.TreeConverter.SymbolInfo(cnfn);
            _NewProcedure.symbol_kind = PascalABCCompiler.TreeConverter.symbol_kind.sk_overload_function;
            _NewProcedure.access_level = PascalABCCompiler.TreeConverter.access_level.al_public;
            _NewProcedureDecl = cnfn;
            sc.AddSymbol(TreeConverter.compiler_string_consts.new_procedure_name, _NewProcedure);

            cnfn = new common_namespace_function_node(TreeConverter.compiler_string_consts.dispose_procedure_name, null, null, system_namespace, null);
            cnfn.parameters.AddElement(new common_parameter("ptr", SystemLibrary.pointer_type, SemanticTree.parameter_type.value,
                cnfn, concrete_parameter_type.cpt_var, null, null));
            _DisposeProcedure = new PascalABCCompiler.TreeConverter.SymbolInfo(cnfn);
            _DisposeProcedure.symbol_kind = PascalABCCompiler.TreeConverter.symbol_kind.sk_overload_function;
            _DisposeProcedure.access_level = PascalABCCompiler.TreeConverter.access_level.al_public;
            _DisposeProcedureDecl = cnfn;
            cnfn.SpecialFunctionKind = SemanticTree.SpecialFunctionKind.Dispose;
            sc.AddSymbol(TreeConverter.compiler_string_consts.dispose_procedure_name, _DisposeProcedure);

            cnfn = new common_namespace_function_node(TreeConverter.compiler_string_consts.new_array_procedure_name, compiled_type_node.get_type_node(typeof(Array)), null, system_namespace, null);
            cnfn.parameters.AddElement(new common_parameter("t", compiled_type_node.get_type_node(typeof(Type)), SemanticTree.parameter_type.value, cnfn,
                concrete_parameter_type.cpt_none, null, null));
            cnfn.parameters.AddElement(new common_parameter("n", SystemLibrary.integer_type, SemanticTree.parameter_type.value, cnfn,
                concrete_parameter_type.cpt_none, null, null));
            cnfn.SpecialFunctionKind = SemanticTree.SpecialFunctionKind.NewArray;
            _NewArrayProcedure = new PascalABCCompiler.TreeConverter.SymbolInfo(cnfn);
            _NewArrayProcedureDecl = cnfn;
            //sc.AddSymbol(TreeConverter.compiler_string_consts.new_procedure_name, _NewProcedure);
            
            basic_function_node break_procedure = new basic_function_node(SemanticTree.basic_function_type.none,
                null, true);
            break_procedure.compile_time_executor = initialization_properties.break_executor;
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.break_procedure_name, new PascalABCCompiler.TreeConverter.SymbolInfo(break_procedure));
            
            basic_function_node continue_procedure = new basic_function_node(SemanticTree.basic_function_type.none,
                null, true);
            continue_procedure.compile_time_executor = initialization_properties.continue_executor;
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.continue_procedure_name, new PascalABCCompiler.TreeConverter.SymbolInfo(continue_procedure));

            basic_function_node exit_procedure = new basic_function_node(SemanticTree.basic_function_type.none,
                null, true);
            exit_procedure.compile_time_executor = initialization_properties.exit_executor;
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.exit_procedure_name, new PascalABCCompiler.TreeConverter.SymbolInfo(exit_procedure));

            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.set_length_procedure_name,
                new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.resize_func, PascalABCCompiler.TreeConverter.access_level.al_public, PascalABCCompiler.TreeConverter.symbol_kind.sk_overload_function));
        }
Пример #19
0
 public procedure_definition_info(common_namespace_node _nspace,
                                  SyntaxTree.procedure_definition _proc)
 {
     nspace = _nspace;
     proc   = _proc;
 }
		public SymbolInfo(common_namespace_node value)
		{
			//_name_information_type=name_information_type.nit_common_namespace;
			_sym_info=value;
			_access_level=access_level.al_public;
			_symbol_kind=symbol_kind.sk_none;
		}
Пример #21
0
 /// <summary>
 /// Конструктор класса.
 /// </summary>
 /// <param name="name">Имя константы.</param>
 /// <param name="cn">Значени константы.</param>
 /// <param name="loc">Расположение определения константы.</param>
 /// <param name="comprehensive_namespace">Пространство имен в котором определена константа.</param>
 public namespace_constant_definition(string name, constant_node cn, location loc, common_namespace_node comprehensive_namespace) :
     base(name,cn,loc)
 {
     _comprehensive_namespace = comprehensive_namespace;
 }
Пример #22
0
        public static common_unit_node make_system_unit(SymbolTable.TreeConverterSymbolTable symbol_table,
            initialization_properties initialization_properties)
        {
            //TODO: В качестве location везде в этом методе следует указывать location system_unit-а. Имя файла мы знаем, а место - там где написано, что integer и прочие типы описаны как бы в модуле system.
            location system_unit_location = null;
            SymbolTable.UnitInterfaceScope main_scope = symbol_table.CreateUnitInterfaceScope(new SymbolTable.Scope[0]);
            SymbolTable.UnitImplementationScope impl_scope = symbol_table.CreateUnitImplementationScope(main_scope,
                new SymbolTable.Scope[0]);
            common_unit_node _system_unit = new common_unit_node(main_scope,impl_scope,null,null);
            
            common_namespace_node cnn = new common_namespace_node(null, _system_unit, PascalABCCompiler.TreeConverter.compiler_string_consts.system_unit_name,
                symbol_table.CreateScope(main_scope),system_unit_location);

            main_scope.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.system_unit_name, new PascalABCCompiler.TreeConverter.SymbolInfo(cnn));

            //SymbolTable.Scope sc = cnn.scope;
            SymbolTable.Scope sc = main_scope;

            //Добавляем типы.
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.byte_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.byte_type));
            //sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.decimal_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.decimal_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.sbyte_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.sbyte_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.short_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.short_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.ushort_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.ushort_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.integer_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.integer_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.uint_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.uint_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.long_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.int64_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.ulong_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.uint64_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.float_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.float_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.real_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.double_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.char_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.char_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.bool_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.bool_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.string_type));
            //sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.object_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.object_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.pointer_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.pointer_type));
            //sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.base_exception_class_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.exception_base_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.base_array_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.array_base_type));
            sc.AddSymbol(PascalABCCompiler.TreeConverter.compiler_string_consts.base_delegate_type_name, new PascalABCCompiler.TreeConverter.SymbolInfo(SystemLibrary.delegate_base_type));

            //TODO: Переделать. Пусть таблица символов создается одна. Как статическая.
            compiled_type_node comp_byte_type = ((compiled_type_node)SystemLibrary.byte_type);
            compiled_type_node comp_sbyte_type = ((compiled_type_node)SystemLibrary.sbyte_type);
            compiled_type_node comp_short_type = ((compiled_type_node)SystemLibrary.short_type);
            compiled_type_node comp_ushort_type = ((compiled_type_node)SystemLibrary.ushort_type);
            compiled_type_node comp_integer_type = ((compiled_type_node)SystemLibrary.integer_type);
            compiled_type_node comp_uint_type = ((compiled_type_node)SystemLibrary.uint_type);
            compiled_type_node comp_long_type = ((compiled_type_node)SystemLibrary.int64_type);
            compiled_type_node comp_ulong_type = ((compiled_type_node)SystemLibrary.uint64_type);
            compiled_type_node comp_float_type = ((compiled_type_node)SystemLibrary.float_type);
            compiled_type_node comp_real_type = ((compiled_type_node)SystemLibrary.double_type);
            compiled_type_node comp_char_type=((compiled_type_node)SystemLibrary.char_type);
            compiled_type_node comp_bool_type = ((compiled_type_node)SystemLibrary.bool_type);
            compiled_type_node comp_string_type=((compiled_type_node)SystemLibrary.string_type);
            compiled_type_node comp_object_type=((compiled_type_node)SystemLibrary.object_type);
            compiled_type_node comp_pointer_type=((compiled_type_node)SystemLibrary.pointer_type);
            compiled_type_node comp_exception_type=((compiled_type_node)SystemLibrary.exception_base_type);
            compiled_type_node comp_array_type = ((compiled_type_node)SystemLibrary.array_base_type);
            compiled_type_node comp_delegate_type = ((compiled_type_node)SystemLibrary.delegate_base_type);
            comp_byte_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_byte_type.compiled_type, symbol_table);
            comp_sbyte_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_sbyte_type.compiled_type, symbol_table);
            comp_short_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_short_type.compiled_type, symbol_table);
            comp_ushort_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_ushort_type.compiled_type, symbol_table);
            comp_integer_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_integer_type.compiled_type, symbol_table);
            comp_uint_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_uint_type.compiled_type, symbol_table);
            comp_long_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_long_type.compiled_type, symbol_table);
            comp_ulong_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_ulong_type.compiled_type, symbol_table);
            comp_real_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_real_type.compiled_type, symbol_table);
            comp_char_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_char_type.compiled_type, symbol_table);
            comp_bool_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_bool_type.compiled_type, symbol_table);
            comp_string_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_string_type.compiled_type, symbol_table);
            comp_object_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_object_type.compiled_type, symbol_table);
            comp_pointer_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_pointer_type.compiled_type, symbol_table);
            comp_exception_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_exception_type.compiled_type, symbol_table);
            comp_array_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_array_type.compiled_type, symbol_table);
            comp_delegate_type.scope = new PascalABCCompiler.NetHelper.NetTypeScope(comp_delegate_type.compiled_type, symbol_table);

            init_temp_methods_and_consts(cnn,sc, initialization_properties,system_unit_location);
            return _system_unit;
        }
Пример #23
0
		public common_type_node(type_node base_type,string name,SemanticTree.type_access_level type_access_level,
			common_namespace_node comprehensive_namespace, SymbolTable.ClassScope cs, location loc)
		{
			_name=name;
			_type_access_level=type_access_level;
			_comprehensive_namespace=comprehensive_namespace;
			//_ref_type = new ref_type_node(this);
            _scope = cs;
            _loc = loc;
            this.SetBaseType(base_type);
		}
Пример #24
0
     public common_namespace_event(string name, type_node del_type, common_namespace_node cont_namespace, common_namespace_function_node add_function, common_namespace_function_node remove_function, common_namespace_function_node raise_function, 
 	                     location loc)
 	{
 		this._name = name;
 		this.del_type = del_type;
 		this._add_function = add_function;
 		this._remove_function = remove_function;
 		this._raise_function = raise_function;
         this._cont_namespace = cont_namespace;
 		this._loc = loc;
 	}
Пример #25
0
 public generic_instance_type_node(type_node original_generic_type,
     List<type_node> param_types,
     type_node base_type, string name, SemanticTree.type_access_level type_access_level,
     common_namespace_node comprehensive_namespace, location loc)
     :
     base(base_type, name, type_access_level, comprehensive_namespace,
     null, loc)
 {
     _original_generic = original_generic_type;
     _instance_params = param_types;
 }
Пример #26
0
 public common_generic_instance_type_node(common_type_node generic_definition,
     List<type_node> param_types,
     type_node base_type, string name,
     SemanticTree.type_access_level type_access_level,
     common_namespace_node comprehensive_namespace,
     location loc)
     :
     base(generic_definition, param_types, base_type, name, type_access_level, comprehensive_namespace,
     loc)
 {
 }
Пример #27
0
		public void leave_block()
		{
			switch (converting_block())
			{
				case block_type.function_block:
				{
                    common_function_node top_func = _func_stack.top();
                    location loc;
                    if (top_func.function_code == null)
                    {
                        loc = top_func.loc;
                    }
                    else if ((top_func.function_code as statements_list) != null)
                    {
                        statements_list stl = (statements_list)top_func.function_code;
                        if (stl.statements.Count > 0)
                        {
                            loc = stl.statements[stl.statements.Count - 1].location;
                        }
                        else
                        {
                            loc = top_func.loc;
                        }
                    }
                    else
                    {
                        loc = top_func.function_code.location;
                    }
                    if (top_func.function_code != null)
                    {
                        if (top_func.return_variable != null)
                        {
                            //TODO: Обратить внимание на преобразования типов. Можно сделать метод, который если тело функции не statement создает список statement-ов и добавляет в него существующий statement.
                            statements_list stl = (statements_list)top_func.function_code;
                            local_variable_reference lvr = new local_variable_reference(top_func.return_variable, 0, loc);
                            stl.statements.AddElement(new return_node(lvr, loc));
                        }
                        else if ((top_func.return_value_type != null) && (_ctn != null))
                        {
                            //TODO: Обратить внимание на преобразования типов. Можно сделать метод, который если тело функции не statement создает список statement-ов и добавляет в него существующий statement.
                            statements_list stl = (statements_list)top_func.function_code;
                            this_node thn = new this_node(_ctn, loc);
                            stl.statements.AddElement(new return_node(thn, loc));
                        }
                    }
                    check_predefinition_defined();
					_func_stack.pop();
					break;
				}
				case block_type.type_block:
				{
                    //TODO: Может и сюда вставить check_predefinition_defined, несмотря на то, что в данный момент он ничего не делает.
                    _cmn.types.AddElement(_ctn);
                    _ctn=null;
					break;
				}
				case block_type.namespace_block:
				{
                    check_predefinition_defined();
					_cmn=null;
					break;
				}
			}
		}
Пример #28
0
 /// <summary>
 /// Добавляет к текущему пространству имен указанное пространство имен.
 /// </summary>
 /// <param name="merge_with">Пространство имен для добавления.</param>
 public void merge_with_namespace(common_namespace_node merge_with)
 {
     _types.AddRange(merge_with._types);
     //ssyy
     _templates.AddRange(merge_with._templates);
     _type_synonyms.AddRange(merge_with._type_synonyms);
     //\ssyy
     _variables.AddRange(merge_with._variables);
     _functions.AddRange(merge_with._functions);
     _constants.AddRange(merge_with._constants);
     _namespaces.AddRange(merge_with._namespaces);
 }
Пример #29
0
 public procedure_definition_info(common_namespace_node _nspace,
     SyntaxTree.procedure_definition _proc)
 {
     nspace = _nspace;
     proc = _proc;
 }
Пример #30
0
 /// <summary>
 /// Клонирует пространство имен.
 /// </summary>
 /// <returns>Копия пространства иен.</returns>
 public common_namespace_node clone()
 {
     common_namespace_node cnn = new common_namespace_node(this._comprehensive_namespace, this._cont_unit,
         this._name, this._scope, this._loc);
     cnn.merge_with_namespace(this);
     return cnn;
 }
Пример #31
0
        /// <summary>
        /// Конструктор узла.
        /// </summary>
        /// <param name="name">Имя функции.</param>
        /// <param name="ret_type">Тип возвращааемого знчения функции.</param>
        /// <param name="loc">Расположение функции.</param>
        /// <param name="nsp">Пространство имен, в котором определена функция.</param>
        /// <param name="scope">Пространство имен функции.</param>
        public common_namespace_function_node(string name, type_node ret_type, location loc, common_namespace_node nsp, SymbolTable.Scope scope) :
			base(name,ret_type,loc,scope)
		{
			_namespace=nsp;
		}
Пример #32
0
 public namespace_variable(string name, type_node type, common_namespace_node cont_namespace, location loc) : base(name, type)
 {
     _cont_namespace = cont_namespace;
     _loc            = loc;
 }
        //процедура сохранения модуля на диск
		public void SaveSemanticTree(CompilationUnit Unit, string TargetFileName, bool IncludeDebugInfo)
		{
            pcu_file.IncludeDebugInfo = IncludeDebugInfo;
            pcu_file.UseRtlDll = compiler.CompilerOptions.UseDllForSystemUnits;
            unit = Unit; cun = (common_unit_node)unit.SemanticTree;
            this.FileName = TargetFileName;
            string program_folder=System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(TargetFileName));
			name = System.IO.Path.GetFileName(TargetFileName);
			//name = name.Substring(0,name.LastIndexOf('.'))+".pcu";
			//FileStream fs = new FileStream(name,FileMode.Create,FileAccess.ReadWrite);
            
            ChangeState(this, PCUReaderWriterState.BeginSaveTree, TargetFileName);

            pcu_file.compiler_directives = cun.compiler_directives;
            if (Path.GetDirectoryName(TargetFileName).ToLower() == Path.GetDirectoryName(Unit.SyntaxTree.file_name).ToLower())
                pcu_file.SourceFileName = Path.GetFileName(Unit.SyntaxTree.file_name);
            else
                pcu_file.SourceFileName = Unit.SyntaxTree.file_name;
			ms = new MemoryStream();
			bw = new BinaryWriter(ms);
			//if (Unit.InterfaceUsedUnits.Count > 0) Console.WriteLine("{0} {1}",name,Unit.InterfaceUsedUnits[0].namespaces[0].namespace_name);
			cur_cnn = cun.namespaces[0];
            
            //(ssyy) формируем список нешаблонных классов
            cur_cnn.MakeNonTemplateTypesList();

            GetUsedUnits();//заполняем список полключаемых модулей
            GetCountOfMembers();//заполняем список имен интерфейсных сущностей
			WriteUnit();//пишем имя interface_namespace
			cur_cnn = cun.namespaces[1];

            //(ssyy) формируем список нешаблонных классов
            cur_cnn.MakeNonTemplateTypesList();

            GetCountOfImplementationMembers();//(ssyy) заполняем список имен сущностей реализации
			WriteUnit();//пишем имя implementation_namespace
            SaveOffsetForAttribute(cun.namespaces[0]);
            bw.Write(0);//attributes;
			cur_cnn = cun.namespaces[0];
            //bw.Write((byte)0);
            //bw.Write((byte)0);

            //ssyy
            VisitTemplateClasses();//сериализуем шаблонные классы
            //\ssyy

            VisitTypeDefinitions();//сериализуем описания типов интерфейсной части

            //ssyy
            pcu_file.interface_synonyms_offset = (int)bw.BaseStream.Position;
            VisitTypeSynonyms();
            //\ssyy

            cur_cnn = cun.namespaces[1];
            is_interface = false;

            //ssyy
            VisitLabelDeclarations(cur_cnn.labels); //сериализуем метки
            type_entity_index = 0;
            VisitTemplateClasses();//сериализуем шаблонные классы
            //\ssyy
            
            VisitTypeDefinitions();//сериализуем описания типов имплемент. части
            //ssyy
            pcu_file.implementation_synonyms_offset = (int)bw.BaseStream.Position;
            VisitTypeSynonyms();
            //\ssyy
            cur_cnn = cun.namespaces[0];
            is_interface = true;
            foreach (common_type_node ctn in cur_cnn.non_template_types)
            {
                VisitTypeMemberDefinition(ctn);
            }
            cur_cnn = cun.namespaces[1];
            is_interface = false;
            foreach (common_type_node ctn in cur_cnn.non_template_types)
            {
                VisitTypeMemberDefinition(ctn);
            }
            cur_cnn = cun.namespaces[0];
            is_interface = true;
            VisitConstantDefinitions();//сериализуем константы
			VisitVariableDefinitions();//сериализуем переменные
            
			VisitFunctionDefinitions();//сериализуем функции
            VisitRefTypeDefinitions();
            VisitEventDefinitions();
            cur_cnn = cun.namespaces[1];
			is_interface = false;
			entity_index = 0;
			//имплементационная часть
			VisitConstantDefinitions();
			VisitVariableDefinitions();
			VisitFunctionDefinitions();
            VisitRefTypeDefinitions();
            VisitEventDefinitions();
            cur_cnn = cun.namespaces[0];
            //сериализуем тела функций
            foreach (common_namespace_function_node cnfn in cur_cnn.functions)
            {
                VisitFunctionImplementation(cnfn);
            }
            //сериализуем тела методов и конструкторов типа
            foreach (common_type_node ctn in cur_cnn.non_template_types)
            {
                VisitTypeImplementation(ctn);
            }
            cur_cnn = cun.namespaces[1];
            //имплементационная часть
			foreach (common_namespace_function_node cnfn in cur_cnn.functions)
			 VisitFunctionImplementation(cnfn);
            foreach (common_type_node ctn in cur_cnn.non_template_types)
            {
                VisitTypeImplementation(ctn);
            }
            
            WriteVariablePositions();
            WriteConstantPositions();
            AddAttributes();
            WriteInitExpressions();
            
            //сохранение интерфейсной и имплементац. частей модуля
            if (ext_offsets.Count != 0)
            {
                List<definition_node> dnl = new List<definition_node>(ext_offsets.Keys);
                foreach (definition_node wdn in dnl)
                {
                    if (wdn is wrapped_definition_node)
                        AddOffsetForMembers(wdn, (wdn as wrapped_definition_node).offset);
                    else
                    if (wdn is wrapped_common_type_node)
                        AddOffsetForMembers(wdn, (wdn as wrapped_common_type_node).offset);
                    else
                    if (PCUReader.AllReadOrWritedDefinitionNodesOffsets.ContainsKey(wdn))
                        AddOffsetForMembers(wdn, PCUReader.AllReadOrWritedDefinitionNodesOffsets[wdn]);
                }
                //ssyy 01.07.2007
                //CloseWriter();
                //\ssyy
            }

            //если нет импортирумых сущностей, смещение которых неизвестно
            else //if (ext_offsets.Count == 0)
            {
                //CloseWriter();
                /*FileStream fs = new FileStream(TargetFileName, FileMode.Create, FileAccess.ReadWrite);
                BinaryWriter fbw = new BinaryWriter(fs);
                WritePCUHeader(fbw); //пишем заголовок PCU
                byte[] buf = new byte[bw.BaseStream.Length];
                bw.Seek(0, SeekOrigin.Begin);
                bw.BaseStream.Read(buf, 0, buf.Length);
                fbw.Write(buf);
                bw.Close();
                ms.Close();
                fbw.Close();
                fs.Close();*/
                //если существовал pcu, который использовался reader-ом и была циклическая связь
                //if (pcu_reader != null) pcu_reader.OpenUnit();
            }
		}
        private void AddNamespaces()
		{
            cun.unit_name=br.ReadString();
            
            common_namespace_node cnn = new common_namespace_node(null, cun, cun.unit_name, cun.scope, ReadDebugInfo());
			cun.namespaces.AddElement(cnn);
            
            cun.add_unit_name_to_namespace();

            cnn = new common_namespace_node(cnn, cun, br.ReadString(), cun.implementation_scope, ReadDebugInfo());
			cun.namespaces.AddElement(cnn);
            var attributes = GetAttributes();
            cun.attributes.AddRange(attributes);
            cun.namespaces[0].attributes.AddRange(attributes);
		}
        //получения индекса модуля в списке подключ. модулей
		private int GetUnitToken(common_namespace_node ns)
		{
			int tok = 0;
			if (!used_units.TryGetValue(ns,out tok))
			{
				return used_units[(ns.cont_unit as common_unit_node).namespaces[0]];
			}
			return tok;
		}
Пример #36
0
		public namespace_variable(string name,type_node type,common_namespace_node cont_namespace,location loc) : base(name,type)
		{
			_cont_namespace=cont_namespace;
            _loc = loc;
		}
 private List<SemanticTree.ICommonTypeNode> ReadGenericParams(common_namespace_node cur_nn)
 {
     if (SemanticRules.RuntimeInitVariablesOfGenericParameters)
     {
         if (!SystemLibrary.SystemLibInitializer.NeedsToRestore.Contains(
             SystemLibrary.SystemLibInitializer.RuntimeInitializeFunction))
         {
             SystemLibrary.SystemLibInitializer.NeedsToRestore.Add(
                 SystemLibrary.SystemLibInitializer.RuntimeInitializeFunction);
         }
     }
     //common_namespace_node cur_nn = (is_interface) ? cun.namespaces[0] : cun.namespaces[1];
     int param_count = br.ReadInt32();
     List<SemanticTree.ICommonTypeNode> type_params = new List<PascalABCCompiler.SemanticTree.ICommonTypeNode>(param_count);
     for (int i = 0; i < param_count; i++)
     {
         string par_name = br.ReadString();
         common_type_node par = new common_type_node(
             par_name, SemanticTree.type_access_level.tal_public, cur_nn,
             SystemLibrary.SystemLibrary.syn_visitor.convertion_data_and_alghoritms.symbol_table.CreateInterfaceScope(null, SystemLibrary.SystemLibrary.object_type.Scope, null),
             null);
         SystemLibrary.SystemLibrary.init_reference_type(par);
         par.SetBaseType(SystemLibrary.SystemLibrary.object_type);
         type_params.Add(par);
     }
     return type_params;
 }
 public void reset()
 {
     _cmn = null;
     _ctn = null;
     _func_stack.clear();
     var_defs.Clear();
     _main_procedure = null;
     _last_created_function = null;
     _cycles_stack.clear();
     _num_of_for_cycles = 0;
     _fal = SemanticTree.field_access_level.fal_private;
     rec_num = 1;
     var_defs_stack.Clear();
     type_stack.Clear();
     clear_special_local_vars();
     _scope_stack.Clear();
     TypedFiles.Clear();
     ShortStringTypes.Clear();
     TypedSets.Clear();
     _compiled_tn = null;
     _explicit_interface_type = null;
     _ctt = null;
     allow_inherited_ctor_call = false;
     _types_predefined.Clear();
     _block_stack.Clear();
     member_decls.Clear();
     possible_incorrect_instances.Clear();
     skip_check_where_sections = false;
     LambdaHelper.Reset(); //lroman//
     SavedContext = null;
     SavedContextStack.Clear();
     compiled_tc_cache.Clear();
     extension_method = false;
     _last_created_function = null;
     in_parameters_block = false;
     is_order_independed_method_description = false;
     
 }