//сохранение константы
 private void VisitConstantDefinition(namespace_constant_definition cnst)
 {
     if (is_interface == true) 
         SavePositionAndConstPool(cnst);
     else 
         SavePositionAndImplementationPool(cnst);
     bw.Write((byte)cnst.semantic_node_type);
     bw.Write(is_interface);
     if (is_interface == true)
         bw.Write(GetNameIndex(cnst));
     else
         bw.Write(cnst.name);
     bw.Write(GetUnitReference(cnst.comprehensive_namespace));
     SaveExpressionAndOffset(cnst.const_value);
     bw.Write(0);
     //VisitExpression(cnst.const_value);
     WriteDebugInfo(cnst.loc);
 }
 private void SaveConstantReferencePosition(namespace_constant_definition nv)
 {
     List<int> offs = (List<int>)const_positions[nv];
     if (offs == null)
     {
         offs = new List<int>();
         const_positions[nv] = offs;
     }
     offs.Add((int)bw.BaseStream.Position);
 }
		private void WriteConstantReference(namespace_constant_definition nv)
		{
			byte is_def = 0;
			int offset = GetConstantReference(nv, ref is_def);
			bw.Write(is_def);
            if (offset == -1) SaveConstantReferencePosition(nv);
			bw.Write(offset);
		}
Esempio n. 4
0
		public constant_definition_node add_const_definition(string name,location loc)
		{
			constant_definition_node cdn=null;
			//cdn.loc=loc;
			switch (converting_block())
			{
				case block_type.function_block:
				{
                    common_function_node top_func = _func_stack.top();
                    function_constant_definition fcd = new function_constant_definition(name, loc, top_func);
					top_func.scope.AddSymbol(name,new SymbolInfo(fcd));
                    top_func.constants.AddElement(fcd);
                    cdn = fcd;
					break;
				}
				case block_type.type_block:
				{
                    class_constant_definition ccd = new class_constant_definition(name, loc, _ctn);
					_ctn.Scope.AddSymbol(name,new SymbolInfo(ccd));
					_ctn.const_defs.AddElement(ccd);
                    cdn = ccd;
					break;
				}
				case block_type.namespace_block:
				{
                    namespace_constant_definition ncd = new namespace_constant_definition(name, loc, _cmn);
					_cmn.scope.AddSymbol(name,new SymbolInfo(ncd));
					_cmn.constants.AddElement(ncd);
                    cdn = ncd;
					break;
				}
			}
			return cdn;
		}
		private int GetConstantReference(namespace_constant_definition nv, ref byte is_def)
		{
            int off = 0;
            if (members.TryGetValue(nv, out off)) //если этот тип описан в этом модуле
            {
                is_def = 1;
                return off;//возвращаем его смещение
            }
            if (!used_units.ContainsKey(nv.comprehensive_namespace))
            {
                is_def = 1;
                return -1;
            }
			is_def = 0;
            ImportedEntity ie = null;
            if (ext_members.TryGetValue(nv, out ie))
            {
                return ie.index * ie.GetSize();
            }
			ie = new ImportedEntity();
			ie.flag = ImportKind.Common;
			ie.num_unit = GetUnitToken(nv.comprehensive_namespace);
			ie.offset = GetExternalOffset(nv);
			int offset = imp_entitles.Count*ie.GetSize();
            ie.index = imp_entitles.Count;
            imp_entitles.Add(ie);
			ext_members[nv] = ie;
			return offset;
		}
Esempio n. 6
0
 public namespace_constant_reference(namespace_constant_definition cdn, location loc) : base(cdn.type, loc)
 {
     this.cdn = cdn;
 }
 //ssyy
 private namespace_constant_definition GetConstantDefinition(int offset)
 {
     definition_node dn = null;
     if (members.TryGetValue(offset, out dn))
         return dn as namespace_constant_definition;
     namespace_constant_definition ncd = null;
     int pos = (int)br.BaseStream.Position;
     br.BaseStream.Seek(start_pos + offset, SeekOrigin.Begin);
     br.ReadByte();
     string name;
     bool is_interface = br.ReadBoolean();
     if (is_interface)//пропускаем флаг - интерфейсности
     {
         name = GetString(br.ReadInt32());
     }
     else
     {
         name = br.ReadString();
     }
     br.ReadInt32();//namespace
     constant_node en = (constant_node)CreateExpressionWithOffset();
     location loc = ReadDebugInfo();
     ncd = new namespace_constant_definition(name, en, loc, cun.namespaces[(is_interface)?0:1]);
     cun.namespaces[(is_interface) ? 0 : 1].constants.AddElement(ncd);        
     br.BaseStream.Seek(pos, SeekOrigin.Begin);
     //???
     AddMember(ncd, offset);
     return ncd;
 }
 private namespace_constant_definition CreateInterfaceConstantDefinition(string name, int offset)
 {
     definition_node dn = null;
     if (members.TryGetValue(offset, out dn))
         return dn as namespace_constant_definition;
     namespace_constant_definition ncd = null;
     br.ReadBoolean();
     br.ReadInt32();
     br.ReadInt32();//namespace
     constant_node en = (constant_node)CreateExpressionWithOffset();
     location loc = ReadDebugInfo();
     ncd = new namespace_constant_definition(name,en,loc,cun.namespaces[0]);
     cun.namespaces[0].constants.AddElement(ncd);
     //???
     AddMember(ncd, offset);
     return ncd;
 }
Esempio n. 9
0
		private void SaveConstant(namespace_constant_definition cfn)
		{
			if (!string.IsNullOrEmpty(cfn.documentation))
			{
				if (!cfn.documentation.Trim(' ','\t').StartsWith("<summary>"))
				{
					xtw.WriteStartElement("member");
					xtw.WriteStartAttribute("name");
					xtw.WriteString((is_assembly?"F:"+unit_name+"."+unit_name+".":"C:")+cfn.name);
					xtw.WriteEndAttribute();
					xtw.WriteStartElement("summary");
					xtw.WriteString(cfn.documentation);
					xtw.WriteEndElement();
					xtw.WriteEndElement();
				}
				else
				{
					string doc = string.Concat("<member name=\""+(is_assembly?"F:"+unit_name+"."+unit_name+".":"C:")+cfn.name+"\">",cfn.documentation,"</member>");
					StringReader sr = new StringReader(doc);
					XmlReader xr = XmlTextReader.Create(sr);
					xr.Read();
					xtw.WriteNode(xr.ReadSubtree(),false);
					sr.Close();
					xr.Close();
				}
			}
		}
        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));
        }