public override void visit(class_definition cd) { type_declaration td = UpperNode(1) as type_declaration; if ((object)td == null) { // Something went wrong return; } if (td.type_name.name != _className.name) { // Not the class we search for // Yoda return; } if (cd.body == null) { return; } var properties = cd.body.class_def_blocks.SelectMany(cm => cm.members.Select(decl => decl as simple_property) .Where(name => (object)name != null) .Select(sp => sp.property_name)); CollectedProperties.UnionWith(properties); }
private type_declaration get_type_declaration(ICSharpCode.NRefactory.Ast.TypeDeclaration td) { type_declaration type_decl = new type_declaration(); type_decl.type_name = new ident(td.Name); if (td.Type == ICSharpCode.NRefactory.Ast.ClassType.Enum) { type_decl.type_def = get_enum_type(td); type_decl.source_context = type_decl.type_def.source_context; return(type_decl); } class_definition class_def = new class_definition(); class_def.source_context = get_source_context(td); if (td.Type == ICSharpCode.NRefactory.Ast.ClassType.Interface) { class_def.keyword = class_keyword.Interface; } else if (td.Type == ICSharpCode.NRefactory.Ast.ClassType.Struct) { class_def.keyword = class_keyword.Record; } class_def.class_parents = get_base_classes(td.BaseTypes); class_def.body = get_class_body(td); type_decl.type_def = class_def; type_decl.source_context = class_def.source_context; return(type_decl); }
public override void visit(class_definition cd) { type_declaration td = UpperNode(1) as type_declaration; if ((object)td == null) { // Something went wrong return; } if (td.type_name.name != _className.name) { // Not the class we search for // Yoda return; } var methods = cd.body.class_def_blocks.SelectMany(cm => cm.members.Select(decl1 => { if (decl1 is procedure_header) { return((decl1 as procedure_header).name.meth_name); } else if (decl1 is procedure_definition) { return((decl1 as procedure_definition).proc_header.name.meth_name); } return(null); }).Where(name => (object)name != null)); CollectedMethods.UnionWith(methods); }
public override void visit(class_definition _class_definition) { if (_class_definition.attribute != class_attribute.None) { text += _class_definition.attribute.ToString() + " "; } text += _class_definition.keyword.ToString(); }
public override void visit(class_definition _class_definition) { prepare_node(_class_definition.attr_list, "attr_list"); prepare_node(_class_definition.class_parents, "parents"); prepare_node(_class_definition.body, "body"); prepare_node(_class_definition.template_args, "template_args"); prepare_node(_class_definition.where_section, "where_section"); }
public class_definition NewRecordType(named_type_reference_list opt_base_classes, where_definition_list opt_where_section, class_body_list component_list_seq, LexLocation loc) { var nnrt = new class_definition(opt_base_classes, component_list_seq, class_keyword.Record, null, opt_where_section, class_attribute.None, false, loc); if (nnrt.body != null && nnrt.body.class_def_blocks != null && nnrt.body.class_def_blocks.Count > 0 && nnrt.body.class_def_blocks[0].access_mod == null) { nnrt.body.class_def_blocks[0].access_mod = new access_modifer_node(access_modifer.public_modifer); } return(nnrt); }
public override void visit(class_definition cd) { if (cd.keyword == class_keyword.Record && cd.Parent is var_def_statement) // безымянная запись { // то пропустить её - она вложенная, мы её уже обошли } else { base.visit(cd); } }
public override void visit(class_definition cl) { type_declarations tds = UpperNode(2) as type_declarations; if (PrintInfo) { var f = tds.types_decl.Find(td => td.type_def == cl); Console.WriteLine(" " + f.type_name); } base.visit(cl); }
public static class_definition BuildClassDefinition(named_type_reference_list parents, params class_members[] cms) { var cb = new class_body_list(); foreach (var cm in cms) { cb.Add(cm); } var cd = new class_definition(parents, cb); return(cd); }
public override void visit(class_definition cd) { type_declaration td = UpperNode(1) as type_declaration; if ((object)td == null) { // Something went wrong return; } if (td.type_name.name.ToLower() != _className.name.ToLower()) { // Not the class we search for // Yoda return; } if (cd.body == null) { return; } /*var fields = cd.body.class_def_blocks.SelectMany(cm => cm.members.Where(decl => decl is var_def_statement) * .Select(decl1 => (decl1 as var_def_statement).vars.idents) * .SelectMany(ids => ids.Select(id => id))); * * * CollectedFields.UnionWith(fields);*/ foreach (var defs in cd.body.class_def_blocks) { // Class members foreach (var decl in defs.members) { // Declaration: fields + procedure defs + headers + etc // Need vars if (decl is var_def_statement vds) { CollectedFields.UnionWith(vds.vars.idents); // Fields /*foreach (var field in vds.vars.idents) * { * CollectedFields.Add(field); * }*/ } else if (decl is simple_const_definition scd) { CollectedFields.Add(scd.const_name); } } } }
// frninja 23/04/16 - для шаблонных классов в yield public static class_definition BuildClassDefinition(named_type_reference_list parents, ident_list template_args, params class_members[] cms) { var cb = new class_body_list(); foreach (var cm in cms) { cb.Add(cm); } var cd = new class_definition(parents, cb, class_keyword.Class, template_args, null, class_attribute.None, false, null); return(cd); }
// var_def_statement.idents + // typed_parameters (параметры процедуры-функции) + // method_name + // template_type_name + // type_declaration.type_name // const_definition.constant_name + public override void visit(class_definition cd) { if (cd == StartUnnamedRecord) { //cd = cd; // то внутри нее не искать - мы как раз с ней и проверяем пересечение имен } else if (StartUnnamedRecord.source_context.In(cd.source_context)) { DefaultVisit(cd); } else { } }
public static class_definition BuildClassOrRecordDefinition(bool is_class, params class_members[] cms) { var cb = new class_body_list(); foreach (var cm in cms) { cb.Add(cm); } var cd = new class_definition(cb); if (!is_class) { cd.keyword = class_keyword.Record; } return(cd); }
public class_definition NewObjectType(class_attribute class_attributes, token_info class_or_interface_keyword, named_type_reference_list opt_base_classes, where_definition_list opt_where_section, class_body_list opt_not_component_list_seq_end, LexLocation loc) { var nnof = new class_definition(opt_base_classes, opt_not_component_list_seq_end, class_keyword.Class, null, opt_where_section, class_attribute.None, false, loc); string kw = class_or_interface_keyword.text.ToLower(); nnof.attribute = class_attributes; if (kw == "record") { nnof.keyword = class_keyword.Record; } else if (kw == "interface") { nnof.keyword = class_keyword.Interface; } else if (kw == "i") { nnof.keyword = class_keyword.TemplateInterface; } else if (kw == "r") { nnof.keyword = class_keyword.TemplateRecord; } else if (kw == "c") { nnof.keyword = class_keyword.TemplateClass; } if (nnof.body != null && ((class_definition)nnof).body.class_def_blocks != null && ((class_definition)nnof).body.class_def_blocks.Count > 0 && ((class_definition)nnof).body.class_def_blocks[0].access_mod == null) { if (nnof.keyword == class_keyword.Class) { nnof.body.class_def_blocks[0].access_mod = new access_modifer_node(access_modifer.internal_modifer); } else { nnof.body.class_def_blocks[0].access_mod = new access_modifer_node(access_modifer.none); } } return(nnof); }
public override void visit(class_definition cd) { type_declaration td = UpperNode(1) as type_declaration; if ((object)td == null) { // Something went wrong return; } if (td.type_name.name != _className.name) { // Not the class we search for // Yoda return; } if (cd.body == null) { return; } var fields = cd.body.class_def_blocks.SelectMany(cm => cm.members.Where(decl => decl is var_def_statement) .Select(decl1 => (decl1 as var_def_statement).vars.idents) .SelectMany(ids => ids.Select(id => id))); CollectedFields.UnionWith(fields); /*foreach (var defs in cd.body.class_def_blocks) * { * // Class members * foreach (var decl in defs.members) * { * // Declaration: fields + procedure defs + headers + etc * // Need vars * if (decl is var_def_statement) * { * var vars = (decl as var_def_statement).vars; * // Fields * foreach (var field in vars.idents) * { * CollectedFields.Add(field); * } * } * } * }*/ }
public string CreateTemplateInstance(List <type_node> instance_params, location loc) { class_definition cl_def = _type_decl.type_def as class_definition; template_type_name ttn = _type_decl.type_name as template_type_name; //if (cl_def == null) //{ // throw new PascalSharp.Internal.TreeConverter.CompilerInternalError("No body definition in template class."); //} //if (cl_def.template_args == null || cl_def.template_args.idents == null) //{ // throw new PascalSharp.Internal.TreeConverter.CompilerInternalError("No template arguments in syntax tree."); //} List <ident> template_formals = (_is_synonym) ? ttn.template_args.idents : cl_def.template_args.idents; if (instance_params.Count != template_formals.Count) { throw new PascalSharp.Internal.TreeConverter.SimpleSemanticError(loc, "TEMPLATE_ARGUMENTS_COUNT_MISMATCH"); } return(GetTemplateInstanceName(instance_params)); }
public CollectDefNamesFromMostUpperLocalContextVisitor(class_definition cd) { StartUnnamedRecord = cd; }
public virtual void visit(class_definition _class_definition) { DefaultVisit(_class_definition); }
public class_definition StartUnnamedRecord; // безымянная запись, до которой и для которой будем искать имена public static CollectDefNamesFromMostUpperLocalContextVisitor New(class_definition cd) { return(new CollectDefNamesFromMostUpperLocalContextVisitor(cd)); }
public OneUnnamedRecordCaptureNamesVisitor(class_definition cd) { StartUnnamedRecord = cd; }
public static OneUnnamedRecordCaptureNamesVisitor New(class_definition cd) { return(new OneUnnamedRecordCaptureNamesVisitor(cd)); }
public override void visit(simple_property _simple_property) { var property_parent_node = _simple_property.Parent; while (property_parent_node != null && property_parent_node.GetType() != typeof(class_members)) { property_parent_node = property_parent_node.Parent; } class_members property_class_members = property_parent_node as class_members; while (property_parent_node != null && property_parent_node.GetType() != typeof(class_body_list)) { property_parent_node = property_parent_node.Parent; } class_body_list class_body = property_parent_node as class_body_list; while (property_parent_node != null && property_parent_node.GetType() != typeof(class_definition)) { property_parent_node = property_parent_node.Parent; } class_definition class_def = property_parent_node as class_definition; var property_type = _simple_property.property_type; var read_accessor = _simple_property.accessors?.read_accessor; var write_accessor = _simple_property.accessors?.write_accessor; var new_class_members = new class_members(access_modifer.private_modifer); if (class_def.keyword == class_keyword.Interface && _simple_property.is_auto) { throw new SyntaxVisitorError( "INVALID_INTERFACE_MEMBER", _simple_property.source_context); } if (class_def.keyword == class_keyword.Interface && read_accessor != null && (read_accessor.pr != null || read_accessor.accessor_name != null)) { throw new SyntaxVisitorError( "INVALID_INTERFACE_MEMBER", read_accessor.source_context); } if (class_def.keyword == class_keyword.Interface && write_accessor != null && (write_accessor.pr != null || write_accessor.accessor_name != null)) { throw new SyntaxVisitorError( "INVALID_INTERFACE_MEMBER", write_accessor.source_context); } if (_simple_property.is_auto) { if (_simple_property.parameter_list != null) { throw new SyntaxVisitorError( "INDEXED_AUTO_PROPERTY", _simple_property.source_context); } AutoPropertyDesugaring(_simple_property, new_class_members); } // pr != null => extended read accessor if (read_accessor != null && read_accessor.pr != null) { ExtendedReadAccessorDesugaring(read_accessor, _simple_property, new_class_members); } // pr != null => extended write accessor if (write_accessor != null && write_accessor.pr != null) { ExtendedWriteAccessorDesugaring(write_accessor, _simple_property, new_class_members); } if (new_class_members.Count > 0) { class_body.InsertBefore(property_class_members, new_class_members); } }
public override void visit(class_definition _class_definition) { throw new NotImplementedException(); }
public virtual void visit(class_definition _class_definition) { }
public override void visit(class_definition _class_definition) { connect(_class_definition); visit_node(_class_definition.body); }
public virtual void post_do_visit(class_definition _class_definition) { }
// end frninja // names и types передаю во внешний мир на предмет анализа того, что они не указатели. Снаружи они инициализируются пустыми списками public static void AddMembersForAutoClass(class_definition cd, ref List <ident> names, ref List <type_definition> types) // SSM 24.03.14 { //var types = new List<type_definition>(); class_body_list cb = cd.body; bool HasToString = false; bool HasConstructor = false; bool HasDeconstruct = false; foreach (var l in cb.class_def_blocks) { foreach (var m in l.members) { var mm = m as var_def_statement; if (mm != null) { if (mm.var_attr != definition_attribute.Static) { foreach (var v in mm.vars.idents) { names.Add(v); if (mm.vars_type != null) { types.Add(mm.vars_type); // во внешний мир для определения pointerов } else { types.Add(BuildSameType(mm.inital_value)); // почему-то только так хочет работать с рекурсивным типом Node<T> } } } } else { var ts = m as procedure_definition; if (!HasConstructor) { if (ts != null && ts.proc_header is constructor && (ts.proc_header.parameters?.params_list.SelectMany(tp => tp.idents.idents).Count() ?? 0) == names.Count ) { HasConstructor = true; // на самом деле это означает, что есть конструктор с точно таким же количеством параметров } } if (!HasDeconstruct) { if (ts != null && ts.proc_header.name != null && ts.proc_header.name.meth_name.name != null) { HasDeconstruct = ts.proc_header.name.meth_name.name.ToLower().Equals("deconstruct"); } } if (!HasToString) { if (ts != null && ts.proc_header.name != null && ts.proc_header.name.meth_name.name != null) { HasToString = ts.proc_header.name.meth_name.name.ToUpper().Equals("TOSTRING"); } } } } } // добавление свойств - временно убрал т.к. свойства нельзя передавать как var-параметры // По идее если это делать, то поля переименовывать везде в классе!!! /*for (var i=0; i<names.Count; i++) * { * if (names[i].name.StartsWith("#")) * continue; * var propName = names[i].TypedClone(); * names[i].name = "!" + names[i].name; * var simpleProp = BuildSimpleReadWriteProperty(propName, names[i].name, types[i]); * var cm = BuildOneMemberSection(simpleProp); * cb.Add(cm); * }*/ if (!HasConstructor) { var fnames = names.Select(x => new ident("f" + x.name.ToLower(), x.source_context)).ToList(); if (fnames.Select(x => x.name).Distinct().Count() != names.Count) // SSM 20/05/2020 #2126 { return; // хак - мы не генерируем конструктор, потому что ошибка одинаковых имен выведется позже } var cm = BuildSimpleConstructorSection(names, fnames, types); cb.Insert(0, cm); //cb.class_def_blocks.Insert(0, cm); } if (!HasDeconstruct) { var fnames = names.Select(x => new ident("f" + x.name, x.source_context)).ToList(); var cm = BuildSimpleDeconstructSection(names, fnames, types); cb.Add(cm); } if (!HasToString) { var tostr = BuildToStringFuncForAutoClass(names); var cm = BuildOneMemberSection(tostr); cb.Add(cm); //cb.class_def_blocks.Insert(0, BuildOneMemberSection(tostr)); } }
public override void visit(class_definition _class_definition) { executer.visit(_class_definition); if (_class_definition.class_parents != null) this.visit((dynamic)_class_definition.class_parents); if (_class_definition.body != null) this.visit((dynamic)_class_definition.body); if (_class_definition.template_args != null) this.visit((dynamic)_class_definition.template_args); if (_class_definition.where_section != null) this.visit((dynamic)_class_definition.where_section); if (_class_definition.attr_list != null) this.visit((dynamic)_class_definition.attr_list); if (_class_definition.attributes != null) this.visit((dynamic)_class_definition.attributes); }
public override void visit(class_definition _class_definition) { DefaultVisit(_class_definition); pre_do_visit(_class_definition); visit(class_definition.class_parents); visit(class_definition.body); visit(class_definition.template_args); visit(class_definition.where_section); post_do_visit(_class_definition); }
// end frninja // names и types передаю во внешний мир на предмет анализа того, что они не указатели. Снаружи они инициализируются пустыми списками public static void AddMembersForAutoClass(class_definition cd, ref List <ident> names, ref List <type_definition> types) // SSM 24.03.14 { //var types = new List<type_definition>(); class_body_list cb = cd.body; bool HasToString = false; bool HasConstructor = false; bool HasDeconstruct = false; foreach (var l in cb.class_def_blocks) { foreach (var m in l.members) { var mm = m as var_def_statement; if (mm != null) { if (mm.var_attr != definition_attribute.Static) { foreach (var v in mm.vars.idents) { names.Add(v); if (mm.vars_type != null) { types.Add(mm.vars_type); // во внешний мир для определения pointerов } else { types.Add(BuildSameType(mm.inital_value)); // почему-то только так хочет работать с рекурсивным типом Node<T> } } } } else { var ts = m as procedure_definition; if (!HasConstructor) { if (ts != null && ts.proc_header is constructor) { HasConstructor = true; } } if (!HasDeconstruct) { if (ts != null && ts.proc_header.name != null && ts.proc_header.name.meth_name.name != null) { HasDeconstruct = ts.proc_header.name.meth_name.name.ToLower().Equals("deconstruct"); } } if (!HasToString) { if (ts != null && ts.proc_header.name != null && ts.proc_header.name.meth_name.name != null) { HasToString = ts.proc_header.name.meth_name.name.ToUpper().Equals("TOSTRING"); } } } } } if (!HasConstructor) { var fnames = names.Select(x => new ident("f" + x.name)).ToList(); var cm = BuildSimpleConstructorSection(names, fnames, types); cb.Insert(0, cm); //cb.class_def_blocks.Insert(0, cm); } if (!HasDeconstruct) { var fnames = names.Select(x => new ident("f" + x.name)).ToList(); var cm = BuildSimpleDeconstructSection(names, fnames, types); cb.Add(cm); } if (!HasToString) { var tostr = BuildToStringFuncForAutoClass(names); cb.Add(BuildOneMemberSection(tostr)); //cb.class_def_blocks.Insert(0, BuildOneMemberSection(tostr)); } }