Ejemplo n.º 1
0
 public override void visit(type_declarations _type_declarations)
 {
     AddPossibleComments(_type_declarations, true, false);
     foreach (type_declaration td in _type_declarations.types_decl)
     {
         td.visit(this);
     }
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public override void visit(type_declarations _type_declarations)
 {
     get_count(_type_declarations.types_decl);
 }
Ejemplo n.º 4
0
 public virtual void visit(type_declarations _type_declarations)
 {
     DefaultVisit(_type_declarations);
 }
Ejemplo n.º 5
0
		public virtual void post_do_visit(type_declarations _type_declarations)
		{
		}
Ejemplo n.º 6
0
		public override void visit(type_declarations _type_declarations)
		{
			DefaultVisit(_type_declarations);
			pre_do_visit(_type_declarations);
			for (int i = 0; i < types_decl.Count; i++)
				visit(type_declarations.types_decl[i]);
			post_do_visit(_type_declarations);
		}
Ejemplo n.º 7
0
 public virtual void visit(type_declarations _type_declarations)
 {
 }
 public override void visit(type_declarations _type_declarations)
 {
     visit_collection(_type_declarations.types_decl);
 }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
		public virtual void visit(type_declarations _type_declarations)
		{
		}
		public virtual void visit(type_declarations _type_declarations)
		{
			DefaultVisit(_type_declarations);
		}
Ejemplo n.º 12
0
 public override void visit(type_declarations _type_declarations)
 {
     prepare_collection(_type_declarations.types_decl, "type definition");
 }
Ejemplo n.º 13
0
		public override void visit(type_declarations _type_declarations)
		{
			executer.visit(_type_declarations);
			if (_type_declarations.types_decl != null)
			foreach (dynamic x in _type_declarations.types_decl)
				if(x != null)
					this.visit(x);
			if (_type_declarations.attributes != null)
				this.visit((dynamic)_type_declarations.attributes);
		}