public void AddDefaultConstructorIfNeed() { if (members != null) { bool has_def_constr = false; foreach (SymScope ss in members) if (ss is ProcScope && (ss as ProcScope).is_constructor) { has_def_constr = true; } if (!has_def_constr) { ProcScope ps = new ProcScope("Create", this, true); ps.Complete(); members.Insert(0, ps); } } }
public virtual TypeScope GetInstance(List<TypeScope> gen_args) { TypeScope ts = new TypeScope(this.kind, this.topScope, this.baseScope); ts.original_type = this; ts.loc = this.loc; for (int i = 0; i < gen_args.Count; i++) { ts.AddGenericParameter(gen_args[i].si.name); ts.AddGenericInstanciation(gen_args[i]); } ts.si.name = this.si.name; ts.documentation = this.documentation; ts.si.description = ts.GetDescription(); if (this.elementType != null) { ts.elementType = internalInstance(this.elementType, gen_args); } if (this.indexers != null && this.indexers.Count > 0) { ts.indexers = new List<TypeScope>(); for (int j = 0; j < this.indexers.Count; j++) ts.indexers.Add(internalInstance(this.indexers[j], gen_args)); } Hashtable procs = new Hashtable(); for (int i = 0; i < members.Count; i++) { SymScope ss = members[i]; ts.members.Add(ss); if (ss is ElementScope) { ElementScope es = ss as ElementScope; ElementScope new_es = new ElementScope(new SymInfo(es.si.name, es.si.kind, es.si.name), es.sc, ts); ts.members[i] = new_es; new_es.loc = es.loc; new_es.documentation = es.documentation; new_es.si.acc_mod = es.si.acc_mod; new_es.si.has_doc = es.si.has_doc; if (es.indexers != null && es.indexers.Count > 0) { new_es.indexers = new List<TypeScope>(); for (int j = 0; j < es.indexers.Count; j++) new_es.indexers.Add(internalInstance(es.indexers[j], gen_args)); } if (es.elementType != null) { new_es.elementType = internalInstance(es.elementType, gen_args); } new_es.sc = internalInstance(es.sc as TypeScope, gen_args); new_es.MakeDescription(); } else if (ss is ProcScope) { ProcScope ps = ss as ProcScope; ProcScope new_proc = new ProcScope(ps.si.name, ts, ps.is_constructor); procs[ps] = new_proc; new_proc.loc = ps.loc; new_proc.documentation = ps.documentation; new_proc.si.acc_mod = ps.si.acc_mod; new_proc.is_static = ps.is_static; new_proc.is_virtual = ps.is_virtual; new_proc.is_abstract = ps.is_abstract; new_proc.is_override = ps.is_override; new_proc.is_reintroduce = ps.is_reintroduce; ts.members[i] = new_proc; if (ps.parameters != null) for (int j = 0; j < ps.parameters.Count; j++) { ElementScope es = ps.parameters[j]; ElementScope es2 = new ElementScope(new SymInfo(es.si.name, es.si.kind, es.si.name), es.sc, new_proc); es2.loc = es.loc; es2.cnst_val = es.cnst_val; es2.si.acc_mod = es.si.acc_mod; es2.param_kind = es.param_kind; es2.sc = internalInstance(es.sc as TypeScope, gen_args); es2.MakeDescription(); new_proc.AddParameter(es2); } new_proc.return_type = internalInstance(ps.return_type, gen_args); new_proc.Complete(); } } foreach (ProcScope ps in procs.Keys) { ProcScope new_ps = procs[ps] as ProcScope; if (ps.nextProc != null && procs[ps.nextProc] != null) { new_ps.nextProc = procs[ps.nextProc] as ProcScope; } } return ts; }
private void add_standart_types(SymScope cur_scope) { string type_name = null; //obj_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.object_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.object_type_name),typeof(object)); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.object_type_name,TypeTable.obj_type); //int_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.integer_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.integer_type_name),typeof(int)); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.integer_type_name, int_type); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.IntType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.int_type); //real_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.real_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.real_type_name),typeof(double)); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.real_type_name,real_type); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.DoubleType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.real_type); //string_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name, SymbolKind.Class,PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name),typeof(string)); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name,TypeTable.string_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name, //new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.string_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.ShortStringTypeName),typeof(string))); //char_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.char_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.char_type_name),typeof(char)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.CharType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.char_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.char_type_name,char_type); //bool_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.bool_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.bool_type_name),typeof(bool)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.BoolType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.bool_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.bool_type_name,bool_type); //byte_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.byte_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.byte_type_name),typeof(byte)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.ByteType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.byte_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.byte_type_name,byte_type); //int16_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.short_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.short_type_name),typeof(short)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.ShortType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.int16_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.short_type_name,int16_type); //sbyte_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.sbyte_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.sbyte_type_name),typeof(sbyte)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.SByteType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.sbyte_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.sbyte_type_name,sbyte_type); //uint16_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.ushort_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.ushort_type_name),typeof(ushort)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.UShortType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.uint16_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.ushort_type_name,uint16_type); //uint32_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.uint_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.uint_type_name),typeof(uint)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.UIntType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.uint32_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.uint_type_name,uint32_type); //int64_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.long_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.long_type_name),typeof(long)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.Int64Type); if (type_name != null) cur_scope.AddName(type_name, TypeTable.int64_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.long_type_name,int64_type); //uint64_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.ulong_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.ulong_type_name),typeof(ulong)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.UInt64Type); if (type_name != null) cur_scope.AddName(type_name, TypeTable.uint64_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.ulong_type_name,uint64_type); //float_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.float_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.float_type_name),typeof(float)); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.FloatType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.float_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.float_type_name,float_type); //ptr_type = new CompiledScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.pointer_type_name, SymbolKind.Type,PascalABCCompiler.TreeConverter.compiler_string_consts.pointer_type_name),Type.GetType("System.Void*")); type_name = this.converter.controller.Parser.LanguageInformation.GetStandardTypeByKeyword(PascalABCCompiler.Parsers.KeywordKind.PointerType); if (type_name != null) cur_scope.AddName(type_name, TypeTable.ptr_type); //cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.pointer_type_name,ptr_type); ProcScope ps = new ProcScope(PascalABCCompiler.TreeConverter.compiler_string_consts.set_length_procedure_name,null); ps.AddParameter(new ElementScope(new SymInfo("arr", SymbolKind.Parameter,"arr"),new ArrayScope(),null,ps)); ps.parameters[0].param_kind = parametr_kind.var_parametr; ps.AddParameter(new ElementScope(new SymInfo("length", SymbolKind.Parameter,"length"),TypeTable.int_type,null,ps)); ps.Complete(); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.set_length_procedure_name,ps); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.true_const_name,new ElementScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.true_const_name, SymbolKind.Constant,PascalABCCompiler.TreeConverter.compiler_string_consts.true_const_name),TypeTable.bool_type,true,null)); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.false_const_name,new ElementScope(new SymInfo(PascalABCCompiler.TreeConverter.compiler_string_consts.false_const_name, SymbolKind.Constant,PascalABCCompiler.TreeConverter.compiler_string_consts.false_const_name),TypeTable.bool_type,false,null)); ps = new ProcScope(PascalABCCompiler.TreeConverter.compiler_string_consts.new_procedure_name,null); ElementScope prm = new ElementScope(new SymInfo("p", SymbolKind.Parameter,"p"),TypeTable.ptr_type,null,ps); prm.param_kind = parametr_kind.var_parametr; ps.AddParameter(prm); ps.Complete(); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.new_procedure_name,ps); ps = new ProcScope(PascalABCCompiler.TreeConverter.compiler_string_consts.dispose_procedure_name,null); prm = new ElementScope(new SymInfo("p", SymbolKind.Parameter,"p"),TypeTable.ptr_type,null,ps); prm.param_kind = parametr_kind.var_parametr; ps.AddParameter(prm); ps.Complete(); cur_scope.AddName(PascalABCCompiler.TreeConverter.compiler_string_consts.dispose_procedure_name,ps); }
public void AddDefaultConstructorIfNeed() { if (members != null) { bool has_def_constr = false; ProcScope last_constr = null; //SymScope cnstr_ss = this.FindNameOnlyInThisType("Create"); foreach (SymScope ss in members) if (ss is ProcScope && (ss as ProcScope).is_constructor) { /*if ((ss as ProcScope).parameters != null && (ss as ProcScope).parameters.Count==0) { has_def_constr = true; break; } else { //last_constr = ss as ProcScope; }*/ has_def_constr = true; } if (!has_def_constr) { ProcScope ps = new ProcScope("Create", this, true); ps.Complete(); /*if (cnstr_ss != null && cnstr_ss is ProcScope) //last_constr.nextProc = ps; ps.nextProc = cnstr_ss as ProcScope; //else*/ //ps.si.name = this.si.name; members.Insert(0, ps); } } }
private ProcScope CreateInterfaceNamespaceFunction(string name, int offset) { //Console.WriteLine(name); ProcScope cnfn = new ProcScope(name,cur_scope); cnfn.declaringUnit = root_scope; if (CanReadObject()) br.ReadInt32(); br.ReadBoolean();//ïðîïóñêàåì ôëàã - èíòåðôåéñíîñòè br.ReadInt32();//name index bool is_generic = br.ReadBoolean(); if (is_generic) { throw new NotSupportedException(); } if (br.ReadByte() == 1) { cnfn.return_type = GetTypeReference(); GetLocalVariable(cnfn); } int num_par = br.ReadInt32(); for (int i=0; i<num_par; i++) cnfn.parameters.Add(GetParameter(cnfn)); br.ReadInt32(); //namespace br.ReadInt32(); //attributes cnfn.is_forward = br.ReadBoolean(); cnfn.Complete(); AddMember(cnfn, offset); return cnfn; }
private ProcScope CreateInterfaceMethod(string name, int offset) { ProcScope cmn = members[offset] as ProcScope; if (cmn != null) return cmn; cmn = new ProcScope(name,cur_scope); cmn.declaringUnit = root_scope; //members[offset] = cmn; AddMember(cmn, offset); int name_ref = br.ReadInt32(); br.ReadByte(); br.ReadByte(); bool is_generic = br.ReadBoolean(); if (is_generic) { throw new NotSupportedException(); } //ssyy //\ssyy if (br.ReadByte() == 1) //return_value_type { cmn.return_type = GetTypeReference(); if (br.ReadByte() == 1) { GetLocalVariable(cmn); } } int num_par = br.ReadInt32(); for (int i = 0; i < num_par; i++) cmn.parameters.Add(GetParameter(cmn)); br.ReadInt32(); br.ReadInt32(); cmn.is_constructor = br.ReadBoolean(); cmn.is_forward = br.ReadBoolean(); br.ReadBoolean(); PascalABCCompiler.SemanticTree.field_access_level fal = (PascalABCCompiler.SemanticTree.field_access_level)br.ReadByte(); PascalABCCompiler.SemanticTree.polymorphic_state ps = (PascalABCCompiler.SemanticTree.polymorphic_state)br.ReadByte(); switch (fal) { case PascalABCCompiler.SemanticTree.field_access_level.fal_internal : cmn.acc_mod = access_modifer.internal_modifer; break; case PascalABCCompiler.SemanticTree.field_access_level.fal_private : cmn.acc_mod = access_modifer.private_modifer; return null; case PascalABCCompiler.SemanticTree.field_access_level.fal_protected : cmn.acc_mod = access_modifer.protected_modifer; break; case PascalABCCompiler.SemanticTree.field_access_level.fal_public : cmn.acc_mod = access_modifer.public_modifer; break; } switch (ps) { case PascalABCCompiler.SemanticTree.polymorphic_state.ps_static : cmn.is_static = true; break; case PascalABCCompiler.SemanticTree.polymorphic_state.ps_virtual : cmn.is_virtual = true; break; } br.ReadInt32(); br.ReadInt32(); cmn.is_override = br.ReadBoolean() == true; cmn.Complete(); return cmn; }
public override void visit(class_definition _class_definition) { //throw new Exception("The method or operation is not implemented."); SymScope tmp = cur_scope; TypeScope ss = null; returned_scope = null; if (_class_definition.class_parents != null && _class_definition.class_parents.types.Count > 0) _class_definition.class_parents.types[0].visit(this); if (returned_scope is TypeScope && has_cyclic_inheritance(returned_scope as TypeScope)) returned_scope = null; if (cur_type_name != null) ss = cur_scope.FindNameOnlyInType(cur_type_name) as TypeScope; if (ss == null || !(ss.members != null && ss.members.Count == 0)) { if (_class_definition.keyword == class_keyword.Record) { ss = new TypeScope(SymbolKind.Struct, cur_scope, returned_scope); if (cur_type_name == null) cur_type_name = "$record"; } else if (_class_definition.keyword == class_keyword.Class) { ss = new TypeScope(SymbolKind.Class, cur_scope, returned_scope); if (_class_definition.attribute == class_attribute.Sealed) ss.is_final = true; if (cur_type_name == null) cur_type_name = "$class"; } else if (_class_definition.keyword == class_keyword.Interface || _class_definition.keyword == class_keyword.TemplateInterface) { ss = new TypeScope(SymbolKind.Interface, cur_scope, returned_scope); if (cur_type_name == null) cur_type_name = "$interface"; } else if (_class_definition.keyword == class_keyword.TemplateClass) { ss = new TypeScope(SymbolKind.Class, cur_scope, returned_scope); if (cur_type_name == null) cur_type_name = "$class"; } else if (_class_definition.keyword == class_keyword.TemplateRecord) { ss = new TypeScope(SymbolKind.Struct, cur_scope, returned_scope); if (cur_type_name == null) cur_type_name = "$record"; } if (ss != null) cur_scope.AddName(cur_type_name, ss); } else ss.baseScope = returned_scope as TypeScope; int num = 0; if (_class_definition.keyword != class_keyword.Interface) num = 1; else ss.baseScope = null; if (_class_definition.class_parents != null && _class_definition.class_parents.types.Count > num) { for (int i=num; i<_class_definition.class_parents.types.Count; i++) { _class_definition.class_parents.types[i].visit(this); if (returned_scope != null && returned_scope is TypeScope && has_cyclic_inheritance(returned_scope as TypeScope)) returned_scope = null; if (returned_scope != null && returned_scope is TypeScope && (returned_scope as TypeScope).si.kind == SymbolKind.Interface) ss.AddImplementedInterface(returned_scope as TypeScope); } } if (has_cyclic_inheritance(ss)) ss.baseScope = null; ss.loc = get_location(_class_definition); cur_scope = ss; if (_class_definition.template_args != null) { foreach (ident id in _class_definition.template_args.idents) ss.AddGenericParameter(id.name); } else if (template_args != null) { foreach (ident id in template_args.idents) ss.AddGenericParameter(id.name); } string tmp_name = cur_type_name; cur_type_name = null; if (_class_definition.body != null) { _class_definition.body.visit(this); ss.body_loc = get_location(_class_definition); ss.real_body_loc = get_location(_class_definition.body); ss.AddDefaultConstructorIfNeed(); if (((_class_definition.attribute & PascalABCCompiler.SyntaxTree.class_attribute.Auto) == class_attribute.Auto)) { ProcScope ps = new ProcScope("Create", ss, true); foreach (class_members members in _class_definition.body.class_def_blocks) { foreach (declaration decl in members.members) { var_def_statement vds = decl as var_def_statement; if (vds == null) continue; vds.vars_type.visit(this); foreach (ident id in vds.vars.list) { ps.parameters.Add(new ElementScope(new SymInfo(id.name, SymbolKind.Parameter,id.name),returned_scope, ps)); } } } ps.return_type = ss; ps.Complete(); ss.AddName("Create", ps); } } cur_type_name = tmp_name; returned_scope = ss; cur_scope = tmp; }