Ejemplo n.º 1
0
 public virtual TypeScope GetInstance(List<TypeScope> gen_args)
 {
     TypeScope ts = new TypeScope(this.kind, this.topScope, this.baseScope);
     ts.original_type = this;
     ts.loc = this.loc;
     for (int i = 0; i < gen_args.Count; i++)
     {
         ts.AddGenericParameter(gen_args[i].si.name);
         ts.AddGenericInstanciation(gen_args[i]);
     }
     ts.si.name = this.si.name;
     ts.documentation = this.documentation;
     ts.si.description = ts.GetDescription();
     if (this.elementType != null)
     {
         ts.elementType = internalInstance(this.elementType, gen_args);
     }
     if (this.indexers != null && this.indexers.Count > 0)
     {
         ts.indexers = new List<TypeScope>();
         for (int j = 0; j < this.indexers.Count; j++)
             ts.indexers.Add(internalInstance(this.indexers[j], gen_args));
     }
     Hashtable procs = new Hashtable();
     for (int i = 0; i < members.Count; i++)
     {
         SymScope ss = members[i];
         ts.members.Add(ss);
         if (ss is ElementScope)
         {
             ElementScope es = ss as ElementScope;
             ElementScope new_es = new ElementScope(new SymInfo(es.si.name, es.si.kind, es.si.name), es.sc, ts);
             ts.members[i] = new_es;
             new_es.loc = es.loc;
             new_es.documentation = es.documentation;
             new_es.si.acc_mod = es.si.acc_mod;
             new_es.si.has_doc = es.si.has_doc;
             if (es.indexers != null && es.indexers.Count > 0)
             {
                 new_es.indexers = new List<TypeScope>();
                 for (int j = 0; j < es.indexers.Count; j++)
                     new_es.indexers.Add(internalInstance(es.indexers[j], gen_args));
             }
             if (es.elementType != null)
             {
                 new_es.elementType = internalInstance(es.elementType, gen_args);
             }
             new_es.sc = internalInstance(es.sc as TypeScope, gen_args);
             new_es.MakeDescription();
         }
         else if (ss is ProcScope)
         {
             ProcScope ps = ss as ProcScope;
             ProcScope new_proc = new ProcScope(ps.si.name, ts, ps.is_constructor);
             procs[ps] = new_proc;
             new_proc.loc = ps.loc;
             new_proc.documentation = ps.documentation;
             new_proc.si.acc_mod = ps.si.acc_mod;
             new_proc.is_static = ps.is_static;
             new_proc.is_virtual = ps.is_virtual;
             new_proc.is_abstract = ps.is_abstract;
             new_proc.is_override = ps.is_override;
             new_proc.is_reintroduce = ps.is_reintroduce;
             ts.members[i] = new_proc;
             if (ps.parameters != null)
                 for (int j = 0; j < ps.parameters.Count; j++)
                 {
                     ElementScope es = ps.parameters[j];
                     ElementScope es2 = new ElementScope(new SymInfo(es.si.name, es.si.kind, es.si.name), es.sc, new_proc);
                     es2.loc = es.loc;
                     es2.cnst_val = es.cnst_val;
                     es2.si.acc_mod = es.si.acc_mod;
                     es2.param_kind = es.param_kind;
                     es2.sc = internalInstance(es.sc as TypeScope, gen_args);
                     es2.MakeDescription();
                     new_proc.AddParameter(es2);
                 }
             new_proc.return_type = internalInstance(ps.return_type, gen_args);
             new_proc.Complete();
         }
     }
     foreach (ProcScope ps in procs.Keys)
     {
         ProcScope new_ps = procs[ps] as ProcScope;
         if (ps.nextProc != null && procs[ps.nextProc] != null)
         {
             new_ps.nextProc = procs[ps.nextProc] as ProcScope;
         }
     }
     return ts;
 }
Ejemplo n.º 2
0
        public override void visit(destructor _destructor)
        {
            //throw new Exception("The method or operation is not implemented.");
            SymScope topScope = cur_scope;
            ProcScope ps = null;
            location loc = get_location(_destructor);
            bool is_realization = false;
            _destructor.name.visit(this);
            if (_destructor.name.class_name != null)
            {
                topScope = cur_scope.FindName(_destructor.name.class_name.name);
                if (topScope != null)
                {
                    ps = topScope.FindNameOnlyInThisType(meth_name) as ProcScope;
                    if (ps == null)
                    {
                        ps = new ProcScope(meth_name, cur_scope);
                        ps.head_loc = loc;
                    }
                    else ps = select_function_definition(ps, _destructor.parameters, null, topScope as TypeScope);
                    //while (ps != null && ps.already_defined) ps = ps.nextProc;
                    if (ps == null)
                    {
                        ps = new ProcScope(meth_name, cur_scope);
                        ps.head_loc = loc;
                    }
                    if (ps.parameters.Count != 0 && _destructor.parameters != null)
                    {
                        ps.parameters.Clear();
                        ps.already_defined = true;
                    }
                    if (impl_scope == null)
                    {
                        ProcRealization pr = new ProcRealization(ps, cur_scope);
                        pr.already_defined = true;
                        ps.proc_realization = pr;
                        pr.loc = cur_loc;
                        pr.head_loc = loc;
                        is_realization = true;
                        entry_scope.AddName("$method", pr);

                    }
                    else
                    {
                        ProcRealization pr = new ProcRealization(ps, impl_scope);
                        pr.already_defined = true;
                        ps.proc_realization = pr;
                        pr.loc = cur_loc;
                        pr.head_loc = loc;
                        is_realization = true;
                        impl_scope.AddName("$method", pr);
                    }
                }
                else
                {
                    ps = new ProcScope(meth_name, cur_scope);
                    ps.head_loc = loc;
                }
            }
            else
            {
                ps = new ProcScope(meth_name, cur_scope);
                ps.head_loc = loc;
                SymScope ss = cur_scope.FindNameOnlyInThisType(meth_name);
                if (ss != null && ss is ProcScope)
                {
                    while ((ss as ProcScope).nextProc != null) ss = (ss as ProcScope).nextProc;
                    (ss as ProcScope).nextProc = ps;
                    cur_scope.AddName("$method", ps);
                    ps.si.name = meth_name;
                }
                else
                {
                    cur_scope.AddName(meth_name, ps);
                }
            }
            if (!is_realization && ps.loc == null)
                ps.loc = cur_loc;
            //ps.head_loc = loc;
            ps.declaringUnit = entry_scope;
            SetAttributes(ps, _destructor.proc_attributes);
            if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_destructor))
                ps.AddDocumentation(this.converter.controller.docs[_destructor]);
            if (is_proc_realization) ps.already_defined = true;
            else ps.loc = loc;
            if (_destructor.name == null || _destructor.name.class_name == null)
            {
                ps.acc_mod = cur_access_mod;
                ps.si.acc_mod = cur_access_mod;
            }
            if (_destructor.parameters != null)
                foreach (typed_parameters pars in _destructor.parameters.params_list)
                {
                    pars.vars_type.visit(this);
                    if (returned_scope != null)
                    {
                        if (returned_scope is ProcScope)
                            returned_scope = new ProcType(returned_scope as ProcScope);
                        foreach (ident id in pars.idents.idents)
                        {
                            ElementScope si = new ElementScope(new SymInfo(id.name, SymbolKind.Parameter, id.name), returned_scope, ps);
                            si.loc = get_location(id);
                            ps.AddName(id.name, si);
                            si.param_kind = pars.param_kind;
                            si.MakeDescription();
                            ps.AddParameter(si);
                        }
                    }
                }
            if (cur_scope is TypeScope)
                ps.AddName("self", new ElementScope(new SymInfo("self", SymbolKind.Parameter, "self"), cur_scope, ps));
            //cur_scope = ps;
            returned_scope = ps;
            ps.Complete();
        }
Ejemplo n.º 3
0
        public override void visit(procedure_header _procedure_header)
        {
            //throw new Exception("The method or operation is not implemented.");
            SymScope topScope;
            ProcScope ps = null;
            bool not_def = false;
            ProcRealization pr = null;
            bool is_realization = false;
            location loc = get_location(_procedure_header);
            if (_procedure_header.name != null)
            {
                _procedure_header.name.visit(this);

                if (_procedure_header.name.class_name != null)
                {
                    topScope = null;
                    if (_procedure_header.name.ln != null && _procedure_header.name.ln.Count > 0)
                    {
                        SymScope tmp_scope = cur_scope;
                        for (int i = 0; i < _procedure_header.name.ln.Count; i++)
                        {
                            tmp_scope = tmp_scope.FindName(_procedure_header.name.ln[i].name);
                            if (tmp_scope == null)
                                break;
                        }
                        topScope = tmp_scope;
                    }
                    else
                        topScope = cur_scope.FindName(_procedure_header.name.class_name.name);
                    if (topScope != null)
                    {
                        ps = topScope.FindNameOnlyInThisType(meth_name) as ProcScope;
                        if (ps != null && ps is CompiledMethodScope)
                            ps = null;
                        if (ps == null)
                        {
                            ps = new ProcScope(meth_name, topScope);
                            ps.head_loc = loc;
                            bool ext = false;
                            if (topScope is CompiledScope || topScope is ArrayScope || topScope is TypeSynonim && ((topScope as TypeSynonim).actType is CompiledScope || (topScope as TypeSynonim).actType is ArrayScope || (topScope as TypeSynonim).actType is DiapasonScope))
                                ext = true;
                            else if (!(topScope is TypeSynonim) && !(topScope is PointerScope) && !(topScope is SetScope) && !(topScope is FileScope))
                                ext = true;
                            if (ext)
                            {
                                not_def = true;
                                ps.is_extension = true;
                                ps.AddName("self", new ElementScope(new SymInfo("self", SymbolKind.Parameter, "self"), topScope, cur_scope));
                                ps.declaringType = topScope as TypeScope;
                                TypeScope ts = topScope as TypeScope;
                                if (topScope is TypeSynonim)
                                    ts = (ts as TypeSynonim).actType;
                                this.entry_scope.AddExtensionMethod(meth_name, ps, ts);
                                topScope.AddExtensionMethod(meth_name, ps, ts);
                            }
                        }
                        //while (ps != null && ps.already_defined) ps = ps.nextProc;
                        else ps = select_function_definition(ps, _procedure_header.parameters, null, topScope as TypeScope);
                        if (ps == null)
                        {
                            ps = new ProcScope(meth_name, cur_scope);
                            ps.head_loc = loc;
                        }
                        if (ps.parameters.Count != 0 && _procedure_header.parameters != null && is_proc_realization)
                        {
                            ps.parameters.Clear();
                            ps.already_defined = true;
                        }
                        if (impl_scope == null)
                        {
                            pr = new ProcRealization(ps, cur_scope);
                            pr.already_defined = true;
                            ps.proc_realization = pr;
                            pr.loc = cur_loc;
                            pr.head_loc = loc;
                            is_realization = true;
                            entry_scope.AddName("$method", pr);
                        }
                        else
                        {
                            pr = new ProcRealization(ps, impl_scope);
                            pr.already_defined = true;
                            ps.proc_realization = pr;
                            pr.loc = cur_loc;
                            is_realization = true;
                            pr.head_loc = loc;
                            impl_scope.AddName("$method", pr);
                        }
                    }
                    else
                    {
                        ps = new ProcScope(meth_name, cur_scope);
                        ps.head_loc = loc;
                    }
                }
                else
                {
                    ps = new ProcScope(meth_name, cur_scope);
                    if (has_extensionmethod_attr(_procedure_header.proc_attributes.proc_attributes) && _procedure_header.parameters.params_list.Count > 0)
                    {
                        ps.is_extension = true;
                        _procedure_header.parameters.params_list[0].vars_type.visit(this);
                        topScope = returned_scope;
                        ps.declaringType = topScope as TypeScope;
                        TypeScope ts = topScope as TypeScope;
                        if (topScope is TypeSynonim)
                            ts = (ts as TypeSynonim).actType;
                        if (ts.original_type != null && ts.instances != null)
                        {
                            bool pure_instance = true;
                            foreach (TypeScope gen_arg in ts.instances)
                            {
                                if (!(gen_arg is TemplateParameterScope))
                                    pure_instance = false;
                            }
                            if (pure_instance)
                                ts = ts.original_type;
                        }
                        this.entry_scope.AddExtensionMethod(meth_name, ps, ts);
                        topScope.AddExtensionMethod(meth_name, ps, ts);
                        pr = new ProcRealization(ps, cur_scope);
                        pr.already_defined = true;
                        ps.proc_realization = pr;
                        pr.loc = cur_loc;
                        pr.head_loc = loc;
                        if (impl_scope != null)
                            impl_scope.AddName("$method", pr);
                        else
                            this.entry_scope.AddName("$method", pr);
                    }
                    ps.head_loc = loc;
                    if (!ps.is_extension)
                    {
                        if (IsForward(_procedure_header))
                        {
                            cur_scope.AddName(meth_name, ps);
                            ps.is_forward = true;
                        }
                        else
                        {
                            bool found_in_top = false;
                            SymScope ss = null;
                            if (cur_scope is ImplementationUnitScope)
                            {
                                ss = (cur_scope as ImplementationUnitScope).topScope.FindNameOnlyInThisType(meth_name);
                                if (ss != null && ss is ProcScope)
                                {
                                    //ps = ss as ProcScope;
                                    //while ((ss as ProcScope).already_defined && (ss as ProcScope).nextProc != null)
                                    //	ss = (ss as ProcScope).nextProc;
                                    ps = select_function_definition(ss as ProcScope, _procedure_header.parameters, null, null);
                                    if (ps == null)
                                    {
                                        ps = new ProcScope(meth_name, cur_scope);
                                        ps.head_loc = loc;
                                    }
                                    //ps = ss as ProcScope;
                                    if (ps.parameters.Count != 0 && _procedure_header.parameters != null)
                                    {
                                        ps.parameters.Clear();
                                        ps.already_defined = true;
                                    }
                                    pr = new ProcRealization(ps, cur_scope);
                                    pr.already_defined = true;
                                    pr.loc = cur_loc;
                                    ps.proc_realization = pr;
                                    pr.head_loc = loc;
                                    is_realization = true;
                                    cur_scope.AddName("$method", pr);
                                    found_in_top = true;
                                }
                            }
                            if (!found_in_top) //ne nashli opisanie v interface chasti modilja
                            {
                                //ss = cur_scope.FindNameOnlyInType(meth_name);
                                ss = cur_scope.FindName(meth_name);
                                if (ss != null && ss is ProcScope)
                                {
                                    if ((ss as ProcScope).is_forward)
                                    {
                                        //if ((ss as ProcScope).parameters.Count != 0 && _procedure_header.parameters != null) (ss as ProcScope).parameters.Clear();
                                        pr = new ProcRealization(ss as ProcScope, cur_scope);
                                        pr.already_defined = true;
                                        pr.loc = cur_loc;
                                        cur_scope.AddName("$method", pr);
                                        returned_scope = pr;
                                        pr.head_loc = loc;
                                        return;
                                    }
                                    else
                                    {
                                        ps = new ProcScope(meth_name, cur_scope);
                                        ps.head_loc = loc;
                                        if (ps.topScope == ss.topScope)
                                        {
                                            while ((ss as ProcScope).nextProc != null && (ss as ProcScope).nextProc.topScope == ps.topScope) ss = (ss as ProcScope).nextProc;
                                            ProcScope tmp_ps = (ss as ProcScope).nextProc;
                                            (ss as ProcScope).nextProc = ps;
                                            ps.nextProc = tmp_ps;
                                            cur_scope.AddName(meth_name, ps);
                                            ps.si.name = meth_name;
                                        }
                                        else
                                        {
                                            ps.nextProc = ss as ProcScope;
                                            cur_scope.AddName(meth_name, ps);
                                        }
                                        //ps = select_function_definition(ss as ProcScope,_procedure_header.parameters);
                                    }
                                }
                                else
                                {
                                    cur_scope.AddName(meth_name, ps);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                ps = new ProcScope("", cur_scope);
                ps.head_loc = loc;
            }
            if ((!is_realization || not_def) && ps.loc == null)
                ps.loc = cur_loc;
            //ps.head_loc = loc;
            ps.declaringUnit = entry_scope;
            if (_procedure_header.template_args != null && !ps.IsGeneric())
            {
                foreach (ident s in _procedure_header.template_args.idents)
                {
                    ps.AddTemplateParameter(s.name);
                    TemplateParameterScope tps = new TemplateParameterScope(s.name, TypeTable.obj_type, ps);
                    tps.loc = get_location(s);
                    ps.AddName(s.name, tps);
                }
            }
            SetAttributes(ps, _procedure_header.proc_attributes);
            ps.is_static = _procedure_header.class_keyword;
            if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_procedure_header))
                ps.AddDocumentation(this.converter.controller.docs[_procedure_header]);

            if (is_proc_realization) ps.already_defined = true;
            else
            {
                ps.loc = loc;
            }
            if (_procedure_header.name == null || _procedure_header.name.class_name == null)
            {
                ps.acc_mod = cur_access_mod;
                ps.si.acc_mod = cur_access_mod;
            }
            SymScope tmp = cur_scope;
            cur_scope = ps;
            if (_procedure_header.parameters != null)
                foreach (typed_parameters pars in _procedure_header.parameters.params_list)
                {
                    pars.vars_type.visit(this);

                    if (returned_scope != null)
                    {
                        if (returned_scope is ProcScope)
                            returned_scope = new ProcType(returned_scope as ProcScope);
                        foreach (ident id in pars.idents.idents)
                        {
                            ElementScope si = new ElementScope(new SymInfo(id.name, SymbolKind.Parameter, id.name), returned_scope, ps);
                            si.loc = get_location(id);
                            si.param_kind = pars.param_kind;
                            if (pars.inital_value != null)
                            {
                                pars.inital_value.visit(this);
                                si.cnst_val = cnst_val.prim_val;
                            }
                            si.MakeDescription();
                            ps.AddName(id.name, si);
                            ps.AddParameter(si);
                        }
                    }
                }
            cur_scope = tmp;
            if (cur_scope is TypeScope && !ps.is_static)
                ps.AddName("self", new ElementScope(new SymInfo("self", SymbolKind.Parameter, "self"), cur_scope, ps));
            //cur_scope = ps;
            returned_scope = ps;
            ps.Complete();
            if (pr != null && not_def)
                pr.Complete();
        }
Ejemplo n.º 4
0
        public override void visit(simple_property _simple_property)
        {
            //throw new Exception("The method or operation is not implemented.");
            _simple_property.property_type.visit(this);
            if (returned_scope == null)
            	return;
            ElementScope es = new ElementScope(new SymInfo(_simple_property.property_name.name, SymbolKind.Property,_simple_property.property_name.name),
                                                                                   returned_scope, cur_scope);
            es.declaringUnit = entry_scope;
            if (_simple_property.array_default != null)
            {
            	TypeScope ts = cur_scope as TypeScope;
            	if (_simple_property.parameter_list != null)
            	{
            		ts.elementType = returned_scope as TypeScope;
            		for (int i=0; i<_simple_property.parameter_list.parameters.Count; i++)
            		{
            			_simple_property.parameter_list.parameters[i].type.visit(this);
            			if (returned_scope == null || !(returned_scope is TypeScope)) return;
            			for (int j=0; j<_simple_property.parameter_list.parameters[i].names.idents.Count; j++)
            				ts.AddIndexer(returned_scope as TypeScope);
            		}
            		
            	}
            }
            if (_simple_property.parameter_list != null)
            {
            	es.elementType = returned_scope as TypeScope;
            	for (int i=0; i<_simple_property.parameter_list.parameters.Count; i++)
            	{
            		_simple_property.parameter_list.parameters[i].type.visit(this);
            		if (returned_scope == null || !(returned_scope is TypeScope)) return;
            		for (int j=0; j<_simple_property.parameter_list.parameters[i].names.idents.Count; j++)
            			es.AddIndexer(returned_scope as TypeScope);
            	}
            	es.MakeDescription();
            }
            es.loc = get_location(_simple_property);
			if (add_doc_from_text && this.converter.controller.docs != null && this.converter.controller.docs.ContainsKey(_simple_property))
        		es.AddDocumentation(this.converter.controller.docs[_simple_property]);
			if (_simple_property.attr == definition_attribute.Static)
				es.is_static = true;
            es.acc_mod = cur_access_mod;
            es.si.acc_mod = cur_access_mod;
            cur_scope.AddName(_simple_property.property_name.name,es);
            
        }