示例#1
0
 internal static TypeScope get_type_instance(Type t, List<TypeScope> generic_args)
 {
     if (t.IsGenericParameter)
     {
         if (t.GenericParameterPosition < generic_args.Count)
             return generic_args[t.GenericParameterPosition];
         else if (generic_args.Count > 0)
             return generic_args[0];
         else
             return TypeTable.get_compiled_type(null, t);
     }
     if (t.IsArray)
         return new ArrayScope(get_type_instance(t.GetElementType(), generic_args), null);
     if (t.ContainsGenericParameters)
     {
         CompiledScope typ = new CompiledScope(new SymInfo(t.Name, SymbolKind.Type, t.Name), t);
         typ.generic_params = new List<string>();
         typ.original_type = TypeTable.get_compiled_type(new SymInfo(t.Name, SymbolKind.Type, t.Name), t);
         Type[] args = t.GetGenericArguments();
         for (int i = 0; i < args.Length; i++)
         {
             if (args[i].IsGenericParameter)
             {
                 if (args[i].GenericParameterPosition < generic_args.Count)
                 {
                     typ.generic_params.Add(generic_args[args[i].GenericParameterPosition].si.name);
                     typ.AddGenericInstanciation(generic_args[args[i].GenericParameterPosition]);
                 }
                 else if (i<generic_args.Count)
                 {
                     typ.generic_params.Add(generic_args[i].si.name);
                     typ.AddGenericInstanciation(generic_args[i]);
                 }
             }
             else
             {
                 TypeScope ts = get_type_instance(args[i], generic_args);
                 typ.generic_params.Add(ts.si.name);
                 typ.AddGenericInstanciation(ts);
             }
         }
         typ.si.description = typ.GetDescription();
         return typ;
     }
     return TypeTable.get_compiled_type(t);
 }
示例#2
0
 public override TypeScope GetInstance(List<TypeScope> gen_args)
 {
     Type t = this.ctn;
     if (!ctn.IsGenericType)
         return this;
     if (!ctn.IsGenericTypeDefinition)
         t = PascalABCCompiler.NetHelper.NetHelper.FindType(this.ctn.Namespace + "." + this.ctn.Name);
     else if (this.instances != null && this.instances.Count > 0)
     {
         if (this.instances.Count != ctn.GetGenericArguments().Length)
         {
             Type t2 = PascalABCCompiler.NetHelper.NetHelper.FindType(this.ctn.Namespace + "." + this.ctn.Name.Substring(0, this.ctn.Name.IndexOf('`')) + "`" + this.instances.Count);
             if (t2 != null)
                 t = t2;
         }
     }
     else if (gen_args.Count != ctn.GetGenericArguments().Length)
     {
         Type t2 = PascalABCCompiler.NetHelper.NetHelper.FindType(this.ctn.Namespace + "." + this.ctn.Name.Substring(0, this.ctn.Name.IndexOf('`')) + "`" + gen_args.Count);
         if (t2 != null)
             t = t2;
     }
     CompiledScope sc = new CompiledScope(new SymInfo(si.name, si.kind, si.description), t);
     sc.generic_params = new List<string>();
     sc.instances = new List<TypeScope>();
     sc.original_type = this;
     if (this.instances != null && this.instances.Count > 0)
         for (int i = 0; i < this.instances.Count; i++)
         {
             if (this.instances[i] is UnknownScope || this.instances[i] is TemplateParameterScope)
             {
                 List<TypeScope> lst = new List<TypeScope>();
                 lst.Add(gen_args[Math.Min(i, gen_args.Count - 1)]);
                 if (lst[0].instances != null && lst[0].instances.Count > 0)
                     lst[0] = lst[0].instances[0];
                 sc.instances.Add(this.instances[i].GetInstance(lst));
             }
             else
                 sc.instances.Add(this.instances[i].GetInstance(gen_args));
         }
     else
         for (int i = 0; i < gen_args.Count; i++)
         {
             sc.generic_params.Add(gen_args[i].si.name);
             sc.instances.Add(gen_args[i]);
         }
     sc.si.description = sc.GetDescription();
     return sc;
 }
示例#3
0
 public override TypeScope GetInstance(List<TypeScope> gen_args)
 {
     Type t = this.ctn;
     if (!ctn.IsGenericTypeDefinition)
         t = PascalABCCompiler.NetHelper.NetHelper.FindType(this.ctn.FullName + "`" + gen_args.Count);
     else if (gen_args.Count != ctn.GetGenericArguments().Length)
     { 
         Type t2 = PascalABCCompiler.NetHelper.NetHelper.FindType(this.ctn.FullName.Substring(0, this.ctn.FullName.IndexOf('`')) + "`" + gen_args.Count);
         if (t2 != null)
             t = t2;
     }
     CompiledScope sc = new CompiledScope(new SymInfo(si.name, si.kind, si.describe), t);
     sc.generic_params = new List<string>();
     sc.instances = new List<TypeScope>();
     sc.original_type = this;
     for (int i = 0; i < gen_args.Count; i++)
     {
         sc.generic_params.Add(gen_args[i].si.name);
         sc.instances.Add(gen_args[i]);
     }
     sc.si.describe = sc.GetDescription();
     return sc;
 }