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 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);
            }
Ejemplo n.º 3
0
 public override void visit(where_definition_list node)
 {
     get_count(node.defs);
 }
Ejemplo n.º 4
0
 public virtual void visit(where_definition_list _where_definition_list)
 {
     DefaultVisit(_where_definition_list);
 }
Ejemplo n.º 5
0
		public override void visit(where_definition_list _where_definition_list)
		{
			DefaultVisit(_where_definition_list);
			pre_do_visit(_where_definition_list);
			for (int i = 0; i < defs.Count; i++)
				visit(where_definition_list.defs[i]);
			post_do_visit(_where_definition_list);
		}
Ejemplo n.º 6
0
		public virtual void post_do_visit(where_definition_list _where_definition_list)
		{
		}
Ejemplo n.º 7
0
 public virtual void visit(where_definition_list _where_definition_list)
 {
 }
        bool VisitInstanceDeclaration(type_declaration instanceDeclaration)
        {
            var instanceDefinition = instanceDeclaration.type_def as instance_definition;

            if (instanceDefinition == null)
            {
                return(false);
            }
            var instanceName = instanceDeclaration.type_name as typeclass_restriction;

            // If it is instance of derived typelass than it should have template parameters
            var templateArgs = new ident_list();
            where_definition_list whereSection = null;
            var originalTypeclass = instancesAndRestrictedFunctions.typeclasses[instanceName.name].type_def as typeclass_definition;
            var typeclassParents  = originalTypeclass.additional_restrictions;

            if (typeclassParents != null && typeclassParents.Count > 0)
            {
                whereSection = new where_definition_list();

                for (int i = 0; i < typeclassParents.Count; i++)
                {
                    ident template_name;
                    if (typeclassParents[i] is typeclass_reference tr)
                    {
                        string name = tr.names[0].name;
                        template_name = TypeclassRestrctionToTemplateName(name, tr.restriction_args);

                        whereSection.Add(GetWhereRestriction(
                                             TypeclassReferenceToInterfaceName(name, instanceName.restriction_args),
                                             template_name));
                    }
                    else
                    {
                        throw new NotImplementedException("Should be syntactic error");
                    }
                    templateArgs.Add(template_name);
                }
            }

            List <type_definition> templateLists = instanceName.restriction_args.params_list.Concat(templateArgs.idents.Select(x => new named_type_reference(x.name)).OfType <type_definition>()).ToList();
            var parents = new named_type_reference_list(new List <named_type_reference> {
                new template_type_reference(instanceName.name, new template_param_list(templateLists)),
                new template_type_reference("I" + instanceName.name, instanceName.restriction_args)
            });
            var instanceDefTranslated =
                SyntaxTreeBuilder.BuildClassDefinition(
                    parents,
                    null, instanceDefinition.body.class_def_blocks.ToArray());

            instanceDefTranslated.template_args  = templateArgs;
            instanceDefTranslated.where_section  = whereSection;
            instanceDefTranslated.source_context = instanceDefinition.source_context;

            for (int i = 0; i < instanceDefTranslated.body.class_def_blocks.Count; i++)
            {
                var cm = instanceDefTranslated.body.class_def_blocks[i].members;

                for (int j = 0; j < cm.Count; j++)
                {
                    procedure_header header = null;
                    if (cm[j] is procedure_header ph)
                    {
                        cm[j] = ph;
                    }
                    else if (cm[j] is procedure_definition pd)
                    {
                        header = pd.proc_header;
                    }
                    header.proc_attributes.Add(new procedure_attribute("override", proc_attribute.attr_override));
                    ConvertOperatorNameIdent(header);
                }
            }

            /*
             * {
             *  // Add constructor
             *  var cm = instanceDefTranslated.body.class_def_blocks[0];
             *  var def = new procedure_definition(
             *      new constructor(),
             *      new statement_list(new empty_statement()));
             *  def.proc_body.Parent = def;
             *  def.proc_header.proc_attributes = new procedure_attributes_list();
             *
             *  cm.Add(def);
             * }
             */
            var typeName = new ident(CreateInstanceName(instanceName.restriction_args as typeclass_param_list, instanceName.name), instanceName.source_context);

            var instanceDeclTranslated = new type_declaration(typeName, instanceDefTranslated, instanceDeclaration.source_context);

            instanceDeclTranslated.attributes = instanceDeclaration.attributes;
            AddAttribute(
                instanceDeclTranslated, "__TypeclassInstanceAttribute",
                new expression_list(new string_const(TypeclassRestrictionToString(instanceName))));
            AddAttribute(instanceDeclTranslated, "__TypeclassAttribute",
                         new expression_list(new string_const(TypeclassRestrictionToString(
                                                                  (originalTypeclass.Parent as type_declaration).type_name as typeclass_restriction))));

            Replace(instanceDeclaration, instanceDeclTranslated);
            visit(instanceDeclTranslated);

            return(true);
        }
Ejemplo n.º 9
0
 public override void visit(where_definition_list _where_definition_list)
 {
     throw new NotImplementedException();
 }
		public virtual void visit(where_definition_list _where_definition_list)
		{
			DefaultVisit(_where_definition_list);
		}
Ejemplo n.º 11
0
 public override void visit(where_definition_list node)
 {
     prepare_collection(node.defs, "defs");
 }
Ejemplo n.º 12
0
        public static procedure_definition BuildShortProcDefinition(formal_parameters fp, procedure_attributes_list att, method_name name, statement st, where_definition_list wdl, SourceContext headsc)
        {
            var ff = new procedure_header(fp, att, name, wdl, headsc);

            return(BuildShortProcFuncDefinition(ff, st));
        }
Ejemplo n.º 13
0
		public override void visit(where_definition_list _where_definition_list)
		{
			executer.visit(_where_definition_list);
			if (_where_definition_list.defs != null)
			foreach (dynamic x in _where_definition_list.defs)
				if(x != null)
					this.visit(x);
		}