private static ident TypeclassRestrctionToTemplateName(string name, template_param_list restriction_args)
 {
     // Concatenate type constraint into new type name
     // For example:
     //      Constaint[T, C] => ConstraintTC
     return(RestrictionsToIdentList(restriction_args).idents.Aggregate(
                new ident(name), (x, y) => x.name + y.name));
 }
        private static ident_list RestrictionsToIdentList(template_param_list restrictions)
        {
            var templates = new ident_list();

            templates.source_context = restrictions.source_context;
            for (int i = 0; i < restrictions.Count; i++)
            {
                templates.Add((restrictions.params_list[i] as named_type_reference).names[0]);
            }

            return(templates);
        }
 public override void visit(template_param_list _template_param_list)
 {
     get_count(_template_param_list.params_list);
 }
 public virtual void visit(template_param_list _template_param_list)
 {
     DefaultVisit(_template_param_list);
 }
		public override void visit(template_param_list _template_param_list)
		{
			DefaultVisit(_template_param_list);
			pre_do_visit(_template_param_list);
			for (int i = 0; i < params_list.Count; i++)
				visit(template_param_list.params_list[i]);
			post_do_visit(_template_param_list);
		}
		public virtual void post_do_visit(template_param_list _template_param_list)
		{
		}
Exemple #7
0
 public virtual void visit(template_param_list _template_param_list)
 {
 }
Exemple #8
0
 public override void visit(template_param_list _template_param_list)
 {
     throw new NotImplementedException();
 }
 private static template_type_reference TypeclassReferenceToInterfaceName(string name, template_param_list restriction_args)
 {
     return(new template_type_reference(
                new named_type_reference("I" + name), restriction_args));
 }
Exemple #10
0
        type_declarations GenClassesForYield(procedure_definition pd, IEnumerable <var_def_statement> fields)
        {
            var fh = (pd.proc_header as function_header);

            if (fh == null)
            {
                throw new SyntaxError("Only functions can contain yields", "", pd.proc_header.source_context, pd.proc_header);
            }
            var seqt = fh.return_type as sequence_type;

            if (seqt == null)
            {
                throw new SyntaxError("Functions with yields must return sequences", "", fh.return_type.source_context, fh.return_type);
            }

            // Теперь на месте функции генерируем класс

            // Захваченные переменные
            var cm = class_members.Public;

            foreach (var m in fields)
            {
                cm.Add(m);
            }

            // Параметры функции
            List <ident> lid  = new List <ident>();
            var          pars = fh.parameters;

            if (pars != null)
            {
                foreach (var ps in pars.params_list)
                {
                    if (ps.param_kind != parametr_kind.none)
                    {
                        throw new SyntaxError("Parameters of functions with yields must not have 'var', 'const' or 'params' modifier", "", pars.source_context, pars);
                    }
                    if (ps.inital_value != null)
                    {
                        throw new SyntaxError("Parameters of functions with yields must not have initial values", "", pars.source_context, pars);
                    }
                    var_def_statement vds = new var_def_statement(ps.idents, ps.vars_type);
                    cm.Add(vds); // все параметры функции делаем полями класса
                    lid.AddRange(vds.vars.idents);
                }
            }

            var stels = seqt.elements_type;

            // Системные поля и методы для реализации интерфейса IEnumerable
            cm.Add(new var_def_statement(Consts.State, "integer"),
                   new var_def_statement(Consts.Current, stels),
                   procedure_definition.EmptyDefaultConstructor,
                   new procedure_definition("Reset"),
                   new procedure_definition("MoveNext", "boolean", pd.proc_body),
                   new procedure_definition("get_Current", "object", new assign("Result", Consts.Current)),
                   new procedure_definition("GetEnumerator", "System.Collections.IEnumerator", new assign("Result", "Self"))
                   );

            var className       = newClassName();
            var classNameHelper = className + "Helper";

            var interfaces = new named_type_reference_list("System.Collections.IEnumerator", "System.Collections.IEnumerable");
            var td         = new type_declaration(classNameHelper, SyntaxTreeBuilder.BuildClassDefinition(interfaces, cm));

            // Изменение тела процедуры

            var stl = new statement_list(new var_statement("res", new new_expr(className)));

            stl.AddMany(lid.Select(id => new assign(new dot_node("res", id), id)));
            stl.Add(new assign("Result", "res"));
            pd.proc_body = new block(stl);

            // Второй класс

            var tpl = new template_param_list(stels);

            var IEnumeratorT = new template_type_reference("System.Collections.Generic.IEnumerator", tpl);

            var cm1 = class_members.Public.Add(
                procedure_definition.EmptyDefaultConstructor,
                new procedure_definition(new function_header("get_Current", stels), new assign("Result", Consts.Current)),
                new procedure_definition(new function_header("GetEnumerator", IEnumeratorT), new assign("Result", "Self")),
                new procedure_definition("Dispose")
                );

            var interfaces1  = new named_type_reference_list(classNameHelper);
            var IEnumerableT = new template_type_reference("System.Collections.Generic.IEnumerable", tpl);

            interfaces1.Add(IEnumerableT).Add(IEnumeratorT);

            var td1 = new type_declaration(className, SyntaxTreeBuilder.BuildClassDefinition(interfaces1, cm1));

            var cct = new type_declarations(td);

            cct.Add(td1);

            return(cct);
        }
		public virtual void visit(template_param_list _template_param_list)
		{
			DefaultVisit(_template_param_list);
		}
Exemple #12
0
 public override void visit(template_param_list _template_param_list)
 {
     prepare_collection(_template_param_list.params_list, "params_list");
     prepare_node(_template_param_list.dereferencing_value, "dereferencing_value");
 }
        public override void visit(ident id)
        {
            var idName = id.name.ToLower();

            SymbolInfo si = _visitor.context.find_first(idName);

            //var q = si.GetHashCode();

            if (si == null)
            {
                /*if (InLambdaContext)
                 * {
                 *  _visitor.AddError(new ThisTypeOfVariablesCannotBeCaptured(_visitor.get_location(id)));
                 *  return;
                 * }*/
                return;
            }

            if (si.sym_info.semantic_node_type == semantic_node_type.namespace_variable ||
                si.sym_info.semantic_node_type == semantic_node_type.common_namespace_function_node ||
                si.sym_info.semantic_node_type == semantic_node_type.namespace_constant_definition ||
                si.sym_info.semantic_node_type == semantic_node_type.compiled_function_node ||
                //si.sym_info.semantic_node_type == semantic_node_type.common_method_node || // SSM bug fix  #1991 11.06.19  конкурирует с #891
                si.sym_info.semantic_node_type == semantic_node_type.compiled_namespace_node ||
                si.sym_info.semantic_node_type == semantic_node_type.compiled_variable_definition ||
                si.sym_info.semantic_node_type == semantic_node_type.common_type_node ||
                si.sym_info.semantic_node_type == semantic_node_type.compiled_type_node ||
                si.sym_info.semantic_node_type == semantic_node_type.basic_interface_node ||
                si.sym_info.semantic_node_type == semantic_node_type.common_unit_node ||
                si.sym_info.semantic_node_type == semantic_node_type.common_namespace_node ||
                si.sym_info.semantic_node_type == semantic_node_type.compiled_unit_node ||
                si.sym_info.semantic_node_type == semantic_node_type.template_type ||
                si.sym_info.semantic_node_type == semantic_node_type.ref_type_node ||
                si.sym_info.semantic_node_type == semantic_node_type.generic_indicator ||
                si.sym_info.semantic_node_type == semantic_node_type.class_constant_definition ||
                si.sym_info.semantic_node_type == semantic_node_type.function_constant_definition || // SSM 03.11.18 bug fix #1449
                si.sym_info.semantic_node_type == semantic_node_type.basic_function_node && (idName == "exit" || idName == "continue" || idName == "break"))
            {
                return;
            }

            var acceptableVarType = si.sym_info.semantic_node_type == semantic_node_type.local_variable ||
                                    si.sym_info.semantic_node_type == semantic_node_type.local_block_variable ||
                                    si.sym_info.semantic_node_type == semantic_node_type.common_parameter ||
                                    si.sym_info.semantic_node_type == semantic_node_type.class_field ||
                                    si.sym_info.semantic_node_type == semantic_node_type.basic_property_node
            ;

            //trjuk, chtoby ne perelopachivat ves kod. zamenjaem ident na self.ident
            // Использую этот трюк для нестатических полей предков - они не захватываются из-за плохого алгоритма захвата
            // aab 12.06.19 begin
            // Добавил такое же переименование для статичесских полей класса. Теперь захват работает
            if ((si.sym_info.semantic_node_type == semantic_node_type.class_field || si.sym_info.semantic_node_type == semantic_node_type.common_method_node ||
                 si.sym_info.semantic_node_type == semantic_node_type.common_event || si.sym_info.semantic_node_type == semantic_node_type.common_property_node ||
                 si.sym_info.semantic_node_type == semantic_node_type.basic_property_node) && InLambdaContext)
            {
                dot_node dn = null;
                // Поменял принцип добавления имени класса для статических полей и функций
                Func <common_type_node, addressed_value> getClassIdent = classNode =>
                {
                    if (classNode.name.Contains("<"))
                    {
                        var classIdent     = new ident(classNode.name.Remove(classNode.name.IndexOf("<")));
                        var templateParams = new template_param_list(classNode.instance_params.Select(x => x.name) /*.Aggregate("", (acc, elem) => acc += elem)*/);
                        return(new ident_with_templateparams(classIdent, templateParams));
                    }
                    else
                    {
                        return(new ident(classNode.name));
                    }
                };
                if (si.sym_info is class_field classField && classField.IsStatic)
                {
                    dn = new dot_node(getClassIdent(classField.cont_type),
                                      new ident(id.name, id.source_context), id.source_context);
                }
                else if (si.sym_info is common_method_node commonMethodNode && commonMethodNode.IsStatic)
                {
                    dn = new dot_node(getClassIdent(commonMethodNode.cont_type),
                                      new ident(id.name, id.source_context), id.source_context);
                }
		public override void visit(template_param_list _template_param_list)
		{
			executer.visit(_template_param_list);
			if (_template_param_list.params_list != null)
			foreach (dynamic x in _template_param_list.params_list)
				if(x != null)
					this.visit(x);
			if (_template_param_list.dereferencing_value != null)
				this.visit((dynamic)_template_param_list.dereferencing_value);
			if (_template_param_list.attributes != null)
				this.visit((dynamic)_template_param_list.attributes);
		}