public FileScope(TypeScope elementType, SymScope topScope) { this.topScope = topScope; if (topScope != null) { if (elementType != null) this.baseScope = topScope.FindName("TypedFile") as TypeScope; else this.baseScope = topScope.FindName("BinaryFile") as TypeScope; } this.elementType = elementType; this.si = new SymInfo(this.ToString(), SymbolKind.Type, this.ToString()); }
public override void AddIndexer(TypeScope ts) { }
private static string GetTypeName(TypeScope typ) { StringBuilder sb = new StringBuilder(); if (typ == null) return ""; if (typ is CompiledScope) sb.Append((typ as CompiledScope).ctn.FullName); else if (typ is ArrayScope) { ArrayScope arr = typ as ArrayScope; if (arr.is_dynamic_arr) { ArrayScope tmp = arr; int j=1; while (tmp.elementType is ArrayScope && (tmp.elementType as ArrayScope).is_dynamic_arr) { j++; tmp = tmp.elementType as ArrayScope; } sb.Append(GetTypeName(tmp.elementType)); for (int k=0; k<j; k++) sb.Append("[]"); } else { sb.Append("@array["); for (int j=0; j<arr.indexes.Length; j++) { sb.Append(GetTypeName(arr.indexes[j])); if (j<arr.indexes.Length-1) sb.Append(","); } sb.Append("]"); sb.Append("["+GetTypeName(arr.elementType)+"]"); } } else if (typ is ProcType) { sb.Append(GetDelegateName((typ as ProcType).target)); } else if (typ is SetScope) { sb.Append("@set["+GetTypeName((typ as SetScope).elementType)+"]"); } else if (typ is FileScope) { if (typ.elementType != null) sb.Append("@fileof["+GetTypeName(typ.elementType)+"]"); else sb.Append("@file"); } else if (typ is TypeSynonim) { sb.Append(GetTypeName((typ as TypeSynonim).actType)); } else if (typ is PointerScope) { PointerScope ptr = typ as PointerScope; int j=1; while (ptr.ref_type is PointerScope) { j++; ptr = ptr.ref_type as PointerScope; } for (int k=0; k<j; k++) sb.Append("*"); sb.Append(ptr.ref_type); } else if (typ is ShortStringScope) { sb.Append("@string["+(typ as ShortStringScope).Length+"]"); } else if (typ is DiapasonScope) { sb.Append("@diap["+(typ as DiapasonScope).left+".."+(typ as DiapasonScope).right+"]"); } else sb.Append(typ.declaringUnit.si.name+"."+typ.si.name); return sb.ToString(); }
public virtual void AddImplementedInterface(TypeScope type) { if (implemented_interfaces == null) implemented_interfaces = new List<TypeScope>(); implemented_interfaces.Add(type); }
public virtual void AddIndexer(TypeScope ts) { indexers.Add(ts); }
public virtual void AddGenericInstanciation(TypeScope ts) { instances.Add(ts); }
protected virtual TypeScope simpleGetInstance(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(); return ts; }
public override bool IsConvertable(TypeScope ts) { if (ts is TypeSynonim) return actType.IsConvertable((ts as TypeSynonim).actType); if (ts is ShortStringScope) return true; return false; }
public ArrayScope(TypeScope elementType, TypeScope[] indexes) { this.elementType = elementType; this.indexes = indexes; if (indexes == null) is_dynamic_arr = true; else { _is_multi_dyn_arr = true; foreach (TypeScope ind_ts in indexes) { if (ind_ts != null) { _is_multi_dyn_arr = false; break; } } } Type tarr = typeof(Array); this.baseScope = TypeTable.get_compiled_type(new SymInfo(tarr.Name, SymbolKind.Type, tarr.FullName), tarr); //if (is_dynamic_arr || _is_multi_dyn_arr) { List<TypeScope> lst = new List<TypeScope>(); lst.Add(elementType); this.implemented_interfaces = new List<TypeScope>(); this.implemented_interfaces.Add(CompiledScope.get_type_instance(typeof(IEnumerable<>), lst)); } this.si = new SymInfo("$" + this.ToString(), SymbolKind.Type, this.ToString()); this.members = new List<SymScope>(); }
public override bool IsConvertable(TypeScope ts) { if (ts is TypeSynonim) ts = (ts as TypeSynonim).actType; if (ts is TypeScope) return this.actType.IsConvertable(ts); return false; }
public override void AddIndexer(TypeScope ts) { actType.AddIndexer(ts); }
public TypeSynonim(SymInfo si, SymScope actType) : base(SymbolKind.Type, null, null) { this.actType = actType as TypeScope; this.si = si; if (actType.si != null && actType.si.description != null) this.si.description = CodeCompletionController.CurrentParser.LanguageInformation.GetDescription(this); //this.si.describe = "type "+this.si.name + " = "+actType.si.name; }
public TemplateParameterScope(string name, TypeScope baseType, SymScope declScope) : base(SymbolKind.Type, null, baseType) { this.declScope = declScope; this.topScope = declScope; this.name = name; si.description = name + " in " + declScope.si.name; }
public override bool IsConvertable(TypeScope ts) { if (ts is FileScope) { if ((ts as FileScope).elementType == null && elementType == null) return true; if ((ts as FileScope).elementType != null && elementType != null) return elementType.IsEqual((ts as FileScope).elementType); return false; } else if (ts is TypeSynonim) return this.IsConvertable((ts as TypeSynonim).actType); return false; }
public List<ProcScope> GetExtensionMethods(TypeScope ts) { if (ts is ArrayScope && !(ts as ArrayScope).is_dynamic_arr) return new List<ProcScope>(); List<ProcScope> lst = new List<ProcScope>(); List<ProcScope> meths = null; TypeScope tmp_ts = ts; if (extension_methods != null) { while (tmp_ts != null) { TypeScope tmp_ts2 = tmp_ts; if (tmp_ts is CompiledScope && (tmp_ts as CompiledScope).CompiledType.IsGenericType && !(tmp_ts as CompiledScope).CompiledType.IsGenericTypeDefinition) tmp_ts2 = TypeTable.get_compiled_type((tmp_ts as CompiledScope).CompiledType.GetGenericTypeDefinition()); if (extension_methods.TryGetValue(tmp_ts2, out meths)) { lst.AddRange(meths); } else { foreach (TypeScope t in extension_methods.Keys) { if (t.GenericTypeDefinition == tmp_ts2.GenericTypeDefinition || t.IsEqual(tmp_ts2) || (t is ArrayScope && tmp_ts2.IsArray) || ( tmp_ts2 is ArrayScope && t.IsArray) || (t is TemplateParameterScope || t is UnknownScope)) { lst.AddRange(extension_methods[t]); } } } tmp_ts = tmp_ts.baseScope; } if (ts.implemented_interfaces != null) foreach (TypeScope int_ts in ts.implemented_interfaces) { TypeScope int_ts2 = int_ts; if (int_ts is CompiledScope && (int_ts as CompiledScope).CompiledType.IsGenericType && !(int_ts as CompiledScope).CompiledType.IsGenericTypeDefinition) int_ts2 = TypeTable.get_compiled_type((int_ts as CompiledScope).CompiledType.GetGenericTypeDefinition()); if (extension_methods.TryGetValue(int_ts2, out meths)) { lst.AddRange(meths); } else { foreach (TypeScope t in extension_methods.Keys) { if (t.GenericTypeDefinition == int_ts2.GenericTypeDefinition || t.IsEqual(int_ts2) || (t is ArrayScope && int_ts2.IsArray) || (int_ts2 is ArrayScope && t.IsArray)) { lst.AddRange(extension_methods[t]); //break; } } } } } if (this.used_units != null) for (int i = 0; i < this.used_units.Count; i++) { if (this.used_units[i] != this) lst.AddRange(this.used_units[i].GetExtensionMethods(ts)); } return lst; }
public void AddExtensionMethod(string name, ProcScope meth, TypeScope ts) { if (extension_methods == null) extension_methods = new Dictionary<TypeScope, List<ProcScope>>(); List<ProcScope> meth_list = null; if (ts is CompiledScope && (ts as CompiledScope).CompiledType.IsGenericType && !(ts as CompiledScope).CompiledType.IsGenericTypeDefinition) ts = TypeTable.get_compiled_type((ts as CompiledScope).CompiledType.GetGenericTypeDefinition()); if (ts.original_type != null) ts = ts.original_type; if (!extension_methods.TryGetValue(ts, out meth_list)) { meth_list = new List<ProcScope>(); extension_methods.Add(ts, meth_list); } meth_list.Add(meth); }
public TypeScope(SymbolKind kind, SymScope topScope, SymScope baseScope) { this.kind = kind; this.baseScope = baseScope as TypeScope; this.topScope = topScope; if (baseScope == null) { if (CodeCompletionController.CurrentParser.LanguageInformation.IncludeDotNetEntities) switch (kind) { case SymbolKind.Struct: this.baseScope = TypeTable.get_compiled_type(new SymInfo(typeof(ValueType).Name, SymbolKind.Struct, typeof(ValueType).FullName), typeof(ValueType)); break; case SymbolKind.Interface: case SymbolKind.Class: this.baseScope = TypeTable.get_compiled_type(new SymInfo(typeof(object).Name, SymbolKind.Class, typeof(object).FullName), typeof(object)); break; case SymbolKind.Enum: this.baseScope = TypeTable.get_compiled_type(new SymInfo(typeof(Enum).Name, SymbolKind.Enum, typeof(Enum).FullName), typeof(Enum)); break; } } //this.ht = new Hashtable(CaseInsensitiveHashCodeProvider.Default,CaseInsensitiveComparer.Default); this.members = new List<SymScope>(); this.indexers = new List<TypeScope>(); this.instances = new List<TypeScope>(); //this.generic_params = new List<string>(); si = new SymInfo("type", kind, "type"); //UnitDocCache.AddDescribeToComplete(this); switch (kind) { case SymbolKind.Struct: si.description = CodeCompletionController.CurrentParser.LanguageInformation.GetKeyword(PascalABCCompiler.Parsers.SymbolKind.Struct); break; case SymbolKind.Class: si.description = CodeCompletionController.CurrentParser.LanguageInformation.GetKeyword(PascalABCCompiler.Parsers.SymbolKind.Class); break; case SymbolKind.Interface: si.description = CodeCompletionController.CurrentParser.LanguageInformation.GetKeyword(PascalABCCompiler.Parsers.SymbolKind.Interface); break; case SymbolKind.Enum: si.description = CodeCompletionController.CurrentParser.LanguageInformation.GetKeyword(PascalABCCompiler.Parsers.SymbolKind.Enum); break; } }
public override bool IsConvertable(TypeScope ts) { if (ts is NullTypeScope && is_dynamic_arr) return true; if (!is_dynamic_arr && !IsMultiDynArray) return base.IsConvertable(ts); ArrayScope arrs = ts as ArrayScope; if (ts is CompiledScope && (ts as CompiledScope).IsArray) { return this.elementType.IsEqual(ts.GetElementType()); } if (arrs == null || !arrs.is_dynamic_arr && !arrs.IsMultiDynArray) if (ts is TypeSynonim) return this.IsConvertable((ts as TypeSynonim).actType); else return false; if (arrs.elementType == null) return true; if (!this.elementType.IsEqual(arrs.elementType)) return false; if (this.IsMultiDynArray && arrs.IsMultiDynArray) { return this.indexes.Length == arrs.indexes.Length; } return true; /*if (this.indexes == null && arrs.indexes == null) return true;//????? if (this.indexes != null && arrs.indexes != null) { if (this.indexes.Length != arrs.indexes.Length) return false; for (int i=0; i<this.indexes.Length; i++) if (this.indexes[i] == null && arrs.indexes[i] == null) continue; else if (this.indexes[i] == null && arrs.indexes[i] != null || this.indexes[i] != null && arrs.indexes[i] == null) return false; else if (!this.indexes[i].IsEqual(arrs.indexes[i])) return false; return true; } return false;*/ }
private TypeScope internalInstance(TypeScope ts, List<TypeScope> gen_args) { if (ts is TemplateParameterScope || ts is UnknownScope) { int ind = this.generic_params.IndexOf(ts.Name); if (ind != -1) { return gen_args[ind]; } else return ts; } else if (ts is ArrayScope) { ArrayScope arr = null; if ((ts as ArrayScope).is_dynamic_arr) { arr = new ArrayScope(internalInstance(ts.elementType, gen_args), (ts as ArrayScope).indexes); arr.is_dynamic_arr = true; } else arr = new ArrayScope(internalInstance(ts.elementType, gen_args), (ts as ArrayScope).indexes); return arr; } else if (ts is TypeScope && ts.instances != null && ts.instances.Count > 0) { return ts.simpleGetInstance(gen_args); } else return ts; }
public SymInfo[] GetSymInfosForExtensionMethods(TypeScope ts) { if (ts is ArrayScope && !(ts as ArrayScope).is_dynamic_arr) return new SymInfo[0]; List<SymInfo> lst = new List<SymInfo>(); List<ProcScope> meth_list = GetExtensionMethods(ts); for (int i = 0; i < meth_list.Count; i++) lst.Add(meth_list[i].si); return lst.ToArray(); }
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; }
public List<ProcScope> GetExtensionMethods(string name, TypeScope ts) { if (ts is ArrayScope && !(ts as ArrayScope).is_dynamic_arr) return new List<ProcScope>(); List<ProcScope> meths = GetExtensionMethods(ts); List<ProcScope> lst = new List<ProcScope>(); for (int i = 0; i < meths.Count; i++) { if (string.Compare(meths[i].si.name, name, true) == 0) { lst.Add(meths[i]); } } return lst; }
public virtual bool IsConvertable(TypeScope ts) { if (IsEqual(ts)) return true; if (this is UnknownScope && ts is CompiledScope && (ts as CompiledScope).CompiledType.IsGenericParameter || ts is UnknownScope && this is CompiledScope && (this as CompiledScope).CompiledType.IsGenericParameter) return true; if (this.IsGenericParameter && ts.IsGenericParameter && this.Name == ts.Name) return true; TypeScope tmp = this.baseScope; while (tmp != null) if (tmp.IsEqual(ts)) return true; else tmp = tmp.baseScope; return false; }
public override bool IsConvertable(TypeScope ts) { return ts.IsConvertable(this); }
public override bool IsConvertable(TypeScope ts) { CompiledScope cs = ts as CompiledScope; if (ts is NullTypeScope && !ctn.IsValueType) return true; if (cs == null) if (ts is TypeSynonim) return this.IsConvertable((ts as TypeSynonim).actType); else if (ts is ShortStringScope && ctn == typeof(string)) return true; else { if (ts is UnknownScope) return true; else if (ts is TemplateParameterScope) return true; else if (ts is ProcType) { ProcType pt = ts as ProcType; MethodInfo invoke_meth = this.ctn.GetMethod("Invoke"); if (invoke_meth == null) { if (this.ctn == typeof(Delegate)) return true; return false; } if (pt.target.parameters == null) if (invoke_meth.GetParameters().Length > 0) return false; if (pt.target.parameters != null && pt.target.parameters.Count != invoke_meth.GetParameters().Length) return false; ParameterInfo[] parameters = invoke_meth.GetParameters(); for (int i = 0; i < parameters.Length; i++) { CompiledScope param_cs = TypeTable.get_compiled_type(null, parameters[i].ParameterType); if (!(pt.target.parameters[i].sc is TypeScope) || !param_cs.IsConvertable(pt.target.parameters[i].sc as TypeScope)) return false; } return true; } else return false; } if (this.ctn == cs.ctn) return true; if (this.ctn.IsSubclassOf(cs.ctn)) return true; TypeCode code1 = Type.GetTypeCode(this.ctn); TypeCode code2 = Type.GetTypeCode(cs.ctn); bool left = false; bool right = false; switch (code1) { case TypeCode.Boolean: case TypeCode.Byte: case TypeCode.Char: case TypeCode.Double: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Object: case TypeCode.SByte: case TypeCode.Single: case TypeCode.String: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: left = true; break; } switch (code2) { case TypeCode.Boolean: case TypeCode.Byte: case TypeCode.Char: case TypeCode.Double: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: case TypeCode.Object: case TypeCode.SByte: case TypeCode.Single: case TypeCode.String: case TypeCode.UInt16: case TypeCode.UInt32: case TypeCode.UInt64: right = true; break; } if (left && right) { type_compare tc = PascalABCCompiler.TreeRealization.type_table.compare_types( compiled_type_node.get_type_node(this.ctn), compiled_type_node.get_type_node(cs.ctn)); if (tc == type_compare.less_type) { if (code1 != TypeCode.String && code1 != TypeCode.Object) if (code1 == TypeCode.Double && code2 != TypeCode.Single) return false; else return true; } if (cs.ctn.IsGenericParameter || this.ctn.IsGenericParameter) return true; return tc == type_compare.less_type; } else { List<SymScope> conv1 = this.FindOverloadNamesOnlyInType("op_Implicit"); List<SymScope> conv2 = cs.FindOverloadNamesOnlyInType("op_Implicit"); if (conv1.Count > 0) { for (int i = 0; i < conv1.Count; i++) if (conv1[i] is ProcScope) { ProcScope ps = conv1[i] as ProcScope; if (ps.parameters != null && ps.parameters.Count > 0 && ps.parameters[0].sc == cs) return true; } } else if (conv2.Count > 0) { for (int i = 0; i < conv2.Count; i++) if (conv2[i] is ProcScope) { ProcScope ps = conv2[i] as ProcScope; if (ps.parameters != null && ps.parameters.Count > 0 && ps.parameters[0].sc == cs) return true; } } } return false; }
public PointerScope(TypeScope ref_type) { this.ref_type = ref_type; this.si = new SymInfo(this.ToString(), SymbolKind.Type, this.ToString()); }
public static string GetDocumentation(TypeScope t) { try { if (t.declaringUnit != null) { CodeCompletionTools.XmlDoc xdoc = (CodeCompletionTools.XmlDoc)ht[t.declaringUnit]; if (xdoc != null) { string s = GetNormalHint(xdoc.GetDocumentation("T:" + t.si.name, true)); return s; } } } catch(Exception e) { } return ""; }
public override bool IsConvertable(TypeScope ts) { if (IsEqual(ts)) return true; return false; }
public static void AddDescribeToComplete(TypeScope value) { elem_cache.Add(value); }
public SetScope(TypeScope elementType) { this.elementType = elementType; this.si = new SymInfo(this.ToString(), SymbolKind.Type, this.ToString()); }