private static List<ident> GetTemplateParametersTypeDependsOn(type_node type)
        {
            if (type.generic_function_container != null)
            {
                return new List<ident>
                    {
                        new ident(type.name)
                    };
            }

            var typeRef = type as ref_type_node;
            if (typeRef != null)
            {
                return GetTemplateParametersTypeDependsOn(typeRef.pointed_type);
            }

            var typeIi = type.get_internal_interface(internal_interface_kind.unsized_array_interface) as array_internal_interface;
            if (typeIi != null)
            {
                return GetTemplateParametersTypeDependsOn(typeIi.element_type);
            }

            if (type.type_special_kind == PascalABCCompiler.SemanticTree.type_special_kind.set_type)
            {
                return GetTemplateParametersTypeDependsOn(type.element_type);
            }

            if (type.IsDelegate)
            {
                var dii = type.get_internal_interface(internal_interface_kind.delegate_interface) as delegate_internal_interface;
                var res = new List<ident>();
                if (dii != null)
                {
                    var paramCount = dii.parameters.Count;
                    for (var i = 0; i < paramCount; i++)
                    {
                        res.AddRange(GetTemplateParametersTypeDependsOn(dii.parameters[i].type));
                    }
                }
                return res;
            }

            if (type.is_generic_type_instance)
            {
                var pcount = type.instance_params.Count;
                var res = new List<ident>();

                for (var i = 0; i < pcount; i++)
                {
                    res.AddRange(GetTemplateParametersTypeDependsOn(type.instance_params[i]));
                }
                return res;
            }

            return new List<ident>();
        }
示例#2
0
 	public common_event(string name, type_node del_type, common_type_node cont_type, common_method_node add_method, common_method_node remove_method, common_method_node raise_method, 
 	                    SemanticTree.field_access_level fal, SemanticTree.polymorphic_state ps, location loc)
 	{
 		this._name = name;
 		this.del_type = del_type;
 		this._add_method = add_method;
 		this._remove_method = remove_method;
 		this._raise_method = raise_method;
 		this._field_access_level = fal;
 		this._polymorphic_state = ps;
 		this._cont_type = cont_type;
 		this._loc = loc;
 	}
示例#3
0
 public static bool TypeDependedFromTemplate(type_node tn)
 {
     common_type_node ctn = tn as common_type_node;
     if (ctn == null)
     {
         return false;
     }
     if (ctn.original_template != null)
     {
         return true;
     }
     switch (tn.type_special_kind)
     {
         case PascalABCCompiler.SemanticTree.type_special_kind.array_kind:
         case PascalABCCompiler.SemanticTree.type_special_kind.set_type:
         //case PascalABCCompiler.SemanticTree.type_special_kind.typed_file:
             return TypeDependedFromTemplate(tn.element_type);
     }
     return false;
 }
 private int GetSizeOfReference(type_node tn)
 {
     if (tn == null)
         return sizeof(byte);
     if (tn.is_generic_parameter)
     {
         return sizeof(byte) + GetSizeOfReference(tn.generic_type_container as type_node) + sizeof(int);
     }
     generic_instance_type_node gitn = tn as generic_instance_type_node;
     if (gitn != null)
     {
         int rez = sizeof(byte) + GetSizeOfReference(gitn.original_generic) + sizeof(int);
         foreach (type_node par in gitn.instance_params)
         {
             rez += GetSizeOfReference(par);
         }
         return rez;
     }
     return sizeof(byte) + sizeof(int);
 }
        //запись ссылки на тип
        //флаг|смещение
		private void WriteTypeReference(type_node type)
		{
            if (type == null)
            {
                bw.Write((System.Byte)255);
                return;
            }
			//если это массив
            if (type.semantic_node_type == semantic_node_type.simple_array)
            {
                WriteArrayType((simple_array)type);
                return;
            }
            //если это указатель
            //Наверно также надо сохранять Pointer,
            //  пока он востанавливается из таблицы nethelper.special_types
            if (type.semantic_node_type == semantic_node_type.ref_type_node)
            {
                WritePointerType((ref_type_node)type);
                return;
            }
            if (type.semantic_node_type == semantic_node_type.short_string)
            {
            	WriteShortStringType((short_string_type_node)type);
            	return;
            }
            internal_interface ii=type.get_internal_interface(internal_interface_kind.unsized_array_interface);
            //(ssyy) 18.05.2008 Убрал проверку на compiled_type_node
            if (ii != null) //&& type.element_type is compiled_type_node)
            {
                array_internal_interface aii=(array_internal_interface)ii;
                WriteUnsizedArrayType(type,aii);
                return;
            }
            /*
            ii = type.get_internal_interface(internal_interface_kind.bounded_array_interface);
            if (ii != null)
            {
                bounded_array_interface bai = (bounded_array_interface)ii;
                WriteBoundedArray(bai);
                return;
            }
            */
            
            //Пишем параметр generic-типа
            if (type.is_generic_parameter)
            {
                WriteGenericParameter(type as common_type_node);
                return;
            }

            //Пишем инстанцию generic-типа
            generic_instance_type_node gitn = type as generic_instance_type_node;
            if (gitn != null)
            {
                WriteGenericTypeInstance(gitn);
                return;
            }

            //Пишем инстанцию шаблонного класса
            common_type_node c_t_n = type as common_type_node;
            if (c_t_n != null && c_t_n.original_template != null)
            {
                WriteTemplateInstance(c_t_n);
                return;
            }

            byte is_def = 0;
			int offset = GetTypeReference(type, ref is_def);
			bw.Write(is_def); //пишем флаг импортируемый ли это тип или нет
			bw.Write(offset); // сохраняем его смещение (это либо смещение в самом модуле, либо в списке импорт. сущностей)
		}
示例#6
0
        /*
        private static void mark_byte_as_ordinal()
        {
            basic_function_node inc_value_method = create_inc_value_method(SemanticTree.basic_function_type.binc, _byte_type);
            basic_function_node dec_value_method = create_dec_value_method(SemanticTree.basic_function_type.bdec, _byte_type);

            basic_function_node inc_method = create_inc_method(SemanticTree.basic_function_type.binc, _byte_type);
            basic_function_node dec_method = create_dec_method(SemanticTree.basic_function_type.bdec, _byte_type);

            SymbolInfo si = _byte_type.find_in_type(compiler_string_consts.greq_name);
            basic_function_node greq = (basic_function_node)si.sym_info;

            si = _byte_type.find(compiler_string_consts.smeq_name);
            basic_function_node loeq = (basic_function_node)si.sym_info;

            constant_node cn_max = new byte_const_node(byte.MaxValue, null);
            constant_node cn_min = new byte_const_node(byte.MinValue, null);

            basic_function_node i2i_method = create_emty_function(byte_type);

            ordinal_type_to_int ordinal_type_to_int = byte_to_int;

            ordinal_type_interface oti = new ordinal_type_interface(inc_method, dec_method, inc_value_method, dec_value_method,
                internal_inc_value, internal_dec_value, loeq, greq, cn_min, cn_max, i2i_method, ordinal_type_to_int);

            _byte_type.add_internal_interface(oti);
        }
        */
        private static void mark_type_as_ordinal(type_node type,
            SemanticTree.basic_function_type inc,SemanticTree.basic_function_type dec,
            SemanticTree.basic_function_type vinc, SemanticTree.basic_function_type vdec,
            constant_node lower_value, constant_node upper_value,
            function_node t2i,ordinal_type_to_int t2i_comp)
        {
            basic_function_node inc_value = create_oti_method(inc, type, SemanticTree.parameter_type.value);
            basic_function_node dec_value = create_oti_method(dec, type, SemanticTree.parameter_type.value);

            basic_function_node inc_var = create_oti_method(vinc, type, SemanticTree.parameter_type.var);
            basic_function_node dec_var = create_oti_method(vdec, type, SemanticTree.parameter_type.var);

            SymbolInfo si = type.find_in_type(compiler_string_consts.greq_name);
            basic_function_node greq = (basic_function_node)si.sym_info;
        
            si = type.find(compiler_string_consts.smeq_name);
            basic_function_node loeq = (basic_function_node)si.sym_info;
			
            si = type.find(compiler_string_consts.sm_name);
            basic_function_node lo = (basic_function_node)si.sym_info;
            
            si = type.find(compiler_string_consts.gr_name);
            basic_function_node gr = (basic_function_node)si.sym_info;
            
            ordinal_type_interface oti = new ordinal_type_interface(inc_value, dec_value, inc_var, dec_var,
                loeq, greq, lo, gr, lower_value, upper_value, t2i, t2i_comp);

            type.add_internal_interface(oti);
        }
示例#7
0
 private static basic_function_node create_dec_method(SemanticTree.basic_function_type bft, type_node type)
 {
     basic_function_node bfn = create_oti_method(bft, type, SemanticTree.parameter_type.var);
     bfn.compile_time_executor = dec_compile_time_executor;
     return bfn;
 }
示例#8
0
 public static void add_generated_funtion_to_type(string oper_name, type_node to, function_node fn)
 {
     to.add_generated_name(oper_name, new SymbolInfo(fn));
 }
示例#9
0
        public static basic_function_node make_type_conversion(type_node from, type_node to, type_compare tc,
            SemanticTree.basic_function_type bft, bool is_implicit)
        {
            basic_function_node conv_method = new basic_function_node(bft, to,false);
            basic_parameter bp = new basic_parameter(compiler_string_consts.unary_param_name,
                from, SemanticTree.parameter_type.value, conv_method);
            conv_method.parameters.AddElement(bp);

            type_table.add_type_conversion_from_defined(from, to, conv_method, tc, is_implicit);
            //type_intersection_node inter_node = new type_intersection_node(tc);
            //inter_node.this_to_another = new type_conversion(conv_method,!is_implicit);
            //from.add_intersection_node(to, inter_node);
			add_stand_type(bft, conv_method);
            return conv_method;
        }
示例#10
0
 public static basic_function_node make_not_equivalence_operator(type_node ctn)
 {
     return make_object_operator(ctn, SemanticTree.basic_function_type.objnoteq, compiler_string_consts.noteq_name, _bool_type);
 }
示例#11
0
 private static basic_function_node make_assign_operator(type_node ctn)
 {
     return make_assign_operator(ctn, SemanticTree.basic_function_type.objassign);
 }
示例#12
0
 public static basic_function_node make_assign_operator(type_node ctn,SemanticTree.basic_function_type assign_method)
 {
     basic_function_node ret = make_object_operator(ctn, assign_method, compiler_string_consts.assign_name,
         ctn, SemanticTree.parameter_type.var);
     ret.operation_kind = special_operation_kind.assign;
     return ret;
 }
示例#13
0
 private static basic_function_node make_object_operator(type_node ctn, SemanticTree.basic_function_type bas_ft, string name,
     type_node ret_type)
 {
     return make_object_operator(ctn, bas_ft, name, ret_type, SemanticTree.parameter_type.value);
 }
示例#14
0
 private static basic_function_node make_object_operator(type_node ctn, SemanticTree.basic_function_type bas_ft,
     string name, type_node ret_type, SemanticTree.parameter_type first_parameter_type)
 {
     basic_function_node bfn = new basic_function_node(bas_ft, ret_type,true,name);
     basic_parameter to = new basic_parameter(compiler_string_consts.left_param_name, ctn,
         first_parameter_type, bfn);
     basic_parameter from = new basic_parameter(compiler_string_consts.right_param_name, ctn,
         SemanticTree.parameter_type.value, bfn);
     bfn.parameters.AddElement(to);
     bfn.parameters.AddElement(from);
     ctn.add_name(name, new SymbolInfo(bfn)); 
     add_stand_type(bas_ft, bfn);
     return bfn;
 }
示例#15
0
 public static bool CanUseThisTypeForTypedFiles(type_node tn)
 {
     return writable_in_typed_files_types[tn] != null;
 }
示例#16
0
 public static basic_function_node make_binary_operator(string operator_name, type_node to)
 {
     return make_binary_operator(operator_name, to, PascalABCCompiler.SemanticTree.basic_function_type.none, to);
 }
示例#17
0
 public static basic_function_node make_type_conversion(type_node from, type_node to, type_compare tc,
     SemanticTree.basic_function_type bft)
 {
     return make_type_conversion(from, to, tc, bft, true);
 }
示例#18
0
 public static void init_reference_type(type_node ctn)
 {
 	if (_bool_type == null) 
 	{
 		wait_add_ref_list.Add(ctn);
 		return;
 	}
     if (!ctn.is_ref_inited)
     {
         make_assign_operator(ctn);
         make_equivalence_operator(ctn);
         make_not_equivalence_operator(ctn);
         ctn.is_ref_inited = true;
     }
 }
示例#19
0
 public static basic_function_node make_generated_type_conversion(type_node from, type_node to, type_compare tc,
     SemanticTree.basic_function_type bft, bool is_implicit)
 {
     basic_function_node conv_method = new basic_function_node(bft, to, false);
     basic_parameter bp = new basic_parameter(compiler_string_consts.unary_param_name,
         from, SemanticTree.parameter_type.value, conv_method);
     conv_method.parameters.AddElement(bp);
     type_table.add_generated_type_conversion_from_defined(from, to, conv_method, tc, is_implicit);
     return conv_method;
 }
示例#20
0
 private static basic_function_node make_unary_function(type_node param_type,
     SemanticTree.basic_function_type bft,type_node ret_val_type)
 {
     basic_function_node bfn = new basic_function_node(bft, ret_val_type, true);
     basic_parameter bpar = new basic_parameter(compiler_string_consts.unary_param_name, param_type,
         SemanticTree.parameter_type.value, bfn);
     bfn.parameters.AddElement(bpar);
     add_stand_type(bft, bfn);
     return bfn;
 }
示例#21
0
 private static basic_function_node create_oti_method(SemanticTree.basic_function_type bft, type_node type, SemanticTree.parameter_type pt)
 {
     basic_function_node bfn = new basic_function_node(bft, type, true);
     basic_parameter cp = new basic_parameter(compiler_string_consts.unary_param_name, type,
         pt, bfn);
     bfn.parameters.AddElement(cp);
     //TODO: Важен порядок вызовов.
     add_stand_type(bft, bfn);
     return bfn;
 }
示例#22
0
 public static basic_function_node make_common_binary_operation(string operator_name,
     type_node def_type,type_node left,type_node right, 
     SemanticTree.basic_function_type bft,type_node ret_value_type)
 {
     basic_function_node bfn = new basic_function_node(bft, ret_value_type,true,operator_name);
     basic_parameter par_left = new basic_parameter(compiler_string_consts.left_param_name, left,
         SemanticTree.parameter_type.value, bfn);
     basic_parameter par_right = new basic_parameter(compiler_string_consts.right_param_name, right,
         SemanticTree.parameter_type.value, bfn);
     bfn.parameters.AddElement(par_left);
     bfn.parameters.AddElement(par_right);
     def_type.add_name(operator_name, new SymbolInfo(bfn));
     add_stand_type(bft, bfn);
     return bfn;
 }
示例#23
0
        /*
        private static expression_node char_to_int(location call_location,expression_node[] expr)
        {
            if (expr.Length != 1)
            {
                return null;
            }
            if (expr[0].type != char_type)
            {
                return null;
            }
            char_const_node ccn = expr[0] as char_const_node;
            if (ccn == null)
            {
                return null;
            }
            return new int_const_node((int)ccn.constant_value, ccn.location);
        }
        */
        private static basic_function_node create_emty_function(type_node ret_type, string name)
        {
            basic_function_node bfn = new basic_function_node(SemanticTree.basic_function_type.none, ret_type, true, name);
            basic_parameter par = new basic_parameter(compiler_string_consts.unary_param_name, ret_type,
                SemanticTree.parameter_type.value, bfn);
            bfn.parameters.AddElement(par);
            bfn.compile_time_executor = delegated_empty_method;
			add_stand_type(SemanticTree.basic_function_type.none, bfn);
            return bfn;
        }
示例#24
0
 public static basic_function_node make_unary_operator(string operator_name, type_node to,
     SemanticTree.basic_function_type bft, type_node ret_value_type)
 {
     basic_function_node bfn = new basic_function_node(bft, ret_value_type,true);
     basic_parameter par = new basic_parameter(compiler_string_consts.unary_param_name, to,
         SemanticTree.parameter_type.value, bfn);
     bfn.parameters.AddElement(par);
     to.add_name(operator_name, new SymbolInfo(bfn));
     add_stand_type(bft, bfn);
     return bfn;
 }
        //получения ссылки на тип
		private int GetTypeReference(type_node tn, ref byte is_def)
		{
			//если это откомпилир. тип
            if (tn.semantic_node_type == semantic_node_type.compiled_type_node)
			{
				is_def = 0;
				compiled_type_node ctn = (compiled_type_node)tn;
                ImportedEntity ie = null; 
                if (ext_members.TryGetValue(ctn,out ie))
                {
                    return ie.index*ie.GetSize();
                }
				//заполняем структуру в списке импортируемых сущностей
                ie = new ImportedEntity();
				ie.index = imp_entitles.Count;
				ie.flag = ImportKind.DotNet;
				ie.num_unit = GetAssemblyToken(ctn.compiled_type.Assembly);
				//ie.offset = (int)ctn.compiled_type.MetadataToken;//токен для типа (уникален в сборке)
                ie.offset = GetTokenForNetEntity(ctn.compiled_type);
				int offset = imp_entitles.Count*ie.GetSize();
				imp_entitles.Add(ie);//добавляем структуру
				ext_members[ctn] = ie;
				return offset;//возвращаем смещение относительно начала списка импорт. сущ-тей
			}
			else
			{
                int off = 0;
                if (members.TryGetValue(tn, out off)) //если этот тип описан в этом модуле
				{
					is_def = 1;
					return off;//возвращаем его смещение
				}
                //иначе он описан в другом модуле
				is_def = 0;
                ImportedEntity ie = null;
                if (ext_members.TryGetValue(tn, out ie))
                {
                    return ie.index * ie.GetSize();
                }
				common_type_node ctn = (common_type_node)tn;
				ie = new ImportedEntity();
				ie.flag = ImportKind.Common;
				ie.num_unit = GetUnitToken(ctn.comprehensive_namespace);//получаем модуль
				ie.offset = GetExternalOffset(ctn);//получаем смещение в другом модуле
				int offset = imp_entitles.Count*ie.GetSize();
                ie.index = imp_entitles.Count;
                imp_entitles.Add(ie);
				ext_members[ctn] = ie;
				return offset;
			}
		}
示例#26
0
 public static basic_function_node make_unary_empty_operator(string operator_name, type_node to,
     type_node ret_value_type)
 {
     basic_function_node bfn = create_emty_function(ret_value_type, operator_name);            
     to.add_name(operator_name,new SymbolInfo(bfn));
     return bfn;
 }
 private void WriteUnsizedArrayType(type_node type,array_internal_interface aii)
 {
     bw.Write((byte)TypeKind.UnsizedArray);
     WriteDebugInfo((type as SemanticTree.ILocated).Location);
     WriteTypeReference(aii.element_type);
     bw.Write(aii.rank);
 }
示例#28
0
 public static basic_function_node make_binary_operator(string operator_name, type_node to,
     SemanticTree.basic_function_type bft, type_node ret_value_type)
 {
     return make_common_binary_operation(operator_name, to, to, to, bft, ret_value_type);
 }
示例#29
0
 private void CheckType(type_node type, expression_node initial_value, location loc)
 {
     if (type.type_special_kind == SemanticTree.type_special_kind.array_wrapper)
     {
         AddHint("DO_NOT_USE_STATIC_ARRAYS", loc);
     }
     else if (type.IsPointer && type.element_type.is_value_type && type.element_type is common_type_node)
     {
         AddHint("DO_NOT_USE_POINTERS_TO_RECORDS", loc);
     }
     else if (type.type_special_kind == SemanticTree.type_special_kind.short_string)
     {
         AddHint("DO_NOT_USE_SHORT_STRINGS", loc);
     }
 }
示例#30
0
 public static basic_function_node make_binary_operator(string operator_name, type_node to, SemanticTree.basic_function_type bft)
 {
     return make_binary_operator(operator_name, to, bft, to);
 }