Ejemplo n.º 1
0
 public override void visit(procedure_header _procedure_header)
 {
     AddPossibleComments(_procedure_header, true, false);
     _procedure_header.name.visit(this);
     if (_procedure_header.parameters != null)
     {
         _procedure_header.parameters.visit(this);
     }
     if (_procedure_header.proc_attributes != null)
     {
         _procedure_header.proc_attributes.visit(this);
     }
     if (_procedure_header.where_defs != null)
     {
         _procedure_header.where_defs.visit(this);
     }
 }
Ejemplo n.º 2
0
        private procedure_header get_method_header(ICSharpCode.NRefactory.Ast.MethodDeclaration method)
        {
            procedure_header proc_header;

            if (is_void(method.TypeReference))
            {
                proc_header = new procedure_header();
            }
            else
            {
                proc_header = new function_header();
            }
            proc_header.name           = new method_name();
            proc_header.name.meth_name = new ident(method.Name);
            proc_header.source_context = get_source_context(method);
            if (proc_header is function_header)
            {
                (proc_header as function_header).return_type = get_type_reference(method.TypeReference);
            }
            proc_header.parameters      = get_parameters(method.Parameters);
            proc_header.proc_attributes = new procedure_attributes_list();
            if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Abstract) == ICSharpCode.NRefactory.Ast.Modifiers.Abstract)
            {
                proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_abstract));
            }
            if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Virtual) == ICSharpCode.NRefactory.Ast.Modifiers.Virtual)
            {
                proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_virtual));
            }
            if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Override) == ICSharpCode.NRefactory.Ast.Modifiers.Override)
            {
                proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_override));
            }
            //if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Overloads) == ICSharpCode.NRefactory.Ast.Modifiers.Overloads)
            //	proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_overload));
            if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.New) == ICSharpCode.NRefactory.Ast.Modifiers.New)
            {
                proc_header.proc_attributes.proc_attributes.Add(new procedure_attribute(proc_attribute.attr_reintroduce));
            }
            if ((method.Modifier & ICSharpCode.NRefactory.Ast.Modifiers.Static) == ICSharpCode.NRefactory.Ast.Modifiers.Static)
            {
                proc_header.class_keyword = true;
            }
            return(proc_header);
        }
Ejemplo n.º 3
0
 public procedure_header NewProcfuncHeading(procedure_header ph)
 {
     //ph.name.explicit_interface_name = ph.name.class_name;
     //ph.name.class_name = null;
     return(ph);
 }
Ejemplo n.º 4
0
 /*public override void visit(typed_parameters tp)
  * {
  *  AddIdentList(tp.idents);
  * }*/
 public override void visit(procedure_header h)
 {
     AddProcHeader(h);
 }
Ejemplo n.º 5
0
 public virtual void visit(procedure_header _procedure_header)
 {
     DefaultVisit(_procedure_header);
 }
Ejemplo n.º 6
0
		public virtual void post_do_visit(procedure_header _procedure_header)
		{
		}
Ejemplo n.º 7
0
		public override void visit(procedure_header _procedure_header)
		{
			DefaultVisit(_procedure_header);
			pre_do_visit(_procedure_header);
			visit(procedure_header.parameters);
			visit(procedure_header.proc_attributes);
			visit(procedure_header.name);
			visit(procedure_header.template_args);
			visit(procedure_header.where_defs);
			post_do_visit(_procedure_header);
		}
Ejemplo n.º 8
0
        public static procedure_definition BuildShortProcDefinition(formal_parameters fp, procedure_attributes_list att, method_name name, statement st, SourceContext headsc)
        {
            var ff = new procedure_header(fp, att, name, null, headsc);

            return(BuildShortProcFuncDefinition(ff, st));
        }
Ejemplo n.º 9
0
 public virtual void visit(procedure_header _procedure_header)
 {
 }
        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);
        }
        bool VisitTypeclassDeclaration(type_declaration typeclassDeclaration)
        {
            var typeclassDefinition = typeclassDeclaration.type_def as typeclass_definition;

            if (typeclassDefinition == null)
            {
                return(false);
            }

            var typeclassName = typeclassDeclaration.type_name as typeclass_restriction;

            // TODO: typeclassDefinition.additional_restrictions - translate to usual classes

            // Creating interface

            // Get members for typeclass interface
            var interfaceMembers = new List <class_members>();

            foreach (var cm in typeclassDefinition.body.class_def_blocks)
            {
                var cmNew = (class_members)cm.Clone();

                for (int i = 0; i < cmNew.members.Count; i++)
                {
                    var member = cmNew.members[i];
                    if (member is function_header || member is procedure_header)
                    {
                        cmNew.members[i] = member;
                    }
                    else if (member is procedure_definition procDef)
                    {
                        cmNew.members[i] = procDef.proc_header;
                    }
                    AddAttribute(cmNew.members[i], "__TypeclassMemberAttribute");
                    if (cmNew.members[i] is procedure_header ph)
                    {
                        ConvertOperatorNameIdent(ph);
                    }
                }

                interfaceMembers.Add(cmNew);
            }
            var interfaceInheritance = (named_type_reference_list)typeclassDefinition.additional_restrictions?.Clone();

            if (interfaceInheritance != null)
            {
                interfaceInheritance.source_context = null;
                for (int i = 0; i < interfaceInheritance.types.Count; i++)
                {
                    if (interfaceInheritance.types[i] is typeclass_reference tr)
                    {
                        interfaceInheritance.types[i] = TypeclassReferenceToInterfaceName(tr.names[0].name, tr.restriction_args);
                    }
                    else
                    {
                        throw new NotImplementedException("Syntactic Error");
                    }
                }
            }
            var typeclassInterfaceDef =
                SyntaxTreeBuilder.BuildClassDefinition(
                    interfaceInheritance,
                    null, interfaceMembers.ToArray());

            typeclassInterfaceDef.keyword = class_keyword.Interface;
            var typeclassInterfaceName = new template_type_name("I" + typeclassName.name, RestrictionsToIdentList(typeclassName.restriction_args));
            var typeclassInterfaceDecl = new type_declaration(typeclassInterfaceName, typeclassInterfaceDef);

            typeclassInterfaceDecl.attributes = typeclassDeclaration.attributes;
            AddAttribute(
                typeclassInterfaceDecl, "__TypeclassAttribute",
                new expression_list(new string_const(TypeclassRestrictionToString(typeclassName))));


            // Creating class

            var typeclassDefTranslated =
                SyntaxTreeBuilder.BuildClassDefinition(
                    new named_type_reference_list(new template_type_reference(typeclassInterfaceName.name, typeclassName.restriction_args)),
                    null, typeclassDefinition.body.class_def_blocks.ToArray());

            typeclassDefTranslated.attribute = class_attribute.Abstract;
            for (int i = 0; i < typeclassDefTranslated.body.class_def_blocks.Count; i++)
            {
                var cm = typeclassDefTranslated.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)
                    {
                        header = ph;
                        header.proc_attributes.Add(new procedure_attribute("abstract", proc_attribute.attr_abstract));
                    }
                    else if (cm[j] is procedure_definition pd)
                    {
                        header = pd.proc_header;
                        header.proc_attributes.Add(new procedure_attribute("virtual", proc_attribute.attr_virtual));
                    }

                    ConvertOperatorNameIdent(header);
                }
            }

            /*
             * {
             *  // Add constructor
             *  var cm = typeclassDefTranslated.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);
             * }
             */
            // Add template parameters for typeclass class(derived typeclasses)
            ident_list templates = RestrictionsToIdentList(typeclassName.restriction_args);

            if (typeclassDefinition.additional_restrictions != null)
            {
                for (int i = 0; i < typeclassDefinition.additional_restrictions.types.Count; i++)
                {
                    string name;
                    string templateName;
                    if (typeclassDefinition.additional_restrictions.types[i] is typeclass_reference tr)
                    {
                        name         = tr.names[0].name;
                        templateName = TypeclassRestrctionToTemplateName(name, tr.restriction_args).name;
                    }
                    else
                    {
                        throw new NotImplementedException("SyntaxError");
                    }

                    // Add template parameter
                    templates.Add(templateName);

                    // Add where restriction
                    if (typeclassDefTranslated.where_section == null)
                    {
                        typeclassDefTranslated.where_section = new where_definition_list();
                    }
                    typeclassDefTranslated.where_section.Add(GetWhereRestriction(
                                                                 interfaceInheritance.types[i],
                                                                 templateName));

                    // Add methods from derived typeclasses
                    var body = (instancesAndRestrictedFunctions.typeclasses[name].type_def as typeclass_definition).body;
                    foreach (var cdb in body.class_def_blocks)
                    {
                        var cdbNew = new class_members(cdb.access_mod == null ? access_modifer.none : cdb.access_mod.access_level);
                        foreach (var member in cdb.members)
                        {
                            procedure_header memberHeaderNew;

                            if (member is procedure_header || member is function_header)
                            {
                                memberHeaderNew = (procedure_header)member.Clone();
                                memberHeaderNew.source_context = null;
                            }
                            else if (member is procedure_definition procDefinition)
                            {
                                memberHeaderNew                = (procedure_header)procDefinition.proc_header.Clone();
                                memberHeaderNew.Parent         = null;
                                memberHeaderNew.source_context = null;
                            }
                            else
                            {
                                continue;
                            }

                            var variableName = templateName + "Instance";
                            var parameters   = memberHeaderNew.parameters.params_list.Aggregate(new expression_list(), (x, y) => new expression_list(x.expressions.Concat(y.idents.idents).ToList()));

                            expression methodCall = null;
                            if (memberHeaderNew.name.meth_name is operator_name_ident oni)
                            {
                                ConvertOperatorNameIdent(memberHeaderNew);
                                Debug.Assert(parameters.expressions.Count == 2, "Parameters count for operation should be equal to 2");
                                //methodCall = new bin_expr(parameters.expressions[0], parameters.expressions[1], oni.operator_type);
                            }
                            var callName = new dot_node(variableName, memberHeaderNew.name.meth_name.name);
                            methodCall = new method_call(callName, parameters);
                            statement exec = null;
                            if (memberHeaderNew is function_header)
                            {
                                exec = new assign("Result", methodCall);
                            }
                            else if (memberHeaderNew is procedure_header)
                            {
                                exec = new procedure_call(methodCall as method_call);
                            }
                            var procDef = new procedure_definition(
                                memberHeaderNew,
                                new statement_list(
                                    GetInstanceSingletonVarStatement(templateName),
                                    exec));
                            cdbNew.Add(procDef);
                        }
                        typeclassDefTranslated.body.class_def_blocks.Add(cdbNew);
                    }
                }
            }

            var typeclassNameTanslated = new template_type_name(typeclassName.name, templates, typeclassName.source_context);

            var typeclassDeclTranslated = new type_declaration(typeclassNameTanslated, typeclassDefTranslated, typeclassDeclaration.source_context);

            typeclassDeclTranslated.attributes = typeclassDeclaration.attributes;
            AddAttribute(
                typeclassDeclTranslated, "__TypeclassAttribute",
                new expression_list(new string_const(TypeclassRestrictionToString(typeclassName))));

            Replace(typeclassDeclaration, typeclassDeclTranslated);
            UpperNodeAs <type_declarations>().InsertBefore(typeclassDeclTranslated, typeclassInterfaceDecl);
            visit(typeclassInterfaceDecl);
            visit(typeclassDeclTranslated);

            return(true);
        }
 public override void visit(procedure_header _procedure_header)
 {
     connect(_procedure_header);
 }
Ejemplo n.º 13
0
 public override void visit(procedure_header proc_header)
 {
     // DO THIS THING!
 }
Ejemplo n.º 14
0
		public virtual void visit(procedure_header _procedure_header)
		{
		}
		public virtual void visit(procedure_header _procedure_header)
		{
			DefaultVisit(_procedure_header);
		}
Ejemplo n.º 16
0
		public override void visit(procedure_header _procedure_header)
		{
			executer.visit(_procedure_header);
			if (_procedure_header.parameters != null)
				this.visit((dynamic)_procedure_header.parameters);
			if (_procedure_header.proc_attributes != null)
				this.visit((dynamic)_procedure_header.proc_attributes);
			if (_procedure_header.name != null)
				this.visit((dynamic)_procedure_header.name);
			if (_procedure_header.template_args != null)
				this.visit((dynamic)_procedure_header.template_args);
			if (_procedure_header.where_defs != null)
				this.visit((dynamic)_procedure_header.where_defs);
			if (_procedure_header.attr_list != null)
				this.visit((dynamic)_procedure_header.attr_list);
			if (_procedure_header.attributes != null)
				this.visit((dynamic)_procedure_header.attributes);
		}