2019-07-28 23:53:15 +03:00
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
2015-06-01 22:15:17 +03:00
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
2015-05-14 22:35:07 +03:00
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.Reflection ;
using System.Text ;
using SymbolTable ;
using PascalABCCompiler.TreeRealization ;
using PascalABCCompiler.SyntaxTree ;
using PascalABCCompiler.Parsers ;
2018-04-14 18:18:42 +03:00
using System.Linq ;
2015-05-14 22:35:07 +03:00
namespace CodeCompletion
{
public enum KeywordKind
{
kw_none ,
kw_new ,
kw_proc ,
kw_constr ,
kw_destr ,
kw_uses ,
kw_inherited ,
kw_raise ,
kw_type ,
kw_var ,
kw_unit ,
kw_punkt ,
kw_colon ,
kw_const ,
kw_program ,
kw_of ,
kw_typedecl
}
public class ExtensionMethodsCache
{
}
class TypeUtility
{
public static bool IsStandType ( Type t )
{
if ( t . IsEnum ) return false ;
switch ( Type . GetTypeCode ( t ) )
{
case TypeCode . Int32 :
case TypeCode . Double :
case TypeCode . Boolean :
case TypeCode . String :
case TypeCode . Char :
case TypeCode . Byte :
case TypeCode . SByte :
case TypeCode . Int16 :
case TypeCode . Int64 :
case TypeCode . UInt16 :
case TypeCode . UInt32 :
case TypeCode . UInt64 :
case TypeCode . Single : return true ;
}
if ( t . IsPointer ) return true ;
return false ;
}
public static string GetTypeName ( Type ctn )
{
TypeCode tc = Type . GetTypeCode ( ctn ) ;
if ( ctn . FullName = = null & & ! ctn . IsArray & & ! ctn . IsGenericTypeDefinition )
return "T" ;
if ( ! ctn . IsEnum )
switch ( tc )
{
case TypeCode . Int32 : return PascalABCCompiler . TreeConverter . compiler_string_consts . integer_type_name ;
case TypeCode . Double : return PascalABCCompiler . TreeConverter . compiler_string_consts . real_type_name ;
case TypeCode . Boolean : return PascalABCCompiler . TreeConverter . compiler_string_consts . bool_type_name ;
case TypeCode . String : return PascalABCCompiler . TreeConverter . compiler_string_consts . string_type_name ;
case TypeCode . Char : return PascalABCCompiler . TreeConverter . compiler_string_consts . char_type_name ;
case TypeCode . Byte : return PascalABCCompiler . TreeConverter . compiler_string_consts . byte_type_name ;
case TypeCode . SByte : return PascalABCCompiler . TreeConverter . compiler_string_consts . sbyte_type_name ;
case TypeCode . Int16 : return PascalABCCompiler . TreeConverter . compiler_string_consts . short_type_name ;
case TypeCode . Int64 : return PascalABCCompiler . TreeConverter . compiler_string_consts . long_type_name ;
case TypeCode . UInt16 : return PascalABCCompiler . TreeConverter . compiler_string_consts . ushort_type_name ;
case TypeCode . UInt32 : return PascalABCCompiler . TreeConverter . compiler_string_consts . uint_type_name ;
case TypeCode . UInt64 : return PascalABCCompiler . TreeConverter . compiler_string_consts . ulong_type_name ;
case TypeCode . Single : return PascalABCCompiler . TreeConverter . compiler_string_consts . float_type_name ;
}
else return ctn . FullName ;
if ( ctn . Name . Contains ( "`" ) )
{
int len = ctn . GetGenericArguments ( ) . Length ;
Type [ ] gen_ps = ctn . GetGenericArguments ( ) ;
System . Text . StringBuilder sb = new System . Text . StringBuilder ( ) ;
sb . Append ( ctn . Namespace + "." + ctn . Name . Substring ( 0 , ctn . Name . IndexOf ( '`' ) ) ) ;
sb . Append ( '<' ) ;
for ( int i = 0 ; i < len ; i + + )
{
sb . Append ( gen_ps [ i ] . Name ) ;
if ( i < len - 1 )
sb . Append ( ',' ) ;
}
sb . Append ( '>' ) ;
return sb . ToString ( ) ;
}
if ( ctn . IsArray ) return "array of " + GetTypeName ( ctn . GetElementType ( ) ) ;
if ( ctn = = Type . GetType ( "System.Void*" ) ) return PascalABCCompiler . TreeConverter . compiler_string_consts . pointer_type_name ;
return ctn . FullName ;
}
public static string GetShortTypeName ( Type ctn )
{
TypeCode tc = Type . GetTypeCode ( ctn ) ;
if ( ctn . FullName = = null & & ! ctn . IsArray & & ! ctn . IsGenericTypeDefinition )
return "T" ;
if ( ctn . IsEnum ) return ctn . Name ;
if ( ctn . Name . Contains ( "`" ) )
{
int len = ctn . GetGenericArguments ( ) . Length ;
System . Text . StringBuilder sb = new System . Text . StringBuilder ( ) ;
sb . Append ( ctn . Name . Substring ( 0 , ctn . Name . IndexOf ( '`' ) ) ) ;
sb . Append ( '<' ) ;
sb . Append ( '>' ) ;
/ * sb . Append ( '<' ) ;
for ( int i = 0 ; i < len ; i + + )
{
sb . Append ( 'T' ) ;
if ( i < len - 1 )
sb . Append ( ',' ) ;
}
sb . Append ( '>' ) ; * /
return sb . ToString ( ) ;
}
//if (ctn.IsArray) return "array of "+GetTypeName(ctn.GetElementType());
//if (ctn == Type.GetType("System.Void*")) return PascalABCCompiler.TreeConverter.compiler_string_consts.pointer_type_name;
return ctn . Name ;
}
public static string GetTopScopeName ( SymScope sc )
{
if ( sc = = null | | sc . si = = null ) return "" ;
if ( sc . si . name = = "" | | sc . si . name . Contains ( "$" ) | | sc . si . name = = PascalABCCompiler . TreeConverter . compiler_string_consts . system_unit_file_name ) return "" ;
if ( sc is ProcScope ) return "" ;
return sc . si . name + "." ;
}
}
public class SymScope : IBaseScope
{
public SymScope topScope ;
public string file_name ;
public List < SymScope > used_units ;
public SymInfo si ;
public location loc ;
public location head_loc ;
public location body_loc ;
public List < SymScope > members ;
public Hashtable symbol_table ;
public int cur_line = - 1 ;
public int cur_col = - 1 ;
public SymScope declaringUnit ;
public string documentation ;
public access_modifer acc_mod ;
public bool is_static = false ;
public bool is_virtual = false ;
public bool is_abstract = false ;
public bool is_override = false ;
public bool is_reintroduce = false ;
2015-12-19 22:48:12 +03:00
2015-05-14 22:35:07 +03:00
public List < Position > regions ;
public Dictionary < TypeScope , List < ProcScope > > extension_methods ;
public SymScope ( ) { }
2015-12-19 22:48:12 +03:00
public SymScope ( SymInfo si , SymScope topScope )
2015-05-14 22:35:07 +03:00
{
this . si = si ;
si . IsUnitNamespace = true ;
this . topScope = topScope ;
this . used_units = new List < SymScope > ( ) ;
members = new List < SymScope > ( ) ;
}
2015-12-19 22:48:12 +03:00
public virtual void Clear ( )
2015-05-14 22:35:07 +03:00
{
2017-12-17 16:41:34 +03:00
if ( members ! = null )
members . Clear ( ) ;
if ( symbol_table ! = null )
symbol_table . Clear ( ) ;
if ( used_units ! = null )
used_units . Clear ( ) ;
if ( extension_methods ! = null )
{
foreach ( TypeScope ts in extension_methods . Keys )
{
List < ProcScope > meths = extension_methods [ ts ] ;
foreach ( ProcScope meth in meths )
ts . RemoveExtensionMethod ( ts , meth ) ;
}
2017-12-30 17:46:38 +03:00
extension_methods . Clear ( ) ;
2017-12-17 16:41:34 +03:00
}
2017-12-30 17:46:38 +03:00
UnitDocCache . RemoveItem ( this ) ;
2015-05-14 22:35:07 +03:00
declaringUnit = null ;
topScope = null ;
}
IList < Position > IBaseScope . Regions
{
get
{
return regions ;
}
}
IBaseScope [ ] IBaseScope . Members
{
get
{
if ( members ! = null )
return members . ToArray ( ) ;
return null ;
}
}
public virtual ScopeKind Kind
{
get
{
return ScopeKind . None ;
}
}
public access_modifer AccessModifier
{
get
{
return acc_mod ;
}
}
public virtual SymInfo SymbolInfo
{
get
{
return si ;
}
}
public virtual PascalABCCompiler . Parsers . SymbolKind ElemKind
{
get
{
switch ( si . kind )
{
case SymbolKind . Block : return PascalABCCompiler . Parsers . SymbolKind . Block ;
case SymbolKind . Class : return PascalABCCompiler . Parsers . SymbolKind . Class ;
case SymbolKind . Constant : return PascalABCCompiler . Parsers . SymbolKind . Constant ;
case SymbolKind . Delegate : return PascalABCCompiler . Parsers . SymbolKind . Delegate ;
case SymbolKind . Enum : return PascalABCCompiler . Parsers . SymbolKind . Enum ;
case SymbolKind . Event : return PascalABCCompiler . Parsers . SymbolKind . Event ;
case SymbolKind . Field : return PascalABCCompiler . Parsers . SymbolKind . Field ;
case SymbolKind . Interface : return PascalABCCompiler . Parsers . SymbolKind . Interface ;
case SymbolKind . Method : return PascalABCCompiler . Parsers . SymbolKind . Method ;
case SymbolKind . Parameter : return PascalABCCompiler . Parsers . SymbolKind . Parameter ;
case SymbolKind . Property : return PascalABCCompiler . Parsers . SymbolKind . Property ;
case SymbolKind . Struct : return PascalABCCompiler . Parsers . SymbolKind . Struct ;
case SymbolKind . Type : return PascalABCCompiler . Parsers . SymbolKind . Type ;
case SymbolKind . Variable : return PascalABCCompiler . Parsers . SymbolKind . Variable ;
}
return PascalABCCompiler . Parsers . SymbolKind . Block ;
}
}
public virtual string Name
{
get
{
return si . name ;
}
}
public virtual string Description
{
get
{
2016-05-01 13:02:40 +03:00
if ( si ! = null ) return si . description ;
2015-05-14 22:35:07 +03:00
return null ;
}
}
public IBaseScope TopScope
{
get
{
return topScope ;
}
}
public virtual IElementScope MakeElementScope ( )
{
return new ElementScope ( this ) ;
}
public void IncreaseEndLine ( )
{
this . loc . end_line_num + = 1 ;
}
2018-11-01 00:19:05 +03:00
protected bool IsHiddenName ( string name )
{
2018-11-01 14:22:34 +03:00
char c = name [ 0 ] ;
2022-12-26 13:14:23 +03:00
return c = = '#' | | c = = '%' | | c = = '<' | | name . Contains ( "$" ) | | name . Contains ( "_<>" ) ;
2018-11-01 00:19:05 +03:00
}
2015-05-14 22:35:07 +03:00
public void AddExtensionMethod ( string name , ProcScope meth , TypeScope ts )
{
2018-08-08 16:54:13 +03:00
if ( ts . original_type ! = null )
{
ts . original_type . AddExtensionMethod ( name , meth , ts . original_type ) ;
}
2015-05-14 22:35:07 +03:00
if ( extension_methods = = null )
extension_methods = new Dictionary < TypeScope , List < ProcScope > > ( ) ;
List < ProcScope > meth_list = null ;
2016-05-29 13:16:22 +03:00
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 ;
2015-05-14 22:35:07 +03:00
if ( ! extension_methods . TryGetValue ( ts , out meth_list ) )
{
meth_list = new List < ProcScope > ( ) ;
extension_methods . Add ( ts , meth_list ) ;
}
meth_list . Add ( meth ) ;
}
2017-12-17 16:41:34 +03:00
public void RemoveExtensionMethod ( TypeScope ts , ProcScope meth )
{
List < ProcScope > meth_list = null ;
if ( extension_methods ! = null & & extension_methods . TryGetValue ( ts , out meth_list ) )
{
if ( meth_list . Contains ( meth ) )
meth_list . Remove ( meth ) ;
}
}
2015-05-14 22:35:07 +03:00
public SymInfo [ ] GetSymInfosForExtensionMethods ( TypeScope ts )
{
2016-11-21 23:12:10 +03:00
/ * if ( ts is ArrayScope & & ! ( ts as ArrayScope ) . is_dynamic_arr )
return new SymInfo [ 0 ] ; * /
2015-05-14 22:35:07 +03:00
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 List < ProcScope > GetExtensionMethods ( string name , TypeScope ts )
{
2016-11-21 23:12:10 +03:00
/ * if ( ts is ArrayScope & & ! ( ts as ArrayScope ) . is_dynamic_arr )
return new List < ProcScope > ( ) ; * /
2022-04-14 11:43:08 +03:00
List < ProcScope > meths = GetExtensionMethods ( ts , name ) ;
2015-05-14 22:35:07 +03:00
List < ProcScope > lst = new List < ProcScope > ( ) ;
2022-04-14 11:43:08 +03:00
2015-05-14 22:35:07 +03:00
for ( int i = 0 ; i < meths . Count ; i + + )
{
if ( string . Compare ( meths [ i ] . si . name , name , true ) = = 0 )
{
lst . Add ( meths [ i ] ) ;
}
}
return lst ;
}
2022-04-14 11:43:08 +03:00
public List < ProcScope > GetExtensionMethods ( TypeScope ts , string name = null )
2015-05-14 22:35:07 +03:00
{
2018-01-07 19:27:56 +03:00
if ( ts is TypeSynonim )
2022-04-14 11:43:08 +03:00
return GetExtensionMethods ( ( ts as TypeSynonim ) . actType , name ) ;
2018-04-08 17:38:23 +03:00
if ( ts . original_type ! = null )
2022-04-14 11:43:08 +03:00
return GetExtensionMethods ( ts . original_type , name ) ;
2015-05-14 22:35:07 +03:00
List < ProcScope > lst = new List < ProcScope > ( ) ;
List < ProcScope > meths = null ;
TypeScope tmp_ts = ts ;
2017-02-12 17:16:06 +03:00
if ( ts is ArrayScope & & ! ( ts as ArrayScope ) . is_dynamic_arr & & ! ( ts as ArrayScope ) . is_multi_dyn_arr )
return lst ;
2015-05-14 22:35:07 +03:00
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 )
2016-05-29 13:16:22 +03:00
tmp_ts2 = TypeTable . get_compiled_type ( ( tmp_ts as CompiledScope ) . CompiledType . GetGenericTypeDefinition ( ) ) ;
2015-05-14 22:35:07 +03:00
if ( extension_methods . TryGetValue ( tmp_ts2 , out meths ) )
{
2022-04-14 11:43:08 +03:00
foreach ( var meth in meths )
{
if ( ! lst . Contains ( meth ) & & ( name = = null | | string . Compare ( meth . si . name , name , true ) = = 0 ) )
lst . Add ( meth ) ;
}
2015-05-14 22:35:07 +03:00
}
else
{
foreach ( TypeScope t in extension_methods . Keys )
{
2017-02-09 23:45:00 +03:00
if ( t . GenericTypeDefinition = = tmp_ts2 . GenericTypeDefinition | |
t . IsEqual ( tmp_ts2 ) | |
( t is ArrayScope & & tmp_ts2 . IsArray & & t . Rank = = tmp_ts2 . Rank ) | |
( tmp_ts2 is ArrayScope & & t . IsArray & & tmp_ts2 . Rank = = t . Rank ) | |
( t is TemplateParameterScope | | t is UnknownScope ) | |
2018-12-31 13:34:32 +03:00
t is FileScope & & tmp_ts2 is FileScope & &
( ( t as FileScope ) . elementType = = null ) = = ( ( tmp_ts2 as FileScope ) . elementType = = null )
2017-02-09 23:45:00 +03:00
)
2015-05-14 22:35:07 +03:00
{
2022-04-14 11:43:08 +03:00
var meth_list = extension_methods [ t ] ;
foreach ( var meth in meth_list )
{
if ( ! lst . Contains ( meth ) & & ( name = = null | | string . Compare ( meth . si . name , name , true ) = = 0 ) )
lst . Add ( meth ) ;
}
2015-05-14 22:35:07 +03:00
}
}
}
2016-11-21 23:12:10 +03:00
if ( ts is ArrayScope & & ! ( ts as ArrayScope ) . is_dynamic_arr )
tmp_ts = null ;
else
tmp_ts = tmp_ts . baseScope ;
2015-05-14 22:35:07 +03:00
}
2017-12-03 16:07:39 +03:00
if ( ts . implemented_interfaces ! = null & & ! ( ts is ArrayScope & & ( ! ( ts as ArrayScope ) . is_dynamic_arr | | ( ts as ArrayScope ) . Rank > 1 ) ) )
2015-05-14 22:35:07 +03:00
{
2017-10-04 22:50:52 +03:00
List < TypeScope > implemented_interfaces = new List < TypeScope > ( ) ;
implemented_interfaces . AddRange ( ts . implemented_interfaces ) ;
if ( ts is ArrayScope )
implemented_interfaces . Add ( ( ts as ArrayScope ) . ilist ) ;
foreach ( TypeScope int_ts in implemented_interfaces )
2015-05-14 22:35:07 +03:00
{
2017-10-04 22:50:52 +03:00
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 ) )
{
2022-04-14 11:43:08 +03:00
foreach ( var meth in meths )
{
if ( ! lst . Contains ( meth ) & & ( name = = null | | string . Compare ( meth . si . name , name , true ) = = 0 ) )
lst . Add ( meth ) ;
}
2017-10-04 22:50:52 +03:00
}
else
2015-05-14 22:35:07 +03:00
{
2017-10-04 22:50:52 +03:00
foreach ( TypeScope t in extension_methods . Keys )
2015-05-14 22:35:07 +03:00
{
2017-10-04 22:50:52 +03:00
if ( t . GenericTypeDefinition = = int_ts2 . GenericTypeDefinition | | t . IsEqual ( int_ts2 ) | |
( t is ArrayScope & & int_ts2 . IsArray & & t . Rank = = int_ts2 . Rank ) | |
( int_ts2 is ArrayScope & & t . IsArray & & int_ts2 . Rank = = t . Rank ) | |
2018-12-31 13:34:32 +03:00
t is FileScope & & int_ts2 is FileScope & &
( ( t as FileScope ) . elementType = = null ) = = ( ( int_ts2 as FileScope ) . elementType = = null ) )
2017-10-04 22:50:52 +03:00
{
2022-04-14 11:43:08 +03:00
var meth_list = extension_methods [ t ] ;
foreach ( var meth in meth_list )
{
if ( ! lst . Contains ( meth ) & & ( name = = null | | string . Compare ( meth . si . name , name , true ) = = 0 ) )
lst . Add ( meth ) ;
}
2017-10-04 22:50:52 +03:00
//break;
}
2015-05-14 22:35:07 +03:00
}
2017-10-04 22:50:52 +03:00
2015-05-14 22:35:07 +03:00
}
}
}
2017-10-04 22:50:52 +03:00
2015-05-14 22:35:07 +03:00
}
if ( this . used_units ! = null )
for ( int i = 0 ; i < this . used_units . Count ; i + + )
{
2017-05-30 23:58:34 +03:00
if ( ! hasUsesCycle ( this ) )
2022-04-14 11:43:08 +03:00
{
var unit_meth_lst = this . used_units [ i ] . GetExtensionMethods ( ts , name ) ;
foreach ( var meth in unit_meth_lst )
{
if ( ! lst . Contains ( meth ) & & ( name = = null | | string . Compare ( meth . si . name , name , true ) = = 0 ) )
lst . Add ( meth ) ;
}
}
2015-05-14 22:35:07 +03:00
}
return lst ;
}
2017-05-30 23:58:34 +03:00
2023-05-01 11:20:12 +03:00
private bool hasUsesCycle ( SymScope unit , int deep = 0 )
2017-05-30 23:58:34 +03:00
{
2018-05-01 15:58:57 +03:00
if ( unit . Name = = "PABCSystem" )
2018-04-29 20:32:27 +03:00
return true ;
2023-05-01 11:20:12 +03:00
if ( deep > 100 )
return true ;
2018-03-25 14:48:26 +03:00
if ( this . used_units ! = null )
2017-05-30 23:58:34 +03:00
for ( int i = 0 ; i < this . used_units . Count ; i + + )
{
2018-08-28 21:11:28 +03:00
if ( this . used_units [ i ] = = unit | | this . used_units [ i ] = = this )
2017-05-30 23:58:34 +03:00
return true ;
2023-05-01 11:20:12 +03:00
else
{
if ( this . used_units [ i ] . hasUsesCycle ( unit , deep + 1 ) )
return true ;
}
2017-05-30 23:58:34 +03:00
}
return false ;
}
2015-12-19 22:48:12 +03:00
public virtual bool IsAssembliesChanged ( )
2015-05-14 22:35:07 +03:00
{
return false ;
}
2015-12-19 22:48:12 +03:00
public virtual void InitAssemblies ( )
2015-05-14 22:35:07 +03:00
{
}
public void AddUsedUnit ( SymScope unit )
{
2018-05-27 15:35:53 +03:00
if ( this . si . name ! = "PABCSystem" | | unit is NamespaceScope )
2017-09-11 22:06:16 +03:00
used_units . Add ( unit ) ;
2015-05-14 22:35:07 +03:00
}
public virtual string GetFullName ( )
{
return si . name ;
}
public virtual string GetDescription ( )
{
if ( si ! = null )
2016-05-01 13:02:40 +03:00
return si . description ;
2015-05-14 22:35:07 +03:00
return "" ;
}
public virtual void MakeSynonimDescription ( )
{
}
public virtual string GetDescriptionWithoutDoc ( )
{
return si . name ;
}
public Position GetPosition ( )
{
Position pos = new Position ( ) ;
if ( loc ! = null )
{
pos . file_name = loc . doc . file_name ;
pos . line = loc . begin_line_num ;
pos . column = loc . begin_column_num ;
pos . end_line = loc . end_line_num ;
pos . end_column = loc . end_column_num ;
}
return pos ;
}
public Position GetHeaderPosition ( )
{
Position pos = new Position ( ) ;
if ( head_loc ! = null )
{
pos . file_name = head_loc . doc . file_name ;
pos . line = head_loc . begin_line_num ;
pos . column = head_loc . begin_column_num ;
pos . end_line = head_loc . end_line_num ;
pos . end_column = head_loc . end_column_num ;
}
return pos ;
}
public Position GetBodyPosition ( )
{
Position pos = new Position ( ) ;
if ( body_loc ! = null )
{
pos . file_name = body_loc . doc . file_name ;
pos . line = body_loc . begin_line_num ;
pos . column = body_loc . begin_column_num ;
pos . end_line = body_loc . end_line_num ;
pos . end_column = body_loc . end_column_num ;
}
return pos ;
}
bool IBaseScope . IsEqual ( IBaseScope scope )
{
2018-07-04 22:15:37 +03:00
return this . IsEqual ( scope as SymScope ) ;
//return this == scope;
2015-05-14 22:35:07 +03:00
}
public virtual bool IsEqual ( SymScope ts )
{
return this = = ts ;
}
public virtual void AddDocumentation ( string doc )
{
try
{
if ( ! string . IsNullOrEmpty ( doc ) )
{
doc = doc . Trim ( ' ' , '\n' , '\t' , '\r' ) ;
if ( ! string . IsNullOrEmpty ( doc ) )
{
string [ ] arr = doc . Split ( new string [ ] { "!!" } , StringSplitOptions . None ) ;
if ( CodeCompletionController . currentLanguageISO = = "en" )
{
if ( arr . Length > 1 )
doc = arr [ 1 ] . Trim ( ) ;
else
doc = "" ;
}
else
doc = arr [ 0 ] . Trim ( ) ;
}
this . documentation = doc ;
if ( doc . Length > 0 & & doc [ 0 ] = = '-' )
{
string s = doc . Substring ( 1 ) ;
if ( s . Length > = 1 & & s [ 0 ] = = '-' )
{
2016-05-01 13:02:40 +03:00
si . description = null ;
2015-05-14 22:35:07 +03:00
si . has_doc = false ;
si . not_include = true ;
return ;
}
s = s . TrimStart ( ' ' , '\t' ) ;
int end_ind = s . IndexOf ( '\n' ) ;
if ( end_ind ! = - 1 )
{
2016-05-01 13:02:40 +03:00
si . description = s . Substring ( 0 , end_ind ) ;
2015-05-14 22:35:07 +03:00
if ( end_ind < s . Length - 1 )
2016-05-01 13:02:40 +03:00
si . description + = "\n" + AssemblyDocCache . GetNormalHint ( s . Substring ( end_ind + 1 ) ) ;
2015-05-14 22:35:07 +03:00
}
else
2016-05-01 13:02:40 +03:00
si . description = s . Substring ( 0 ) ;
2015-05-14 22:35:07 +03:00
//si.describe = s.TrimStart(' ','\t');
}
else if ( doc . Length > 0 & & doc [ 0 ] = = '<' )
{
this . documentation = AssemblyDocCache . GetNormalHint ( doc ) ;
2016-05-01 13:02:40 +03:00
si . description + = "\n" + this . documentation ;
2015-05-14 22:35:07 +03:00
}
else
{
2016-05-01 13:02:40 +03:00
si . description + = "\n" + doc ;
2015-05-14 22:35:07 +03:00
}
si . has_doc = true ;
}
}
catch
{
}
}
public virtual void ClearNames ( )
{
if ( members ! = null )
foreach ( SymScope ss in members )
if ( ss is ProcScope ) ss . ClearNames ( ) ;
}
2015-12-19 22:48:12 +03:00
public virtual bool InUsesRange ( int line , int column )
2015-05-14 22:35:07 +03:00
{
2015-12-19 22:48:12 +03:00
return false ;
2015-05-14 22:35:07 +03:00
}
//proverka na vhozhdenie v scope
2022-11-01 12:23:10 +03:00
public virtual bool IsInScope ( location loc , int line , int column )
2015-05-14 22:35:07 +03:00
{
if ( loc = = null ) return false ;
if ( loc . begin_line_num < line & & loc . end_line_num > line )
return true ;
if ( loc . begin_line_num > line | | loc . end_line_num < line )
return false ;
if ( loc . begin_line_num = = line & & loc . end_line_num = = line )
{
if ( loc . begin_column_num < = column & & loc . end_column_num > = column ) return true ;
else return false ;
}
else if ( loc . end_line_num ! = line & & loc . begin_column_num < = column ) return true ;
else if ( loc . begin_line_num ! = line & & loc . end_column_num > = column ) return true ;
return false ;
}
public virtual SymInfo [ ] GetNamesAsInBaseClass ( ExpressionVisitor ev , bool is_static )
{
return new SymInfo [ 0 ] ;
}
public virtual bool IsChildScopeOf ( SymScope ss )
{
return false ;
}
IBaseScope IBaseScope . FindScopeByLocation ( int line , int column )
{
return this . FindScopeByLocation ( line , column ) ;
}
//naiti scope po location
//algoritm lokalizueztsja scope v glubinu poka ne naidetsja istinnyj scope, soderzhashij mesto gde nahodimsja
public virtual SymScope FindScopeByLocation ( int line , int column )
{
SymScope res = null ;
cur_line = line ;
cur_col = column ;
if ( members = = null ) return null ;
//if (loc != null && loc.begin_line_num <= line && loc.end_line_num >= line && loc.begin_column_num <= column && loc.end_column_num >= column)
if ( IsInScope ( loc , line , column ) )
res = this ;
2018-03-06 22:39:05 +03:00
TypeScope ts = this as TypeScope ;
if ( res = = null & & ts ! = null & & ts . predef_loc ! = null & & IsInScope ( ts . predef_loc , line , column ) )
res = this ;
2015-05-14 22:35:07 +03:00
foreach ( SymScope ss in members )
2019-12-23 22:04:05 +03:00
if ( this ! = ss & & this . topScope ! = ss & & ss . loc ! = null & & ( loc = = null | | loc ! = null & & loc . doc ! = null & & ss . loc . doc . file_name = = loc . doc . file_name ) )
2015-05-14 22:35:07 +03:00
{
if ( IsInScope ( ss . loc , line , column ) )
{
2021-02-28 12:51:31 +03:00
if ( this is TypeScope & & ss . loc . end_line_num > loc . end_line_num )
continue ;
2015-05-14 22:35:07 +03:00
res = ss ;
SymScope tmp = ss . FindScopeByLocation ( line , column ) ;
2017-08-26 16:59:43 +03:00
if ( tmp ! = null )
return tmp ;
else
return res ;
2015-05-14 22:35:07 +03:00
}
else if ( ! ( ss is CompiledScope ) )
{
SymScope tmp = ss . FindScopeByLocation ( line , column ) ;
if ( tmp ! = null ) return tmp ;
}
}
return res ;
}
//poluchenie vseh imen posle tochki
public virtual SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
List < SymInfo > lst = new List < SymInfo > ( ) ;
foreach ( SymScope ss in members )
{
2018-11-01 00:19:05 +03:00
if ( ss ! = this & & ! ( ss is NamespaceScope ) & & ss . si . kind ! = SymbolKind . Namespace & & ! IsHiddenName ( ss . si . name ) )
2015-05-14 22:35:07 +03:00
{
lst . Add ( ss . si ) ;
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
}
return lst . ToArray ( ) ;
}
2017-08-31 22:01:34 +03:00
protected bool IsClassMember ( SymScope scope )
{
if ( scope is ProcScope & & ( scope as ProcScope ) . declaringType ! = null )
return true ;
if ( scope is ElementScope & & ( scope as ElementScope ) . declaringUnit is TypeScope )
return true ;
return false ;
}
2015-05-14 22:35:07 +03:00
protected bool IsAfterDefinition ( int def_line , int def_col )
{
if ( cur_line = = - 1 | | cur_col = = - 1 ) return true ;
if ( cur_line > def_line ) return true ;
if ( cur_line = = def_line ) return ( cur_col > def_col ) ;
return false ;
}
public virtual SymInfo [ ] GetNames ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
List < SymInfo > lst = new List < SymInfo > ( ) ;
foreach ( SymScope ss in members )
{
2018-11-01 00:19:05 +03:00
if ( ss ! = this & & ! IsHiddenName ( ss . si . name ) )
2015-05-14 22:35:07 +03:00
{
if ( ss . loc ! = null & & loc ! = null )
{
if ( string . Compare ( ss . loc . doc . file_name , loc . doc . file_name , true ) = = 0 )
{
if ( IsAfterDefinition ( ss . loc . begin_line_num , ss . loc . begin_column_num ) )
{
lst . Add ( ss . si ) ;
}
}
else lst . Add ( ss . si ) ;
}
else
lst . Add ( ss . si ) ;
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
}
if ( topScope ! = null ) lst . AddRange ( topScope . GetNames ( ) ) ;
return lst . ToArray ( ) ;
}
2019-06-21 13:24:19 +03:00
public SymInfo [ ] GetNamesInAllTopScopesNonVirtual ( bool all_names , ExpressionVisitor ev , bool is_static )
2015-05-14 22:35:07 +03:00
{
List < SymInfo > lst = new List < SymInfo > ( ) ;
foreach ( SymScope ss in members )
{
2018-03-06 22:39:05 +03:00
TypeScope ts = ss as TypeScope ;
2018-11-01 00:19:05 +03:00
if ( ss ! = this & & ! IsHiddenName ( ss . si . name ) )
2015-05-14 22:35:07 +03:00
{
2018-12-09 14:09:59 +03:00
//if (ts != null && !is_static && ts.IsStatic)
// continue;
2015-05-14 22:35:07 +03:00
if ( ss . loc ! = null & & loc ! = null )
{
if ( string . Compare ( ss . loc . doc . file_name , loc . doc . file_name , true ) = = 0 )
{
if ( IsAfterDefinition ( ss . loc . begin_line_num , ss . loc . begin_column_num ) )
{
lst . Add ( ss . si ) ;
}
2018-03-06 22:39:05 +03:00
else if ( ts ! = null & & ts . predef_loc ! = null & & IsAfterDefinition ( ts . predef_loc . begin_line_num , ts . predef_loc . begin_column_num ) )
{
lst . Add ( ss . si ) ;
}
2015-05-14 22:35:07 +03:00
}
else lst . Add ( ss . si ) ;
}
else
lst . Add ( ss . si ) ;
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
}
2017-11-19 21:15:33 +03:00
if ( topScope ! = null )
lst . AddRange ( topScope . GetNamesInAllTopScopes ( all_names , ev , is_static ) ) ;
2015-05-14 22:35:07 +03:00
if ( used_units ! = null & & all_names )
for ( int i = 0 ; i < used_units . Count ; i + + )
{
lst . AddRange ( used_units [ i ] . GetNames ( ) ) ;
}
return lst . ToArray ( ) ;
}
2019-06-21 13:24:19 +03:00
//poluchenie vseh imen vnutri Scope i vo vseh objemlushih scopah
//ispolzuetsja pri nazhatii ctrl+space
public virtual SymInfo [ ] GetNamesInAllTopScopes ( bool all_names , ExpressionVisitor ev , bool is_static )
{
return GetNamesInAllTopScopesNonVirtual ( all_names , ev , is_static ) ;
}
2015-05-14 22:35:07 +03:00
public virtual SymInfo [ ] GetNamesAsInObject ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
List < SymInfo > lst = new List < SymInfo > ( ) ;
foreach ( SymScope ss in members )
{
if ( ss ! = this & & ! ( ss is NamespaceScope ) & & ss . si . kind ! = SymbolKind . Namespace ) lst . Add ( ss . si ) ;
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
return lst . ToArray ( ) ;
}
//poisk v scope IsAfterDefinition proverjaet nahoditsja li opisanie do ispolzovanija
//eto nuzhno tak kak u nas tablicy vse zapolneny
protected SymScope internal_find ( string name , bool check_for_def )
{
2016-02-07 14:24:18 +03:00
if ( name . Length > 0 & & name [ 0 ] = = '?' )
name = name . Substring ( 1 ) ;
2015-05-14 22:35:07 +03:00
if ( symbol_table ! = null )
{
object o = symbol_table [ name ] ;
if ( o = = null )
return null ;
SymScope ss = null ;
if ( o is SymScope )
ss = o as SymScope ;
else
if ( ! CodeCompletionController . CurrentParser . LanguageInformation . CaseSensitive )
ss = ( o as List < SymScope > ) [ 0 ] ;
else
{
List < SymScope > lst = o as List < SymScope > ;
foreach ( SymScope s in lst )
{
if ( s . si . name = = name )
ss = s ;
}
}
if ( ss = = null ) return null ;
2018-03-06 22:39:05 +03:00
TypeScope ts = ss as TypeScope ;
2015-05-14 22:35:07 +03:00
if ( CodeCompletionController . CurrentParser . LanguageInformation . CaseSensitive )
if ( ss . si . name ! = name )
return null ;
if ( ss . loc ! = null & & loc ! = null & & check_for_def & & cur_line ! = - 1 & & cur_col ! = - 1 )
{
if ( string . Compare ( ss . loc . doc . file_name , loc . doc . file_name , true ) = = 0 & & this ! = ss )
{
2018-03-06 22:39:05 +03:00
if ( IsClassMember ( ss ) | | IsAfterDefinition ( ss . loc . begin_line_num , ss . loc . begin_column_num ) | |
ts ! = null & & ts . predef_loc ! = null & & IsAfterDefinition ( ts . predef_loc . begin_line_num , ts . predef_loc . begin_column_num ) )
2015-05-14 22:35:07 +03:00
{
return ss ;
}
else return null ;
}
else return ss ;
}
else return ss ;
}
else
2015-10-20 22:19:54 +03:00
if ( members ! = null )
2015-05-14 22:35:07 +03:00
foreach ( SymScope ss in members )
if ( string . Compare ( ss . si . name , name , ! CodeCompletionController . CurrentParser . LanguageInformation . CaseSensitive ) = = 0 )
if ( ss . loc ! = null & & loc ! = null & & check_for_def & & cur_line ! = - 1 & & cur_col ! = - 1 )
{
if ( string . Compare ( ss . loc . doc . file_name , loc . doc . file_name , ! CodeCompletionController . CurrentParser . LanguageInformation . CaseSensitive ) = = 0 & & this ! = ss )
{
2017-08-31 22:01:34 +03:00
if ( IsClassMember ( ss ) | | IsAfterDefinition ( ss . loc . begin_line_num , ss . loc . begin_column_num ) )
2015-05-14 22:35:07 +03:00
{
return ss ;
}
else return null ;
}
else return ss ;
}
else return ss ;
return null ;
}
protected List < SymScope > internal_find_overloads ( string name , bool check_for_def )
{
List < SymScope > names = new List < SymScope > ( ) ;
if ( symbol_table ! = null )
{
object o = symbol_table [ name ] ;
if ( o = = null )
return names ;
List < SymScope > tmp_names = new List < SymScope > ( ) ;
if ( o is SymScope )
tmp_names . Add ( o as SymScope ) ;
else
tmp_names . AddRange ( o as List < SymScope > ) ;
foreach ( SymScope ss in tmp_names )
if ( ss . loc ! = null & & loc ! = null & & check_for_def & & cur_line ! = - 1 & & cur_col ! = - 1 )
{
if ( string . Compare ( ss . loc . doc . file_name , loc . doc . file_name , true ) = = 0 & & this ! = ss )
{
if ( IsAfterDefinition ( ss . loc . begin_line_num , ss . loc . begin_column_num ) )
{
names . Add ( ss ) ;
}
//else return null;
}
else names . Add ( ss ) ;
}
else names . Add ( ss ) ;
}
2016-02-06 15:57:44 +03:00
else if ( members ! = null )
2015-05-14 22:35:07 +03:00
foreach ( SymScope ss in members )
if ( string . Compare ( ss . si . name , name , ! CodeCompletionController . CurrentParser . LanguageInformation . CaseSensitive ) = = 0 )
if ( ss . loc ! = null & & loc ! = null & & check_for_def & & cur_line ! = - 1 & & cur_col ! = - 1 )
{
2019-06-23 13:01:24 +03:00
if ( string . Compare ( ss . loc . doc . file_name , loc . doc . file_name , true ) = = 0 & & this ! = ss & & ss . topScope ! = this )
2015-05-14 22:35:07 +03:00
{
if ( IsAfterDefinition ( ss . loc . begin_line_num , ss . loc . begin_column_num ) )
{
names . Add ( ss ) ;
}
//else return null;
}
else
names . Add ( ss ) ;
}
else
names . Add ( ss ) ;
return names ;
}
ITypeScope IBaseScope . GetElementType ( )
{
return this . GetElementType ( ) ;
}
public virtual TypeScope GetElementType ( )
{
return null ;
}
public virtual void AddName ( string name , SymScope sc )
{
//ht[name] = sc;
sc . si . name = name ;
members . Add ( sc ) ;
}
IBaseScope IBaseScope . FindNameOnlyInType ( string name )
{
return this . FindNameOnlyInType ( name ) ;
}
public virtual SymScope FindNameOnlyInType ( string name )
{
return internal_find ( name , false ) ;
}
public virtual List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return internal_find_overloads ( name , false ) ;
}
public virtual SymScope FindNameOnlyInThisType ( string name )
{
return internal_find ( name , false ) ;
}
public virtual List < SymScope > FindOverloadNames ( string name )
{
List < SymScope > names = internal_find_overloads ( name , true ) ;
if ( topScope ! = null )
names . AddRange ( topScope . FindOverloadNames ( name ) ) ;
if ( used_units ! = null )
for ( int i = 0 ; i < used_units . Count ; i + + )
{
names . AddRange ( used_units [ i ] . FindOverloadNamesOnlyInType ( name ) ) ;
}
return names ;
}
public virtual SymScope FindName ( string name )
{
SymScope sc = internal_find ( name , true ) ;
2022-11-03 22:56:14 +03:00
if ( sc ! = null & & ! ( sc is InterfaceUnitScope ) )
return sc ;
SymScope saved_sc = sc ;
if ( topScope ! = null )
return topScope . FindName ( name ) ;
2015-05-14 22:35:07 +03:00
for ( int i = 0 ; i < used_units . Count ; i + + )
{
sc = used_units [ i ] . FindNameOnlyInType ( name ) ;
2022-11-03 22:56:14 +03:00
if ( sc ! = null )
return sc ;
2015-05-14 22:35:07 +03:00
}
2022-11-03 22:56:14 +03:00
return saved_sc ;
2015-05-14 22:35:07 +03:00
}
public virtual ProcScope FindNameOnlyInUses ( string name )
{
if ( used_units ! = null )
{
foreach ( SymScope ss in used_units )
{
SymScope tmp = ss . FindNameOnlyInType ( name ) ;
if ( tmp ! = null & & tmp is ProcScope )
return tmp as ProcScope ;
}
}
return null ;
}
IBaseScope IBaseScope . FindNameInAnyOrder ( string name )
{
return this . FindNameInAnyOrder ( name ) ;
}
public virtual SymScope FindNameInAnyOrder ( string name )
{
SymScope sc = internal_find ( name , false ) ;
2022-11-03 22:56:14 +03:00
if ( sc ! = null & & ! ( sc is InterfaceUnitScope ) )
return sc ;
SymScope saved_sc = sc ;
if ( topScope ! = null )
return topScope . FindName ( name ) ;
2015-05-14 22:35:07 +03:00
for ( int i = 0 ; i < used_units . Count ; i + + )
{
sc = used_units [ i ] . FindNameOnlyInType ( name ) ;
2022-11-03 22:56:14 +03:00
if ( sc ! = null )
return sc ;
2015-05-14 22:35:07 +03:00
}
2022-11-03 22:56:14 +03:00
return saved_sc ;
2015-05-14 22:35:07 +03:00
}
}
2018-02-19 22:17:00 +03:00
2015-05-14 22:35:07 +03:00
public class InterfaceUnitScope : SymScope , IInterfaceUnitScope
{
public ImplementationUnitScope impl_scope ;
2015-12-19 22:48:12 +03:00
private List < Assembly > ref_assms ;
public location uses_source_range ;
2019-06-21 13:24:19 +03:00
private bool is_namespace ;
private List < InterfaceUnitScope > namespace_units = new List < InterfaceUnitScope > ( ) ;
private InterfaceUnitScope main_namespace_unit ;
2015-05-14 22:35:07 +03:00
2019-06-21 13:24:19 +03:00
public InterfaceUnitScope ( SymInfo si , SymScope topScope , bool isNamespace = false , string fileName = null )
2015-12-19 22:48:12 +03:00
: base ( si , topScope )
2015-05-14 22:35:07 +03:00
{
UnitDocCache . AddDescribeToComplete ( this ) ;
this . symbol_table = new Hashtable ( StringComparer . CurrentCultureIgnoreCase ) ;
2019-06-21 13:24:19 +03:00
is_namespace = isNamespace ;
file_name = fileName ;
2019-06-21 15:03:27 +03:00
si . description = this . ToString ( ) ;
2015-05-14 22:35:07 +03:00
}
2017-12-30 17:46:38 +03:00
~ InterfaceUnitScope ( )
{
}
2017-02-19 12:58:42 +03:00
IImplementationUnitScope IInterfaceUnitScope . ImplementationUnitScope
{
get
{
return impl_scope ;
}
}
2019-06-21 13:24:19 +03:00
public void AddNamespaceUnit ( InterfaceUnitScope unit )
{
InterfaceUnitScope to_remove = null ;
foreach ( var un in namespace_units )
if ( un . file_name = = unit . file_name )
{
to_remove = un ;
break ;
}
if ( to_remove ! = null )
namespace_units . Remove ( to_remove ) ;
namespace_units . Add ( unit ) ;
unit . main_namespace_unit = this ;
}
2015-12-19 22:48:12 +03:00
public override bool InUsesRange ( int line , int column )
{
if ( this . uses_source_range ! = null )
return IsInScope ( this . uses_source_range , line , this . uses_source_range . end_column_num ) ;
return false ;
}
public override void Clear ( )
{
2019-06-21 13:24:19 +03:00
if ( is_namespace )
return ;
2015-12-19 22:48:12 +03:00
base . Clear ( ) ;
2017-12-17 16:41:34 +03:00
if ( ref_assms ! = null )
ref_assms . Clear ( ) ;
2015-12-19 22:48:12 +03:00
}
public override bool IsAssembliesChanged ( )
{
if ( ref_assms ! = null )
foreach ( Assembly a in ref_assms )
if ( PascalABCCompiler . NetHelper . NetHelper . IsAssemblyChanged ( a . ManifestModule . ScopeName ) )
return true ;
return false ;
}
public override void InitAssemblies ( )
{
if ( ref_assms ! = null )
foreach ( Assembly a in ref_assms )
PascalABCCompiler . NetHelper . NetHelper . init_namespaces ( a ) ;
}
public void AddReferencedAssembly ( System . Reflection . Assembly assm )
{
if ( ref_assms = = null ) ref_assms = new List < Assembly > ( ) ;
ref_assms . Add ( assm ) ;
List < Type > lst = PascalABCCompiler . NetHelper . NetHelper . entry_types [ assm ] as List < Type > ;
Type entry_type = null ;
if ( lst ! = null )
entry_type = lst [ 0 ] ;
if ( entry_type ! = null )
{
NamespaceScope ns = new NamespaceScope ( entry_type . Namespace ) ;
ns . entry_type = TypeTable . get_compiled_type ( new SymInfo ( "" , SymbolKind . Type , "" ) , entry_type ) ;
used_units . Add ( ns ) ;
}
}
2015-05-14 22:35:07 +03:00
public override void AddName ( string name , SymScope sc )
{
2019-12-24 14:27:02 +03:00
string pure_name = name ;
int ind = name . IndexOf ( '`' ) ;
if ( ind ! = - 1 )
pure_name = name . Substring ( 0 , ind ) ;
sc . si . name = pure_name ;
object o = symbol_table [ pure_name ] ;
if ( o ! = null & & ! IsHiddenName ( pure_name ) )
2015-05-14 22:35:07 +03:00
{
if ( o is SymScope )
{
List < SymScope > lst = new List < SymScope > ( ) ;
lst . Add ( o as SymScope ) ;
lst . Add ( sc ) ;
symbol_table [ name ] = lst ;
2019-12-24 14:27:02 +03:00
if ( pure_name ! = name )
symbol_table [ pure_name ] = lst ;
2015-05-14 22:35:07 +03:00
}
else
{
( o as List < SymScope > ) . Add ( sc ) ;
}
}
else
2019-12-24 14:27:02 +03:00
{
2015-05-14 22:35:07 +03:00
symbol_table [ name ] = sc ;
2019-12-24 14:27:02 +03:00
if ( pure_name ! = name )
symbol_table [ pure_name ] = sc ;
}
2015-05-14 22:35:07 +03:00
members . Add ( sc ) ;
}
public override ScopeKind Kind
{
get
{
return ScopeKind . UnitInterface ;
}
}
2019-06-21 13:40:33 +03:00
public bool IsNamespaceUnit
{
get
{
return is_namespace ;
}
}
2019-06-21 13:24:19 +03:00
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
SymInfo [ ] names = base . GetNamesAsInObject ( ev ) ;
if ( namespace_units . Count = = 0 )
return names ;
List < SymInfo > lst = new List < SymInfo > ( ) ;
lst . AddRange ( names ) ;
foreach ( var un in namespace_units )
lst . AddRange ( un . GetNamesAsInObject ( ev ) ) ;
return lst . ToArray ( ) ;
}
public override SymInfo [ ] GetNames ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
SymInfo [ ] names = base . GetNames ( ) ;
if ( namespace_units . Count = = 0 )
return names ;
List < SymInfo > lst = new List < SymInfo > ( ) ;
lst . AddRange ( names ) ;
foreach ( var un in namespace_units )
lst . AddRange ( un . GetNames ( ) ) ;
return lst . ToArray ( ) ;
}
public override SymInfo [ ] GetNamesInAllTopScopes ( bool all_names , ExpressionVisitor ev , bool is_static )
{
SymInfo [ ] names = base . GetNamesInAllTopScopes ( all_names , ev , is_static ) ;
if ( namespace_units . Count = = 0 & & main_namespace_unit = = null )
return names ;
List < SymInfo > lst = new List < SymInfo > ( ) ;
lst . AddRange ( names ) ;
if ( main_namespace_unit ! = null )
{
foreach ( var un in main_namespace_unit . namespace_units )
if ( un ! = this )
lst . AddRange ( un . GetNamesInAllTopScopesNonVirtual ( all_names , ev , is_static ) ) ;
}
else
{
foreach ( var un in namespace_units )
lst . AddRange ( un . GetNamesInAllTopScopes ( all_names , ev , is_static ) ) ;
}
return lst . ToArray ( ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( )
{
SymInfo [ ] names = base . GetNamesAsInObject ( ) ;
if ( namespace_units . Count = = 0 )
return names ;
List < SymInfo > lst = new List < SymInfo > ( ) ;
lst . AddRange ( names ) ;
foreach ( var un in namespace_units )
lst . AddRange ( un . GetNamesAsInObject ( ) ) ;
return lst . ToArray ( ) ;
}
2015-05-14 22:35:07 +03:00
public override string ToString ( )
{
2023-02-19 00:00:00 +03:00
return CodeCompletionController . CurrentParser ? . LanguageInformation . GetSimpleDescription ( this ) ;
2015-05-14 22:35:07 +03:00
}
}
2018-02-19 22:17:00 +03:00
public class NamespaceUnitScope : SymScope
{
public List < InterfaceUnitScope > units ;
public NamespaceUnitScope ( SymInfo si , SymScope topScope ) : base ( si , topScope )
{
units = new List < InterfaceUnitScope > ( ) ;
}
public override SymScope FindName ( string name )
{
foreach ( InterfaceUnitScope unit in units )
{
SymScope ss = unit . FindName ( name ) ;
if ( ss ! = null )
return ss ;
}
return null ;
}
}
2015-05-14 22:35:07 +03:00
//interfejsnyj scope
public class ImplementationUnitScope : SymScope , IImplementationUnitScope
{
2015-12-19 22:48:12 +03:00
public location uses_source_range ;
public ImplementationUnitScope ( SymInfo si , SymScope topScope )
: base ( si , topScope )
2015-05-14 22:35:07 +03:00
{
2018-11-01 14:22:34 +03:00
this . symbol_table = new Hashtable ( StringComparer . CurrentCultureIgnoreCase ) ;
2015-05-14 22:35:07 +03:00
}
2015-12-19 22:48:12 +03:00
public override bool InUsesRange ( int line , int column )
{
if ( this . uses_source_range ! = null )
return IsInScope ( this . uses_source_range , line , this . uses_source_range . end_column_num ) ;
return false ;
}
2015-05-14 22:35:07 +03:00
public override ScopeKind Kind
{
get
{
return ScopeKind . UnitImplementation ;
}
}
//osobyj porjadok poiska
//ishem v scope, potom v usesah scopa, potom v interfacenom scope (i usesah intefejsnogo scopa)
public override SymScope FindName ( string name )
{
SymScope sc = internal_find ( name , true ) ;
if ( sc ! = null ) return sc ;
for ( int i = 0 ; i < used_units . Count ; i + + )
{
sc = used_units [ i ] . FindNameOnlyInType ( name ) ;
if ( sc ! = null ) return sc ;
}
if ( topScope ! = null ) return topScope . FindName ( name ) ;
return null ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
List < SymScope > names = internal_find_overloads ( name , true ) ;
for ( int i = 0 ; i < used_units . Count ; i + + )
{
names . AddRange ( used_units [ i ] . FindOverloadNamesOnlyInType ( name ) ) ;
}
if ( topScope ! = null )
names . AddRange ( topScope . FindOverloadNames ( name ) ) ;
return names ;
}
2018-11-01 14:22:34 +03:00
public override void AddName ( string name , SymScope sc )
{
2019-12-24 14:27:02 +03:00
string pure_name = name ;
int ind = name . IndexOf ( '`' ) ;
if ( ind ! = - 1 )
pure_name = name . Substring ( 0 , ind ) ;
sc . si . name = pure_name ;
object o = symbol_table [ pure_name ] ;
if ( o ! = null & & ! IsHiddenName ( pure_name ) )
2018-11-01 14:22:34 +03:00
{
if ( o is SymScope )
{
List < SymScope > lst = new List < SymScope > ( ) ;
lst . Add ( o as SymScope ) ;
lst . Add ( sc ) ;
symbol_table [ name ] = lst ;
2019-12-24 14:27:02 +03:00
if ( pure_name ! = name )
symbol_table [ pure_name ] = lst ;
2018-11-01 14:22:34 +03:00
}
else
{
( o as List < SymScope > ) . Add ( sc ) ;
}
}
else
2019-12-24 14:27:02 +03:00
{
2018-11-01 14:22:34 +03:00
symbol_table [ name ] = sc ;
2019-12-24 14:27:02 +03:00
if ( pure_name ! = name )
symbol_table [ pure_name ] = sc ;
}
2018-11-01 14:22:34 +03:00
members . Add ( sc ) ;
}
2015-05-14 22:35:07 +03:00
public override SymScope FindNameInAnyOrder ( string name )
{
SymScope sc = internal_find ( name , false ) ;
if ( sc ! = null ) return sc ;
for ( int i = 0 ; i < used_units . Count ; i + + )
{
sc = used_units [ i ] . FindNameOnlyInType ( name ) ;
if ( sc ! = null ) return sc ;
}
if ( topScope ! = null ) return topScope . FindName ( name ) ;
return null ;
}
}
/// <summary>
///element - perem, pole, parametr, svojstvo, konstanta
///takzhe obertka nad vsem ostalnym, ispolzuetsja v ExpressionVisitor
/// </summary>
public class ElementScope : SymScope , IElementScope
{
public SymScope sc ;
public PascalABCCompiler . SyntaxTree . parametr_kind param_kind ;
public object cnst_val ;
public List < TypeScope > indexers ;
public TypeScope elementType ;
2018-05-08 21:39:55 +03:00
public bool is_readonly ;
2015-05-14 22:35:07 +03:00
public ElementScope ( ) { }
public ElementScope ( SymInfo si , SymScope sc , SymScope topScope )
{
this . si = si ;
this . sc = sc ;
this . topScope = topScope ;
2018-05-08 21:39:55 +03:00
2015-05-14 22:35:07 +03:00
MakeDescription ( ) ;
//UnitDocCache.AddDescribeToComplete(this);
//if (sc is ProcScope) si.kind = SymbolKind.Delegate;
//si.describe = si.name + ": " + sc.ToString();
}
public ElementScope ( SymInfo si , SymScope sc , object cnst_val , SymScope topScope )
{
this . si = si ;
this . sc = sc ;
this . topScope = topScope ;
this . cnst_val = cnst_val ;
MakeDescription ( ) ;
//UnitDocCache.AddDescribeToComplete(this);
}
public ElementScope ( SymScope sc )
{
this . si = new SymInfo ( "" , SymbolKind . Type , "" ) ;
this . sc = sc ;
if ( sc ! = null )
this . acc_mod = sc . acc_mod ;
//UnitDocCache.AddDescribeToComplete(this);
if ( sc is ProcScope )
{
MakeDescription ( ) ;
si . kind = SymbolKind . Delegate ;
}
}
public virtual bool IsReadOnly
{
get
{
2018-05-08 21:39:55 +03:00
return is_readonly ;
2015-05-14 22:35:07 +03:00
}
}
public override ScopeKind Kind
{
get
{
return ScopeKind . ElementScope ;
}
}
2020-01-26 20:24:07 +03:00
public bool IsIndexedProperty
{
get
{
return this . ElemKind = = SymbolKind . Property & & indexers ! = null & & indexers . Count > 0 ;
}
}
2015-05-14 22:35:07 +03:00
public PascalABCCompiler . SyntaxTree . parametr_kind ParamKind
{
get
{
return param_kind ;
}
}
public IBaseScope Type
{
get
{
return sc ;
}
}
public object ConstantValue
{
get
{
return cnst_val ;
}
}
public virtual ITypeScope ElementType
{
get
{
return elementType ;
}
}
public ITypeScope [ ] Indexers
{
get
{
return GetIndexers ( ) ;
}
}
public virtual bool IsVirtual
{
get
{
return is_virtual ;
}
}
public virtual bool IsOverride
{
get
{
return is_override ;
}
}
public virtual bool IsStatic
{
get
{
return is_static ;
}
}
public virtual bool IsAbstract
{
get
{
return is_abstract ;
}
}
public virtual bool IsReintroduce
{
get
{
return is_reintroduce ;
}
}
public void MakeDescription ( )
{
2016-05-01 13:02:40 +03:00
si . description = CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
2016-05-27 10:22:52 +03:00
if ( ! string . IsNullOrEmpty ( documentation ) )
si . description + = Environment . NewLine + documentation ;
2015-05-14 22:35:07 +03:00
}
public virtual void AddIndexer ( TypeScope ts )
{
if ( indexers = = null ) indexers = new List < TypeScope > ( ) ;
indexers . Add ( ts ) ;
}
public virtual TypeScope [ ] GetIndexers ( )
{
if ( indexers ! = null & & indexers . Count > 0 )
return indexers . ToArray ( ) ;
else return new TypeScope [ 0 ] ;
}
public override SymScope FindName ( string s )
{
2017-08-31 22:01:34 +03:00
if ( string . Compare ( si . name , s , true ) = = 0 )
return this ;
2018-10-14 16:06:15 +03:00
return topScope . FindName ( s ) ;
2015-05-14 22:35:07 +03:00
}
public override List < SymScope > FindOverloadNames ( string name )
{
2018-12-31 13:12:08 +03:00
if ( string . Compare ( si . name , name , true ) = = 0 )
return new List < SymScope > ( ) { this } ;
2017-08-26 16:59:43 +03:00
List < SymScope > names = sc . FindOverloadNames ( name ) ;
if ( topScope ! = null )
names . AddRange ( topScope . FindOverloadNames ( name ) ) ;
return names ;
2015-05-14 22:35:07 +03:00
}
public override TypeScope GetElementType ( )
{
return sc . GetElementType ( ) ;
}
// public override SymInfo[] GetNames(ExpressionVisitor ev)
// {
// return sc.GetNamesAsInObject(ev);
// }
public override SymInfo [ ] GetNamesAsInObject ( )
{
return sc . GetNamesAsInObject ( ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
return sc . GetNamesAsInObject ( ev ) ;
}
public override SymScope FindNameOnlyInType ( string name )
{
return sc . FindNameOnlyInType ( name ) ;
}
public override SymScope FindNameOnlyInThisType ( string name )
{
return sc . FindNameOnlyInThisType ( name ) ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return sc . FindOverloadNamesOnlyInType ( name ) ;
}
public override SymInfo [ ] GetNames ( )
{
return sc . GetNamesAsInObject ( ) ;
}
2018-01-31 22:24:16 +03:00
public override SymInfo [ ] GetNamesInAllTopScopes ( bool all_names , ExpressionVisitor ev , bool is_static )
{
return topScope . GetNamesInAllTopScopes ( all_names , ev , is_static ) ;
}
2015-05-14 22:35:07 +03:00
public override bool IsEqual ( SymScope ts )
{
2019-12-26 13:53:19 +03:00
if ( this = = ts )
return true ;
if ( this . Name ! = ts . Name )
return false ;
ElementScope es = ts as ElementScope ;
2015-05-14 22:35:07 +03:00
if ( es = = null )
return false ;
2019-12-26 13:53:19 +03:00
if ( this . sc ! = es . sc )
2015-05-14 22:35:07 +03:00
return false ;
2019-12-26 13:53:19 +03:00
if ( this . si . kind ! = SymbolKind . Parameter | | ts . si . kind ! = SymbolKind . Parameter )
return false ;
ProcScope ps1 = this . topScope as ProcScope ;
ProcScope ps2 = es . topScope as ProcScope ;
if ( ps1 = = null | | ps2 = = null )
return false ;
if ( ps1 = = ps2 | | ps1 is ProcRealization & & ( ps1 as ProcRealization ) . def_proc = = ps2 | | ps1 . procRealization = = ps2 )
return true ;
return false ;
2015-05-14 22:35:07 +03:00
}
public override string ToString ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetSimpleDescription ( this ) ;
}
}
//relizacija procedury delegiruet vse metody svoemu opisaniju
public class ProcRealization : ProcScope , IProcRealizationScope
{
public ProcScope def_proc ;
public SymScope top_mod_scope ;
public ProcRealization ( ProcScope def_proc , SymScope top_mod_scope )
{
this . def_proc = def_proc ;
this . top_mod_scope = top_mod_scope ;
2017-12-29 22:04:24 +03:00
def_proc . procRealization = this ;
2015-05-14 22:35:07 +03:00
if ( def_proc ! = null )
this . topScope = def_proc . topScope ;
2016-05-01 13:02:40 +03:00
this . si = new SymInfo ( def_proc . si . name , def_proc . si . kind , def_proc . si . description ) ;
2015-05-14 22:35:07 +03:00
}
public override ScopeKind Kind
{
get
{
return ScopeKind . ProcRealization ;
}
}
public IProcScope DefProc
{
get
{
return def_proc ;
}
}
public override bool IsVirtual
{
get
{
return def_proc . is_virtual ;
}
}
public override bool IsOverride
{
get
{
return def_proc . is_override ;
}
}
public override bool IsStatic
{
get
{
return def_proc . is_static ;
}
}
public override bool IsAbstract
{
get
{
return def_proc . is_abstract ;
}
}
public override bool IsReintroduce
{
get
{
return def_proc . is_reintroduce ;
}
}
public override IElementScope [ ] Parameters
{
get
{
return def_proc . Parameters ;
}
}
public override void AddName ( string name , SymScope sc )
{
//ht[name] = sc;
def_proc . AddName ( name , sc ) ;
}
public override bool IsConstructor ( )
{
return def_proc . IsConstructor ( ) ;
}
public override void AddParameter ( ElementScope par )
{
def_proc . AddParameter ( par ) ;
}
public override void ClearNames ( )
{
def_proc . ClearNames ( ) ;
}
public override SymScope FindScopeByLocation ( int line , int column )
{
return def_proc . FindScopeByLocation ( line , column ) ;
}
public override string GetDescriptionWithoutDoc ( )
{
string s = def_proc . GetDescriptionWithoutDoc ( ) ;
if ( def_proc . topScope is TypeScope )
{
return TypeUtility . GetTopScopeName ( def_proc . topScope ) + s ;
}
return s ;
}
public override SymScope FindName ( string name )
{
//SymScope sc = ht[name] as SymScope;
2017-10-12 21:52:33 +03:00
/ * SymScope sc = def_proc . FindNameOnlyInType ( name ) ;
2015-05-14 22:35:07 +03:00
if ( sc ! = null ) return sc ;
if ( top_mod_scope ! = null )
return top_mod_scope . FindName ( name ) ;
2017-10-12 21:52:33 +03:00
return null ; * /
return def_proc . FindName ( name ) ;
2015-05-14 22:35:07 +03:00
}
public override SymScope FindNameOnlyInType ( string name )
{
//SymScope sc = ht[name] as SymScope;
return def_proc . FindNameOnlyInType ( name ) ;
}
public override SymScope FindNameOnlyInThisType ( string name )
{
//SymScope sc = ht[name] as SymScope;
return def_proc . FindNameOnlyInType ( name ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( )
{
return def_proc . GetNamesAsInObject ( ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
return def_proc . GetNamesAsInObject ( ev ) ;
}
public override SymInfo [ ] GetNames ( )
{
List < SymInfo > names = new List < SymInfo > ( ) ;
names . AddRange ( def_proc . GetNames ( ) ) ;
if ( top_mod_scope ! = null )
names . AddRange ( top_mod_scope . GetNames ( ) ) ;
return names . ToArray ( ) ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
SymScope sc = def_proc . FindNameInAnyOrder ( name ) ;
if ( sc ! = null ) return sc ;
if ( top_mod_scope ! = null ) return top_mod_scope . FindNameInAnyOrder ( name ) ;
return null ;
}
public override int GetParametersCount ( )
{
return def_proc . GetParametersCount ( ) ;
}
public override SymInfo [ ] GetNamesAsInBaseClass ( ExpressionVisitor ev , bool is_static )
{
return def_proc . GetNamesAsInBaseClass ( ev , is_static ) ;
}
// public override SymInfo[] GetNames(ExpressionVisitor ev)
// {
// List<SymInfo> names = new List<SymInfo>();
// names.AddRange(def_proc.GetNames(ev));
// if (top_mod_scope != null)
// names.AddRange(top_mod_scope.GetNames(ev));
// return names.ToArray();
// }
public override SymInfo [ ] GetNamesInAllTopScopes ( bool all_names , ExpressionVisitor ev , bool is_static )
{
List < SymInfo > names = new List < SymInfo > ( ) ;
//names.AddRange(def_proc.GetNamesInAllTopScopes(all_names,ev,is_static));
names . AddRange ( def_proc . GetNames ( ) ) ;
if ( top_mod_scope ! = null )
names . AddRange ( top_mod_scope . GetNamesInAllTopScopes ( all_names , ev , is_static ) ) ;
return names . ToArray ( ) ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
return def_proc . FindOverloadNames ( name ) ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return def_proc . FindOverloadNamesOnlyInType ( name ) ;
}
public override bool IsEqual ( SymScope ts )
{
return def_proc . IsEqual ( ts ) ;
}
public override string ToString ( )
{
return def_proc . ToString ( ) ;
}
}
2020-01-26 20:24:07 +03:00
public class IndexedPropertyType : TypeScope
{
public TypeScope propertyType ;
public IndexedPropertyType ( TypeScope propertyType )
{
this . propertyType = propertyType ;
}
}
2015-05-14 22:35:07 +03:00
public class ProcType : TypeScope , IProcType
{
public ProcScope target ;
2018-09-20 22:21:16 +03:00
private CompiledScope parent ;
2018-10-04 22:31:31 +03:00
private ProcScope invokeMeth ;
2015-05-14 22:35:07 +03:00
public ProcType ( ProcScope target )
{
this . target = target ;
this . si = new SymInfo ( this . ToString ( ) , SymbolKind . Delegate , this . ToString ( ) ) ;
2018-09-20 22:21:16 +03:00
this . parent = TypeTable . get_compiled_type ( PascalABCCompiler . NetHelper . NetHelper . MulticastDelegateType ) ;
2018-10-04 22:31:31 +03:00
2015-05-14 22:35:07 +03:00
}
2016-12-18 20:18:51 +03:00
public ProcType ( ProcScope target , List < string > generic_params ) : this ( target )
{
this . generic_params = generic_params ;
}
2015-05-14 22:35:07 +03:00
IProcScope IProcType . Target
{
get
{
return target ;
}
}
2017-02-19 23:20:56 +03:00
public override bool IsDelegate
{
get
{
return true ;
}
}
2015-05-14 22:35:07 +03:00
public override PascalABCCompiler . Parsers . SymbolKind ElemKind
{
get { return PascalABCCompiler . Parsers . SymbolKind . Delegate ; }
}
public override ScopeKind Kind
{
get
{
return ScopeKind . Delegate ;
}
}
2018-10-04 22:31:31 +03:00
public ProcScope InvokeMethod
{
get
{
if ( invokeMeth = = null )
{
invokeMeth = new ProcScope ( "Invoke" , target ) ;
invokeMeth . declaringType = parent ;
invokeMeth . parameters = target . parameters ;
invokeMeth . return_type = target . return_type ;
invokeMeth . is_virtual = true ;
invokeMeth . Complete ( ) ;
}
return invokeMeth ;
}
}
2019-02-03 14:35:17 +03:00
private ProcScope beginInvokeMethod ;
private ProcScope endInvokeMethod ;
public ProcScope BeginInvokeMethod
{
get
{
if ( beginInvokeMethod = = null )
{
beginInvokeMethod = new ProcScope ( "BeginInvoke" , target ) ;
beginInvokeMethod . declaringType = parent ;
beginInvokeMethod . parameters = new List < ElementScope > ( ) ;
beginInvokeMethod . parameters . Add ( new ElementScope ( new SymInfo ( "callback" , SymbolKind . Parameter , "callback" ) , TypeTable . get_compiled_type ( typeof ( AsyncCallback ) ) , beginInvokeMethod ) ) ;
beginInvokeMethod . parameters . Add ( new ElementScope ( new SymInfo ( "object" , SymbolKind . Parameter , "object" ) , TypeTable . obj_type , beginInvokeMethod ) ) ;
beginInvokeMethod . return_type = TypeTable . get_compiled_type ( typeof ( IAsyncResult ) ) ;
beginInvokeMethod . is_virtual = true ;
beginInvokeMethod . Complete ( ) ;
}
return beginInvokeMethod ;
}
}
public ProcScope EndInvokeMethod
{
get
{
if ( endInvokeMethod = = null )
{
endInvokeMethod = new ProcScope ( "EndInvoke" , target ) ;
endInvokeMethod . declaringType = parent ;
endInvokeMethod . parameters = new List < ElementScope > ( ) ;
endInvokeMethod . parameters . Add ( new ElementScope ( new SymInfo ( "result" , SymbolKind . Parameter , "result" ) , TypeTable . get_compiled_type ( typeof ( IAsyncResult ) ) , endInvokeMethod ) ) ;
//endInvokeMethod.return_type = TypeTable.get_compiled_type(typeof(IAsyncResult));
endInvokeMethod . is_virtual = true ;
endInvokeMethod . Complete ( ) ;
}
return endInvokeMethod ;
}
}
2018-05-13 15:02:48 +03:00
public override TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2015-05-14 22:35:07 +03:00
{
return this ;
}
2018-10-04 22:31:31 +03:00
public override List < SymScope > FindOverloadNames ( string name )
{
List < SymScope > lst = new List < SymScope > ( ) ;
2019-02-03 14:35:17 +03:00
if ( string . Compare ( name , "Invoke" , true ) = = 0 )
2018-10-04 22:31:31 +03:00
lst . Add ( InvokeMethod ) ;
2019-02-03 14:35:17 +03:00
else if ( string . Compare ( name , "BeginInvoke" , true ) = = 0 )
lst . Add ( BeginInvokeMethod ) ;
else if ( string . Compare ( name , "EndInvoke" , true ) = = 0 )
lst . Add ( EndInvokeMethod ) ;
2018-10-04 22:31:31 +03:00
else
lst . AddRange ( parent . FindOverloadNames ( name ) ) ;
return lst ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
List < SymScope > lst = new List < SymScope > ( ) ;
2019-02-03 14:35:17 +03:00
if ( string . Compare ( name , "Invoke" , true ) = = 0 )
2018-10-04 22:31:31 +03:00
lst . Add ( InvokeMethod ) ;
2019-02-03 14:35:17 +03:00
else if ( string . Compare ( name , "BeginInvoke" , true ) = = 0 )
lst . Add ( BeginInvokeMethod ) ;
else if ( string . Compare ( name , "EndInvoke" , true ) = = 0 )
lst . Add ( EndInvokeMethod ) ;
2018-10-04 22:31:31 +03:00
else
lst . AddRange ( parent . FindOverloadNamesOnlyInType ( name ) ) ;
return lst ;
}
2015-05-14 22:35:07 +03:00
public override SymInfo [ ] GetNames ( )
{
2018-10-04 22:31:31 +03:00
List < SymInfo > lst = new List < SymInfo > ( ) ;
lst . Add ( InvokeMethod . si ) ;
2019-02-03 14:35:17 +03:00
lst . Add ( BeginInvokeMethod . si ) ;
lst . Add ( EndInvokeMethod . si ) ;
2018-10-04 22:31:31 +03:00
lst . AddRange ( parent . GetNames ( ) ) ;
return lst . ToArray ( ) ;
2015-05-14 22:35:07 +03:00
}
public override SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword , bool called_in_base )
{
2018-10-04 22:31:31 +03:00
return parent . GetNames ( ev , keyword , called_in_base ) ;
2015-05-14 22:35:07 +03:00
}
public override string GetDescription ( )
{
return this . ToString ( ) ;
}
public override ProcScope GetConstructor ( )
{
return null ;
}
public override List < ProcScope > GetConstructors ( bool search_in_base )
{
return new List < ProcScope > ( 0 ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( )
{
2018-10-04 22:31:31 +03:00
List < SymInfo > lst = new List < SymInfo > ( ) ;
lst . Add ( InvokeMethod . si ) ;
2019-02-03 14:35:17 +03:00
lst . Add ( BeginInvokeMethod . si ) ;
lst . Add ( EndInvokeMethod . si ) ;
2018-10-04 22:31:31 +03:00
lst . AddRange ( parent . GetNamesAsInObject ( ) ) ;
return lst . ToArray ( ) ;
2015-05-14 22:35:07 +03:00
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
2018-10-04 22:31:31 +03:00
List < SymInfo > lst = new List < SymInfo > ( ) ;
lst . Add ( InvokeMethod . si ) ;
2019-02-03 14:35:17 +03:00
lst . Add ( BeginInvokeMethod . si ) ;
lst . Add ( EndInvokeMethod . si ) ;
2018-10-04 22:31:31 +03:00
lst . AddRange ( parent . GetNamesAsInObject ( ev ) ) ;
return lst . ToArray ( ) ;
2015-05-14 22:35:07 +03:00
}
public override SymScope FindName ( string name )
{
2018-10-04 22:31:31 +03:00
return topScope . FindName ( name ) ;
2015-05-14 22:35:07 +03:00
}
public override SymScope FindNameInAnyOrder ( string name )
{
2018-10-04 22:31:31 +03:00
return parent . FindNameInAnyOrder ( name ) ;
2015-05-14 22:35:07 +03:00
}
public override SymScope FindNameOnlyInType ( string name )
{
2018-10-04 22:31:31 +03:00
return parent . FindNameOnlyInType ( name ) ;
2015-05-14 22:35:07 +03:00
}
public override SymScope FindNameOnlyInThisType ( string name )
{
2018-10-04 22:31:31 +03:00
return parent . FindNameOnlyInThisType ( name ) ;
2015-05-14 22:35:07 +03:00
}
2018-11-12 22:52:25 +03:00
public override bool IsConvertable ( TypeScope ts , bool strong = false )
2015-05-14 22:35:07 +03:00
{
if ( IsEqual ( ts ) )
return true ;
if ( ts is CompiledScope )
2018-11-12 22:52:25 +03:00
return ts . IsConvertable ( this , strong ) ;
2018-09-02 13:36:09 +03:00
if ( ts is TemplateParameterScope | | ts . IsGenericParameter )
return true ;
2015-05-14 22:35:07 +03:00
return false ;
}
public override bool IsEqual ( SymScope ts )
{
if ( ts is NullTypeScope )
return true ;
if ( ts is TypeSynonim )
return this . IsEqual ( ( ts as TypeSynonim ) . actType ) ;
if ( ts is ProcType )
return target . IsParamsEquals ( ( ts as ProcType ) . target ) ;
2017-06-04 18:48:35 +03:00
if ( ts is CompiledScope )
return ts . IsEqual ( this ) ;
2015-05-14 22:35:07 +03:00
return false ;
}
public override string ToString ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
//procedura-funcija-metod
public class ProcScope : SymScope , IProcScope
{
public string name ;
public List < ElementScope > parameters ;
public TypeScope return_type ;
public ProcScope nextProc ; //sled. peregruzhennaja procedura
public bool is_constructor ;
public bool is_forward = false ;
public bool already_defined = false ; //sush. li realizacija
2017-12-29 22:04:24 +03:00
public ProcRealization procRealization ; //ssylka na realizaciju
2015-05-14 22:35:07 +03:00
public List < string > template_parameters ;
public TypeScope declaringType ;
public bool is_extension = false ;
public List < string > generic_params ;
public List < string > generic_args ;
2017-08-11 15:37:35 +03:00
public ProcScope original_function ;
2015-05-14 22:35:07 +03:00
public ProcScope ( )
{
}
public ProcScope ( string name , SymScope topScope )
{
this . name = name ;
this . topScope = topScope ;
this . si = new SymInfo ( name , SymbolKind . Method , name ) ;
2017-02-12 22:48:33 +03:00
//this.si.name = CodeCompletionController.CurrentParser.LanguageInformation.GetShortName(this);
2015-05-14 22:35:07 +03:00
parameters = new List < ElementScope > ( ) ;
members = new List < SymScope > ( ) ;
//UnitDocCache.AddDescribeToComplete(this);
if ( topScope is TypeScope ) declaringType = topScope as TypeScope ;
}
public ProcScope ( string name , SymScope topScope , bool is_constructor )
{
this . name = name ;
this . topScope = topScope ;
this . si = new SymInfo ( name , SymbolKind . Method , name ) ;
2017-02-12 22:48:33 +03:00
//this.si.name = CodeCompletionController.CurrentParser.LanguageInformation.GetShortName(this);
2015-05-14 22:35:07 +03:00
parameters = new List < ElementScope > ( ) ;
members = new List < SymScope > ( ) ;
this . is_constructor = is_constructor ;
//UnitDocCache.AddDescribeToComplete(this);
if ( topScope is TypeScope ) declaringType = topScope as TypeScope ;
}
public override ScopeKind Kind
{
get
{
return ScopeKind . Procedure ;
}
}
public virtual bool IsVirtual
{
get
{
return is_virtual ;
}
}
public virtual bool IsExtension
{
get { return is_extension ; }
}
public virtual bool IsOverride
{
get
{
return is_override ;
}
}
2017-08-25 18:37:16 +03:00
public bool OfTypeInstance
{
get
{
return original_function ! = null | | declaringType ! = null & & declaringType . instances ! = null & & declaringType . instances . Count > 0 ;
}
}
2015-05-14 22:35:07 +03:00
public virtual bool IsStatic
{
get
{
return is_static ;
}
}
public virtual bool IsAbstract
{
get
{
return is_abstract ;
}
}
public virtual bool IsReintroduce
{
get
{
return is_reintroduce ;
}
}
2016-12-04 14:46:04 +03:00
ITypeScope IProcScope . DeclaringType
{
get
{
return declaringType ;
}
}
2015-05-14 22:35:07 +03:00
public virtual IElementScope [ ] Parameters
{
get
{
if ( parameters ! = null )
return parameters . ToArray ( ) ;
return null ;
}
}
public virtual string [ ] TemplateParameters
{
get
{
if ( template_parameters ! = null )
return template_parameters . ToArray ( ) ;
return null ;
}
}
public virtual IProcScope NextFunction
{
get
{
return nextProc ;
}
}
public virtual ITypeScope ReturnType
{
get
{
return return_type ;
}
}
public IProcRealizationScope Realization
{
get
{
2017-12-29 22:04:24 +03:00
return procRealization ;
2015-05-14 22:35:07 +03:00
}
}
public override void ClearNames ( )
{
members . Clear ( ) ;
//members
}
2022-11-01 12:23:10 +03:00
public override bool IsInScope ( location loc , int line , int column )
{
bool res = base . IsInScope ( loc , line , column ) ;
if ( res )
return res ;
if ( procRealization ! = null & & procRealization ! = this )
return procRealization . IsInScope ( loc , line , column ) ;
return false ;
}
2015-05-14 22:35:07 +03:00
public ProcScope GetInstance ( List < TypeScope > gen_args )
{
2019-09-09 22:00:01 +03:00
List < string > template_parameters = this . template_parameters ;
if ( ( this . template_parameters = = null | | this . template_parameters . Count = = 0 ) )
{
bool has_instance = false ;
if ( this . topScope is TypeScope )
{
TypeScope ts = this . topScope as TypeScope ;
if ( ts . instances ! = null & & ts . instances . Count > 0 & & gen_args . Count > 0 )
{
has_instance = true ;
gen_args = ts . instances ;
template_parameters = new List < string > ( ts . TemplateArguments ) ;
}
2020-02-02 14:07:36 +03:00
2019-09-09 22:00:01 +03:00
}
if ( ! has_instance )
return this ;
}
2020-02-02 14:07:36 +03:00
2015-05-14 22:35:07 +03:00
ProcScope instance = new ProcScope ( this . name , this . topScope , this . is_constructor ) ;
2017-02-19 12:58:42 +03:00
instance . is_extension = this . is_extension ;
2017-08-11 15:37:35 +03:00
instance . original_function = this ;
2017-06-11 00:46:17 +03:00
instance . loc = this . loc ;
instance . body_loc = this . body_loc ;
2015-05-14 22:35:07 +03:00
instance . parameters = new List < ElementScope > ( this . parameters . Count ) ;
int i = 0 ;
foreach ( ElementScope parameter in this . parameters )
{
2016-04-03 13:57:12 +03:00
i + + ;
2016-03-20 16:23:41 +03:00
if ( parameter . sc is UnknownScope | | ( parameter . sc is TypeScope ) & & ( parameter . sc as TypeScope ) . IsGenericParameter )
2015-05-14 22:35:07 +03:00
{
2019-09-09 22:00:01 +03:00
int ind = template_parameters . IndexOf ( ( parameter . sc as TypeScope ) . Name ) ;
2015-05-14 22:35:07 +03:00
ElementScope inst_param = null ;
if ( gen_args . Count > ind & & ind ! = - 1 )
2018-04-12 21:16:11 +03:00
inst_param = new ElementScope ( new SymInfo ( parameter . si . name , parameter . si . kind , parameter . si . description ) , gen_args [ ind ] , parameter . topScope ) ;
2015-05-14 22:35:07 +03:00
else
2018-04-12 21:16:11 +03:00
inst_param = new ElementScope ( new SymInfo ( parameter . si . name , parameter . si . kind , parameter . si . description ) , parameter . sc , parameter . topScope ) ;
2015-05-14 22:35:07 +03:00
instance . parameters . Add ( inst_param ) ;
}
else
{
ElementScope inst_param = null ;
if ( ( parameter . sc as TypeScope ) . IsGeneric )
2018-04-12 21:16:11 +03:00
inst_param = new ElementScope ( new SymInfo ( parameter . si . name , parameter . si . kind , parameter . si . description ) , ( parameter . sc as TypeScope ) . GetInstance ( gen_args ) , parameter . topScope ) ;
2021-12-12 15:49:48 +03:00
else if ( parameter . param_kind = = parametr_kind . params_parametr & & ( parameter . sc as TypeScope ) . IsArray & & ( parameter . sc as TypeScope ) . GetElementType ( ) . IsGenericParameter & & i - 1 < gen_args . Count & & gen_args [ i - 1 ] . IsArray )
2020-01-26 19:38:18 +03:00
{
gen_args [ i - 1 ] = gen_args [ i - 1 ] . GetElementType ( ) ;
inst_param = new ElementScope ( new SymInfo ( parameter . si . name , parameter . si . kind , parameter . si . description ) , ( parameter . sc as TypeScope ) . GetInstance ( gen_args ) , parameter . topScope ) ;
}
2017-02-12 16:48:22 +03:00
else if ( ( parameter . sc as TypeScope ) . GetElementType ( ) ! = null & & ( parameter . sc as TypeScope ) . GetElementType ( ) . IsGenericParameter )
2018-04-12 21:16:11 +03:00
inst_param = new ElementScope ( new SymInfo ( parameter . si . name , parameter . si . kind , parameter . si . description ) , ( parameter . sc as TypeScope ) . GetInstance ( gen_args ) , parameter . topScope ) ;
2015-05-14 22:35:07 +03:00
else
2018-04-12 21:16:11 +03:00
inst_param = new ElementScope ( new SymInfo ( parameter . si . name , parameter . si . kind , parameter . si . description ) , parameter . sc , parameter . topScope ) ;
2015-05-14 22:35:07 +03:00
instance . parameters . Add ( inst_param ) ;
}
2016-04-03 13:57:12 +03:00
if ( parameter . param_kind = = parametr_kind . params_parametr & & i < gen_args . Count )
gen_args . RemoveRange ( i , gen_args . Count - i ) ;
2015-05-14 22:35:07 +03:00
}
instance . si = this . si ;
2017-08-10 18:30:51 +03:00
if ( this . return_type ! = null )
2018-08-09 15:14:35 +03:00
{
bool exact = true ;
2019-09-09 22:00:01 +03:00
if ( template_parameters ! = null & & template_parameters . Count > 0 )
2018-08-09 15:14:35 +03:00
{
foreach ( ElementScope parameter in this . parameters )
{
TypeScope ts = parameter . sc as TypeScope ;
if ( ts . IsGeneric & & ! ts . IsGenericParameter )
{
foreach ( TypeScope inst_ts in ts . instances )
{
2020-02-02 14:07:36 +03:00
if ( this . template_parameters ! = null & & this . template_parameters . Contains ( inst_ts . name ) )
2018-08-09 15:14:35 +03:00
{
exact = false ;
2020-01-26 14:33:06 +03:00
if ( ts . IsDelegate )
{
2020-02-02 13:09:44 +03:00
for ( int j = 0 ; j < gen_args . Count ; j + + )
2020-01-26 14:33:06 +03:00
{
TypeScope gen_ts = gen_args [ j ] ;
if ( gen_ts is ProcType )
{
gen_args [ j ] = ( gen_ts as ProcType ) . InvokeMethod . return_type ;
}
}
}
2020-02-02 13:09:44 +03:00
/ * for ( int j = 0 ; j < gen_args . Count ; j + + )
{
TypeScope gen_ts = gen_args [ j ] ;
if ( gen_ts . IsGeneric & & gen_ts . original_type ! = null )
{
int ind = gen_ts . original_type . generic_params . IndexOf ( inst_ts . name ) ;
if ( ind ! = - 1 )
{
gen_args [ j ] = gen_ts . instances [ ind ] ;
}
}
} * /
2018-08-09 15:14:35 +03:00
break ;
}
}
}
2020-02-02 13:09:44 +03:00
else if ( ts . GetElementType ( ) ! = null & & ts . GetElementType ( ) . IsGeneric )
{
foreach ( TypeScope inst_ts in ts . GetElementType ( ) . instances )
{
if ( this . template_parameters . Contains ( inst_ts . name ) )
{
exact = false ;
if ( ts . IsDelegate )
{
for ( int j = 0 ; j < gen_args . Count ; j + + )
{
TypeScope gen_ts = gen_args [ j ] ;
if ( gen_ts is ProcType )
{
gen_args [ j ] = ( gen_ts as ProcType ) . InvokeMethod . return_type ;
}
}
}
break ;
}
}
}
/ * else if ( ts . GetElementType ( ) ! = null & & ts . GetElementType ( ) . IsGenericParameter )
{
if ( this . template_parameters . Contains ( ts . GetElementType ( ) . name ) )
{
exact = false ;
}
} * /
2020-02-02 14:07:36 +03:00
}
2018-08-09 15:14:35 +03:00
}
instance . return_type = this . return_type . GetInstance ( gen_args , exact ) ;
}
2020-02-02 14:07:36 +03:00
2015-05-14 22:35:07 +03:00
return instance ;
}
public virtual int GetParametersCount ( )
{
if ( parameters = = null ) return 0 ;
return parameters . Count ;
}
public virtual bool IsConstructor ( )
{
return is_constructor ;
}
public override void MakeSynonimDescription ( )
{
//aliased = true;
2016-05-01 13:02:40 +03:00
si . description = CodeCompletionController . CurrentParser . LanguageInformation . GetSynonimDescription ( this ) ;
2015-05-14 22:35:07 +03:00
}
//zavershenie opisanija, vyzyvaetsja kogda parametry razobrany
public void Complete ( )
{
if ( documentation ! = null & & documentation . Length > 0 & & documentation [ 0 ] = = '-' ) return ;
2016-05-01 13:02:40 +03:00
this . si . description = this . ToString ( ) ;
2017-02-12 22:48:33 +03:00
this . si . addit_name = CodeCompletionController . CurrentParser . LanguageInformation . GetShortName ( this ) ;
2016-05-01 13:02:40 +03:00
if ( documentation ! = null ) this . si . description + = "\n" + this . documentation ;
2015-05-14 22:35:07 +03:00
}
public void AddTemplateParameter ( string name )
{
if ( template_parameters = = null ) template_parameters = new List < string > ( ) ;
template_parameters . Add ( name ) ;
}
public override void AddName ( string name , SymScope sc )
{
//ht[name] = sc;
sc . si . name = name ;
members . Add ( sc ) ;
}
public virtual void AddParameter ( ElementScope par )
{
parameters . Add ( par ) ;
}
public bool IsGeneric ( )
{
return template_parameters ! = null & & template_parameters . Count > 0 ;
}
public override SymScope FindName ( string name )
{
//SymScope sc = ht[name] as SymScope;
SymScope sc = internal_find ( name , true ) ;
if ( sc ! = null ) return sc ;
if ( topScope ! = null ) sc = topScope . FindName ( name ) ;
if ( sc ! = null ) return sc ;
2017-12-29 22:04:24 +03:00
if ( procRealization ! = null & & procRealization . top_mod_scope ! = null )
return procRealization . top_mod_scope . FindName ( name ) ;
2015-05-14 22:35:07 +03:00
return null ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
List < SymScope > names = internal_find_overloads ( name , true ) ;
if ( topScope ! = null )
names . AddRange ( topScope . FindOverloadNames ( name ) ) ;
2017-12-29 22:04:24 +03:00
if ( procRealization ! = null & & procRealization . top_mod_scope ! = null )
names . AddRange ( procRealization . top_mod_scope . FindOverloadNames ( name ) ) ;
2015-05-14 22:35:07 +03:00
return names ;
}
public override SymInfo [ ] GetNames ( )
{
List < SymInfo > lst = new List < SymInfo > ( ) ;
/ * foreach ( string s in ht . Keys )
{
SymScope sc = ht [ s ] as SymScope ;
lst . Add ( sc . si ) ;
} * /
foreach ( SymScope ss in members )
2018-11-01 00:19:05 +03:00
if ( ss ! = this & & ! IsHiddenName ( ss . si . name ) )
2015-05-14 22:35:07 +03:00
{
if ( ss . loc ! = null & & loc ! = null )
{
if ( string . Compare ( ss . loc . doc . file_name , loc . doc . file_name , true ) = = 0 )
{
if ( IsAfterDefinition ( ss . loc . begin_line_num , ss . loc . begin_column_num ) )
{
lst . Add ( ss . si ) ;
}
}
else lst . Add ( ss . si ) ;
}
else
lst . Add ( ss . si ) ;
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
lst . AddRange ( this . topScope . GetNames ( ) ) ;
//if (proc_realization != null) lst.AddRange(proc_realization.top_mod_scope.GetNames());
return lst . ToArray ( ) ;
}
public override SymInfo [ ] GetNamesInAllTopScopes ( bool all_names , ExpressionVisitor ev , bool is_static )
{
List < SymInfo > lst = new List < SymInfo > ( ) ;
foreach ( SymScope ss in members )
2018-11-01 00:19:05 +03:00
if ( ss ! = this & & ! IsHiddenName ( ss . si . name ) )
2015-05-14 22:35:07 +03:00
{
if ( ss . loc ! = null & & loc ! = null )
{
if ( string . Compare ( ss . loc . doc . file_name , loc . doc . file_name , true ) = = 0 )
{
if ( IsAfterDefinition ( ss . loc . begin_line_num , ss . loc . begin_column_num ) )
{
lst . Add ( ss . si ) ;
}
}
else lst . Add ( ss . si ) ;
}
else
lst . Add ( ss . si ) ;
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
2017-11-19 21:15:33 +03:00
if ( topScope ! = null )
lst . AddRange ( topScope . GetNamesInAllTopScopes ( all_names , ev , this . is_static ) ) ;
2017-12-29 22:04:24 +03:00
if ( procRealization ! = null )
lst . AddRange ( procRealization . GetNamesInAllTopScopes ( all_names , ev , this . is_static ) ) ;
2015-05-14 22:35:07 +03:00
//if (proc_realization != null && proc_realization.top_mod_scope != null) lst.AddRange(proc_realization.top_mod_scope.GetNamesInAllTopScopes(all_names,ev,is_static));
return lst . ToArray ( ) ;
}
public virtual bool IsParamsEquals ( ProcScope ps )
{
try
{
if ( ps is CompiledMethodScope )
{
return ( ps as CompiledMethodScope ) . IsParamsEquals ( this ) ;
}
else if ( ps is CompiledConstructorScope )
{
return ( ps as CompiledConstructorScope ) . IsParamsEquals ( this ) ;
}
else
{
if ( this . parameters = = null | | this . parameters . Count = = 0 )
if ( ps . parameters = = null | | ps . parameters . Count = = 0 )
{
if ( this . return_type = = null )
{
if ( ps . return_type = = null )
return true ;
else
return false ;
}
else
return this . return_type . IsEqual ( ps . return_type ) ;
}
else
return false ;
if ( this . parameters . Count ! = ps . parameters . Count )
return false ;
for ( int i = 0 ; i < this . parameters . Count ; i + + )
{
if ( this . parameters [ i ] . param_kind ! = ps . parameters [ i ] . param_kind )
return false ;
if ( ! this . parameters [ i ] . sc . IsEqual ( ps . parameters [ i ] . sc ) )
2020-12-31 12:26:12 +03:00
if ( this . parameters [ i ] . sc is UnknownScope )
return true ;
else
return false ;
2015-05-14 22:35:07 +03:00
}
if ( this . return_type = = null )
if ( ps . return_type ! = null )
return false ;
else
return true ;
return this . return_type . IsEqual ( ps . return_type ) ;
}
}
catch
{
return false ;
}
}
private bool equal_parameters_and_result ( ProcScope ps )
{
if ( this . parameters = = null )
{
if ( ps . parameters ! = null )
return false ;
else
if ( this . return_type = = null )
{
if ( ps . return_type = = null )
return true ;
else
return false ;
}
return this . return_type . IsEqual ( ps . return_type ) ;
}
else
if ( ps . parameters = = null )
return false ;
if ( ps . parameters . Count ! = this . parameters . Count )
return false ;
for ( int i = 0 ; i < this . parameters . Count ; i + + )
{
if ( ! this . parameters [ i ] . sc . IsEqual ( ps . parameters [ i ] . sc ) )
return false ;
if ( this . parameters [ i ] . param_kind ! = ps . parameters [ i ] . param_kind )
return false ;
}
if ( this . return_type = = null )
{
if ( ps . return_type = = null )
return true ;
else
return false ;
}
return this . return_type . IsEqual ( ps . return_type ) ;
}
public override bool IsEqual ( SymScope ts )
{
ProcScope ps = ts as ProcScope ;
if ( ps = = null ) return false ;
if ( ps is ProcRealization ) ps = ( ps as ProcRealization ) . def_proc ;
if ( this = = ps ) return true ;
if ( ps . nextProc ! = null ) return IsEqual ( ps . nextProc ) ;
2019-12-26 13:13:07 +03:00
if ( this . nextProc ! = null ) return this . nextProc . IsEqual ( ts ) ;
2015-05-14 22:35:07 +03:00
return false ;
}
private string simp_descr ;
public override string GetDescriptionWithoutDoc ( )
{
if ( simp_descr = = null ) ToString ( ) ;
return simp_descr ;
}
public override string ToString ( )
{
simp_descr = CodeCompletionController . CurrentParser . LanguageInformation . GetSimpleDescription ( this ) ;
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
//perechislenie
public class EnumScope : TypeScope , IEnumScope
{
private List < string > enum_consts = new List < string > ( ) ; //konstanty perechislenija
public EnumScope ( SymbolKind kind , SymScope topScope , SymScope baseScope )
: base ( kind , topScope , baseScope )
{
}
public override ScopeKind Kind
{
get
{
return ScopeKind . Enum ;
}
}
public string [ ] EnumConsts
{
get
{
return enum_consts . ToArray ( ) ;
}
}
2018-05-13 15:02:48 +03:00
public override TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2015-05-14 22:35:07 +03:00
{
return this ;
}
public void AddEnumConstant ( string name )
{
enum_consts . Add ( name ) ;
}
2018-11-12 22:52:25 +03:00
public override bool IsConvertable ( TypeScope ts , bool strong = false )
2015-05-14 22:35:07 +03:00
{
if ( IsEqual ( ts ) )
return true ;
return false ;
}
public override bool IsEqual ( SymScope ts )
{
EnumScope es = ts as EnumScope ;
if ( es = = null ) return false ;
if ( enum_consts . Count ! = es . enum_consts . Count ) return false ;
for ( int i = 0 ; i < es . enum_consts . Count ; i + + )
2017-05-30 23:58:34 +03:00
if ( string . Compare ( enum_consts [ i ] , this . enum_consts [ i ] , true ) ! = 0 ) return false ;
2015-05-14 22:35:07 +03:00
return true ;
}
public override SymScope FindName ( string name )
{
if ( topScope ! = null ) return topScope . FindName ( name ) ;
return null ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
if ( topScope ! = null ) return topScope . FindNameInAnyOrder ( name ) ;
return null ;
}
public override SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword , bool called_in_base )
{
return base . GetNames ( ev , keyword , true ) ;
}
public override ProcScope GetConstructor ( )
{
return null ;
}
public override List < ProcScope > GetConstructors ( bool search_in_base )
{
return new List < ProcScope > ( 0 ) ;
}
public override string GetDescription ( )
{
return this . ToString ( ) ;
}
public override string ToString ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
//mnozhestvo
public class SetScope : TypeScope , ISetScope
{
public SetScope ( TypeScope elementType )
{
this . elementType = elementType ;
this . si = new SymInfo ( this . ToString ( ) , SymbolKind . Type , this . ToString ( ) ) ;
}
public override ScopeKind Kind
{
get
{
return ScopeKind . Set ;
}
}
public override string GetDescription ( )
{
return this . ToString ( ) ;
}
2018-05-13 15:02:48 +03:00
public override TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2015-05-14 22:35:07 +03:00
{
return this ;
}
public override SymInfo [ ] GetNames ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return null ;
}
public override SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword , bool called_in_base )
{
return null ;
}
public override ProcScope GetConstructor ( )
{
return null ;
}
public override List < ProcScope > GetConstructors ( bool search_in_base )
{
return new List < ProcScope > ( 0 ) ;
}
// public override SymInfo[] GetNames(ExpressionVisitor ev)
// {
// //SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
// return new SymInfo[0];
// }
public override SymInfo [ ] GetNamesAsInObject ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return new SymInfo [ 0 ] ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return new SymInfo [ 0 ] ;
}
public override SymScope FindName ( string name )
{
if ( topScope ! = null ) return topScope . FindName ( name ) ;
return null ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
List < SymScope > names = new List < SymScope > ( ) ;
if ( topScope ! = null )
names . AddRange ( topScope . FindOverloadNames ( name ) ) ;
return names ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
if ( topScope ! = null ) return topScope . FindNameInAnyOrder ( name ) ;
return null ;
}
public override SymScope FindNameOnlyInType ( string name )
{
return null ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return new List < SymScope > ( 0 ) ;
}
public override SymScope FindNameOnlyInThisType ( string name )
{
return null ;
}
2018-11-12 22:52:25 +03:00
public override bool IsConvertable ( TypeScope ts , bool strong = false )
2015-05-14 22:35:07 +03:00
{
2018-08-08 14:26:55 +03:00
if ( IsEqual ( ts ) | | ts is TemplateParameterScope | | ts . IsGenericParameter )
2015-05-14 22:35:07 +03:00
return true ;
return false ;
}
public override bool IsEqual ( SymScope ts )
{
if ( ts is SetScope )
return elementType . IsEqual ( ( ts as SetScope ) . elementType ) ;
return false ;
}
public override string ToString ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
//file [of type]
public class FileScope : TypeScope , IFileScope
{
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 ScopeKind Kind
{
get
{
return ScopeKind . File ;
}
}
public override string GetDescription ( )
{
return this . ToString ( ) ;
}
public override SymInfo [ ] GetNames ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
if ( this . baseScope ! = null )
return this . baseScope . GetNames ( ) ;
return null ;
}
public override SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword , bool called_in_base )
{
if ( this . baseScope ! = null )
return this . baseScope . GetNames ( ev , keyword , called_in_base ) ;
return null ;
}
public override List < ProcScope > GetConstructors ( bool search_in_base )
{
return new List < ProcScope > ( 0 ) ;
}
public override ProcScope GetConstructor ( )
{
return null ;
}
public override SymInfo [ ] GetNamesAsInObject ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
if ( this . baseScope ! = null )
return this . baseScope . GetNamesAsInObject ( ) ;
return new SymInfo [ 0 ] ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
if ( this . baseScope ! = null )
return this . baseScope . GetNamesAsInObject ( ev ) ;
return new SymInfo [ 0 ] ;
}
public override SymScope FindName ( string name )
{
if ( this . baseScope ! = null )
return this . baseScope . FindName ( name ) ;
return null ;
}
public override SymScope FindNameOnlyInType ( string name )
{
if ( this . baseScope ! = null )
return this . baseScope . FindNameOnlyInType ( name ) ;
return null ;
}
public override SymScope FindNameOnlyInThisType ( string name )
{
if ( this . baseScope ! = null )
return this . baseScope . FindNameOnlyInThisType ( name ) ;
return null ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
if ( this . baseScope ! = null )
return this . baseScope . FindNameInAnyOrder ( name ) ;
return null ;
}
2018-05-13 15:02:48 +03:00
public override TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2015-05-14 22:35:07 +03:00
{
2017-02-19 12:58:42 +03:00
return new FileScope ( gen_args [ 0 ] , this . topScope ) ;
2015-05-14 22:35:07 +03:00
}
2018-11-12 22:52:25 +03:00
public override bool IsConvertable ( TypeScope ts , bool strong = false )
2015-05-14 22:35:07 +03:00
{
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 override bool IsEqual ( SymScope 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 ;
}
return false ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
if ( this . baseScope ! = null )
return baseScope . FindOverloadNames ( name ) ;
return null ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
if ( this . baseScope ! = null )
return baseScope . FindOverloadNamesOnlyInType ( name ) ;
return null ;
}
public override SymInfo [ ] GetNamesAsInBaseClass ( ExpressionVisitor ev , bool is_static )
{
if ( this . baseScope ! = null )
return baseScope . GetNamesAsInBaseClass ( ev , is_static ) ;
return null ;
}
public override string ToString ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
public class TemplateParameterScope : TypeScope , ITemplateParameterScope
{
private SymScope declScope ;
public TemplateParameterScope ( string name , TypeScope baseType , SymScope declScope )
: base ( SymbolKind . Type , null , baseType )
{
this . declScope = declScope ;
2015-12-06 21:25:05 +03:00
this . topScope = declScope ;
2015-05-14 22:35:07 +03:00
this . name = name ;
2016-05-01 13:02:40 +03:00
si . description = name + " in " + declScope . si . name ;
2015-05-14 22:35:07 +03:00
}
2018-05-13 15:02:48 +03:00
public override TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2016-04-03 13:57:12 +03:00
{
if ( gen_args . Count > 0 )
return gen_args [ 0 ] ;
return this ;
}
2016-03-20 16:23:41 +03:00
public override bool IsGenericParameter
{
get
{
return true ;
}
}
2015-05-14 22:35:07 +03:00
}
//sinonim type myreal = real;
public class TypeSynonim : TypeScope , ITypeSynonimScope
{
public TypeScope actType ;
2016-12-18 20:18:51 +03:00
public TypeSynonim ( SymInfo si , SymScope actType , List < string > generic_params )
2015-05-14 22:35:07 +03:00
: base ( SymbolKind . Type , null , null )
{
this . actType = actType as TypeScope ;
this . si = si ;
2016-12-18 20:18:51 +03:00
this . generic_params = generic_params ;
2016-05-01 13:02:40 +03:00
if ( actType . si ! = null & & actType . si . description ! = null )
this . si . description = CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
2015-05-14 22:35:07 +03:00
//this.si.describe = "type "+this.si.name + " = "+actType.si.name;
}
public override ScopeKind Kind
{
get
{
return ScopeKind . TypeSynonim ;
}
}
public ITypeScope ActType
{
get
{
return actType ;
}
}
2019-12-25 15:17:32 +03:00
public TypeScope GetLeafActType ( int level = 0 )
{
if ( actType is TypeSynonim & & level < 10 )
return ( actType as TypeSynonim ) . GetLeafActType ( level + 1 ) ;
return actType ;
}
2015-05-14 22:35:07 +03:00
public override SymInfo [ ] GetNames ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return actType . GetNames ( ) ;
}
public override SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword , bool called_in_base )
{
return actType . GetNames ( ev , keyword , called_in_base ) ;
}
public override TypeScope GetElementType ( )
{
return actType . GetElementType ( ) ;
}
public override SymInfo [ ] GetNamesAsInBaseClass ( ExpressionVisitor ev , bool is_static )
{
return actType . GetNamesAsInBaseClass ( ev , is_static ) ;
}
public override SymScope FindName ( string name )
{
SymScope ss = actType . FindName ( name ) ;
if ( ss ! = null ) return ss ;
if ( topScope ! = null ) return topScope . FindName ( name ) ;
return null ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
SymScope ss = actType . FindNameInAnyOrder ( name ) ;
if ( ss ! = null ) return ss ;
if ( topScope ! = null ) return topScope . FindNameInAnyOrder ( name ) ;
return null ;
}
public override SymScope FindNameOnlyInThisType ( string name )
{
return actType . FindNameOnlyInThisType ( name ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( )
{
return actType . GetNamesAsInObject ( ) ;
}
public override TypeScope [ ] GetIndexers ( )
{
return actType . GetIndexers ( ) ;
}
2018-05-13 15:02:48 +03:00
public override TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2015-05-14 22:35:07 +03:00
{
2015-12-19 22:48:12 +03:00
TypeScope original_type = actType ;
if ( actType . original_type ! = null )
original_type = actType . original_type ;
2018-05-13 15:02:48 +03:00
TypeScope ts = original_type . GetInstance ( gen_args , exact ) ;
2017-08-31 22:01:34 +03:00
ts . aliased = true ;
return ts ;
2015-05-14 22:35:07 +03:00
}
2018-11-11 14:10:55 +03:00
public override ITypeScope ElementType
{
get
{
return actType . ElementType ;
}
}
2019-12-25 15:17:32 +03:00
public override bool IsDelegate
{
get
{
return actType . IsDelegate ;
}
}
2019-12-25 11:53:05 +03:00
public override void AddIndexer ( TypeScope ts , bool is_static )
2015-05-14 22:35:07 +03:00
{
2019-12-25 11:53:05 +03:00
actType . AddIndexer ( ts , is_static ) ;
2015-05-14 22:35:07 +03:00
}
public override SymScope FindNameOnlyInType ( string name )
{
return actType . FindNameOnlyInType ( name ) ;
}
public override ProcScope GetConstructor ( )
{
return actType . GetConstructor ( ) ;
}
public override List < ProcScope > GetConstructors ( bool search_in_base )
{
return actType . GetConstructors ( search_in_base ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
return actType . GetNamesAsInObject ( ev ) ;
}
public override SymInfo [ ] GetNamesInAllTopScopes ( bool all_names , ExpressionVisitor ev , bool is_static )
{
return actType . GetNamesInAllTopScopes ( all_names , ev , is_static ) ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
2018-12-31 13:12:08 +03:00
List < SymScope > names = actType . FindOverloadNames ( name ) ;
if ( names . Count > 0 )
return names ;
if ( topScope ! = null ) return topScope . FindOverloadNames ( name ) ;
return names ;
2015-05-14 22:35:07 +03:00
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return actType . FindOverloadNamesOnlyInType ( name ) ;
}
2018-11-12 22:52:25 +03:00
public override bool IsConvertable ( TypeScope ts , bool strong = false )
2015-05-14 22:35:07 +03:00
{
if ( ts is TypeSynonim )
ts = ( ts as TypeSynonim ) . actType ;
if ( ts is TypeScope )
2018-11-12 22:52:25 +03:00
return this . actType . IsConvertable ( ts , strong ) ;
2015-05-14 22:35:07 +03:00
return false ;
}
public override bool IsEqual ( SymScope ts )
{
if ( ts is TypeSynonim ) return string . Compare ( this . si . name , ts . si . name , true ) = = 0 ;
if ( ts is TypeScope )
return this . actType . IsEqual ( ts as TypeScope ) ;
return false ;
//if (ts is TypeSynonim) return actType.IsEqual((ts as TypeSynonim).actType);
//return actType.IsEqual(ts);
}
public override string ToString ( )
{
return si . name ;
}
}
public class ShortStringScope : TypeScope , IShortStringScope
{
private CompiledScope actType ;
private object len ;
public ShortStringScope ( CompiledScope actType , object len )
{
this . actType = actType ;
this . len = len ;
if ( len ! = null )
{
this . si = new SymInfo ( "string" , SymbolKind . Type , "string" ) ;
2016-05-01 13:02:40 +03:00
this . si . description = CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
2015-05-14 22:35:07 +03:00
}
else this . si = actType . si ;
}
public object Length
{
get
{
return len ;
}
}
public override ScopeKind Kind
{
get
{
return ScopeKind . ShortString ;
}
}
public override SymInfo [ ] GetNames ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return actType . GetNames ( ) ;
}
public override SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword , bool called_in_base )
{
return actType . GetNames ( ev , keyword , called_in_base ) ;
}
public override ITypeScope [ ] Indexers
{
get { return actType . Indexers ; }
}
public override ITypeScope ElementType
{
get { return actType . ElementType ; }
}
2018-05-13 15:02:48 +03:00
public override TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2015-05-14 22:35:07 +03:00
{
return this ;
}
public override TypeScope GetElementType ( )
{
return actType . GetElementType ( ) ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
return actType . FindOverloadNames ( name ) ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return actType . FindOverloadNamesOnlyInType ( name ) ;
}
public override SymScope FindName ( string name )
{
SymScope ss = actType . FindName ( name ) ;
if ( ss ! = null ) return ss ;
if ( topScope ! = null ) return topScope . FindName ( name ) ;
return null ;
}
public override SymScope FindNameOnlyInThisType ( string name )
{
return actType . FindNameOnlyInThisType ( name ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( )
{
return actType . GetNamesAsInObject ( ) ;
}
public override TypeScope [ ] GetIndexers ( )
{
return actType . GetIndexers ( ) ;
}
2019-12-25 11:53:05 +03:00
public override void AddIndexer ( TypeScope ts , bool is_static )
2015-05-14 22:35:07 +03:00
{
2019-12-25 11:53:05 +03:00
actType . AddIndexer ( ts , is_static ) ;
2015-05-14 22:35:07 +03:00
}
public override SymScope FindNameOnlyInType ( string name )
{
return actType . FindNameOnlyInType ( name ) ;
}
public override ProcScope GetConstructor ( )
{
return actType . GetConstructor ( ) ;
}
public override List < ProcScope > GetConstructors ( bool search_in_base )
{
return actType . GetConstructors ( search_in_base ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
return actType . GetNamesAsInObject ( ev ) ;
}
public override SymInfo [ ] GetNamesInAllTopScopes ( bool all_names , ExpressionVisitor ev , bool is_static )
{
return actType . GetNamesInAllTopScopes ( all_names , ev , is_static ) ;
}
public override bool IsEqual ( SymScope ts )
{
if ( ts is TypeSynonim ) return actType . IsEqual ( ( ts as TypeSynonim ) . actType ) ;
if ( ts is ShortStringScope ) return this . len = = ( ts as ShortStringScope ) . len ;
return false ;
}
2018-11-12 22:52:25 +03:00
public override bool IsConvertable ( TypeScope ts , bool strong = false )
2015-05-14 22:35:07 +03:00
{
2018-11-12 22:52:25 +03:00
if ( ts is TypeSynonim ) return actType . IsConvertable ( ( ts as TypeSynonim ) . actType , strong ) ;
2015-05-14 22:35:07 +03:00
if ( ts is ShortStringScope ) return true ;
return false ;
}
public override string ToString ( )
{
return si . name ;
}
}
//massiv (dinamicheskij i staticheskij)
public class ArrayScope : TypeScope , IArrayScope
{
public TypeScope [ ] indexes ;
2017-02-12 17:16:06 +03:00
private bool _is_dynamic_arr = false ;
2015-05-14 22:35:07 +03:00
private bool _is_multi_dyn_arr = false ;
2017-10-04 22:50:52 +03:00
internal TypeScope ilist ;
2015-05-14 22:35:07 +03:00
public ArrayScope ( )
{
2017-02-12 17:16:06 +03:00
_is_dynamic_arr = true ;
2015-05-14 22:35:07 +03:00
this . si = new SymInfo ( "$" + this . ToString ( ) , SymbolKind . Type , this . ToString ( ) ) ;
}
public ArrayScope ( TypeScope elementType , TypeScope [ ] indexes )
{
this . elementType = elementType ;
this . indexes = indexes ;
if ( indexes = = null )
2017-02-12 17:16:06 +03:00
_is_dynamic_arr = true ;
2015-05-14 22:35:07 +03:00
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 ) ) ;
2017-10-04 22:50:52 +03:00
ilist = CompiledScope . get_type_instance ( typeof ( IList < > ) , lst ) ;
2017-10-04 22:20:30 +03:00
//this.implemented_interfaces.Add(CompiledScope.get_type_instance(typeof(IList<>), lst));
2015-05-14 22:35:07 +03:00
}
this . si = new SymInfo ( "$" + this . ToString ( ) , SymbolKind . Type , this . ToString ( ) ) ;
this . members = new List < SymScope > ( ) ;
}
2016-11-21 23:12:10 +03:00
public override int Rank
{
get
{
if ( indexes = = null )
return 1 ;
return indexes . Length ;
}
}
2015-05-14 22:35:07 +03:00
public bool IsMultiDynArray
{
get
{
return _is_multi_dyn_arr ;
}
}
2017-02-12 17:16:06 +03:00
public bool is_multi_dyn_arr
{
get
{
return _is_multi_dyn_arr ;
}
}
public bool is_dynamic_arr
{
get
{
return _is_dynamic_arr ;
}
set
{
_is_dynamic_arr = value ;
}
}
2015-05-14 22:35:07 +03:00
public override ScopeKind Kind
{
get
{
return ScopeKind . Array ;
}
}
2016-05-08 20:45:37 +03:00
public override ITypeScope [ ] Indexers
2015-05-14 22:35:07 +03:00
{
get
{
return indexes ;
}
}
public bool IsDynamic
{
get
{
return is_dynamic_arr ;
}
}
public override bool IsArray
{
get
{
return true ;
}
}
public override TypeScope [ ] GetIndexers ( )
{
return indexes ;
}
public override string GetDescription ( )
{
return this . ToString ( ) ;
}
2018-05-13 15:02:48 +03:00
public override TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2015-05-14 22:35:07 +03:00
{
if ( ( elementType is UnknownScope | | elementType is TemplateParameterScope ) & & gen_args . Count > 0 )
2016-12-04 14:46:04 +03:00
return new ArrayScope ( gen_args [ gen_args . Count - 1 ] , Rank > 1 ? indexes : null ) ;
2015-05-14 22:35:07 +03:00
return this ;
}
public override SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword , bool called_in_base )
{
2021-07-05 23:33:44 +03:00
if ( is_dynamic_arr | | IsMultiDynArray )
{
List < SymInfo > syms = new List < SymInfo > ( ) ;
syms . AddRange ( base . GetNames ( ev , keyword , called_in_base ) ) ;
if ( ! IsMultiDynArray & & implemented_interfaces ! = null )
{
foreach ( TypeScope ts in implemented_interfaces )
syms . AddRange ( ts . GetNamesAsInObject ( ev ) ) ;
}
return syms . ToArray ( ) ;
}
2015-05-14 22:35:07 +03:00
return new SymInfo [ 0 ] ;
2021-07-05 23:33:44 +03:00
//return new SymInfo[0];
//return base.GetNames(ev, keyword, called_in_base);
2015-05-14 22:35:07 +03:00
}
//u staticheskogo massiva prinimaem, chto net metodov i sv-v, u dinam. est
public override SymInfo [ ] GetNamesAsInObject ( )
{
if ( is_dynamic_arr | | IsMultiDynArray )
return base . GetNamesAsInObject ( ) ;
return new SymInfo [ 0 ] ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
if ( is_dynamic_arr | | IsMultiDynArray )
{
List < SymInfo > syms = new List < SymInfo > ( ) ;
syms . AddRange ( base . GetNamesAsInObject ( ev ) ) ;
2016-07-28 21:06:12 +03:00
if ( ! IsMultiDynArray & & implemented_interfaces ! = null )
2015-05-14 22:35:07 +03:00
{
foreach ( TypeScope ts in implemented_interfaces )
syms . AddRange ( ts . GetNamesAsInObject ( ev ) ) ;
}
return syms . ToArray ( ) ;
}
return new SymInfo [ 0 ] ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
2017-01-30 22:48:17 +03:00
if ( ! is_dynamic_arr & & ! IsMultiDynArray )
2016-06-22 21:55:05 +03:00
return new List < SymScope > ( ) ;
2015-05-14 22:35:07 +03:00
List < SymScope > syms = base . FindOverloadNamesOnlyInType ( name ) ;
2018-11-25 22:47:06 +03:00
/ * if ( implemented_interfaces ! = null )
2015-05-14 22:35:07 +03:00
{
foreach ( TypeScope ts in implemented_interfaces )
syms . AddRange ( ts . FindOverloadNamesOnlyInType ( name ) ) ;
2018-11-25 22:47:06 +03:00
} * /
2015-05-14 22:35:07 +03:00
return syms ;
}
public override SymScope FindName ( string name )
{
2017-08-31 22:01:34 +03:00
if ( string . Compare ( si . name , name , true ) = = 0 )
return this ;
2017-01-30 22:48:17 +03:00
if ( ! is_dynamic_arr & & ! IsMultiDynArray )
2016-06-22 21:55:05 +03:00
return null ;
2015-05-14 22:35:07 +03:00
SymScope sc = null ;
if ( baseScope ! = null & & is_dynamic_arr ) sc = baseScope . FindNameOnlyInType ( name ) ;
if ( sc ! = null ) return sc ;
if ( topScope ! = null ) return topScope . FindName ( name ) ;
return null ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
List < SymScope > names = new List < SymScope > ( ) ;
2017-01-30 22:48:17 +03:00
if ( ! is_dynamic_arr & & ! IsMultiDynArray )
2016-06-22 21:55:05 +03:00
return names ;
2015-05-14 22:35:07 +03:00
if ( baseScope ! = null & & is_dynamic_arr ) names . AddRange ( baseScope . FindOverloadNamesOnlyInType ( name ) ) ;
if ( topScope ! = null )
names . AddRange ( topScope . FindOverloadNames ( name ) ) ;
return names ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
2017-01-30 22:48:17 +03:00
if ( ! is_dynamic_arr & & ! IsMultiDynArray )
2016-06-22 21:55:05 +03:00
return null ;
2015-05-14 22:35:07 +03:00
SymScope sc = null ;
if ( baseScope ! = null & & is_dynamic_arr ) sc = baseScope . FindNameOnlyInType ( name ) ;
if ( sc ! = null ) return sc ;
if ( topScope ! = null ) return topScope . FindNameInAnyOrder ( name ) ;
return null ;
}
public override SymScope FindNameOnlyInType ( string name )
{
if ( is_dynamic_arr | | IsMultiDynArray )
return base . FindNameOnlyInType ( name ) ;
return null ;
}
public override SymScope FindNameOnlyInThisType ( string name )
{
if ( is_dynamic_arr | | IsMultiDynArray )
return base . FindNameOnlyInThisType ( name ) ;
return null ;
}
2019-12-25 11:53:05 +03:00
public override void AddIndexer ( TypeScope ts , bool is_static )
2015-05-14 22:35:07 +03:00
{
}
2018-11-12 22:52:25 +03:00
public override bool IsConvertable ( TypeScope ts , bool strong = false )
2015-05-14 22:35:07 +03:00
{
if ( ts is NullTypeScope & & is_dynamic_arr )
return true ;
2018-08-09 15:14:35 +03:00
if ( ts is TemplateParameterScope | | ts . IsGenericParameter )
return true ;
2018-03-07 23:12:31 +03:00
if ( ts is CompiledScope & & ( ts as CompiledScope ) . ctn = = PascalABCCompiler . NetHelper . NetHelper . ArrayType )
return true ;
2015-05-14 22:35:07 +03:00
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 ;
2021-11-18 22:40:35 +03:00
if ( arrs . elementType = = null | | arrs . elementType is TemplateParameterScope )
2015-05-14 22:35:07 +03:00
return true ;
if ( ! this . elementType . IsEqual ( arrs . elementType ) ) return false ;
if ( this . IsMultiDynArray & & arrs . IsMultiDynArray )
{
return this . indexes . Length = = arrs . indexes . Length ;
}
2015-12-04 22:17:20 +03:00
return true ;
2015-05-14 22:35:07 +03:00
}
public override bool IsEqual ( SymScope ts )
{
2017-12-17 16:08:06 +03:00
if ( ! is_dynamic_arr & & ! is_multi_dyn_arr ) return base . IsEqual ( ts ) ;
2015-05-14 22:35:07 +03:00
if ( ts is NullTypeScope & & is_dynamic_arr )
return true ;
ArrayScope arrs = ts as ArrayScope ;
2017-08-13 20:56:04 +03:00
if ( ts is CompiledScope & & ( ts as CompiledScope ) . IsArray )
{
return this . elementType . IsEqual ( ts . GetElementType ( ) ) ;
}
2017-12-17 16:08:06 +03:00
if ( arrs = = null | | ! arrs . is_dynamic_arr & & ! arrs . is_multi_dyn_arr )
if ( ts is TypeSynonim )
return this . IsEqual ( ( ts as TypeSynonim ) . actType ) ;
else
return false ;
2021-11-18 22:40:35 +03:00
if ( arrs . elementType = = null | | arrs . elementType is TemplateParameterScope )
return true ;
2017-12-17 16:08:06 +03:00
if ( ! this . elementType . IsEqual ( arrs . elementType ) )
return false ;
if ( is_multi_dyn_arr & & ! arrs . is_multi_dyn_arr )
return false ;
if ( ! is_multi_dyn_arr & & arrs . is_multi_dyn_arr )
return false ;
if ( is_multi_dyn_arr & & arrs . is_multi_dyn_arr )
return this . indexes . Length = = arrs . indexes . Length ;
2015-05-14 22:35:07 +03:00
return true ;
2017-08-13 20:56:04 +03:00
2015-05-14 22:35:07 +03:00
}
public override ProcScope GetConstructor ( )
{
return null ;
}
public override List < ProcScope > GetConstructors ( bool search_in_base )
{
return new List < ProcScope > ( 0 ) ;
}
public override TypeScope GetElementType ( )
{
return elementType ;
}
public override string ToString ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
//diapason
public class DiapasonScope : TypeScope , IDiapasonScope
{
public object left ;
public object right ;
public DiapasonScope ( object left , object right )
{
this . left = left ;
this . right = right ;
this . si = new SymInfo ( this . ToString ( ) , SymbolKind . Type , this . ToString ( ) ) ;
}
public override ScopeKind Kind
{
get
{
return ScopeKind . Diapason ;
}
}
public object Left
{
get
{
return left ;
}
}
public object Right
{
get
{
return right ;
}
}
2018-05-13 15:02:48 +03:00
public override TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2015-05-14 22:35:07 +03:00
{
return this ;
}
public override SymInfo [ ] GetNames ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return new SymInfo [ 0 ] ;
}
public override SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword , bool called_in_base )
{
return new SymInfo [ 0 ] ;
}
public override ProcScope GetConstructor ( )
{
return null ;
}
public override List < ProcScope > GetConstructors ( bool search_in_base )
{
return new List < ProcScope > ( 0 ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return new SymInfo [ 0 ] ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return new SymInfo [ 0 ] ;
}
public override SymScope FindName ( string name )
{
if ( topScope ! = null ) return topScope . FindName ( name ) ;
return null ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
if ( topScope ! = null ) return topScope . FindOverloadNames ( name ) ;
return new List < SymScope > ( 0 ) ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
if ( topScope ! = null ) return topScope . FindNameInAnyOrder ( name ) ;
return null ;
}
public override SymScope FindNameOnlyInType ( string name )
{
return null ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return new List < SymScope > ( 0 ) ;
}
public override SymScope FindNameOnlyInThisType ( string name )
{
return null ;
}
public override string GetDescription ( )
{
return this . ToString ( ) ;
}
public override string ToString ( )
{
//return left.ToString() + ".." + right.ToString();
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
//obsolete
public class RecordScope : TypeScope
{
public RecordScope ( )
{
//ht = new Hashtable();
baseScope = TypeTable . get_compiled_type ( new SymInfo ( typeof ( ValueType ) . Name , SymbolKind . Struct , typeof ( ValueType ) . FullName ) , typeof ( ValueType ) ) ;
si = new SymInfo ( "record" , SymbolKind . Struct , "record" ) ;
this . members = new List < SymScope > ( ) ;
}
public override string ToString ( )
{
return "record" ;
}
}
public class NullTypeScope : TypeScope
{
public NullTypeScope ( )
{
}
2018-11-12 22:52:25 +03:00
public override bool IsConvertable ( TypeScope ts , bool strong = false )
2015-05-14 22:35:07 +03:00
{
2018-07-12 22:41:05 +03:00
if ( ts is NullTypeScope )
return false ;
2015-05-14 22:35:07 +03:00
return ts . IsConvertable ( this ) ;
}
public override SymScope FindName ( string name )
{
return null ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
return null ;
}
public override SymScope FindNameOnlyInThisType ( string name )
{
return null ;
}
public override SymInfo [ ] GetNames ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return new SymInfo [ 0 ] ;
}
public override SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword , bool called_in_base )
{
return new SymInfo [ 0 ] ;
}
public override ProcScope GetConstructor ( )
{
return null ;
}
public override SymInfo [ ] GetNamesAsInObject ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return new SymInfo [ 0 ] ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return new SymInfo [ 0 ] ;
}
}
//tip-ukazatel
public class PointerScope : TypeScope , IPointerScope
{
public TypeScope ref_type ;
public PointerScope ( )
{
this . si = new SymInfo ( "" , SymbolKind . Type , "" ) ;
}
public PointerScope ( TypeScope ref_type )
{
this . ref_type = ref_type ;
this . si = new SymInfo ( this . ToString ( ) , SymbolKind . Type , this . ToString ( ) ) ;
}
public override ScopeKind Kind
{
get
{
return ScopeKind . Pointer ;
}
}
2018-05-13 15:02:48 +03:00
public override TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2015-05-14 22:35:07 +03:00
{
return this ;
}
public override ITypeScope ElementType
{
get { return ref_type ; }
}
2018-11-12 22:52:25 +03:00
public override bool IsConvertable ( TypeScope ts , bool strong = false )
2015-05-14 22:35:07 +03:00
{
if ( IsEqual ( ts ) )
return true ;
return false ;
}
public override bool IsEqual ( SymScope ts )
{
if ( ts is NullTypeScope )
return true ;
2019-09-08 11:59:56 +03:00
if ( ! ( ts is PointerScope ) )
return false ;
2015-05-14 22:35:07 +03:00
if ( ts is PointerScope )
if ( ( ts as PointerScope ) . ref_type = = null )
return true ;
2019-09-08 11:59:56 +03:00
2015-05-14 22:35:07 +03:00
return ref_type = = ( ts as PointerScope ) . ref_type ;
}
public override string GetDescription ( )
{
return this . ToString ( ) ;
}
public override SymInfo [ ] GetNames ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return new SymInfo [ 0 ] ;
}
public override SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword , bool called_in_base )
{
return new SymInfo [ 0 ] ;
}
public override List < ProcScope > GetConstructors ( bool search_in_base )
{
return new List < ProcScope > ( 0 ) ;
}
public override ProcScope GetConstructor ( )
{
return null ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
return new SymInfo [ 0 ] ;
}
public override SymScope FindName ( string name )
{
if ( topScope ! = null ) return topScope . FindName ( name ) ;
return null ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
return new List < SymScope > ( 0 ) ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
if ( topScope ! = null ) return topScope . FindNameInAnyOrder ( name ) ;
return null ;
}
public override SymScope FindNameOnlyInType ( string name )
{
return null ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return new List < SymScope > ( 0 ) ;
}
public override SymScope FindNameOnlyInThisType ( string name )
{
return null ;
}
public override string ToString ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
//opisanie tipa (klassa, zapisi) ot nego est nasledniki. sdelal ih dlja udobstva.
public class TypeScope : SymScope , ITypeScope
{
public SymbolKind kind ;
public TypeScope baseScope ;
public location real_body_loc ;
2018-03-06 22:39:05 +03:00
public location predef_loc ;
2015-05-14 22:35:07 +03:00
public string name ;
//public List<SymScope> members;
public TypeScope elementType ;
public TypeScope original_type ;
private List < TypeScope > indexers ;
2019-12-25 11:53:05 +03:00
private List < TypeScope > static_indexers ;
2015-05-14 22:35:07 +03:00
public List < TypeScope > implemented_interfaces ;
public List < TypeScope > instances ;
2022-10-31 16:02:17 +03:00
public List < TypeScope > other_partials ;
2020-02-02 13:09:44 +03:00
public List < string > generic_params ;
2015-05-14 22:35:07 +03:00
public bool is_final ;
public bool aliased = false ;
2018-08-06 20:01:31 +03:00
internal bool lazy_instance = false ;
2022-05-08 12:02:24 +03:00
private static Dictionary < TypeScope , List < TypeScope > > instance_cache = new Dictionary < TypeScope , List < TypeScope > > ( ) ;
2015-05-14 22:35:07 +03:00
public TypeScope ( ) { }
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 . members = new List < SymScope > ( ) ;
2019-12-25 11:53:05 +03:00
//this.indexers = new List<TypeScope>();
2015-05-14 22:35:07 +03:00
this . instances = new List < TypeScope > ( ) ;
2019-12-25 11:53:05 +03:00
//this.static_indexers = new List<TypeScope>();
2015-05-14 22:35:07 +03:00
si = new SymInfo ( "type" , kind , "type" ) ;
switch ( kind )
{
2016-05-01 13:02:40 +03:00
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 ;
2015-05-14 22:35:07 +03:00
}
}
2018-09-22 18:49:47 +03:00
public virtual bool IsStatic
{
get
{
return is_static ;
}
}
2016-11-21 23:12:10 +03:00
public virtual int Rank
{
get
{
return 0 ;
}
}
2019-09-09 22:00:01 +03:00
public override void Clear ( )
{
base . Clear ( ) ;
if ( generic_params ! = null )
generic_params . Clear ( ) ;
}
2022-10-31 16:02:17 +03:00
public bool HasPartial ( TypeScope ts )
{
if ( other_partials = = null )
return false ;
return other_partials . Contains ( ts ) ;
}
public void AddPartial ( TypeScope ts )
{
if ( other_partials = = null )
other_partials = new List < TypeScope > ( ) ;
if ( ! other_partials . Contains ( ts ) )
other_partials . Add ( ts ) ;
}
2016-03-20 16:23:41 +03:00
public virtual List < TypeScope > GetInstances ( )
{
return this . instances ;
}
public virtual TypeScope GenericTypeDefinition
{
get
{
return this ;
}
}
public virtual bool IsGenericParameter
{
get
{
return false ;
}
}
2015-05-14 22:35:07 +03:00
public override ScopeKind Kind
{
get
{
return ScopeKind . Type ;
}
}
public bool Aliased
{
get
{
return aliased ;
}
}
2017-02-19 23:20:56 +03:00
public virtual bool IsDelegate
{
get
{
return false ;
}
}
2015-05-14 22:35:07 +03:00
public virtual bool IsArray
{
get
{
return false ;
}
}
public virtual ITypeScope [ ] Indexers
{
get
{
return this . GetIndexers ( ) ;
}
}
2019-12-25 11:53:05 +03:00
public virtual ITypeScope [ ] StaticIndexers
{
get
{
return this . GetStaticIndexers ( ) ;
}
}
2015-05-14 22:35:07 +03:00
public virtual bool IsFinal
{
get
{
return is_final ;
}
}
2017-11-19 20:30:00 +03:00
public virtual bool IsAbstract
{
get
{
return is_abstract ;
}
}
2015-05-14 22:35:07 +03:00
public virtual ITypeScope [ ] GenericInstances
{
get
{
return instances . ToArray ( ) ;
}
}
public virtual string [ ] TemplateArguments
{
get
{
if ( generic_params ! = null & & generic_params . Count > 0 )
{
return generic_params . ToArray ( ) ;
}
return null ;
}
}
public IBaseScope BaseType
{
get
{
return baseScope ;
}
}
public virtual ITypeScope ElementType
{
get
{
return elementType ;
}
}
public virtual void AddGenericInstanciation ( TypeScope ts )
{
instances . Add ( ts ) ;
}
public void AddDefaultConstructorIfNeed ( )
{
2018-09-22 18:49:47 +03:00
if ( members ! = null & & ! is_static )
2015-05-14 22:35:07 +03:00
{
2022-10-31 16:02:17 +03:00
foreach ( SymScope ss in GetMergedMembers ( ) )
2018-08-28 21:11:28 +03:00
{
ProcScope ps = ss as ProcScope ;
if ( ps ! = null & & ps . is_constructor & & ( ps . parameters = = null | | ps . parameters . Count = = 0 ) & & ! ps . is_static )
2015-05-14 22:35:07 +03:00
{
2018-08-28 21:11:28 +03:00
return ;
2015-05-14 22:35:07 +03:00
}
}
2018-08-28 21:11:28 +03:00
2018-09-30 15:41:58 +03:00
ProcScope other_constr = this . FindNameOnlyInType ( "Create" ) as ProcScope ;
2018-08-28 21:11:28 +03:00
ProcScope constr = new ProcScope ( "Create" , this , true ) ;
2019-04-23 23:00:35 +03:00
if ( other_constr ! = null & & other_constr . declaringType = = this )
constr . si . acc_mod = access_modifer . protected_modifer ;
else
constr . si . acc_mod = access_modifer . public_modifer ;
2018-08-28 21:11:28 +03:00
//constr.head_loc = this.loc;
//constr.loc = this.loc;
2018-09-04 22:25:13 +03:00
constr . is_constructor = true ;
2019-04-23 23:00:35 +03:00
2018-08-28 21:11:28 +03:00
constr . Complete ( ) ;
2018-09-30 15:41:58 +03:00
constr . nextProc = other_constr ;
2018-08-28 21:11:28 +03:00
members . Insert ( 0 , constr ) ;
2015-05-14 22:35:07 +03:00
}
}
public override bool IsChildScopeOf ( SymScope ss )
{
if ( ss = = null | | ! ( ss is TypeScope ) )
return false ;
TypeScope ts = this ;
while ( ts . baseScope ! = null )
if ( ts . baseScope = = ss )
return true ;
else ts = ts . baseScope ;
return false ;
}
public virtual List < ProcScope > GetOverridableMethods ( )
{
List < ProcScope > procs = new List < ProcScope > ( ) ;
if ( members ! = null )
foreach ( SymScope ss in members )
if ( ss is ProcScope & & ss . is_virtual )
procs . Add ( ss as ProcScope ) ;
if ( baseScope ! = null )
procs . AddRange ( baseScope . GetOverridableMethods ( ) ) ;
return procs ;
}
public virtual List < ProcScope > GetAbstractMethods ( )
{
List < ProcScope > procs = new List < ProcScope > ( ) ;
if ( members ! = null )
foreach ( SymScope ss in members )
if ( ss is ProcScope & & ( ss . is_abstract | | this . si . kind = = SymbolKind . Interface ) )
procs . Add ( ss as ProcScope ) ;
if ( si . kind = = SymbolKind . Interface & & implemented_interfaces ! = null )
foreach ( TypeScope t in implemented_interfaces )
procs . AddRange ( t . GetAbstractMethods ( ) ) ;
return procs ;
}
2018-02-04 13:27:23 +03:00
public virtual List < ProcScope > GetMethods ( )
{
List < ProcScope > procs = new List < ProcScope > ( ) ;
if ( members ! = null )
foreach ( SymScope ss in members )
if ( ss is ProcScope )
procs . Add ( ss as ProcScope ) ;
return procs ;
}
2015-05-14 22:35:07 +03:00
private TypeScope internalInstance ( TypeScope ts , List < TypeScope > gen_args )
{
if ( ts is TemplateParameterScope | | ts is UnknownScope )
{
2022-10-31 16:02:17 +03:00
if ( this . generic_params = = null )
return ts ;
2015-05-14 22:35:07 +03:00
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 virtual bool IsGeneric
{
get
{
return generic_params ! = null & & generic_params . Count > 0 ;
}
}
protected virtual TypeScope simpleGetInstance ( List < TypeScope > gen_args )
{
TypeScope ts = new TypeScope ( this . kind , this . topScope , this . baseScope ) ;
ts . original_type = this ;
2018-08-06 20:01:31 +03:00
ts . lazy_instance = true ;
2022-10-31 16:02:17 +03:00
ts . other_partials = this . other_partials ;
2015-05-14 22:35:07 +03:00
ts . loc = this . loc ;
for ( int i = 0 ; i < gen_args . Count ; i + + )
{
2020-12-31 15:53:18 +03:00
TypeScope gen_arg = gen_args [ i ] ;
if ( gen_arg . instances ! = null & & gen_arg . original_type ! = null )
{
if ( gen_arg . original_type . generic_params ! = null & & this . generic_params ! = null )
for ( int j = 0 ; j < gen_arg . original_type . generic_params . Count ; j + + )
{
if ( string . Compare ( gen_arg . original_type . generic_params [ j ] , this . generic_params [ j ] , true ) = = 0 )
{
ts . AddGenericInstanceParameter ( gen_arg . instances [ j ] . si . name ) ;
ts . AddGenericInstanciation ( gen_arg . instances [ j ] ) ;
}
}
}
else
{
ts . AddGenericInstanceParameter ( gen_args [ i ] . si . name ) ;
ts . AddGenericInstanciation ( gen_args [ i ] ) ;
}
2015-05-14 22:35:07 +03:00
}
ts . si . name = this . si . name ;
ts . documentation = this . documentation ;
2016-05-01 13:02:40 +03:00
ts . si . description = ts . GetDescription ( ) ;
2015-05-14 22:35:07 +03:00
return ts ;
}
2018-05-13 15:02:48 +03:00
public virtual TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2015-05-14 22:35:07 +03:00
{
TypeScope ts = new TypeScope ( this . kind , this . topScope , this . baseScope ) ;
ts . original_type = this ;
ts . loc = this . loc ;
2022-10-31 16:02:17 +03:00
ts . other_partials = this . other_partials ;
2017-12-03 16:07:39 +03:00
List < TypeScope > new_gen_args = new List < TypeScope > ( ) ;
2015-05-14 22:35:07 +03:00
for ( int i = 0 ; i < gen_args . Count ; i + + )
{
2017-12-03 16:07:39 +03:00
TypeScope gen_arg = gen_args [ i ] ;
2018-05-13 15:02:48 +03:00
if ( gen_arg . instances ! = null & & gen_arg . original_type ! = null & & ! exact )
2017-12-03 16:07:39 +03:00
{
2017-12-10 16:43:39 +03:00
if ( gen_arg . original_type . generic_params ! = null & & this . generic_params ! = null )
2018-05-13 15:02:48 +03:00
for ( int j = 0 ; j < gen_arg . original_type . generic_params . Count ; j + + )
2017-12-03 16:07:39 +03:00
{
2018-05-13 15:02:48 +03:00
if ( string . Compare ( gen_arg . original_type . generic_params [ j ] , this . generic_params [ j ] , true ) = = 0 )
{
new_gen_args . Add ( gen_arg . instances [ j ] ) ;
2018-10-14 13:47:33 +03:00
ts . AddGenericInstanceParameter ( gen_arg . instances [ j ] . si . name ) ;
2018-05-13 15:02:48 +03:00
ts . AddGenericInstanciation ( gen_arg . instances [ j ] ) ;
}
2017-12-03 16:07:39 +03:00
}
}
else
{
2018-10-14 13:47:33 +03:00
ts . AddGenericInstanceParameter ( gen_args [ i ] . si . name ) ;
2017-12-03 16:07:39 +03:00
ts . AddGenericInstanciation ( gen_args [ i ] ) ;
new_gen_args . Add ( gen_args [ i ] ) ;
}
2015-05-14 22:35:07 +03:00
}
2017-12-03 16:07:39 +03:00
gen_args = new_gen_args ;
2015-05-14 22:35:07 +03:00
ts . si . name = this . si . name ;
ts . documentation = this . documentation ;
2016-05-01 13:02:40 +03:00
ts . si . description = ts . GetDescription ( ) ;
2015-05-14 22:35:07 +03:00
if ( this . elementType ! = null )
{
ts . elementType = internalInstance ( this . elementType , gen_args ) ;
}
2017-08-18 22:23:13 +03:00
if ( implemented_interfaces ! = null )
{
ts . implemented_interfaces = new List < TypeScope > ( ) ;
for ( int j = 0 ; j < this . implemented_interfaces . Count ; j + + )
ts . implemented_interfaces . Add ( internalInstance ( this . implemented_interfaces [ j ] , gen_args ) ) ;
}
2015-05-14 22:35:07 +03:00
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 ) ;
2018-08-06 20:01:31 +03:00
ts . members [ ts . members . IndexOf ( ss ) ] = new_es ;
2015-05-14 22:35:07 +03:00
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 ;
2018-09-04 22:25:13 +03:00
new_proc . si . description = ps . si . description ;
2015-05-14 22:35:07 +03:00
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 ;
2018-08-06 20:01:31 +03:00
ts . members [ ts . members . IndexOf ( ss ) ] = new_proc ;
2015-05-14 22:35:07 +03:00
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 virtual void ClearInstances ( )
{
if ( instances ! = null )
instances . Clear ( ) ;
}
2022-11-01 12:23:10 +03:00
public virtual void AddGenericParameter ( string name , location loc )
2015-05-14 22:35:07 +03:00
{
if ( generic_params = = null ) generic_params = new List < string > ( ) ;
generic_params . Add ( name ) ;
2022-11-01 12:23:10 +03:00
var ts = new TemplateParameterScope ( name , TypeTable . obj_type , this ) ;
ts . loc = loc ;
AddName ( name , ts ) ;
2015-05-14 22:35:07 +03:00
}
2018-10-14 13:47:33 +03:00
public virtual void AddGenericInstanceParameter ( string name )
{
if ( generic_params = = null ) generic_params = new List < string > ( ) ;
generic_params . Add ( name ) ;
}
2015-05-14 22:35:07 +03:00
public virtual void AddImplementedInterface ( TypeScope type )
{
if ( implemented_interfaces = = null ) implemented_interfaces = new List < TypeScope > ( ) ;
implemented_interfaces . Add ( type ) ;
}
public override void MakeSynonimDescription ( )
{
aliased = true ;
2016-05-01 13:02:40 +03:00
si . description = CodeCompletionController . CurrentParser . LanguageInformation . GetSynonimDescription ( this ) ;
2015-05-14 22:35:07 +03:00
}
2018-11-12 22:52:25 +03:00
public virtual bool IsConvertable ( TypeScope ts , bool strong = false )
2015-05-14 22:35:07 +03:00
{
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 ;
2016-04-03 13:57:12 +03:00
if ( this . IsGenericParameter & & ts . IsGenericParameter & & this . Name = = ts . Name )
return true ;
2018-08-28 22:58:09 +03:00
if ( ts is TemplateParameterScope | | ts . IsGenericParameter )
2017-09-28 21:57:28 +03:00
return true ;
2015-05-14 22:35:07 +03:00
TypeScope tmp = this . baseScope ;
while ( tmp ! = null )
if ( tmp . IsEqual ( ts ) )
return true ;
else
tmp = tmp . baseScope ;
2018-05-03 21:04:00 +03:00
SymScope ss = this . FindNameOnlyInType ( "operator implicit" ) ;
if ( ss is ProcScope & & ( ss as ProcScope ) . return_type = = ts )
return true ;
2015-05-14 22:35:07 +03:00
return false ;
}
//dlja sravnivanija tipov
public override bool IsEqual ( SymScope ts )
{
bool eq = this = = ts as TypeScope ;
2018-12-31 13:12:08 +03:00
if ( ts = = null )
return false ;
2015-05-14 22:35:07 +03:00
if ( ts is NullTypeScope & & this . kind = = SymbolKind . Class )
return true ;
if ( eq )
return true ;
TypeScope typ = ts as TypeScope ;
if ( ( typ is TemplateParameterScope | | typ is UnknownScope ) & & this is TemplateParameterScope )
return string . Compare ( this . si . name , typ . si . name , true ) = = 0 ;
if ( this . original_type ! = null & & typ . original_type ! = null )
{
if ( this . original_type . IsEqual ( typ . original_type ) & & this . instances . Count = = typ . instances . Count )
{
for ( int i = 0 ; i < this . instances . Count ; i + + )
{
if ( ! this . instances [ i ] . IsEqual ( typ . instances [ i ] ) )
return false ;
if ( typ . instances [ i ] is UnknownScope & & this . instances [ i ] is TemplateParameterScope )
typ . instances [ i ] = this . instances [ i ] ;
}
return true ;
}
else
return false ;
}
else
return false ;
}
2021-12-12 13:53:50 +03:00
public virtual bool IsTypeStrictEqual ( TypeScope ts )
{
var eq = this . IsEqual ( ts ) ;
if ( ! eq )
return false ;
if ( this . instances ! = null & & ts . instances = = null )
return false ;
if ( this . instances = = null & & ts . instances ! = null )
return false ;
if ( this . instances . Count ! = ts . instances . Count )
return false ;
for ( int i = 0 ; i < this . instances . Count ; i + + )
{
if ( ! this . instances [ i ] . IsTypeStrictEqual ( ts . instances [ i ] ) )
return false ;
}
return true ;
}
2015-05-14 22:35:07 +03:00
public virtual ProcScope GetConstructor ( )
{
2022-10-31 16:02:17 +03:00
foreach ( SymScope ss in GetMergedMembers ( ) )
2015-05-14 22:35:07 +03:00
if ( ss is ProcScope & & ( ss as ProcScope ) . IsConstructor ( ) ) return ss as ProcScope ;
if ( baseScope ! = null )
return baseScope . GetConstructor ( ) ;
return null ;
}
IProcScope ITypeScope . GetConstructor ( )
{
return this . GetConstructor ( ) ;
}
public virtual List < ProcScope > GetConstructors ( bool search_in_base )
{
List < ProcScope > constrs = new List < ProcScope > ( ) ;
bool must_inherite = true ;
2022-10-31 16:02:17 +03:00
foreach ( SymScope ss in GetMergedMembers ( ) )
2018-08-20 22:34:35 +03:00
if ( ss is ProcScope & & ( ss as ProcScope ) . IsConstructor ( ) & & ! ss . is_static )
2015-05-14 22:35:07 +03:00
{
if ( ss . loc ! = null )
must_inherite = false ;
constrs . Add ( ss as ProcScope ) ;
}
if ( baseScope ! = null & & ( must_inherite | | search_in_base ) )
{
List < ProcScope > lst = baseScope . GetConstructors ( true ) ;
for ( int i = 0 ; i < lst . Count ; i + + )
{
if ( lst [ i ] . parameters ! = null & & lst [ i ] . parameters . Count > 0 )
constrs . Add ( lst [ i ] ) ;
}
}
return constrs ;
}
//opisanie, vysvechivaetsja v zheltkom okoshke
public override string GetDescription ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
//dubl?????
public override SymInfo [ ] GetNames ( )
{
List < SymInfo > lst = new List < SymInfo > ( ) ;
/ * foreach ( string s in ht . Keys )
{
SymScope sc = ht [ s ] as SymScope ;
lst . Add ( sc . si ) ;
} * /
2022-10-31 16:02:17 +03:00
foreach ( SymScope ss in GetMergedMembers ( ) )
2015-05-14 22:35:07 +03:00
{
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( ss . si . name ) )
2015-05-14 22:35:07 +03:00
{
lst . Add ( ss . si ) ;
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
}
if ( baseScope ! = null )
lst . AddRange ( baseScope . GetNames ( ) ) ;
/ * if ( topScope ! = null )
lst . AddRange ( topScope . GetNames ( ) ) ; * /
return lst . ToArray ( ) ;
}
//eto
public override SymInfo [ ] GetNamesAsInBaseClass ( ExpressionVisitor ev , bool is_static )
{
List < SymInfo > lst = new List < SymInfo > ( ) ;
2022-10-31 16:02:17 +03:00
foreach ( SymScope ss in GetMergedMembers ( ) )
2015-05-14 22:35:07 +03:00
{
2018-05-08 21:07:55 +03:00
//if (ss is ProcScope && (ss as ProcScope).IsConstructor())
// continue;
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( ss . si . name ) )
2015-05-14 22:35:07 +03:00
{
if ( ss . si . acc_mod = = access_modifer . private_modifer )
{
if ( ev . CheckPrivateForBaseAccess ( ev . entry_scope , this ) )
if ( ! is_static ) lst . Add ( ss . si ) ;
else if ( ss . is_static ) lst . Add ( ss . si ) ;
}
else if ( ss . si . acc_mod = = access_modifer . protected_modifer )
{
if ( ev . CheckForBaseAccess ( ev . entry_scope , this ) )
if ( ! is_static ) lst . Add ( ss . si ) ;
else if ( ss . is_static ) lst . Add ( ss . si ) ;
}
else
if ( ! is_static ) lst . Add ( ss . si ) ;
else if ( ss . is_static ) lst . Add ( ss . si ) ;
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
}
if ( baseScope ! = null )
lst . AddRange ( baseScope . GetNamesAsInBaseClass ( ev , is_static ) ) ;
return lst . ToArray ( ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( )
{
//SortedDictionary<string,SymInfo> dict = new SortedDictionary<string,SymInfo>();
List < SymInfo > lst = new List < SymInfo > ( ) ;
/ * foreach ( string s in ht . Keys )
{
SymScope sc = ht [ s ] as SymScope ;
lst . Add ( sc . si ) ;
} * /
2022-10-31 16:02:17 +03:00
foreach ( SymScope ss in GetMergedMembers ( ) )
2015-05-14 22:35:07 +03:00
{
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( ss . si . name ) & & ! ss . is_static )
2015-05-14 22:35:07 +03:00
if ( ! ( ss is ProcScope ) & & ! ( ss is TemplateParameterScope ) )
{
lst . Add ( ss . si ) ;
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
else if ( ! ( ss as ProcScope ) . IsConstructor ( ) )
{
lst . Add ( ss . si ) ;
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
}
if ( baseScope ! = null ) lst . AddRange ( baseScope . GetNamesAsInObject ( ) ) ;
return lst . ToArray ( ) ;
}
public override TypeScope GetElementType ( )
{
if ( elementType ! = null ) return elementType ;
2018-05-06 12:05:06 +03:00
TypeScope elem_ts = null ;
if ( baseScope ! = null )
{
elem_ts = baseScope . GetElementType ( ) ;
if ( elem_ts ! = null )
return elem_ts ;
}
if ( implemented_interfaces ! = null )
foreach ( TypeScope ts in implemented_interfaces )
{
elem_ts = ts . GetElementType ( ) ;
if ( elem_ts ! = null )
return elem_ts ;
}
2015-05-14 22:35:07 +03:00
return null ;
}
2022-10-31 16:02:17 +03:00
protected List < SymScope > GetMergedMembers ( )
{
if ( other_partials = = null )
return members ;
List < SymScope > merged_members = new List < SymScope > ( ) ;
merged_members . AddRange ( members ) ;
foreach ( var ts in other_partials )
merged_members . AddRange ( ts . members ) ;
return merged_members ;
}
2015-05-14 22:35:07 +03:00
//esli naprimer nazhali ctrl-probel(all_name = treu) ili shift-probel (all_names = false)
//visitor vsegda nuzhen tak kak hranit scope, gde my nazhali
public override SymInfo [ ] GetNamesInAllTopScopes ( bool all_names , ExpressionVisitor ev , bool is_static )
{
List < SymInfo > lst = new List < SymInfo > ( ) ;
2022-10-31 16:02:17 +03:00
foreach ( SymScope ss in GetMergedMembers ( ) )
2015-05-14 22:35:07 +03:00
{
if ( ss is ProcScope & & ( ss as ProcScope ) . IsConstructor ( ) )
continue ;
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( ss . si . name ) )
2015-05-14 22:35:07 +03:00
{
if ( ss . si . acc_mod = = access_modifer . private_modifer )
{
if ( ev . CheckPrivateForBaseAccess ( ev . entry_scope , this ) )
if ( ! is_static ) lst . Add ( ss . si ) ;
else if ( ss . is_static ) lst . Add ( ss . si ) ;
}
else if ( ss . si . acc_mod = = access_modifer . protected_modifer )
{
if ( ev . CheckForBaseAccess ( ev . entry_scope , this ) )
if ( ! is_static ) lst . Add ( ss . si ) ;
else if ( ss . is_static ) lst . Add ( ss . si ) ;
}
else
if ( ! is_static ) lst . Add ( ss . si ) ;
else if ( ss . is_static ) lst . Add ( ss . si ) ;
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
}
if ( baseScope ! = null )
lst . AddRange ( baseScope . GetNamesAsInBaseClass ( ev , is_static ) ) ;
if ( topScope ! = null )
lst . AddRange ( topScope . GetNamesInAllTopScopes ( all_names , ev , is_static ) ) ;
return lst . ToArray ( ) ;
}
//poluchit imena s klassa s kluchevym slovom
//vyzyvaetsja, kogda procedure TClass. tut vse ekzemplarnye i staticheskie
public virtual SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword , bool called_in_base )
{
List < SymInfo > lst = new List < SymInfo > ( ) ;
2022-10-31 16:02:17 +03:00
foreach ( SymScope ss in GetMergedMembers ( ) )
2015-05-14 22:35:07 +03:00
{
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( ss . si . name ) )
2015-05-14 22:35:07 +03:00
{
if ( keyword ! = PascalABCCompiler . Parsers . KeywordKind . Function & & keyword ! = PascalABCCompiler . Parsers . KeywordKind . Constructor & & keyword ! = PascalABCCompiler . Parsers . KeywordKind . Destructor /*!(ev.entry_scope is InterfaceUnitScope) && !(ev.entry_scope is ImplementationUnitScope)*/ )
{
if ( ss . si . acc_mod = = access_modifer . private_modifer )
{
if ( ss . is_static & & ev . CheckPrivateForBaseAccess ( ev . entry_scope , this ) )
lst . Add ( ss . si ) ;
}
else if ( ss . si . acc_mod = = access_modifer . protected_modifer )
{
if ( ss . is_static & & ev . CheckForBaseAccess ( ev . entry_scope , this ) )
lst . Add ( ss . si ) ;
}
2018-12-30 23:37:40 +03:00
else if ( ss . is_static )
{
if ( ! ( ( ss is ProcScope ) & & ( ss as ProcScope ) . IsConstructor ( ) ) )
lst . Add ( ss . si ) ;
}
else if ( ( ss is ProcScope ) & & ( ss as ProcScope ) . IsConstructor ( ) )
if ( ! ( ( ss as ProcScope ) . parameters = = null | | ( ss as ProcScope ) . parameters . Count = = 0 ) | | ! called_in_base )
2015-05-14 22:35:07 +03:00
lst . Add ( ss . si ) ;
}
else
{
if ( ss is ProcScope & & ! ( ss as ProcScope ) . already_defined )
{
if ( keyword = = PascalABCCompiler . Parsers . KeywordKind . Function | | keyword = = PascalABCCompiler . Parsers . KeywordKind . Destructor )
lst . Add ( ss . si ) ;
else if ( ( ss as ProcScope ) . IsConstructor ( ) )
lst . Add ( ss . si ) ;
}
}
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
}
if ( baseScope ! = null & & keyword ! = PascalABCCompiler . Parsers . KeywordKind . Constructor & & keyword ! = PascalABCCompiler . Parsers . KeywordKind . Destructor )
lst . AddRange ( baseScope . GetNames ( ev , keyword , true ) ) ;
/ * if ( topScope ! = null )
lst . AddRange ( topScope . GetNames ( ) ) ; * /
return lst . ToArray ( ) ;
}
//poluchit vse imena kak po tochke iz objektnoj peremennoj, sootv. ekzemplarnye chleny klassa i nadklassov
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
//if (original_type != null)
// return original_type.GetNamesAsInObject(ev);
List < SymInfo > lst = new List < SymInfo > ( ) ;
2022-10-31 16:02:17 +03:00
foreach ( SymScope ss in GetMergedMembers ( ) )
2015-05-14 22:35:07 +03:00
{
if ( ss is ProcScope & & ( ss as ProcScope ) . IsConstructor ( ) ) continue ;
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( ss . si . name ) & & ! ss . is_static & & ! ( ss is TemplateParameterScope ) )
2015-05-14 22:35:07 +03:00
{
if ( ss . si . acc_mod = = access_modifer . private_modifer )
{
if ( ev . CheckPrivateForBaseAccess ( ev . entry_scope , this ) )
lst . Add ( ss . si ) ;
}
else if ( ss . si . acc_mod = = access_modifer . protected_modifer )
{
if ( ev . CheckForBaseAccess ( ev . entry_scope , this ) )
lst . Add ( ss . si ) ;
}
else
lst . Add ( ss . si ) ;
if ( ! ss . si . has_doc )
UnitDocCache . AddDescribeToComplete ( ss ) ;
}
}
2016-05-01 13:02:40 +03:00
if ( this . documentation ! = null & & this . documentation . Contains ( "!#" ) & & baseScope is CompiledScope )
return lst . ToArray ( ) ;
2015-05-14 22:35:07 +03:00
if ( baseScope ! = null )
{
lst . AddRange ( baseScope . GetNamesAsInObject ( ev ) ) ;
}
2016-07-28 21:06:12 +03:00
if ( implemented_interfaces ! = null & & ! ( this is ArrayScope & & ( this as ArrayScope ) . IsMultiDynArray ) )
2015-05-14 22:35:07 +03:00
foreach ( TypeScope ts in implemented_interfaces )
lst . AddRange ( ts . GetNamesAsInObject ( ev ) ) ;
return lst . ToArray ( ) ;
}
public virtual TypeScope [ ] GetIndexers ( )
{
2019-12-25 11:53:05 +03:00
if ( indexers = = null )
return new TypeScope [ 0 ] ;
2015-05-14 22:35:07 +03:00
if ( indexers . Count > 0 )
return indexers . ToArray ( ) ;
if ( baseScope ! = null ) return baseScope . GetIndexers ( ) ;
else return indexers . ToArray ( ) ;
}
2019-12-25 11:53:05 +03:00
public virtual TypeScope [ ] GetStaticIndexers ( )
2015-05-14 22:35:07 +03:00
{
2019-12-25 11:53:05 +03:00
if ( static_indexers = = null )
return new TypeScope [ 0 ] ;
if ( static_indexers . Count > 0 )
return static_indexers . ToArray ( ) ;
if ( baseScope ! = null ) return baseScope . GetStaticIndexers ( ) ;
else return static_indexers . ToArray ( ) ;
}
public virtual void AddIndexer ( TypeScope ts , bool is_static )
{
if ( indexers = = null )
indexers = new List < TypeScope > ( ) ;
if ( static_indexers = = null )
static_indexers = new List < TypeScope > ( ) ;
if ( ! is_static )
indexers . Add ( ts ) ;
else
static_indexers . Add ( ts ) ;
2015-05-14 22:35:07 +03:00
}
//poisk v classe, nadklassah i scope v kotorom klass opisan a takzhe vo vseh uses
public override SymScope FindName ( string name )
{
//SymScope sc = ht[name] as SymScope;
SymScope sc = internal_find ( name , true ) ;
if ( sc ! = null ) return sc ;
2022-10-31 16:02:17 +03:00
if ( other_partials ! = null )
foreach ( TypeScope part in other_partials )
{
sc = part . internal_find ( name , true ) ;
if ( sc ! = null )
return sc ;
}
2015-05-14 22:35:07 +03:00
if ( baseScope ! = null ) sc = baseScope . FindNameOnlyInType ( name ) ;
if ( sc ! = null ) return sc ;
if ( topScope ! = null ) return topScope . FindName ( name ) ;
return null ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
List < SymScope > names = internal_find_overloads ( name , true ) ;
2022-10-31 16:02:17 +03:00
if ( other_partials ! = null )
foreach ( TypeScope part in other_partials )
{
names . AddRange ( part . internal_find_overloads ( name , true ) ) ;
}
2015-05-14 22:35:07 +03:00
if ( baseScope ! = null )
names . AddRange ( baseScope . FindOverloadNamesOnlyInType ( name ) ) ;
if ( topScope ! = null )
names . AddRange ( topScope . FindOverloadNames ( name ) ) ;
return names ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
//SymScope sc = ht[name] as SymScope;
SymScope sc = internal_find ( name , false ) ;
if ( sc ! = null ) return sc ;
2022-10-31 16:02:17 +03:00
if ( other_partials ! = null )
foreach ( TypeScope part in other_partials )
{
sc = part . internal_find ( name , true ) ;
if ( sc ! = null )
return sc ;
}
2015-05-14 22:35:07 +03:00
if ( baseScope ! = null ) sc = baseScope . FindNameOnlyInType ( name ) ;
if ( sc ! = null ) return sc ;
if ( topScope ! = null ) return topScope . FindNameInAnyOrder ( name ) ;
return null ;
}
//poisk tolko v etom klasse
public override SymScope FindNameOnlyInThisType ( string name )
{
SymScope sc = null ;
if ( original_type ! = null )
return original_type . FindNameOnlyInThisType ( name ) ;
2022-10-31 16:02:17 +03:00
if ( name ! = null )
sc = internal_find ( name , false ) ;
if ( sc ! = null )
return sc ;
if ( other_partials ! = null )
foreach ( TypeScope part in other_partials )
{
sc = part . internal_find ( name , false ) ;
if ( sc ! = null )
return sc ;
}
return null ;
2015-05-14 22:35:07 +03:00
}
//poisk tolko v klasse i nadklassah
public override SymScope FindNameOnlyInType ( string name )
{
SymScope sc = null ;
2017-12-17 17:05:33 +03:00
if ( name ! = null )
sc = internal_find ( name , false ) ;
if ( sc ! = null )
return sc ;
2022-10-31 16:02:17 +03:00
if ( other_partials ! = null )
foreach ( TypeScope part in other_partials )
{
sc = part . internal_find ( name , false ) ;
if ( sc ! = null )
return sc ;
}
2015-10-11 22:48:37 +03:00
if ( sc = = null & & baseScope ! = null )
sc = baseScope . FindNameOnlyInType ( name ) ;
if ( sc = = null & & implemented_interfaces ! = null )
foreach ( TypeScope ts in implemented_interfaces )
{
2019-02-17 16:02:54 +03:00
if ( ts ! = this )
2015-10-11 22:48:37 +03:00
sc = ts . FindNameOnlyInType ( name ) ;
if ( sc ! = null )
break ;
}
2017-12-17 17:05:33 +03:00
if ( sc = = null & & original_type ! = null )
return original_type . FindNameOnlyInType ( name ) ;
2019-12-24 18:23:34 +03:00
if ( sc ! = null & & is_static & & sc is ProcScope & & ( sc as ProcScope ) . IsConstructor ( ) )
return null ;
2015-05-14 22:35:07 +03:00
return sc ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
List < SymScope > names = internal_find_overloads ( name , false ) ;
2022-10-31 16:02:17 +03:00
if ( other_partials ! = null )
foreach ( TypeScope part in other_partials )
{
names . AddRange ( part . internal_find_overloads ( name , false ) ) ;
}
2015-05-14 22:35:07 +03:00
if ( baseScope ! = null )
names . AddRange ( baseScope . FindOverloadNamesOnlyInType ( name ) ) ;
2018-07-05 22:49:37 +03:00
if ( implemented_interfaces ! = null )
foreach ( TypeScope ts in implemented_interfaces )
{
names . AddRange ( ts . FindOverloadNamesOnlyInType ( name ) ) ;
}
2015-05-14 22:35:07 +03:00
return names ;
}
public override void AddName ( string name , SymScope sc )
{
/ * if ( name ! = null )
ht [ name ] = sc ; * /
sc . si . name = name ;
if ( members = = null )
members = new List < SymScope > ( ) ;
members . Add ( sc ) ;
}
public override string ToString ( )
{
return si . name ;
}
2018-08-08 16:54:13 +03:00
public IProcScope FindExtensionMethod ( string name )
{
List < ProcScope > meths = null ;
if ( original_type ! = null )
meths = original_type . GetExtensionMethods ( name , original_type ) ;
else
meths = GetExtensionMethods ( name , this ) ;
if ( meths ! = null & & meths . Count > 0 )
return meths [ 0 ] ;
return null ;
}
2015-05-14 22:35:07 +03:00
}
// public class GenericInstanceScope : TypeScope, IGenericInstanceScope
// {
// public TypeScope actType;
// public List<TypeScope> gen_args;
//
// public GenericInstanceScope(TypeScope actType, List<TypeScope> gen_args)
// {
// this.actType = actType;
// this.gen_args = gen_args;
// CopyType();
// }
//
// private void CopyType()
// {
// actType = actType.GetInstance(List<TypeScope> gen_args);
// }
//
// }
public class NamespaceTypeScope : SymScope , INamespaceTypeScope
{
private CompiledScope entry_type ;
public NamespaceTypeScope ( CompiledScope entry_type )
{
this . entry_type = entry_type ;
}
public override ScopeKind Kind
{
get
{
return ScopeKind . NamespaceTypeScope ;
}
}
public override SymScope FindName ( string s )
{
return entry_type . FindName ( s ) ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
return entry_type . FindOverloadNames ( name ) ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return entry_type . FindOverloadNamesOnlyInType ( name ) ;
}
public override SymScope FindNameOnlyInType ( string name )
{
return entry_type . FindNameOnlyInType ( name ) ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
return entry_type . FindName ( name ) ;
}
public override SymInfo [ ] GetNames ( )
{
return entry_type . GetStaticNames ( ) ;
}
}
public class NamespaceScope : SymScope , INamespaceScope
{
public string name ;
public CompiledScope entry_type ;
public NamespaceScope ( string name )
{
this . name = name ;
this . si = new SymInfo ( name , SymbolKind . Namespace , name ) ;
Refactoring of Compiler.cs (#2984)
* Add first comments
* Finish commenting for Compile and CompileUnit
* Write TODO sections
* Add a few clarifications
* splitted some functions from compile
* Written some methods from Compile to functions
* Update variable names
* Refactor - stage 1
Refactor GetUsesSection and IsPossibleNameSpace
* Refactor - stage 2
Rename a few functions and variables
* Correct an inaccuracy
* Added comments, look through CompileUnit
* Rename a few functions and add new comments
* Split CompileUnit to Subfunctions
Add IsUnitCompiled, IsUnitInPCU, InitializeNewUnit, GetSourceCode, GenSyntaxTree, GenUnitDocumentation, CheckDLLDirectiveOnlyForLibraries, MatchErrorsToBadNodes, CheckIfUnitModule, SetUseDLLForSystemUnits,
CompileInterfaceDependencies, CompileCurrentUnitInterface, GetImplementationUsesSection, CompileImplementationDependencies, CompileCurrentUnitImplementation
* Added some TODOs
* Return uses_unit_in original name
Renaming of syntax tree nodes leads to internal compiler errors
* Extract GenerateILCode method
* Add checking if recompilation needed method
Needs to be discussed and revised
* Add functions for catch blocks in Compile
* Extract building semantic tree method
Creating main function to be moved to another class
* Rename UnitsSortedList
* Edit CompileUnitsFromDelayedList method
* Change a few variable names, make CreateRCFile function and add comments
* Make code more "user-friendly"
* Add TODOs 31.11.23
* Create PrebuildSemanticTreeActionsMethod
* Refactor semantic checks section in initialize new unit method
* Refactor Adding standard units to uses method
* Return file_name and compiler_directives original names to avoid internal compilation errors
* Refactor GetReferences Method
* Initial refactoring of IncludeNamespaces function
* Create three more methods and wrap important code in regions
* Add TODO's
* Resolve merge conflicts
* Add returned value to ConstructSyntaxTree method
* Fix UnitsSortedList NotFoundError in PCUWriter
* Workaround commit
* Update PABCSystem after tests' changes
* Rename syntax trees in some methods
* Delete CurrentSyntaxUnit variable
* Revert unnecessary project files changes
* Squashed commit of the following:
commit f4d7599f1a39252feac97bd5391f46dfdc25f6f4
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:29 2023 +0300
added links to identarranger
commit 3bd5d33e2b2969884e61a3279ff9c353013b57fe
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:03 2023 +0300
Change extension for verybasic to yavb
commit 61294c6e7d405e1c68516cc81d3a109e8a1ee295
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:33:57 2023 +0300
Change Program Example
commit 86971488341ed6bf13c39e13a513d7ac0c51c285
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:28:59 2023 +0300
Add IndentArranger to Compile
commit 2ce50bbbf9db22c4243b247b870f6935ce206d26
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 17 10:00:31 2023 +0300
Add Semicolon After Each Statement
commit 796309d340e8d8ba730ff9418fa376f34fb7fd36
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Wed Nov 15 18:49:11 2023 +0300
Add Alpha Version of Python-style If-statement
commit 5eb88f946fe8254b4f5c5a56ed0a567b3be51227
Merge: ab4ce5b0 0162b637
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:54:26 2023 +0300
Merge branch 'IndentArranger' into VeryBasicLanguage
commit ab4ce5b0e32d42004726e3dc45cc0d8a65e53f56
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:53:51 2023 +0300
Fixes from seminar
commit af74012289d0d08517c13499a2a66cb543fc06d2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 18:57:29 2023 +0300
finally working!
fully implemented compatibility
commit 58a39c313324b468d1eec207ba3f5f6eddf74ef2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 11:58:16 2023 +0300
more compatibility with pabc
Now verybasic statements translate to pascal compiler
added .bat script for autobuilding verybasic
commit 0162b6376b8fe970704f26213bf9f0f670dfb12e
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:06:14 2023 +0300
Update test.txt
commit 1b759ab1cd7ee2ffeb14afff0418ddf0f30b0399
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:05:36 2023 +0300
Add Indent and Unindent Keywords to Generated File
commit cabda7f3985651cff2a8740f1a5bdea8fe7ac892
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 10 21:25:52 2023 +0300
Add Generation of Output File
commit 306f033d0176ab559e3622b8505427dbe2e0e203
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:42:18 2023 +0300
Update IndentArranger.sln
commit 60c0ceced1aa3a7d2e33de0facb1126e295f43b5
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:41:22 2023 +0300
Add IndentArranger
commit 1f4556c4573dae154fcc167b41ff6ab9e8122136
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Mon Nov 6 22:48:36 2023 +0300
Made my own VeryBasicParser project
Copied some code from SaushkinParser
Tried to compile it and implement into Pascal
Doesn't work due to grammatik issue
* Squashed commit of the following:
commit 4e73d9ac3ffef68312f06a74dc83afffcf3ccbee
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 15:08:10 2023 +0300
Fixed GPPG (i think so at least)
commit e5cfc220828b37fb2f35e565683019716ec3f0ce
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:44:27 2023 +0300
Update Compiler.cs
commit 4698e2e75a5f3b4f523a8bc7733a50e8abb4fca1
Merge: 22aaf2b2 f4d7599f
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:54 2023 +0300
Merge branch 'IndentArrangerTemp' into VeryBasicLanguage
commit f4d7599f1a39252feac97bd5391f46dfdc25f6f4
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:29 2023 +0300
added links to identarranger
commit 3bd5d33e2b2969884e61a3279ff9c353013b57fe
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:03 2023 +0300
Change extension for verybasic to yavb
commit 22aaf2b2508278a9ffce525ffed52419bf72c23f
Merge: c326174f 61294c6e
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:26:36 2023 +0300
Merge branch 'IndentArrangerTemp' into VeryBasicLanguage
commit 61294c6e7d405e1c68516cc81d3a109e8a1ee295
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:33:57 2023 +0300
Change Program Example
commit 86971488341ed6bf13c39e13a513d7ac0c51c285
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:28:59 2023 +0300
Add IndentArranger to Compile
commit c326174ff5ecccf9c4f76d58aea4653f047af049
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 19 15:03:19 2023 +0300
Added UniversalParserHelper and GPPG
ShiftReduceParser moved to another project
UniversalParserHelper project added, most of it copied from SaushkinParser
commit 2ce50bbbf9db22c4243b247b870f6935ce206d26
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 17 10:00:31 2023 +0300
Add Semicolon After Each Statement
commit 796309d340e8d8ba730ff9418fa376f34fb7fd36
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Wed Nov 15 18:49:11 2023 +0300
Add Alpha Version of Python-style If-statement
commit 5eb88f946fe8254b4f5c5a56ed0a567b3be51227
Merge: ab4ce5b0 0162b637
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:54:26 2023 +0300
Merge branch 'IndentArranger' into VeryBasicLanguage
commit ab4ce5b0e32d42004726e3dc45cc0d8a65e53f56
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:53:51 2023 +0300
Fixes from seminar
commit af74012289d0d08517c13499a2a66cb543fc06d2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 18:57:29 2023 +0300
finally working!
fully implemented compatibility
commit 58a39c313324b468d1eec207ba3f5f6eddf74ef2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 11:58:16 2023 +0300
more compatibility with pabc
Now verybasic statements translate to pascal compiler
added .bat script for autobuilding verybasic
commit 0162b6376b8fe970704f26213bf9f0f670dfb12e
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:06:14 2023 +0300
Update test.txt
commit 1b759ab1cd7ee2ffeb14afff0418ddf0f30b0399
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:05:36 2023 +0300
Add Indent and Unindent Keywords to Generated File
commit cabda7f3985651cff2a8740f1a5bdea8fe7ac892
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 10 21:25:52 2023 +0300
Add Generation of Output File
commit 306f033d0176ab559e3622b8505427dbe2e0e203
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:42:18 2023 +0300
Update IndentArranger.sln
commit 60c0ceced1aa3a7d2e33de0facb1126e295f43b5
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:41:22 2023 +0300
Add IndentArranger
commit 1f4556c4573dae154fcc167b41ff6ab9e8122136
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Mon Nov 6 22:48:36 2023 +0300
Made my own VeryBasicParser project
Copied some code from SaushkinParser
Tried to compile it and implement into Pascal
Doesn't work due to grammatik issue
* Changed GPPG project NET Framework version, added .dll to gitignore
* Adding UniversalParserHelper to project, trying to include VeryBasic
* Managed dependencies and got VeryBasicLanguage to work
* Change extension of a test program
* Rebuild changes
What should be added to .gitignore?
* Fix bug related to err0524_res_unit.pas
* Rebuild Parser
* Change Indent and Unindent tokens
* Add Symbol Table to ParserABC.y
* Change Indent Space Number to 2
* Add While Loop
* Add Some Operations to Parser
* Make Initialization Node at the Beginning of a program
* Create Grammar.txt
* Test program added
* Add ELIF and SyntaxHighlight
* Fix TableSymbol
* Add Division
* Add Method Call
* Add For Loop
* Rename SPython Parser Folder
* Add documented comments for CompileUnit method
* Added Errors to SPython
Added Errors.cs
Removed link to PABCSaushkinParser
Minor fixes
* Create default constructor for SourceContext
* Move null check of currentUnit to upper level in CompileUnit
* Move CreateMainFunction method from Compiler to TreeConverter class
* Add gppg and parserhelper to visualpascalabcnet dependencies
* Updated installer files to include GPPG and UniversalParserHelper
* Rename GPPG to ShiftReduceParser
* Fix ShiftReduceParser project dependencies
* Fix ShiftReduceParserDependencies second iteration
* Workaround commit
* Update PABCSystem after tests' changes
* Refactor ConvertDirectives method
* Get rid of legacy standard modules code
* Return varBeginOffset and beginOffset calculation to Compiler class
Размещение метода в SyntaxTreeToSemanticTreeConverter не целесообразно. В комментарии видимо имелось в виду что-то другое.
* Workaround commit
* Update PABCSystem after tests' changes
* Revert SPython changes
Оставляем только изменения связанные с рефакторингом.
* Update .gitignore
Co-authored-by: Sun Serega <sunserega2@gmail.com>
* Resolve a few Sun Serega treds
* Delete comments in ParsersController.cs
* Replace specific path with path variable in Studio.bat
* Add comment in Studio.bat file and return FileName in CompilerError.cs
* Fix TreeSubsidiary.cs encoding and sectCore.nsh indents
* Return old version of TestRunner.exe
* Rename some variables and polish a few methods
* Uncomment accidentally commented code
* Replace spaces with tabs
* Changed dll name from GPPG
* Revert "Changed dll name from GPPG"
This reverts commit c485cc8cb787809b7e9dfa8a361e75f17ed39893.
* Update .gitignore
* Delete Libraries/ShiftReduceParser.dll
* Delete bin\ShiftReduceParser.dll
* Replace tabs with spaces
* Update encoding in Studio.bat
* Fix bug with PABCrtl excluded files
* Refactor StandardModule class
* Add null checks to make debuging easier
* Delete unnecessary null checks in SymTable.cs
---------
Co-authored-by: Владислав Крылов <krylov@sfedu.ru>
Co-authored-by: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Co-authored-by: Sun Serega <sunserega2@gmail.com>
2023-12-18 22:33:27 +03:00
this . si . description = CodeCompletionController . CurrentParser ? . LanguageInformation . GetDescription ( this ) ;
2015-05-14 22:35:07 +03:00
}
public override ScopeKind Kind
{
get
{
return ScopeKind . Namespace ;
}
}
2017-10-15 15:37:49 +03:00
private SymInfo convertToDefaultNETNames ( Type t , SymInfo si )
{
if ( ! t . IsPrimitive )
return si ;
SymInfo new_si = new SymInfo ( si ) ;
new_si . name = t . Name ;
return new_si ;
}
2015-05-14 22:35:07 +03:00
public SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword )
{
List < SymInfo > syms = new List < SymInfo > ( ) ;
Type [ ] types = PascalABCCompiler . NetHelper . NetHelper . FindTypesInNamespace ( name ) ;
string [ ] ns = PascalABCCompiler . NetHelper . NetHelper . FindSubNamespaces ( name ) ;
Hashtable ht = new Hashtable ( ) ;
if ( keyword ! = PascalABCCompiler . Parsers . KeywordKind . Uses )
if ( types ! = null )
foreach ( Type t in types )
{
2018-11-01 00:19:05 +03:00
if ( ! t . IsNotPublic & & ! t . IsSpecialName & & t . IsVisible & & ! IsHiddenName ( t . Name ) & & ! t . IsNested )
2015-05-14 22:35:07 +03:00
{
2023-04-30 13:07:29 +03:00
if ( t . IsArray )
continue ;
2015-05-14 22:35:07 +03:00
if ( t . BaseType = = typeof ( MulticastDelegate ) )
//syms.Add(new CompiledScope(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Delegate, "delegate "+TypeUtility.GetTypeName(t) + "\n" + AssemblyDocCache.GetDocumentation(t)),t));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Delegate , null ) , t ) . si ) ;
else
if ( t . IsClass )
//syms.Add(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Type, "class "+TypeUtility.GetTypeName(t)+ "\n" +AssemblyDocCache.GetDocumentation(t)));
2017-10-15 15:37:49 +03:00
syms . Add ( convertToDefaultNETNames ( t , TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Class , null ) , t ) . si ) ) ;
2015-05-14 22:35:07 +03:00
else if ( t . IsInterface )
//syms.Add(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Interface, "interface "+TypeUtility.GetTypeName(t)+ "\n" +AssemblyDocCache.GetDocumentation(t)));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Interface , null ) , t ) . si ) ;
else if ( t . IsEnum )
//syms.Add(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Enum, "enum "+TypeUtility.GetTypeName(t)+ "\n" +AssemblyDocCache.GetDocumentation(t)));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Enum , null ) , t ) . si ) ;
else if ( t . IsValueType )
//syms.Add(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Struct, "record "+TypeUtility.GetTypeName(t)+ "\n" +AssemblyDocCache.GetDocumentation(t)));
2017-10-15 15:37:49 +03:00
syms . Add ( convertToDefaultNETNames ( t , TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Struct , null ) , t ) . si ) ) ;
2015-05-14 22:35:07 +03:00
}
}
if ( ns ! = null )
foreach ( string s in ns )
{
2018-11-01 00:19:05 +03:00
if ( ! s . Contains ( "." ) & & ! IsHiddenName ( s ) )
2015-05-14 22:35:07 +03:00
syms . Add ( new SymInfo ( s , SymbolKind . Namespace , "" ) ) ;
}
if ( syms . Count ! = 0 ) return syms . ToArray ( ) ;
return null ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
List < SymScope > names = new List < SymScope > ( 0 ) ;
SymScope ss = FindName ( name ) ;
if ( ss ! = null )
names . Add ( ss ) ;
return names ;
}
public override SymScope FindName ( string s )
{
2016-05-08 20:45:37 +03:00
string full_name = name + "." + s ;
bool is_ns = PascalABCCompiler . NetHelper . NetHelper . IsNetNamespace ( full_name ) ;
2015-05-14 22:35:07 +03:00
if ( is_ns )
{
2016-05-08 20:45:37 +03:00
return new NamespaceScope ( full_name ) ;
2015-05-14 22:35:07 +03:00
}
else
{
2016-05-08 20:45:37 +03:00
Type t = PascalABCCompiler . NetHelper . NetHelper . FindType ( full_name ) ;
if ( t = = null ) t = PascalABCCompiler . NetHelper . NetHelper . FindType ( full_name + PascalABCCompiler . TreeConverter . compiler_string_consts . generic_params_infix + "1" ) ;
if ( t = = null ) t = PascalABCCompiler . NetHelper . NetHelper . FindType ( full_name + PascalABCCompiler . TreeConverter . compiler_string_consts . generic_params_infix + "2" ) ;
2015-05-14 22:35:07 +03:00
if ( t ! = null )
{
2016-05-08 20:45:37 +03:00
return TypeTable . get_compiled_type ( new SymInfo ( s , SymbolKind . Type , full_name ) , t ) ;
2015-05-14 22:35:07 +03:00
}
else
{
2018-04-14 18:18:42 +03:00
List < PascalABCCompiler . TreeConverter . SymbolInfo > sil = null ;
2015-05-14 22:35:07 +03:00
if ( entry_type ! = null )
{
t = PascalABCCompiler . NetHelper . NetHelper . FindType ( entry_type . ctn . Namespace + "." + s ) ;
if ( t ! = null ) return TypeTable . get_compiled_type ( new SymInfo ( s , SymbolKind . Type , entry_type . ctn . Namespace + "." + s ) , t ) ;
else
{
object [ ] attrs = entry_type . ctn . GetCustomAttributes ( false ) ;
for ( int j = 0 ; j < attrs . Length ; j + + )
if ( attrs [ j ] . GetType ( ) . Name = = "$GlobAttr" )
{
2017-10-23 11:21:15 +03:00
sil = PascalABCCompiler . NetHelper . NetHelper . FindName ( entry_type . ctn , s ) ;
if ( sil ! = null ) break ;
2015-05-14 22:35:07 +03:00
}
}
}
2017-10-23 11:21:15 +03:00
if ( sil ! = null )
2018-04-14 18:18:42 +03:00
switch ( sil . FirstOrDefault ( ) . sym_info . semantic_node_type )
2015-05-14 22:35:07 +03:00
{
case semantic_node_type . compiled_function_node :
{
2018-04-14 18:18:42 +03:00
CompiledMethodScope cms = new CompiledMethodScope ( new SymInfo ( s , SymbolKind . Method , s ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_function_node ) . method_info , entry_type , true ) ;
2017-10-23 11:21:15 +03:00
sil . RemoveAt ( 0 ) ;
if ( sil . Count ( ) = = 0 )
sil = null ;
2015-05-14 22:35:07 +03:00
CompiledMethodScope tmp = cms ;
SortedDictionary < int , List < CompiledMethodScope > > meths = new SortedDictionary < int , List < CompiledMethodScope > > ( ) ;
if ( cms . acc_mod ! = access_modifer . internal_modifer & & cms . acc_mod ! = access_modifer . private_modifer )
{
int par_num = cms . mi . GetParameters ( ) . Length ;
meths [ par_num ] = new List < CompiledMethodScope > ( ) ;
meths [ par_num ] . Add ( cms ) ;
}
2017-10-23 11:21:15 +03:00
if ( sil ! = null )
2015-05-14 22:35:07 +03:00
{
2018-04-14 18:18:42 +03:00
foreach ( var si in sil )
2015-05-14 22:35:07 +03:00
{
2017-10-23 11:21:15 +03:00
if ( si . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & si . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private & & si . sym_info . semantic_node_type = = semantic_node_type . compiled_function_node )
2017-05-20 21:20:02 +03:00
{
2017-10-23 11:21:15 +03:00
tmp = new CompiledMethodScope ( new SymInfo ( s , SymbolKind . Method , s ) , ( si . sym_info as compiled_function_node ) . method_info , entry_type ) ;
2017-05-20 21:20:02 +03:00
tmp . is_global = true ;
//tmp.nextProc = cms;
//cms = tmp;
int par_num = tmp . mi . GetParameters ( ) . Length ;
if ( ! meths . ContainsKey ( par_num ) )
meths [ par_num ] = new List < CompiledMethodScope > ( ) ;
meths [ par_num ] . Add ( tmp ) ;
}
2015-05-14 22:35:07 +03:00
}
}
bool beg = false ;
tmp = null ;
cms = null ;
foreach ( List < CompiledMethodScope > lst in meths . Values )
{
foreach ( CompiledMethodScope m in lst )
{
if ( beg = = false )
{
tmp = m ;
cms = tmp ;
beg = true ;
}
else
{
tmp . nextProc = m ;
tmp = tmp . nextProc as CompiledMethodScope ;
}
}
}
return cms ;
}
case semantic_node_type . compiled_variable_definition :
2018-04-14 18:18:42 +03:00
if ( sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private )
2015-05-14 22:35:07 +03:00
{
2018-04-14 18:18:42 +03:00
CompiledFieldScope fld = new CompiledFieldScope ( new SymInfo ( s , SymbolKind . Field , s ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_variable_definition ) . compiled_field , entry_type , true ) ;
2015-05-14 22:35:07 +03:00
return fld ;
}
break ;
case semantic_node_type . compiled_class_constant_definition :
2018-04-14 18:18:42 +03:00
if ( sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private )
2015-05-14 22:35:07 +03:00
{
2018-04-14 18:18:42 +03:00
CompiledFieldScope fld = new CompiledFieldScope ( new SymInfo ( s , SymbolKind . Constant , s ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_class_constant_definition ) . field , entry_type , true ) ;
2015-05-14 22:35:07 +03:00
return fld ;
}
break ;
}
}
return null ;
}
}
2018-07-04 22:15:37 +03:00
public override bool IsEqual ( SymScope ts )
{
if ( ts is NamespaceScope )
return string . Compare ( this . name , ( ts as NamespaceScope ) . name , true ) = = 0 ;
return false ;
}
2015-05-14 22:35:07 +03:00
public override SymScope FindNameOnlyInType ( string name )
{
return FindName ( name ) ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return FindOverloadNames ( name ) ;
}
public override SymInfo [ ] GetNames ( )
{
List < SymInfo > syms = new List < SymInfo > ( ) ;
Type [ ] types = PascalABCCompiler . NetHelper . NetHelper . FindTypesInNamespace ( name ) ;
string [ ] ns = PascalABCCompiler . NetHelper . NetHelper . FindSubNamespaces ( name ) ;
Hashtable ht = new Hashtable ( ) ;
if ( types ! = null )
foreach ( Type t in types )
{
2020-01-26 16:29:47 +03:00
if ( ! t . IsNotPublic & & ! t . IsSpecialName & & t . IsVisible & & ! IsHiddenName ( t . Name ) & & ! t . IsNested )
2015-05-14 22:35:07 +03:00
{
if ( t . BaseType = = typeof ( MulticastDelegate ) )
//syms.Add(new CompiledScope(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Delegate, "delegate "+TypeUtility.GetTypeName(t) + "\n" + AssemblyDocCache.GetDocumentation(t)),t));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Delegate , null ) , t ) . si ) ;
else
if ( t . IsClass )
//syms.Add(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Class, "class "+TypeUtility.GetTypeName(t)+ "\n" +AssemblyDocCache.GetDocumentation(t)));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Class , null ) , t ) . si ) ;
else if ( t . IsInterface )
// syms.Add(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Interface, "interface "+TypeUtility.GetTypeName(t)+ "\n" +AssemblyDocCache.GetDocumentation(t)));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Interface , null ) , t ) . si ) ;
else if ( t . IsEnum )
//syms.Add(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Enum, "enum "+TypeUtility.GetTypeName(t)+ "\n" +AssemblyDocCache.GetDocumentation(t)));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Enum , null ) , t ) . si ) ;
else if ( t . IsValueType )
//syms.Add(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Struct, "record "+TypeUtility.GetTypeName(t)+ "\n" +AssemblyDocCache.GetDocumentation(t)));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Struct , null ) , t ) . si ) ;
}
}
if ( ns ! = null )
foreach ( string s in ns )
{
syms . Add ( new SymInfo ( s , SymbolKind . Namespace , "" ) ) ;
}
return syms . ToArray ( ) ;
//return null;
}
public override SymInfo [ ] GetNamesAsInObject ( )
{
List < SymInfo > syms = new List < SymInfo > ( ) ;
Type [ ] types = PascalABCCompiler . NetHelper . NetHelper . FindTypesInNamespace ( name ) ;
string [ ] ns = PascalABCCompiler . NetHelper . NetHelper . FindSubNamespaces ( name ) ;
Hashtable ht = new Hashtable ( ) ;
if ( types ! = null )
foreach ( Type t in types )
{
2018-11-01 00:19:05 +03:00
if ( ! t . IsNotPublic & & ! t . IsSpecialName & & t . IsVisible & & ! IsHiddenName ( t . Name ) )
2015-05-14 22:35:07 +03:00
{
if ( t . BaseType = = typeof ( MulticastDelegate ) )
//syms.Add(new CompiledScope(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Delegate, "delegate "+TypeUtility.GetTypeName(t) + "\n" + AssemblyDocCache.GetDocumentation(t)),t));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Delegate , null ) , t ) . si ) ;
else
if ( t . IsClass )
//syms.Add(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Class, "class "+TypeUtility.GetTypeName(t)+ "\n" +AssemblyDocCache.GetDocumentation(t)));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Class , null ) , t ) . si ) ;
else if ( t . IsInterface )
//syms.Add(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Interface, "interface "+TypeUtility.GetTypeName(t)+ "\n" +AssemblyDocCache.GetDocumentation(t)));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Interface , null ) , t ) . si ) ;
else if ( t . IsEnum )
//syms.Add(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Enum, "enum "+TypeUtility.GetTypeName(t)+ "\n" +AssemblyDocCache.GetDocumentation(t)));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Enum , null ) , t ) . si ) ;
else if ( t . IsValueType )
//syms.Add(new SymInfo(TypeUtility.GetShortTypeName(t), SymbolKind.Struct, "record "+TypeUtility.GetTypeName(t)+ "\n" +AssemblyDocCache.GetDocumentation(t)));
syms . Add ( TypeTable . get_compiled_type ( new SymInfo ( null , SymbolKind . Struct , null ) , t ) . si ) ;
}
}
return syms . ToArray ( ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
return GetNames ( ) ;
}
}
public class CompiledScope : TypeScope , ICompiledTypeScope
{
public Type ctn ;
private TypeScope [ ] indices ;
private PropertyInfo default_property ;
private bool is_def_prop_searched = false ;
public CompiledScope ( SymInfo si , Type ctn )
{
this . ctn = ctn ;
this . si = si ;
this . instances = new List < TypeScope > ( ) ;
2022-10-23 15:31:48 +03:00
if ( ctn = = null )
{
}
2015-05-14 22:35:07 +03:00
if ( ctn . BaseType ! = null )
2016-05-08 20:45:37 +03:00
baseScope = TypeTable . get_compiled_type ( ctn . BaseType ) ;
2015-05-14 22:35:07 +03:00
Type t = ctn . GetElementType ( ) ;
2017-06-05 17:09:24 +03:00
if ( t = = null & & ctn = = typeof ( string ) )
t = typeof ( char ) ;
2015-05-14 22:35:07 +03:00
if ( t ! = null )
{
2016-05-08 20:45:37 +03:00
elementType = TypeTable . get_compiled_type ( t ) ;
2015-05-14 22:35:07 +03:00
is_def_prop_searched = true ;
}
if ( si . name = = null )
AssemblyDocCache . AddDescribeToComplete ( this . si , ctn ) ;
Refactoring of Compiler.cs (#2984)
* Add first comments
* Finish commenting for Compile and CompileUnit
* Write TODO sections
* Add a few clarifications
* splitted some functions from compile
* Written some methods from Compile to functions
* Update variable names
* Refactor - stage 1
Refactor GetUsesSection and IsPossibleNameSpace
* Refactor - stage 2
Rename a few functions and variables
* Correct an inaccuracy
* Added comments, look through CompileUnit
* Rename a few functions and add new comments
* Split CompileUnit to Subfunctions
Add IsUnitCompiled, IsUnitInPCU, InitializeNewUnit, GetSourceCode, GenSyntaxTree, GenUnitDocumentation, CheckDLLDirectiveOnlyForLibraries, MatchErrorsToBadNodes, CheckIfUnitModule, SetUseDLLForSystemUnits,
CompileInterfaceDependencies, CompileCurrentUnitInterface, GetImplementationUsesSection, CompileImplementationDependencies, CompileCurrentUnitImplementation
* Added some TODOs
* Return uses_unit_in original name
Renaming of syntax tree nodes leads to internal compiler errors
* Extract GenerateILCode method
* Add checking if recompilation needed method
Needs to be discussed and revised
* Add functions for catch blocks in Compile
* Extract building semantic tree method
Creating main function to be moved to another class
* Rename UnitsSortedList
* Edit CompileUnitsFromDelayedList method
* Change a few variable names, make CreateRCFile function and add comments
* Make code more "user-friendly"
* Add TODOs 31.11.23
* Create PrebuildSemanticTreeActionsMethod
* Refactor semantic checks section in initialize new unit method
* Refactor Adding standard units to uses method
* Return file_name and compiler_directives original names to avoid internal compilation errors
* Refactor GetReferences Method
* Initial refactoring of IncludeNamespaces function
* Create three more methods and wrap important code in regions
* Add TODO's
* Resolve merge conflicts
* Add returned value to ConstructSyntaxTree method
* Fix UnitsSortedList NotFoundError in PCUWriter
* Workaround commit
* Update PABCSystem after tests' changes
* Rename syntax trees in some methods
* Delete CurrentSyntaxUnit variable
* Revert unnecessary project files changes
* Squashed commit of the following:
commit f4d7599f1a39252feac97bd5391f46dfdc25f6f4
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:29 2023 +0300
added links to identarranger
commit 3bd5d33e2b2969884e61a3279ff9c353013b57fe
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:03 2023 +0300
Change extension for verybasic to yavb
commit 61294c6e7d405e1c68516cc81d3a109e8a1ee295
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:33:57 2023 +0300
Change Program Example
commit 86971488341ed6bf13c39e13a513d7ac0c51c285
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:28:59 2023 +0300
Add IndentArranger to Compile
commit 2ce50bbbf9db22c4243b247b870f6935ce206d26
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 17 10:00:31 2023 +0300
Add Semicolon After Each Statement
commit 796309d340e8d8ba730ff9418fa376f34fb7fd36
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Wed Nov 15 18:49:11 2023 +0300
Add Alpha Version of Python-style If-statement
commit 5eb88f946fe8254b4f5c5a56ed0a567b3be51227
Merge: ab4ce5b0 0162b637
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:54:26 2023 +0300
Merge branch 'IndentArranger' into VeryBasicLanguage
commit ab4ce5b0e32d42004726e3dc45cc0d8a65e53f56
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:53:51 2023 +0300
Fixes from seminar
commit af74012289d0d08517c13499a2a66cb543fc06d2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 18:57:29 2023 +0300
finally working!
fully implemented compatibility
commit 58a39c313324b468d1eec207ba3f5f6eddf74ef2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 11:58:16 2023 +0300
more compatibility with pabc
Now verybasic statements translate to pascal compiler
added .bat script for autobuilding verybasic
commit 0162b6376b8fe970704f26213bf9f0f670dfb12e
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:06:14 2023 +0300
Update test.txt
commit 1b759ab1cd7ee2ffeb14afff0418ddf0f30b0399
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:05:36 2023 +0300
Add Indent and Unindent Keywords to Generated File
commit cabda7f3985651cff2a8740f1a5bdea8fe7ac892
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 10 21:25:52 2023 +0300
Add Generation of Output File
commit 306f033d0176ab559e3622b8505427dbe2e0e203
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:42:18 2023 +0300
Update IndentArranger.sln
commit 60c0ceced1aa3a7d2e33de0facb1126e295f43b5
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:41:22 2023 +0300
Add IndentArranger
commit 1f4556c4573dae154fcc167b41ff6ab9e8122136
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Mon Nov 6 22:48:36 2023 +0300
Made my own VeryBasicParser project
Copied some code from SaushkinParser
Tried to compile it and implement into Pascal
Doesn't work due to grammatik issue
* Squashed commit of the following:
commit 4e73d9ac3ffef68312f06a74dc83afffcf3ccbee
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 15:08:10 2023 +0300
Fixed GPPG (i think so at least)
commit e5cfc220828b37fb2f35e565683019716ec3f0ce
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:44:27 2023 +0300
Update Compiler.cs
commit 4698e2e75a5f3b4f523a8bc7733a50e8abb4fca1
Merge: 22aaf2b2 f4d7599f
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:54 2023 +0300
Merge branch 'IndentArrangerTemp' into VeryBasicLanguage
commit f4d7599f1a39252feac97bd5391f46dfdc25f6f4
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:29 2023 +0300
added links to identarranger
commit 3bd5d33e2b2969884e61a3279ff9c353013b57fe
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:03 2023 +0300
Change extension for verybasic to yavb
commit 22aaf2b2508278a9ffce525ffed52419bf72c23f
Merge: c326174f 61294c6e
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:26:36 2023 +0300
Merge branch 'IndentArrangerTemp' into VeryBasicLanguage
commit 61294c6e7d405e1c68516cc81d3a109e8a1ee295
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:33:57 2023 +0300
Change Program Example
commit 86971488341ed6bf13c39e13a513d7ac0c51c285
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:28:59 2023 +0300
Add IndentArranger to Compile
commit c326174ff5ecccf9c4f76d58aea4653f047af049
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 19 15:03:19 2023 +0300
Added UniversalParserHelper and GPPG
ShiftReduceParser moved to another project
UniversalParserHelper project added, most of it copied from SaushkinParser
commit 2ce50bbbf9db22c4243b247b870f6935ce206d26
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 17 10:00:31 2023 +0300
Add Semicolon After Each Statement
commit 796309d340e8d8ba730ff9418fa376f34fb7fd36
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Wed Nov 15 18:49:11 2023 +0300
Add Alpha Version of Python-style If-statement
commit 5eb88f946fe8254b4f5c5a56ed0a567b3be51227
Merge: ab4ce5b0 0162b637
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:54:26 2023 +0300
Merge branch 'IndentArranger' into VeryBasicLanguage
commit ab4ce5b0e32d42004726e3dc45cc0d8a65e53f56
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:53:51 2023 +0300
Fixes from seminar
commit af74012289d0d08517c13499a2a66cb543fc06d2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 18:57:29 2023 +0300
finally working!
fully implemented compatibility
commit 58a39c313324b468d1eec207ba3f5f6eddf74ef2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 11:58:16 2023 +0300
more compatibility with pabc
Now verybasic statements translate to pascal compiler
added .bat script for autobuilding verybasic
commit 0162b6376b8fe970704f26213bf9f0f670dfb12e
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:06:14 2023 +0300
Update test.txt
commit 1b759ab1cd7ee2ffeb14afff0418ddf0f30b0399
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:05:36 2023 +0300
Add Indent and Unindent Keywords to Generated File
commit cabda7f3985651cff2a8740f1a5bdea8fe7ac892
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 10 21:25:52 2023 +0300
Add Generation of Output File
commit 306f033d0176ab559e3622b8505427dbe2e0e203
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:42:18 2023 +0300
Update IndentArranger.sln
commit 60c0ceced1aa3a7d2e33de0facb1126e295f43b5
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:41:22 2023 +0300
Add IndentArranger
commit 1f4556c4573dae154fcc167b41ff6ab9e8122136
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Mon Nov 6 22:48:36 2023 +0300
Made my own VeryBasicParser project
Copied some code from SaushkinParser
Tried to compile it and implement into Pascal
Doesn't work due to grammatik issue
* Changed GPPG project NET Framework version, added .dll to gitignore
* Adding UniversalParserHelper to project, trying to include VeryBasic
* Managed dependencies and got VeryBasicLanguage to work
* Change extension of a test program
* Rebuild changes
What should be added to .gitignore?
* Fix bug related to err0524_res_unit.pas
* Rebuild Parser
* Change Indent and Unindent tokens
* Add Symbol Table to ParserABC.y
* Change Indent Space Number to 2
* Add While Loop
* Add Some Operations to Parser
* Make Initialization Node at the Beginning of a program
* Create Grammar.txt
* Test program added
* Add ELIF and SyntaxHighlight
* Fix TableSymbol
* Add Division
* Add Method Call
* Add For Loop
* Rename SPython Parser Folder
* Add documented comments for CompileUnit method
* Added Errors to SPython
Added Errors.cs
Removed link to PABCSaushkinParser
Minor fixes
* Create default constructor for SourceContext
* Move null check of currentUnit to upper level in CompileUnit
* Move CreateMainFunction method from Compiler to TreeConverter class
* Add gppg and parserhelper to visualpascalabcnet dependencies
* Updated installer files to include GPPG and UniversalParserHelper
* Rename GPPG to ShiftReduceParser
* Fix ShiftReduceParser project dependencies
* Fix ShiftReduceParserDependencies second iteration
* Workaround commit
* Update PABCSystem after tests' changes
* Refactor ConvertDirectives method
* Get rid of legacy standard modules code
* Return varBeginOffset and beginOffset calculation to Compiler class
Размещение метода в SyntaxTreeToSemanticTreeConverter не целесообразно. В комментарии видимо имелось в виду что-то другое.
* Workaround commit
* Update PABCSystem after tests' changes
* Revert SPython changes
Оставляем только изменения связанные с рефакторингом.
* Update .gitignore
Co-authored-by: Sun Serega <sunserega2@gmail.com>
* Resolve a few Sun Serega treds
* Delete comments in ParsersController.cs
* Replace specific path with path variable in Studio.bat
* Add comment in Studio.bat file and return FileName in CompilerError.cs
* Fix TreeSubsidiary.cs encoding and sectCore.nsh indents
* Return old version of TestRunner.exe
* Rename some variables and polish a few methods
* Uncomment accidentally commented code
* Replace spaces with tabs
* Changed dll name from GPPG
* Revert "Changed dll name from GPPG"
This reverts commit c485cc8cb787809b7e9dfa8a361e75f17ed39893.
* Update .gitignore
* Delete Libraries/ShiftReduceParser.dll
* Delete bin\ShiftReduceParser.dll
* Replace tabs with spaces
* Update encoding in Studio.bat
* Fix bug with PABCrtl excluded files
* Refactor StandardModule class
* Add null checks to make debuging easier
* Delete unnecessary null checks in SymTable.cs
---------
Co-authored-by: Владислав Крылов <krylov@sfedu.ru>
Co-authored-by: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Co-authored-by: Sun Serega <sunserega2@gmail.com>
2023-12-18 22:33:27 +03:00
this . si . name = CodeCompletionController . CurrentParser ? . LanguageInformation . GetShortName ( this ) ;
2015-05-14 22:35:07 +03:00
this . si . kind = get_kind ( ) ;
2016-05-01 13:02:40 +03:00
this . si . description = GetDescription ( ) ;
2017-02-19 23:20:56 +03:00
2016-03-20 16:23:41 +03:00
if ( ctn . IsGenericType & & ! ctn . IsGenericTypeDefinition )
{
2016-05-08 20:45:37 +03:00
this . original_type = TypeTable . get_compiled_type ( ctn . GetGenericTypeDefinition ( ) ) ;
2016-03-20 16:23:41 +03:00
}
2017-12-03 16:07:39 +03:00
if ( ctn . IsGenericType /*&& ctn.IsGenericTypeDefinition*/ )
{
generic_params = new List < string > ( ) ;
foreach ( Type gen_t in ctn . GetGenericArguments ( ) )
{
generic_params . Add ( gen_t . Name ) ;
}
}
2015-05-14 22:35:07 +03:00
if ( ctn . GetInterfaces ( ) . Length > 0 )
{
this . implemented_interfaces = new List < TypeScope > ( ) ;
foreach ( Type intf in ctn . GetInterfaces ( ) )
{
2016-05-08 20:45:37 +03:00
this . implemented_interfaces . Add ( TypeTable . get_compiled_type ( intf ) ) ;
2015-05-14 22:35:07 +03:00
}
}
}
2018-03-18 16:44:30 +03:00
public ICompiledTypeScope [ ] GetCompiledGenericArguments ( )
{
List < ICompiledTypeScope > types = new List < ICompiledTypeScope > ( ) ;
foreach ( Type t in ctn . GetGenericArguments ( ) )
types . Add ( TypeTable . get_compiled_type ( t ) ) ;
return types . ToArray ( ) ;
}
2015-05-14 22:35:07 +03:00
internal static TypeScope get_type_instance ( Type t , List < TypeScope > generic_args )
{
if ( t . IsGenericParameter )
2015-05-18 22:13:35 +03:00
{
if ( t . GenericParameterPosition < generic_args . Count )
return generic_args [ t . GenericParameterPosition ] ;
2016-04-10 12:02:05 +03:00
else if ( generic_args . Count > 0 )
2015-05-18 22:13:35 +03:00
return generic_args [ 0 ] ;
2016-04-10 12:02:05 +03:00
else
return TypeTable . get_compiled_type ( null , t ) ;
2015-05-18 22:13:35 +03:00
}
2015-05-14 22:35:07 +03:00
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 > ( ) ;
2015-12-19 22:48:12 +03:00
typ . original_type = TypeTable . get_compiled_type ( new SymInfo ( t . Name , SymbolKind . Type , t . Name ) , t ) ;
2015-05-14 22:35:07 +03:00
Type [ ] args = t . GetGenericArguments ( ) ;
for ( int i = 0 ; i < args . Length ; i + + )
{
if ( args [ i ] . IsGenericParameter )
{
2015-05-18 22:13:35 +03:00
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 ] ) ;
}
2015-05-14 22:35:07 +03:00
}
else
{
TypeScope ts = get_type_instance ( args [ i ] , generic_args ) ;
typ . generic_params . Add ( ts . si . name ) ;
typ . AddGenericInstanciation ( ts ) ;
}
}
2016-05-01 13:02:40 +03:00
typ . si . description = typ . GetDescription ( ) ;
2015-05-14 22:35:07 +03:00
return typ ;
}
2016-05-08 20:45:37 +03:00
return TypeTable . get_compiled_type ( t ) ;
2015-05-14 22:35:07 +03:00
}
2018-11-11 14:10:55 +03:00
/ * public override ITypeScope ElementType
{
get
{
return GetElementType ( ) ;
}
} * /
2018-09-22 18:49:47 +03:00
public override bool IsStatic
{
get
{
return ctn . IsSealed & & ctn . IsAbstract ;
}
}
2017-02-19 23:20:56 +03:00
public override bool IsGeneric
{
get
{
return original_type ! = null ;
}
}
public override bool IsDelegate
{
get
{
return ctn = = PascalABCCompiler . NetHelper . NetHelper . MulticastDelegateType | | ctn . BaseType = = PascalABCCompiler . NetHelper . NetHelper . MulticastDelegateType ;
}
}
2016-11-21 23:12:10 +03:00
public override int Rank
{
get
{
return this . ctn . GetArrayRank ( ) ;
}
}
2016-03-20 16:23:41 +03:00
public override List < TypeScope > GetInstances ( )
{
if ( this . instances . Count = = 0 & & ctn . IsGenericType & & ! ctn . IsGenericTypeDefinition )
{
foreach ( Type inst_t in ctn . GetGenericArguments ( ) )
2016-05-08 20:45:37 +03:00
this . instances . Add ( TypeTable . get_compiled_type ( inst_t ) ) ;
2016-03-20 16:23:41 +03:00
}
return base . GetInstances ( ) ;
}
2015-05-14 22:35:07 +03:00
private SymbolKind get_kind ( )
{
if ( ctn . BaseType = = typeof ( MulticastDelegate ) ) return SymbolKind . Delegate ;
if ( ctn . IsClass ) return SymbolKind . Class ;
if ( ctn . IsInterface ) return SymbolKind . Interface ;
if ( ctn . IsEnum ) return SymbolKind . Enum ;
if ( ctn . IsValueType ) return SymbolKind . Struct ;
return SymbolKind . Type ;
}
2016-03-20 16:23:41 +03:00
public override TypeScope GenericTypeDefinition
{
get
{
if ( this . ctn . IsGenericType )
2016-05-08 20:45:37 +03:00
return TypeTable . get_compiled_type ( this . ctn . GetGenericTypeDefinition ( ) ) ;
2016-03-20 16:23:41 +03:00
return this ;
}
}
public override bool IsGenericParameter
{
get
{
return this . ctn . IsGenericParameter ;
}
}
2015-05-14 22:35:07 +03:00
public override ScopeKind Kind
{
get
{
return ScopeKind . CompiledType ;
}
}
public override bool IsArray
{
get
{
return ctn . IsArray ;
}
}
public override PascalABCCompiler . Parsers . SymbolKind ElemKind
{
get
{
if ( TypeUtility . IsStandType ( ctn ) ) return PascalABCCompiler . Parsers . SymbolKind . Type ;
if ( ctn . IsClass ) return PascalABCCompiler . Parsers . SymbolKind . Class ;
if ( ctn . IsEnum ) return PascalABCCompiler . Parsers . SymbolKind . Enum ;
if ( ctn . IsValueType ) return PascalABCCompiler . Parsers . SymbolKind . Struct ;
if ( ctn . IsInterface ) return PascalABCCompiler . Parsers . SymbolKind . Interface ;
return PascalABCCompiler . Parsers . SymbolKind . Type ;
}
}
public override bool IsFinal
{
get
{
return ctn . IsSealed ;
}
}
2017-11-19 20:30:00 +03:00
public override bool IsAbstract
{
get
{
return ctn . IsAbstract ;
}
}
2015-05-14 22:35:07 +03:00
public Type CompiledType
{
get
{
return ctn ;
}
}
2020-12-31 15:53:18 +03:00
protected override TypeScope simpleGetInstance ( List < TypeScope > gen_args )
{
return this . GetInstance ( gen_args ) ;
}
2018-05-13 15:02:48 +03:00
public override TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2015-05-14 22:35:07 +03:00
{
Type t = this . ctn ;
2016-05-29 15:39:14 +03:00
if ( ! ctn . IsGenericType )
return this ;
2015-05-14 22:35:07 +03:00
if ( ! ctn . IsGenericTypeDefinition )
2022-10-23 15:31:48 +03:00
{
2016-04-03 13:57:12 +03:00
t = PascalABCCompiler . NetHelper . NetHelper . FindType ( this . ctn . Namespace + "." + this . ctn . Name ) ;
2022-10-23 15:31:48 +03:00
if ( t = = null & & this . instances ! = null & & this . instances . Count > 0 & & ctn . DeclaringType ! = null & & this . ctn . DeclaringType . IsGenericTypeDefinition )
{
t = PascalABCCompiler . NetHelper . NetHelper . FindType ( this . ctn . Namespace + "." + this . ctn . DeclaringType . Name . Substring ( 0 , this . ctn . DeclaringType . Name . IndexOf ( '`' ) ) + "`" + this . instances . Count + "+" + ctn . Name ) ;
}
}
2016-04-03 13:57:12 +03:00
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 ;
}
2022-10-23 15:31:48 +03:00
2016-04-03 13:57:12 +03:00
}
2015-05-14 22:35:07 +03:00
else if ( gen_args . Count ! = ctn . GetGenericArguments ( ) . Length )
2016-04-03 13:57:12 +03:00
{
Type t2 = PascalABCCompiler . NetHelper . NetHelper . FindType ( this . ctn . Namespace + "." + this . ctn . Name . Substring ( 0 , this . ctn . Name . IndexOf ( '`' ) ) + "`" + gen_args . Count ) ;
2015-05-14 22:35:07 +03:00
if ( t2 ! = null )
t = t2 ;
}
2016-05-01 13:02:40 +03:00
CompiledScope sc = new CompiledScope ( new SymInfo ( si . name , si . kind , si . description ) , t ) ;
2015-05-14 22:35:07 +03:00
sc . generic_params = new List < string > ( ) ;
sc . instances = new List < TypeScope > ( ) ;
2015-12-19 22:48:12 +03:00
sc . original_type = this ;
2018-06-05 22:31:33 +03:00
if ( this . instances ! = null & & this . instances . Count > 0 )
2016-04-03 13:57:12 +03:00
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 > ( ) ;
2020-02-02 13:09:44 +03:00
TypeScope ts = gen_args [ Math . Min ( i , gen_args . Count - 1 ) ] ;
if ( ts . instances ! = null & & ts . instances . Count > 0 & & ! exact )
{
List < string > template_args = ts . original_type . generic_params ;
int ind = template_args . IndexOf ( this . instances [ i ] . name ) ;
if ( ind ! = - 1 )
{
sc . instances . Add ( ts . instances [ ind ] ) ;
sc . generic_params . Add ( ts . generic_params [ ind ] ) ;
continue ;
}
}
2016-04-03 13:57:12 +03:00
lst . Add ( gen_args [ Math . Min ( i , gen_args . Count - 1 ) ] ) ;
2016-04-10 12:02:05 +03:00
if ( lst [ 0 ] . instances ! = null & & lst [ 0 ] . instances . Count > 0 )
2018-03-07 23:12:31 +03:00
lst [ 0 ] = lst [ 0 ] . instances [ Math . Min ( i , lst [ 0 ] . instances . Count - 1 ) ] ;
2018-08-09 15:14:35 +03:00
if ( exact )
sc . instances . Add ( gen_args [ Math . Min ( i , gen_args . Count - 1 ) ] ) ;
else
sc . instances . Add ( this . instances [ i ] . GetInstance ( lst ) ) ;
2017-03-02 22:27:17 +03:00
if ( i < gen_args . Count )
sc . generic_params . Add ( gen_args [ i ] . si . name ) ;
2016-04-03 13:57:12 +03:00
}
else
2016-12-04 14:46:04 +03:00
{
2018-04-12 21:41:19 +03:00
if ( this . instances [ i ] . instances ! = null & & this . instances [ i ] . instances . Count > 0 & & i < gen_args . Count & & gen_args [ i ] . elementType ! = null )
2017-02-12 16:48:22 +03:00
{
List < TypeScope > lst = new List < TypeScope > ( ) ;
lst . Add ( gen_args [ i ] . elementType ) ;
sc . instances . Add ( this . instances [ i ] . GetInstance ( lst ) ) ;
2017-03-02 22:27:17 +03:00
if ( i < gen_args . Count )
sc . generic_params . Add ( gen_args [ i ] . elementType . si . name ) ;
2017-02-12 16:48:22 +03:00
}
else
{
2018-05-05 19:24:47 +03:00
if ( i < gen_args . Count & & gen_args [ i ] ! = null )
2017-03-02 22:27:17 +03:00
sc . generic_params . Add ( gen_args [ i ] . si . name ) ;
2018-06-05 22:31:33 +03:00
if ( this . instances [ i ] . original_type = = null & & ! ( this . instances [ i ] . elementType is TemplateParameterScope ) )
{
if ( exact )
2021-09-06 21:37:31 +03:00
sc . instances . Add ( gen_args [ Math . Min ( i , gen_args . Count - 1 ) ] ) ;
2018-06-05 22:31:33 +03:00
else
sc . instances . Add ( this . instances [ i ] ) ;
}
else
sc . instances . Add ( this . instances [ i ] . GetInstance ( gen_args ) ) ;
2017-02-12 16:48:22 +03:00
}
2017-08-18 22:23:13 +03:00
}
2016-04-03 13:57:12 +03:00
}
else
for ( int i = 0 ; i < gen_args . Count ; i + + )
{
2018-05-02 22:11:44 +03:00
if ( gen_args [ i ] = = null )
continue ;
2017-03-02 22:27:17 +03:00
if ( i < gen_args . Count )
sc . generic_params . Add ( gen_args [ i ] . si . name ) ;
2016-04-03 13:57:12 +03:00
sc . instances . Add ( gen_args [ i ] ) ;
}
2017-08-18 22:23:13 +03:00
sc . implemented_interfaces = new List < TypeScope > ( ) ;
if ( this . implemented_interfaces ! = null )
for ( int i = 0 ; i < this . implemented_interfaces . Count ; i + + )
sc . implemented_interfaces . Add ( this . implemented_interfaces [ i ] . GetInstance ( gen_args ) ) ;
2016-05-01 13:02:40 +03:00
sc . si . description = sc . GetDescription ( ) ;
2015-05-14 22:35:07 +03:00
return sc ;
}
private void get_default_property ( )
{
PropertyInfo [ ] pis = ctn . GetProperties ( ) ;
is_def_prop_searched = true ;
for ( int i = 0 ; i < pis . Length ; i + + )
{
ParameterInfo [ ] prms = pis [ i ] . GetIndexParameters ( ) ;
if ( prms . Length > 0 )
{
default_property = pis [ i ] ;
if ( generic_params ! = null & & default_property . PropertyType . IsGenericParameter )
{
elementType = instances [ default_property . PropertyType . GenericParameterPosition ] ;
}
else
2016-05-08 20:45:37 +03:00
elementType = TypeTable . get_compiled_type ( pis [ i ] . PropertyType ) ;
2015-05-14 22:35:07 +03:00
break ;
}
}
}
public override string GetFullName ( )
{
//return ctn.FullName;
return CodeCompletionController . CurrentParser . LanguageInformation . GetSimpleDescription ( this ) ;
}
public override List < ProcScope > GetOverridableMethods ( )
{
List < ProcScope > syms = new List < ProcScope > ( ) ;
MemberInfo [ ] mis = ctn . GetMembers ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance | BindingFlags . FlattenHierarchy ) ;
if ( ctn . IsInterface )
{
List < MemberInfo > mems = new List < MemberInfo > ( ) ;
mems . AddRange ( mis ) ;
Type [ ] tt = ctn . GetInterfaces ( ) ;
foreach ( Type t in tt )
mems . AddRange ( t . GetMembers ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance | BindingFlags . FlattenHierarchy ) ) ;
mis = mems . ToArray ( ) ;
}
foreach ( MemberInfo mi in mis )
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( mi . Name ) )
2015-05-14 22:35:07 +03:00
switch ( mi . MemberType )
{
case MemberTypes . Method : if ( ! ( mi as MethodInfo ) . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
CompiledMethodScope member = new CompiledMethodScope ( si2 , mi as MethodInfo , this ) ;
si2 = member . si ;
if ( ( mi as MethodInfo ) . IsVirtual & & ! ( mi as MethodInfo ) . IsFinal )
{
if ( si2 . acc_mod = = access_modifer . protected_modifer )
{
syms . Add ( member ) ;
}
else if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( member ) ;
}
}
break ;
}
return syms ;
}
public override List < ProcScope > GetAbstractMethods ( )
{
List < ProcScope > syms = new List < ProcScope > ( ) ;
MemberInfo [ ] mis = ctn . GetMembers ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance | BindingFlags . FlattenHierarchy ) ;
if ( ctn . IsInterface )
{
List < MemberInfo > mems = new List < MemberInfo > ( ) ;
mems . AddRange ( mis ) ;
Type [ ] tt = ctn . GetInterfaces ( ) ;
foreach ( Type t in tt )
mems . AddRange ( t . GetMembers ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance | BindingFlags . FlattenHierarchy ) ) ;
mis = mems . ToArray ( ) ;
}
foreach ( MemberInfo mi in mis )
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( mi . Name ) )
2015-05-14 22:35:07 +03:00
switch ( mi . MemberType )
{
case MemberTypes . Method : if ( ! ( mi as MethodInfo ) . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
CompiledMethodScope member = new CompiledMethodScope ( si2 , mi as MethodInfo , this ) ;
si2 = member . si ;
if ( ( mi as MethodInfo ) . IsAbstract | | ( ctn . IsInterface & & ( mi as MethodInfo ) . DeclaringType = = ctn ) )
{
if ( si2 . acc_mod = = access_modifer . protected_modifer )
{
syms . Add ( member ) ;
}
else if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( member ) ;
}
}
break ;
}
return syms ;
}
private void AddIndexers ( )
{
List < TypeScope > indexers = new List < TypeScope > ( ) ;
if ( ctn . IsArray )
{
/ * Type t = ctn . GetElementType ( ) ;
while ( t ! = null )
{
indexers . Add ( new CompiledScope ( new SymInfo ( t . Name , SymbolKind . Type , t . FullName ) , t ) ) ;
t = t . GetElementType ( ) ;
} * /
Type t = typeof ( int ) ;
2016-05-08 20:45:37 +03:00
indexers . Add ( TypeTable . get_compiled_type ( t ) ) ;
2015-05-14 22:35:07 +03:00
}
else
{
if ( ! is_def_prop_searched ) get_default_property ( ) ;
if ( default_property ! = null )
{
ParameterInfo [ ] pis = default_property . GetIndexParameters ( ) ;
for ( int i = 0 ; i < pis . Length ; i + + )
{
if ( generic_params ! = null & & pis [ i ] . ParameterType . IsGenericParameter )
{
indexers . Add ( instances [ pis [ i ] . ParameterType . GenericParameterPosition ] ) ;
}
else
2016-05-08 20:45:37 +03:00
indexers . Add ( TypeTable . get_compiled_type ( pis [ i ] . ParameterType ) ) ;
2015-05-14 22:35:07 +03:00
}
}
}
indices = indexers . ToArray ( ) ;
}
public override TypeScope [ ] GetIndexers ( )
{
if ( indices = = null ) AddIndexers ( ) ;
return indices ;
}
public override void ClearInstances ( )
{
if ( instances ! = null )
instances . Clear ( ) ;
}
2018-11-12 22:52:25 +03:00
public override bool IsConvertable ( TypeScope ts , bool strong = false )
2015-05-14 22:35:07 +03:00
{
CompiledScope cs = ts as CompiledScope ;
2017-08-10 18:30:51 +03:00
if ( ts = = null )
return true ;
2015-05-14 22:35:07 +03:00
if ( ts is NullTypeScope & & ! ctn . IsValueType )
return true ;
if ( cs = = null )
if ( ts is TypeSynonim )
2018-11-12 22:52:25 +03:00
return this . IsConvertable ( ( ts as TypeSynonim ) . actType , strong ) ;
2015-05-14 22:35:07 +03:00
else
if ( ts is ShortStringScope & & ctn = = typeof ( string ) )
2015-12-04 22:17:20 +03:00
return true ;
else
{
if ( ts is UnknownScope )
2015-05-14 22:35:07 +03:00
return true ;
2016-03-13 00:11:19 +03:00
else if ( ts is TemplateParameterScope )
return true ;
2015-12-04 22:17:20 +03:00
else if ( ts is ProcType )
2015-05-14 22:35:07 +03:00
{
2015-12-04 22:17:20 +03:00
ProcType pt = ts as ProcType ;
MethodInfo invoke_meth = this . ctn . GetMethod ( "Invoke" ) ;
if ( invoke_meth = = null )
2015-05-14 22:35:07 +03:00
{
2015-12-04 22:17:20 +03:00
if ( this . ctn = = typeof ( Delegate ) )
return true ;
return false ;
}
if ( pt . target . parameters = = null )
if ( invoke_meth . GetParameters ( ) . Length > 0 )
2015-05-14 22:35:07 +03:00
return false ;
2015-12-04 22:17:20 +03:00
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 + + )
{
2016-03-20 16:23:41 +03:00
CompiledScope param_cs = TypeTable . get_compiled_type ( null , parameters [ i ] . ParameterType ) ;
2018-11-12 22:52:25 +03:00
if ( ! ( pt . target . parameters [ i ] . sc is TypeScope ) | | ! param_cs . IsConvertable ( pt . target . parameters [ i ] . sc as TypeScope , strong ) )
2015-05-14 22:35:07 +03:00
return false ;
}
2017-06-04 18:48:35 +03:00
return CompiledScope . get_type_instance ( invoke_meth . ReturnType , new List < TypeScope > ( ) ) . IsConvertable ( pt . target . return_type ) ;
2015-05-14 22:35:07 +03:00
}
2015-12-04 22:17:20 +03:00
else
return false ;
}
2015-05-14 22:35:07 +03:00
if ( this . ctn = = cs . ctn )
return true ;
2018-07-16 22:39:58 +03:00
if ( cs . ctn . IsByRef & & this . ctn = = cs . ctn . GetElementType ( ) )
return true ;
2015-05-14 22:35:07 +03:00
if ( this . ctn . IsSubclassOf ( cs . ctn ) )
return true ;
2017-08-27 20:04:24 +03:00
if ( implemented_interfaces ! = null )
foreach ( TypeScope interf in implemented_interfaces )
if ( interf . IsEqual ( ts ) )
return true ;
2015-05-14 22:35:07 +03:00
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 ;
2019-03-10 16:28:47 +03:00
else if ( strong & & code1 = = TypeCode . Char & & code2 ! = TypeCode . Char & & code2 ! = TypeCode . String )
return false ;
2015-05-14 22:35:07 +03:00
else
return true ;
}
if ( cs . ctn . IsGenericParameter | | this . ctn . IsGenericParameter )
return true ;
2018-11-12 22:52:25 +03:00
if ( ! strong & & tc = = type_compare . greater_type & & this . ctn . IsPrimitive & & cs . ctn . IsPrimitive )
{
if ( code1 ! = TypeCode . Double & & code2 ! = TypeCode . Single )
return true ;
}
2015-05-14 22:35:07 +03:00
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 override bool IsEqual ( SymScope ts )
{
CompiledScope cs = ts as CompiledScope ;
if ( cs = = null )
if ( ts is TypeSynonim ) return this . IsEqual ( ( ts as TypeSynonim ) . actType ) ;
else return false ;
return this . ctn = = cs . ctn ;
}
2019-12-25 11:53:05 +03:00
public override void AddIndexer ( TypeScope ts , bool is_static )
2015-05-14 22:35:07 +03:00
{
}
public override string GetDescription ( )
{
Refactoring of Compiler.cs (#2984)
* Add first comments
* Finish commenting for Compile and CompileUnit
* Write TODO sections
* Add a few clarifications
* splitted some functions from compile
* Written some methods from Compile to functions
* Update variable names
* Refactor - stage 1
Refactor GetUsesSection and IsPossibleNameSpace
* Refactor - stage 2
Rename a few functions and variables
* Correct an inaccuracy
* Added comments, look through CompileUnit
* Rename a few functions and add new comments
* Split CompileUnit to Subfunctions
Add IsUnitCompiled, IsUnitInPCU, InitializeNewUnit, GetSourceCode, GenSyntaxTree, GenUnitDocumentation, CheckDLLDirectiveOnlyForLibraries, MatchErrorsToBadNodes, CheckIfUnitModule, SetUseDLLForSystemUnits,
CompileInterfaceDependencies, CompileCurrentUnitInterface, GetImplementationUsesSection, CompileImplementationDependencies, CompileCurrentUnitImplementation
* Added some TODOs
* Return uses_unit_in original name
Renaming of syntax tree nodes leads to internal compiler errors
* Extract GenerateILCode method
* Add checking if recompilation needed method
Needs to be discussed and revised
* Add functions for catch blocks in Compile
* Extract building semantic tree method
Creating main function to be moved to another class
* Rename UnitsSortedList
* Edit CompileUnitsFromDelayedList method
* Change a few variable names, make CreateRCFile function and add comments
* Make code more "user-friendly"
* Add TODOs 31.11.23
* Create PrebuildSemanticTreeActionsMethod
* Refactor semantic checks section in initialize new unit method
* Refactor Adding standard units to uses method
* Return file_name and compiler_directives original names to avoid internal compilation errors
* Refactor GetReferences Method
* Initial refactoring of IncludeNamespaces function
* Create three more methods and wrap important code in regions
* Add TODO's
* Resolve merge conflicts
* Add returned value to ConstructSyntaxTree method
* Fix UnitsSortedList NotFoundError in PCUWriter
* Workaround commit
* Update PABCSystem after tests' changes
* Rename syntax trees in some methods
* Delete CurrentSyntaxUnit variable
* Revert unnecessary project files changes
* Squashed commit of the following:
commit f4d7599f1a39252feac97bd5391f46dfdc25f6f4
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:29 2023 +0300
added links to identarranger
commit 3bd5d33e2b2969884e61a3279ff9c353013b57fe
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:03 2023 +0300
Change extension for verybasic to yavb
commit 61294c6e7d405e1c68516cc81d3a109e8a1ee295
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:33:57 2023 +0300
Change Program Example
commit 86971488341ed6bf13c39e13a513d7ac0c51c285
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:28:59 2023 +0300
Add IndentArranger to Compile
commit 2ce50bbbf9db22c4243b247b870f6935ce206d26
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 17 10:00:31 2023 +0300
Add Semicolon After Each Statement
commit 796309d340e8d8ba730ff9418fa376f34fb7fd36
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Wed Nov 15 18:49:11 2023 +0300
Add Alpha Version of Python-style If-statement
commit 5eb88f946fe8254b4f5c5a56ed0a567b3be51227
Merge: ab4ce5b0 0162b637
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:54:26 2023 +0300
Merge branch 'IndentArranger' into VeryBasicLanguage
commit ab4ce5b0e32d42004726e3dc45cc0d8a65e53f56
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:53:51 2023 +0300
Fixes from seminar
commit af74012289d0d08517c13499a2a66cb543fc06d2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 18:57:29 2023 +0300
finally working!
fully implemented compatibility
commit 58a39c313324b468d1eec207ba3f5f6eddf74ef2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 11:58:16 2023 +0300
more compatibility with pabc
Now verybasic statements translate to pascal compiler
added .bat script for autobuilding verybasic
commit 0162b6376b8fe970704f26213bf9f0f670dfb12e
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:06:14 2023 +0300
Update test.txt
commit 1b759ab1cd7ee2ffeb14afff0418ddf0f30b0399
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:05:36 2023 +0300
Add Indent and Unindent Keywords to Generated File
commit cabda7f3985651cff2a8740f1a5bdea8fe7ac892
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 10 21:25:52 2023 +0300
Add Generation of Output File
commit 306f033d0176ab559e3622b8505427dbe2e0e203
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:42:18 2023 +0300
Update IndentArranger.sln
commit 60c0ceced1aa3a7d2e33de0facb1126e295f43b5
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:41:22 2023 +0300
Add IndentArranger
commit 1f4556c4573dae154fcc167b41ff6ab9e8122136
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Mon Nov 6 22:48:36 2023 +0300
Made my own VeryBasicParser project
Copied some code from SaushkinParser
Tried to compile it and implement into Pascal
Doesn't work due to grammatik issue
* Squashed commit of the following:
commit 4e73d9ac3ffef68312f06a74dc83afffcf3ccbee
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 15:08:10 2023 +0300
Fixed GPPG (i think so at least)
commit e5cfc220828b37fb2f35e565683019716ec3f0ce
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:44:27 2023 +0300
Update Compiler.cs
commit 4698e2e75a5f3b4f523a8bc7733a50e8abb4fca1
Merge: 22aaf2b2 f4d7599f
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:54 2023 +0300
Merge branch 'IndentArrangerTemp' into VeryBasicLanguage
commit f4d7599f1a39252feac97bd5391f46dfdc25f6f4
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:29 2023 +0300
added links to identarranger
commit 3bd5d33e2b2969884e61a3279ff9c353013b57fe
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:43:03 2023 +0300
Change extension for verybasic to yavb
commit 22aaf2b2508278a9ffce525ffed52419bf72c23f
Merge: c326174f 61294c6e
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 22 11:26:36 2023 +0300
Merge branch 'IndentArrangerTemp' into VeryBasicLanguage
commit 61294c6e7d405e1c68516cc81d3a109e8a1ee295
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:33:57 2023 +0300
Change Program Example
commit 86971488341ed6bf13c39e13a513d7ac0c51c285
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Tue Nov 21 09:28:59 2023 +0300
Add IndentArranger to Compile
commit c326174ff5ecccf9c4f76d58aea4653f047af049
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 19 15:03:19 2023 +0300
Added UniversalParserHelper and GPPG
ShiftReduceParser moved to another project
UniversalParserHelper project added, most of it copied from SaushkinParser
commit 2ce50bbbf9db22c4243b247b870f6935ce206d26
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 17 10:00:31 2023 +0300
Add Semicolon After Each Statement
commit 796309d340e8d8ba730ff9418fa376f34fb7fd36
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Wed Nov 15 18:49:11 2023 +0300
Add Alpha Version of Python-style If-statement
commit 5eb88f946fe8254b4f5c5a56ed0a567b3be51227
Merge: ab4ce5b0 0162b637
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:54:26 2023 +0300
Merge branch 'IndentArranger' into VeryBasicLanguage
commit ab4ce5b0e32d42004726e3dc45cc0d8a65e53f56
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Wed Nov 15 16:53:51 2023 +0300
Fixes from seminar
commit af74012289d0d08517c13499a2a66cb543fc06d2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 18:57:29 2023 +0300
finally working!
fully implemented compatibility
commit 58a39c313324b468d1eec207ba3f5f6eddf74ef2
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Sun Nov 12 11:58:16 2023 +0300
more compatibility with pabc
Now verybasic statements translate to pascal compiler
added .bat script for autobuilding verybasic
commit 0162b6376b8fe970704f26213bf9f0f670dfb12e
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:06:14 2023 +0300
Update test.txt
commit 1b759ab1cd7ee2ffeb14afff0418ddf0f30b0399
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Sun Nov 12 10:05:36 2023 +0300
Add Indent and Unindent Keywords to Generated File
commit cabda7f3985651cff2a8740f1a5bdea8fe7ac892
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Fri Nov 10 21:25:52 2023 +0300
Add Generation of Output File
commit 306f033d0176ab559e3622b8505427dbe2e0e203
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:42:18 2023 +0300
Update IndentArranger.sln
commit 60c0ceced1aa3a7d2e33de0facb1126e295f43b5
Author: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Date: Thu Nov 9 20:41:22 2023 +0300
Add IndentArranger
commit 1f4556c4573dae154fcc167b41ff6ab9e8122136
Author: Владислав Крылов <krylov@sfedu.ru>
Date: Mon Nov 6 22:48:36 2023 +0300
Made my own VeryBasicParser project
Copied some code from SaushkinParser
Tried to compile it and implement into Pascal
Doesn't work due to grammatik issue
* Changed GPPG project NET Framework version, added .dll to gitignore
* Adding UniversalParserHelper to project, trying to include VeryBasic
* Managed dependencies and got VeryBasicLanguage to work
* Change extension of a test program
* Rebuild changes
What should be added to .gitignore?
* Fix bug related to err0524_res_unit.pas
* Rebuild Parser
* Change Indent and Unindent tokens
* Add Symbol Table to ParserABC.y
* Change Indent Space Number to 2
* Add While Loop
* Add Some Operations to Parser
* Make Initialization Node at the Beginning of a program
* Create Grammar.txt
* Test program added
* Add ELIF and SyntaxHighlight
* Fix TableSymbol
* Add Division
* Add Method Call
* Add For Loop
* Rename SPython Parser Folder
* Add documented comments for CompileUnit method
* Added Errors to SPython
Added Errors.cs
Removed link to PABCSaushkinParser
Minor fixes
* Create default constructor for SourceContext
* Move null check of currentUnit to upper level in CompileUnit
* Move CreateMainFunction method from Compiler to TreeConverter class
* Add gppg and parserhelper to visualpascalabcnet dependencies
* Updated installer files to include GPPG and UniversalParserHelper
* Rename GPPG to ShiftReduceParser
* Fix ShiftReduceParser project dependencies
* Fix ShiftReduceParserDependencies second iteration
* Workaround commit
* Update PABCSystem after tests' changes
* Refactor ConvertDirectives method
* Get rid of legacy standard modules code
* Return varBeginOffset and beginOffset calculation to Compiler class
Размещение метода в SyntaxTreeToSemanticTreeConverter не целесообразно. В комментарии видимо имелось в виду что-то другое.
* Workaround commit
* Update PABCSystem after tests' changes
* Revert SPython changes
Оставляем только изменения связанные с рефакторингом.
* Update .gitignore
Co-authored-by: Sun Serega <sunserega2@gmail.com>
* Resolve a few Sun Serega treds
* Delete comments in ParsersController.cs
* Replace specific path with path variable in Studio.bat
* Add comment in Studio.bat file and return FileName in CompilerError.cs
* Fix TreeSubsidiary.cs encoding and sectCore.nsh indents
* Return old version of TestRunner.exe
* Rename some variables and polish a few methods
* Uncomment accidentally commented code
* Replace spaces with tabs
* Changed dll name from GPPG
* Revert "Changed dll name from GPPG"
This reverts commit c485cc8cb787809b7e9dfa8a361e75f17ed39893.
* Update .gitignore
* Delete Libraries/ShiftReduceParser.dll
* Delete bin\ShiftReduceParser.dll
* Replace tabs with spaces
* Update encoding in Studio.bat
* Fix bug with PABCrtl excluded files
* Refactor StandardModule class
* Add null checks to make debuging easier
* Delete unnecessary null checks in SymTable.cs
---------
Co-authored-by: Владислав Крылов <krylov@sfedu.ru>
Co-authored-by: MovchanGitHub <92666028+MovchanGitHub@users.noreply.github.com>
Co-authored-by: Sun Serega <sunserega2@gmail.com>
2023-12-18 22:33:27 +03:00
return CodeCompletionController . CurrentParser ? . LanguageInformation . GetDescription ( this ) ;
2015-05-14 22:35:07 +03:00
}
public override SymInfo [ ] GetNames ( ExpressionVisitor ev , PascalABCCompiler . Parsers . KeywordKind keyword , bool called_in_base )
{
List < SymInfo > syms = new List < SymInfo > ( ) ;
if ( ! CodeCompletionController . CurrentParser . LanguageInformation . IncludeDotNetEntities )
return syms . ToArray ( ) ;
MemberInfo [ ] mis = ctn . GetMembers ( BindingFlags . Public | BindingFlags . NonPublic | /*BindingFlags.Instance|*/ BindingFlags . Static | BindingFlags . FlattenHierarchy ) ;
List < MemberInfo > constrs = new List < MemberInfo > ( ) ;
//constrs.AddRange(ctn.GetNestedTypes(BindingFlags.Public));
//if (ctn != typeof(object))
ConstructorInfo [ ] cis = ctn . GetConstructors ( BindingFlags . Instance | BindingFlags . Public | BindingFlags . NonPublic ) ;
foreach ( ConstructorInfo ci in cis )
if ( ! called_in_base )
constrs . Add ( ci ) ;
else if ( ci . GetParameters ( ) . Length > 0 )
constrs . Add ( ci ) ;
constrs . AddRange ( mis ) ;
2015-12-05 21:32:49 +03:00
//constrs.AddRange(PascalABCCompiler.NetHelper.NetHelper.GetExtensionMethods(ctn));
2015-05-14 22:35:07 +03:00
mis = constrs . ToArray ( ) ;
if ( ctn . IsInterface )
{
return syms . ToArray ( ) ;
}
foreach ( MemberInfo mi in mis )
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( mi . Name ) )
2015-05-14 22:35:07 +03:00
switch ( mi . MemberType )
{
case MemberTypes . Method : if ( ! ( mi as MethodInfo ) . IsSpecialName & & ( mi as MethodInfo ) . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
CompiledMethodScope member = new CompiledMethodScope ( si2 , mi as MethodInfo , this ) ;
si2 = member . si ;
if ( si2 . acc_mod = = access_modifer . protected_modifer )
{
if ( ev . CheckForBaseAccess ( ev . entry_scope , this ) )
syms . Add ( si2 ) ;
}
else if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
break ;
case MemberTypes . Field :
{
if ( ! ( mi as FieldInfo ) . IsSpecialName & & ( mi as FieldInfo ) . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Field , null ) ;
if ( ( mi as FieldInfo ) . IsLiteral ) si2 . kind = SymbolKind . Constant ;
si2 = new CompiledFieldScope ( si2 , mi as FieldInfo , this ) . si ;
if ( si2 . acc_mod = = access_modifer . protected_modifer )
{
if ( ev . CheckForBaseAccess ( ev . entry_scope , this ) )
syms . Add ( si2 ) ;
}
else if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
}
break ;
case MemberTypes . Constructor :
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
CompiledConstructorScope member = new CompiledConstructorScope ( si2 , mi as ConstructorInfo , this ) ;
si2 = member . si ;
if ( si2 . acc_mod = = access_modifer . protected_modifer )
{
if ( ev . CheckForBaseAccess ( ev . entry_scope , this ) )
syms . Add ( si2 ) ;
}
else if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
break ;
case MemberTypes . Property :
{
PropertyInfo pi = mi as PropertyInfo ;
if ( pi . GetGetMethod ( true ) ! = null & & pi . GetGetMethod ( true ) . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Property , null ) ;
si2 = new CompiledPropertyScope ( si2 , mi as PropertyInfo , this ) . si ;
if ( si2 . acc_mod = = access_modifer . protected_modifer )
{
if ( ev . CheckForBaseAccess ( ev . entry_scope , this ) )
syms . Add ( si2 ) ;
}
else if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
}
break ;
case MemberTypes . Event :
{
MethodInfo acc_mi = ( mi as EventInfo ) . GetAddMethod ( true ) ;
if ( acc_mi ! = null & & acc_mi . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Event , null ) ;
si2 = new CompiledEventScope ( si2 , mi as EventInfo , this ) . si ;
syms . Add ( si2 ) ;
if ( si2 . acc_mod = = access_modifer . protected_modifer )
{
if ( ev . CheckForBaseAccess ( ev . entry_scope , this ) )
syms . Add ( si2 ) ;
}
else if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
}
break ;
case MemberTypes . NestedType :
{
if ( ( mi as Type ) . IsNestedPublic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Type , null ) ;
CompiledScope member = TypeTable . get_compiled_type ( si2 , mi as Type ) ;
si2 = member . si ;
syms . Add ( si2 ) ;
}
}
break ;
}
return syms . ToArray ( ) ;
}
public override ProcScope GetConstructor ( )
{
ConstructorInfo [ ] constrs = ctn . GetConstructors ( ) ;
ProcScope ps = null ;
ProcScope tmp = null ;
if ( constrs . Length > 0 )
{
ps = new CompiledConstructorScope ( new SymInfo ( "constructor" , SymbolKind . Method , "constructor" ) , constrs [ 0 ] , this ) ;
tmp = ps ;
}
for ( int i = 1 ; i < constrs . Length ; i + + )
{
tmp . nextProc = new CompiledConstructorScope ( new SymInfo ( "constructor" , SymbolKind . Method , "constructor" ) , constrs [ i ] , this ) ;
tmp = tmp . nextProc ;
}
return ps ;
}
public override List < ProcScope > GetConstructors ( bool search_in_base )
{
ConstructorInfo [ ] constrs = ctn . GetConstructors ( ) ;
ProcScope ps = null ;
ProcScope tmp = null ;
List < ProcScope > names = new List < ProcScope > ( ) ;
if ( constrs . Length > 0 )
{
ps = new CompiledConstructorScope ( new SymInfo ( "constructor" , SymbolKind . Method , "constructor" ) , constrs [ 0 ] , this ) ;
names . Add ( ps ) ;
tmp = ps ;
}
for ( int i = 1 ; i < constrs . Length ; i + + )
{
tmp . nextProc = new CompiledConstructorScope ( new SymInfo ( "constructor" , SymbolKind . Method , "constructor" ) , constrs [ i ] , this ) ;
names . Add ( tmp . nextProc ) ;
tmp = tmp . nextProc ;
}
return names ;
}
public SymInfo [ ] GetStaticNames ( )
{
List < SymInfo > syms = new List < SymInfo > ( ) ;
if ( ! CodeCompletionController . CurrentParser . LanguageInformation . IncludeDotNetEntities )
return syms . ToArray ( ) ;
MemberInfo [ ] mis = ctn . GetMembers ( BindingFlags . Public | BindingFlags . NonPublic | /*BindingFlags.Instance|*/ BindingFlags . Static | BindingFlags . FlattenHierarchy ) ;
if ( ctn . IsInterface )
{
return syms . ToArray ( ) ;
}
foreach ( MemberInfo mi in mis )
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( mi . Name ) )
2015-05-14 22:35:07 +03:00
switch ( mi . MemberType )
{
case MemberTypes . Method : if ( ! ( mi as MethodInfo ) . IsSpecialName & & ( mi as MethodInfo ) . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
CompiledMethodScope member = new CompiledMethodScope ( si2 , mi as MethodInfo , this ) ;
si2 = member . si ;
if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
break ;
case MemberTypes . Field :
{
if ( ! ( mi as FieldInfo ) . IsSpecialName & & ( mi as FieldInfo ) . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Field , null ) ;
if ( ( mi as FieldInfo ) . IsLiteral ) si2 . kind = SymbolKind . Constant ;
si2 = new CompiledFieldScope ( si2 , mi as FieldInfo , this ) . si ;
if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
}
break ;
case MemberTypes . Constructor :
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
CompiledConstructorScope member = new CompiledConstructorScope ( si2 , mi as ConstructorInfo , this ) ;
si2 = member . si ;
if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
break ;
case MemberTypes . Property :
{
PropertyInfo pi = mi as PropertyInfo ;
if ( pi . GetGetMethod ( true ) ! = null & & pi . GetGetMethod ( true ) . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Property , null ) ;
si2 = new CompiledPropertyScope ( si2 , mi as PropertyInfo , this ) . si ;
if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
}
break ;
case MemberTypes . Event :
{
MethodInfo acc_mi = ( mi as EventInfo ) . GetAddMethod ( true ) ;
if ( acc_mi ! = null & & acc_mi . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Event , null ) ;
si2 = new CompiledEventScope ( si2 , mi as EventInfo , this ) . si ;
syms . Add ( si2 ) ;
if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
}
break ;
case MemberTypes . NestedType :
{
if ( ( mi as Type ) . IsNestedPublic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Type , null ) ;
CompiledScope member = TypeTable . get_compiled_type ( si2 , mi as Type ) ;
si2 = member . si ;
syms . Add ( si2 ) ;
}
}
break ;
}
return syms . ToArray ( ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
List < SymInfo > syms = new List < SymInfo > ( ) ;
if ( ! CodeCompletionController . CurrentParser . LanguageInformation . IncludeDotNetEntities )
return syms . ToArray ( ) ;
MemberInfo [ ] mis = ctn . GetMembers ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance | BindingFlags . FlattenHierarchy ) ;
List < MemberInfo > members = new List < MemberInfo > ( ) ;
members . AddRange ( mis ) ;
IEnumerable < MemberInfo > en = PascalABCCompiler . NetHelper . NetHelper . GetExtensionMethods ( ctn ) ;
members . AddRange ( en ) ;
mis = members . ToArray ( ) ;
if ( ctn . IsInterface )
{
List < MemberInfo > mems = new List < MemberInfo > ( ) ;
mems . AddRange ( mis ) ;
mems . AddRange ( typeof ( object ) . GetMembers ( BindingFlags . Public | BindingFlags . Instance ) ) ;
Type [ ] types = ctn . GetInterfaces ( ) ;
foreach ( Type t in types )
mems . AddRange ( t . GetMembers ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance | BindingFlags . FlattenHierarchy ) ) ;
mis = mems . ToArray ( ) ;
}
foreach ( MemberInfo mi in mis )
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( mi . Name ) )
2015-05-14 22:35:07 +03:00
switch ( mi . MemberType )
{
case MemberTypes . Method : if ( ! ( mi as MethodInfo ) . IsSpecialName )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
si2 = new CompiledMethodScope ( si2 , mi as MethodInfo , this ) . si ;
if ( si2 . acc_mod = = access_modifer . protected_modifer )
{
if ( ev . CheckForBaseAccess ( ev . entry_scope , this ) )
syms . Add ( si2 ) ;
}
else if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
break ;
case MemberTypes . Field :
{
if ( ! ( mi as FieldInfo ) . IsSpecialName )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Field , null ) ;
if ( ( mi as FieldInfo ) . IsLiteral ) si2 . kind = SymbolKind . Constant ;
si2 = new CompiledFieldScope ( si2 , mi as FieldInfo , this ) . si ;
if ( si2 . acc_mod = = access_modifer . protected_modifer )
{
if ( ev . CheckForBaseAccess ( ev . entry_scope , this ) )
syms . Add ( si2 ) ;
}
else if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
}
break ;
case MemberTypes . Property :
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Property , null ) ;
si2 = new CompiledPropertyScope ( si2 , mi as PropertyInfo , this ) . si ;
if ( si2 . acc_mod = = access_modifer . protected_modifer )
{
if ( ev . CheckForBaseAccess ( ev . entry_scope , this ) )
syms . Add ( si2 ) ;
}
else if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
break ;
case MemberTypes . Event :
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Event , null ) ;
si2 = new CompiledEventScope ( si2 , mi as EventInfo , this ) . si ;
if ( si2 . acc_mod = = access_modifer . protected_modifer )
{
if ( ev . CheckForBaseAccess ( ev . entry_scope , this ) )
syms . Add ( si2 ) ;
}
else if ( si2 . acc_mod ! = access_modifer . private_modifer & & si2 . acc_mod ! = access_modifer . internal_modifer )
syms . Add ( si2 ) ;
}
break ;
}
if ( implemented_interfaces ! = null & & false )
{
foreach ( TypeScope ts in implemented_interfaces )
syms . AddRange ( ts . GetNamesAsInObject ( ev ) ) ;
}
return syms . ToArray ( ) ;
}
public override SymInfo [ ] GetNamesAsInBaseClass ( ExpressionVisitor ev , bool is_static )
{
List < SymInfo > syms = new List < SymInfo > ( ) ;
if ( ! CodeCompletionController . CurrentParser . LanguageInformation . IncludeDotNetEntities )
return syms . ToArray ( ) ;
MemberInfo [ ] mis = ctn . GetMembers ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance | BindingFlags . Static | BindingFlags . FlattenHierarchy ) ;
if ( ctn . IsInterface )
{
List < MemberInfo > mems = new List < MemberInfo > ( ) ;
mems . AddRange ( mis ) ;
mems . AddRange ( typeof ( object ) . GetMembers ( ) ) ;
Type [ ] types = ctn . GetInterfaces ( ) ;
foreach ( Type t in types )
mems . AddRange ( t . GetMembers ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance | BindingFlags . FlattenHierarchy ) ) ;
mis = mems . ToArray ( ) ;
}
if ( ! is_static )
{
foreach ( MemberInfo mi in mis )
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( mi . Name ) )
2015-05-14 22:35:07 +03:00
{
switch ( mi . MemberType )
{
case MemberTypes . Method : if ( ! ( mi as MethodInfo ) . IsSpecialName & & ( ( mi as MethodInfo ) . IsPublic | | ( mi as MethodInfo ) . IsFamily ) )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
si2 = new CompiledMethodScope ( si2 , mi as MethodInfo , this ) . si ;
syms . Add ( si2 ) ;
}
break ;
case MemberTypes . Field :
{
if ( ! ( mi as FieldInfo ) . IsSpecialName & & ( ( mi as FieldInfo ) . IsPublic | | ( mi as FieldInfo ) . IsFamily ) )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Field , null ) ;
if ( ( mi as FieldInfo ) . IsLiteral ) si2 . kind = SymbolKind . Constant ;
si2 = new CompiledFieldScope ( si2 , mi as FieldInfo , this ) . si ;
syms . Add ( si2 ) ;
}
//syms.Add(new SymInfo(mi.Name,SymbolKind.Field,mi.Name)); break;
}
break ;
case MemberTypes . Property :
{
PropertyInfo pi = mi as PropertyInfo ;
MethodInfo acc_mi = pi . GetGetMethod ( true ) ;
if ( acc_mi ! = null & & ( acc_mi . IsPublic | | acc_mi . IsFamily ) )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Property , null ) ;
si2 = new CompiledPropertyScope ( si2 , mi as PropertyInfo , this ) . si ;
syms . Add ( si2 ) ;
}
//syms.Add(new SymInfo(mi.Name,SymbolKind.Property,mi.Name));
}
break ;
case MemberTypes . Event :
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Event , null ) ;
si2 = new CompiledEventScope ( si2 , mi as EventInfo , this ) . si ;
syms . Add ( si2 ) ;
//syms.Add(new SymInfo(mi.Name,SymbolKind.Event,mi.Name));
}
break ;
2018-05-08 21:07:55 +03:00
case MemberTypes . Constructor :
if ( ( ( mi as ConstructorInfo ) . IsPublic | | ( mi as ConstructorInfo ) . IsFamily ) )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
si2 = new CompiledConstructorScope ( si2 , mi as ConstructorInfo , this ) . si ;
syms . Add ( si2 ) ;
}
break ;
2015-05-14 22:35:07 +03:00
}
}
}
else
foreach ( MemberInfo mi in mis )
switch ( mi . MemberType )
{
case MemberTypes . Method : if ( ! ( ( mi as MethodInfo ) . IsSpecialName ) & & ( mi as MethodInfo ) . IsStatic & & ( mi as MethodInfo ) . IsPublic | | ( mi as MethodInfo ) . IsFamily )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
si2 = new CompiledMethodScope ( si2 , mi as MethodInfo , this ) . si ;
syms . Add ( si2 ) ;
}
break ;
case MemberTypes . Field :
{
if ( ( mi as FieldInfo ) . IsStatic & & ! ( mi as FieldInfo ) . IsSpecialName & & ( mi as FieldInfo ) . IsPublic | | ( mi as FieldInfo ) . IsFamily )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Field , null ) ;
if ( ( mi as FieldInfo ) . IsLiteral ) si2 . kind = SymbolKind . Constant ;
si2 = new CompiledFieldScope ( si2 , mi as FieldInfo , this ) . si ;
syms . Add ( si2 ) ;
}
//syms.Add(new SymInfo(mi.Name,SymbolKind.Field,mi.Name)); break;
}
break ;
case MemberTypes . Property :
{
PropertyInfo pi = mi as PropertyInfo ;
MethodInfo acc_mi = pi . GetGetMethod ( true ) ;
if ( acc_mi ! = null & & acc_mi . IsStatic & & ( acc_mi . IsFamily | | acc_mi . IsPublic ) )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Property , null ) ;
si2 = new CompiledPropertyScope ( si2 , mi as PropertyInfo , this ) . si ;
syms . Add ( si2 ) ;
}
//syms.Add(new SymInfo(mi.Name,SymbolKind.Property,mi.Name));
}
break ;
case MemberTypes . Event :
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Event , null ) ;
si2 = new CompiledEventScope ( si2 , mi as EventInfo , this ) . si ;
syms . Add ( si2 ) ;
//syms.Add(new SymInfo(mi.Name,SymbolKind.Event,mi.Name));
}
break ;
}
return syms . ToArray ( ) ;
}
public override SymInfo [ ] GetNames ( )
{
List < SymInfo > syms = new List < SymInfo > ( ) ;
if ( ! CodeCompletionController . CurrentParser . LanguageInformation . IncludeDotNetEntities )
return syms . ToArray ( ) ;
MemberInfo [ ] mis = ctn . GetMembers ( BindingFlags . Public | BindingFlags . Instance | BindingFlags . Static | BindingFlags . FlattenHierarchy ) ;
if ( ctn . IsInterface )
{
List < MemberInfo > mems = new List < MemberInfo > ( ) ;
mems . AddRange ( mis ) ;
mems . AddRange ( typeof ( object ) . GetMembers ( ) ) ;
Type [ ] types = ctn . GetInterfaces ( ) ;
foreach ( Type t in types )
mems . AddRange ( t . GetMembers ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance | BindingFlags . FlattenHierarchy ) ) ;
mis = mems . ToArray ( ) ;
}
if ( si . kind ! = SymbolKind . Type )
{
foreach ( MemberInfo mi in mis )
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( mi . Name ) )
2015-05-14 22:35:07 +03:00
switch ( mi . MemberType )
{
case MemberTypes . Method : if ( ! ( mi as MethodInfo ) . IsSpecialName )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
si2 = new CompiledMethodScope ( si2 , mi as MethodInfo , this ) . si ;
syms . Add ( si2 ) ;
}
break ;
case MemberTypes . Field :
{
if ( ! ( mi as FieldInfo ) . IsSpecialName )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Field , null ) ;
if ( ( mi as FieldInfo ) . IsLiteral ) si2 . kind = SymbolKind . Constant ;
si2 = new CompiledFieldScope ( si2 , mi as FieldInfo , this ) . si ;
syms . Add ( si2 ) ;
}
//syms.Add(new SymInfo(mi.Name,SymbolKind.Field,mi.Name)); break;
}
break ;
case MemberTypes . Property :
{
PropertyInfo pi = mi as PropertyInfo ;
MethodInfo acc_mi = pi . GetGetMethod ( true ) ;
if ( acc_mi ! = null & & ! acc_mi . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Property , null ) ;
si2 = new CompiledPropertyScope ( si2 , mi as PropertyInfo , this ) . si ;
syms . Add ( si2 ) ;
}
//syms.Add(new SymInfo(mi.Name,SymbolKind.Property,mi.Name));
}
break ;
case MemberTypes . Event :
{
MethodInfo acc_mi = ( mi as EventInfo ) . GetAddMethod ( true ) ;
if ( acc_mi . IsPublic & & ! acc_mi . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Event , null ) ;
si2 = new CompiledEventScope ( si2 , mi as EventInfo , this ) . si ;
syms . Add ( si2 ) ;
}
//syms.Add(new SymInfo(mi.Name,SymbolKind.Event,mi.Name));
}
break ;
}
}
else
foreach ( MemberInfo mi in mis )
switch ( mi . MemberType )
{
case MemberTypes . Method : if ( ! ( ( mi as MethodInfo ) . IsSpecialName ) & & ( mi as MethodInfo ) . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
si2 = new CompiledMethodScope ( si2 , mi as MethodInfo , this ) . si ;
syms . Add ( si2 ) ;
}
break ;
case MemberTypes . Field :
{
if ( ( mi as FieldInfo ) . IsStatic & & ! ( mi as FieldInfo ) . IsSpecialName )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Field , null ) ;
if ( ( mi as FieldInfo ) . IsLiteral ) si2 . kind = SymbolKind . Constant ;
si2 = new CompiledFieldScope ( si2 , mi as FieldInfo , this ) . si ;
syms . Add ( si2 ) ;
}
}
break ;
case MemberTypes . Property :
{
PropertyInfo pi = mi as PropertyInfo ;
MethodInfo acc_mi = pi . GetGetMethod ( true ) ;
if ( acc_mi ! = null & & acc_mi . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Property , null ) ;
si2 = new CompiledPropertyScope ( si2 , mi as PropertyInfo , this ) . si ;
syms . Add ( si2 ) ;
}
}
break ;
case MemberTypes . Event :
{
MethodInfo acc_mi = ( mi as EventInfo ) . GetAddMethod ( true ) ;
if ( acc_mi . IsPublic & & acc_mi . IsStatic )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Event , null ) ;
si2 = new CompiledEventScope ( si2 , mi as EventInfo , this ) . si ;
syms . Add ( si2 ) ;
}
//syms.Add(new SymInfo(mi.Name,SymbolKind.Event,mi.Name));
}
break ;
}
return syms . ToArray ( ) ;
}
public override SymInfo [ ] GetNamesAsInObject ( )
{
List < SymInfo > syms = new List < SymInfo > ( ) ;
if ( ! CodeCompletionController . CurrentParser . LanguageInformation . IncludeDotNetEntities )
return syms . ToArray ( ) ;
MemberInfo [ ] mis = ctn . GetMembers ( BindingFlags . Public | BindingFlags . Instance ) ;
foreach ( MemberInfo mi in mis )
2018-11-01 00:19:05 +03:00
if ( ! IsHiddenName ( mi . Name ) )
2015-05-14 22:35:07 +03:00
switch ( mi . MemberType )
{
case MemberTypes . Method : if ( ! ( mi as MethodInfo ) . IsSpecialName )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Method , null ) ;
si2 = new CompiledMethodScope ( si2 , mi as MethodInfo , this ) . si ;
syms . Add ( si2 ) ;
}
break ;
case MemberTypes . Field :
{
if ( ! ( mi as FieldInfo ) . IsSpecialName )
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Field , null ) ;
if ( ( mi as FieldInfo ) . IsLiteral ) si2 . kind = SymbolKind . Constant ;
si2 = new CompiledFieldScope ( si2 , mi as FieldInfo , this ) . si ;
syms . Add ( si2 ) ;
}
//syms.Add(new SymInfo(mi.Name,SymbolKind.Field,mi.Name)); break;
}
break ;
case MemberTypes . Property :
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Property , null ) ;
si2 = new CompiledPropertyScope ( si2 , mi as PropertyInfo , this ) . si ;
syms . Add ( si2 ) ;
//syms.Add(new SymInfo(mi.Name,SymbolKind.Property,mi.Name));
}
break ;
case MemberTypes . Event :
{
SymInfo si2 = new SymInfo ( null , SymbolKind . Event , null ) ;
si2 = new CompiledEventScope ( si2 , mi as EventInfo , this ) . si ;
syms . Add ( si2 ) ;
//syms.Add(new SymInfo(mi.Name,SymbolKind.Event,mi.Name));
}
break ;
}
return syms . ToArray ( ) ;
}
public override SymScope FindNameOnlyInType ( string name )
{
return FindName ( name ) ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return FindOverloadNames ( name ) ;
}
public override SymScope FindNameOnlyInThisType ( string name )
{
return FindName ( name ) ;
}
2017-10-08 13:47:36 +03:00
private bool HasEnumerable ( )
{
if ( ctn = = typeof ( IEnumerable < > ) )
return true ;
if ( ctn . IsGenericType & & ctn . GetGenericTypeDefinition ( ) = = typeof ( IEnumerable < > ) )
return true ;
if ( implemented_interfaces ! = null )
foreach ( TypeScope t in implemented_interfaces )
if ( t is CompiledScope & & ( t as CompiledScope ) . HasEnumerable ( ) )
return true ;
return false ;
}
2015-05-14 22:35:07 +03:00
public override TypeScope GetElementType ( )
{
2015-12-20 00:59:15 +03:00
if ( ! is_def_prop_searched )
get_default_property ( ) ;
2017-11-07 23:34:10 +03:00
if ( elementType ! = null )
return elementType ;
2017-11-05 18:57:17 +03:00
if ( HasEnumerable ( ) )
2015-12-20 00:59:15 +03:00
{
2017-11-05 18:57:17 +03:00
if ( instances . Count > 0 )
return instances [ 0 ] ;
else if ( ctn . GetGenericArguments ( ) . Length > 0 )
return CompiledScope . get_type_instance ( ctn . GetGenericArguments ( ) [ 0 ] , new List < TypeScope > ( ) ) ;
2017-11-05 19:57:51 +03:00
return elementType ;
2015-12-20 00:59:15 +03:00
}
2015-05-14 22:35:07 +03:00
return elementType ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
List < SymScope > names = new List < SymScope > ( ) ;
2018-04-14 18:18:42 +03:00
List < PascalABCCompiler . TreeConverter . SymbolInfo > sil = PascalABCCompiler . NetHelper . NetHelper . FindNameIncludeProtected ( ctn , name ) ;
2015-05-14 22:35:07 +03:00
//IEnumerable<MemberInfo> ext_meths = PascalABCCompiler.NetHelper.NetHelper.GetExtensionMethods(ctn);
List < ProcScope > pascal_ext_meths = this . GetExtensionMethods ( name , this ) ;
2019-12-27 13:51:57 +03:00
if ( sil ! = null & & sil . Count > 1 & & sil . FirstOrDefault ( ) . sym_info . semantic_node_type = = semantic_node_type . basic_property_node )
{
sil . Add ( sil . FirstOrDefault ( ) ) ;
sil . RemoveAt ( 0 ) ;
}
2017-10-23 11:21:15 +03:00
if ( sil = = null & & names . Count = = 0 )
2015-05-14 22:35:07 +03:00
{
if ( string . Compare ( name , "Create" , true ) = = 0 & & this . ctn ! = typeof ( object ) )
2017-10-23 11:21:15 +03:00
sil = PascalABCCompiler . NetHelper . NetHelper . GetConstructor ( ctn ) ;
if ( sil = = null )
2015-05-14 22:35:07 +03:00
{
if ( pascal_ext_meths . Count > 0 )
{
foreach ( SymScope ss in pascal_ext_meths )
names . Add ( ss ) ;
return names ;
}
if ( members ! = null )
{
return base . FindOverloadNames ( name ) ;
}
else
return names ;
}
}
2021-08-11 13:02:20 +03:00
if ( sil . Count > 1 & & sil [ 0 ] . sym_info . semantic_node_type ! = semantic_node_type . compiled_function_node & & sil [ 0 ] . sym_info . semantic_node_type ! = semantic_node_type . compiled_constructor_node )
{
var si = sil [ 0 ] ;
sil . Remove ( sil [ 0 ] ) ;
sil . Add ( si ) ;
}
2018-04-14 18:18:42 +03:00
switch ( sil . FirstOrDefault ( ) . sym_info . semantic_node_type )
2015-05-14 22:35:07 +03:00
{
case semantic_node_type . compiled_function_node :
{
2018-04-14 18:18:42 +03:00
CompiledMethodScope cms = new CompiledMethodScope ( new SymInfo ( name , SymbolKind . Method , name ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_function_node ) . method_info , this ) ;
2015-05-14 22:35:07 +03:00
names . Insert ( 0 , cms ) ;
2017-10-23 11:21:15 +03:00
sil . RemoveAt ( 0 ) ;
if ( sil . Count ( ) = = 0 )
sil = null ;
2015-05-14 22:35:07 +03:00
CompiledMethodScope tmp = cms ;
SortedDictionary < int , List < CompiledMethodScope > > meths = new SortedDictionary < int , List < CompiledMethodScope > > ( ) ;
if ( cms . acc_mod ! = access_modifer . internal_modifer & & cms . acc_mod ! = access_modifer . private_modifer )
{
int par_num = cms . mi . GetParameters ( ) . Length ;
meths [ par_num ] = new List < CompiledMethodScope > ( ) ;
meths [ par_num ] . Add ( cms ) ;
}
2017-10-23 11:21:15 +03:00
if ( sil ! = null ) {
2018-04-14 18:18:42 +03:00
foreach ( var si in sil )
2015-05-14 22:35:07 +03:00
{
2017-10-23 11:21:15 +03:00
if ( si . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & si . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private & & si . sym_info . semantic_node_type = = semantic_node_type . compiled_function_node )
2017-05-20 21:20:02 +03:00
{
2017-10-23 11:21:15 +03:00
tmp = new CompiledMethodScope ( new SymInfo ( name , SymbolKind . Method , name ) , ( si . sym_info as compiled_function_node ) . method_info , this ) ;
2017-05-20 21:20:02 +03:00
names . Insert ( 0 , tmp ) ;
//tmp.nextProc = cms;
//cms = tmp;
int par_num = tmp . mi . GetParameters ( ) . Length ;
if ( ! meths . ContainsKey ( par_num ) ) meths [ par_num ] = new List < CompiledMethodScope > ( ) ;
meths [ par_num ] . Add ( tmp ) ;
}
2015-05-14 22:35:07 +03:00
}
}
bool beg = false ;
tmp = null ;
cms = null ;
foreach ( List < CompiledMethodScope > lst in meths . Values )
{
foreach ( CompiledMethodScope m in lst )
{
if ( beg = = false )
{
tmp = m ;
cms = tmp ;
beg = true ;
}
else
{
tmp . nextProc = m ;
tmp = tmp . nextProc as CompiledMethodScope ;
}
}
}
}
break ;
case semantic_node_type . compiled_constructor_node :
{
2018-04-14 18:18:42 +03:00
CompiledConstructorScope cms = new CompiledConstructorScope ( new SymInfo ( "Create" , SymbolKind . Method , "Create" ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_constructor_node ) . constructor_info , this ) ;
2015-05-14 22:35:07 +03:00
names . Insert ( 0 , cms ) ;
2017-10-23 11:21:15 +03:00
sil . RemoveAt ( 0 ) ;
if ( sil . Count ( ) = = 0 )
sil = null ;
2015-05-14 22:35:07 +03:00
CompiledConstructorScope tmp = cms ;
SortedDictionary < int , List < CompiledConstructorScope > > meths = new SortedDictionary < int , List < CompiledConstructorScope > > ( ) ;
if ( cms . acc_mod ! = access_modifer . internal_modifer & & cms . acc_mod ! = access_modifer . private_modifer )
{
int par_num = cms . mi . GetParameters ( ) . Length ;
meths [ par_num ] = new List < CompiledConstructorScope > ( ) ;
meths [ par_num ] . Add ( cms ) ;
}
2017-10-23 11:21:15 +03:00
if ( sil ! = null )
2015-05-14 22:35:07 +03:00
{
2018-04-14 18:18:42 +03:00
foreach ( var si in sil )
2015-05-14 22:35:07 +03:00
{
2017-10-23 11:21:15 +03:00
if ( si . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & si . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private & & si . sym_info . semantic_node_type = = semantic_node_type . compiled_constructor_node )
2017-05-20 21:20:02 +03:00
{
2017-10-23 11:21:15 +03:00
tmp = new CompiledConstructorScope ( new SymInfo ( "Create" , SymbolKind . Method , "Create" ) , ( si . sym_info as compiled_constructor_node ) . constructor_info , this ) ;
2017-05-20 21:20:02 +03:00
//tmp.nextProc = cms;
//cms = tmp;
names . Insert ( 0 , tmp ) ;
int par_num = tmp . mi . GetParameters ( ) . Length ;
if ( ! meths . ContainsKey ( par_num ) ) meths [ par_num ] = new List < CompiledConstructorScope > ( ) ;
meths [ par_num ] . Add ( tmp ) ;
}
2015-05-14 22:35:07 +03:00
}
}
bool beg = false ;
tmp = null ;
cms = null ;
foreach ( List < CompiledConstructorScope > lst in meths . Values )
{
foreach ( CompiledConstructorScope m in lst )
{
if ( beg = = false )
{
tmp = m ;
cms = tmp ;
beg = true ;
}
else
{
tmp . nextProc = m ;
tmp = tmp . nextProc as CompiledConstructorScope ;
}
}
}
}
break ;
case semantic_node_type . compiled_variable_definition :
2018-04-14 18:18:42 +03:00
if ( sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private )
names . Add ( new CompiledFieldScope ( new SymInfo ( name , SymbolKind . Field , name ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_variable_definition ) . compiled_field , this ) ) ;
2015-05-14 22:35:07 +03:00
break ;
case semantic_node_type . basic_property_node :
2018-04-14 18:18:42 +03:00
if ( sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private )
names . Add ( new CompiledPropertyScope ( new SymInfo ( name , SymbolKind . Property , name ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_property_node ) . property_info , this ) ) ;
2015-05-14 22:35:07 +03:00
break ;
case semantic_node_type . compiled_class_constant_definition :
2018-04-14 18:18:42 +03:00
if ( sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private )
names . Add ( new CompiledFieldScope ( new SymInfo ( name , SymbolKind . Constant , name ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_class_constant_definition ) . field , this ) ) ;
2015-05-14 22:35:07 +03:00
break ;
case semantic_node_type . compiled_event :
2018-04-14 18:18:42 +03:00
if ( sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private )
names . Add ( new CompiledEventScope ( new SymInfo ( name , SymbolKind . Constant , name ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_event ) . event_info , this ) ) ;
2015-05-14 22:35:07 +03:00
break ;
//case semantic_node_type.compiled_event: return new CompiledScope(null,(si.sym_info as compiled_event).event_info.);
//case semantic_node_type.compiled_event: return new CompiledScope(null,(si.sym_info as compiled_event).
}
2015-05-21 23:09:31 +03:00
2015-05-14 22:35:07 +03:00
return names ;
}
public override SymScope FindName ( string name )
{
2018-04-14 18:18:42 +03:00
List < PascalABCCompiler . TreeConverter . SymbolInfo > sil = PascalABCCompiler . NetHelper . NetHelper . FindNameIncludeProtected ( ctn , name ) ;
2015-05-14 22:35:07 +03:00
if ( ! CodeCompletionController . CurrentParser . LanguageInformation . IncludeDotNetEntities )
return null ;
2017-10-23 11:21:15 +03:00
if ( sil = = null )
2015-05-14 22:35:07 +03:00
{
if ( string . Compare ( name , "Create" , true ) = = 0 )
2017-10-23 11:21:15 +03:00
sil = PascalABCCompiler . NetHelper . NetHelper . GetConstructor ( ctn ) ;
if ( sil = = null )
2015-12-15 00:03:22 +03:00
{
2015-05-14 22:35:07 +03:00
return null ;
2015-12-15 00:03:22 +03:00
}
2015-05-14 22:35:07 +03:00
}
2018-04-14 18:18:42 +03:00
switch ( sil . FirstOrDefault ( ) . sym_info . semantic_node_type )
2015-05-14 22:35:07 +03:00
{
case semantic_node_type . compiled_function_node :
{
2018-04-14 18:18:42 +03:00
CompiledMethodScope cms = new CompiledMethodScope ( new SymInfo ( name , SymbolKind . Method , name ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_function_node ) . method_info , this ) ;
2017-10-23 11:21:15 +03:00
sil . RemoveAt ( 0 ) ;
if ( sil . Count ( ) = = 0 )
sil = null ;
2015-05-14 22:35:07 +03:00
CompiledMethodScope tmp = cms ;
SortedDictionary < int , List < CompiledMethodScope > > meths = new SortedDictionary < int , List < CompiledMethodScope > > ( ) ;
if ( cms . acc_mod ! = access_modifer . internal_modifer & & cms . acc_mod ! = access_modifer . private_modifer )
{
int par_num = cms . mi . GetParameters ( ) . Length ;
meths [ par_num ] = new List < CompiledMethodScope > ( ) ;
meths [ par_num ] . Add ( cms ) ;
}
2017-10-23 11:21:15 +03:00
if ( sil ! = null )
2015-05-14 22:35:07 +03:00
{
2018-04-14 18:18:42 +03:00
foreach ( var si in sil )
2015-05-14 22:35:07 +03:00
{
2017-10-23 11:21:15 +03:00
if ( si . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & si . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private & & si . sym_info . semantic_node_type = = semantic_node_type . compiled_function_node )
2017-05-20 21:20:02 +03:00
{
2017-10-23 11:21:15 +03:00
tmp = new CompiledMethodScope ( new SymInfo ( name , SymbolKind . Method , name ) , ( si . sym_info as compiled_function_node ) . method_info , this ) ;
2017-05-20 21:20:02 +03:00
//tmp.nextProc = cms;
//cms = tmp;
int par_num = tmp . mi . GetParameters ( ) . Length ;
if ( ! meths . ContainsKey ( par_num ) ) meths [ par_num ] = new List < CompiledMethodScope > ( ) ;
meths [ par_num ] . Add ( tmp ) ;
}
2017-10-23 11:21:15 +03:00
else if ( si . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & si . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private & & si . sym_info is compiled_property_node )
2017-05-20 21:20:02 +03:00
{
2017-10-23 11:21:15 +03:00
return new CompiledPropertyScope ( new SymInfo ( name , SymbolKind . Property , name ) , ( si . sym_info as compiled_property_node ) . property_info , this ) ;
2017-05-20 21:20:02 +03:00
}
2015-05-14 22:35:07 +03:00
}
}
bool beg = false ;
tmp = null ;
cms = null ;
foreach ( List < CompiledMethodScope > lst in meths . Values )
{
foreach ( CompiledMethodScope m in lst )
{
if ( beg = = false )
{
tmp = m ;
cms = tmp ;
beg = true ;
}
else
{
tmp . nextProc = m ;
tmp = tmp . nextProc as CompiledMethodScope ;
}
}
}
return cms ;
}
case semantic_node_type . compiled_constructor_node :
{
2018-04-14 18:18:42 +03:00
CompiledConstructorScope cms = new CompiledConstructorScope ( new SymInfo ( "Create" , SymbolKind . Method , "Create" ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_constructor_node ) . constructor_info , this ) ;
2017-10-23 11:21:15 +03:00
sil . RemoveAt ( 0 ) ;
if ( sil . Count ( ) = = 0 )
sil = null ;
2015-05-14 22:35:07 +03:00
CompiledConstructorScope tmp = cms ;
SortedDictionary < int , List < CompiledConstructorScope > > meths = new SortedDictionary < int , List < CompiledConstructorScope > > ( ) ;
if ( cms . acc_mod ! = access_modifer . internal_modifer & & cms . acc_mod ! = access_modifer . private_modifer )
{
int par_num = cms . mi . GetParameters ( ) . Length ;
meths [ par_num ] = new List < CompiledConstructorScope > ( ) ;
meths [ par_num ] . Add ( cms ) ;
}
2017-10-23 11:21:15 +03:00
if ( sil ! = null )
2015-05-14 22:35:07 +03:00
{
2018-04-14 18:18:42 +03:00
foreach ( var si in sil )
2015-05-14 22:35:07 +03:00
{
2017-10-23 11:21:15 +03:00
if ( si . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & si . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private & & si . sym_info . semantic_node_type = = semantic_node_type . compiled_constructor_node )
2017-05-20 21:20:02 +03:00
{
2017-10-23 11:21:15 +03:00
tmp = new CompiledConstructorScope ( new SymInfo ( "Create" , SymbolKind . Method , "Create" ) , ( si . sym_info as compiled_constructor_node ) . constructor_info , this ) ;
2017-05-20 21:20:02 +03:00
//tmp.nextProc = cms;
//cms = tmp;
int par_num = tmp . mi . GetParameters ( ) . Length ;
if ( ! meths . ContainsKey ( par_num ) ) meths [ par_num ] = new List < CompiledConstructorScope > ( ) ;
meths [ par_num ] . Add ( tmp ) ;
}
2015-05-14 22:35:07 +03:00
}
}
bool beg = false ;
tmp = null ;
cms = null ;
foreach ( List < CompiledConstructorScope > lst in meths . Values )
{
foreach ( CompiledConstructorScope m in lst )
{
if ( beg = = false )
{
tmp = m ;
cms = tmp ;
beg = true ;
}
else
{
tmp . nextProc = m ;
tmp = tmp . nextProc as CompiledConstructorScope ;
}
}
}
return cms ;
}
case semantic_node_type . compiled_variable_definition :
2018-04-14 18:18:42 +03:00
if ( sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private )
return new CompiledFieldScope ( new SymInfo ( name , SymbolKind . Field , name ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_variable_definition ) . compiled_field , this ) ;
2015-05-14 22:35:07 +03:00
break ;
case semantic_node_type . basic_property_node :
2018-04-14 18:18:42 +03:00
if ( sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private )
return new CompiledPropertyScope ( new SymInfo ( name , SymbolKind . Property , name ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_property_node ) . property_info , this ) ;
2015-05-14 22:35:07 +03:00
break ;
case semantic_node_type . compiled_class_constant_definition :
2018-04-14 18:18:42 +03:00
if ( sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private )
return new CompiledFieldScope ( new SymInfo ( name , SymbolKind . Constant , name ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_class_constant_definition ) . field , this ) ;
2015-05-14 22:35:07 +03:00
break ;
case semantic_node_type . compiled_event :
2018-04-14 18:18:42 +03:00
if ( sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private )
return new CompiledEventScope ( new SymInfo ( name , SymbolKind . Constant , name ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_event ) . event_info , this ) ;
2015-05-14 22:35:07 +03:00
break ;
case semantic_node_type . compiled_type_node :
2018-04-14 18:18:42 +03:00
if ( sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_internal & & sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_private & & sil . FirstOrDefault ( ) . access_level ! = PascalABCCompiler . TreeConverter . access_level . al_protected )
return TypeTable . get_compiled_type ( new SymInfo ( name , SymbolKind . Type , name ) , ( sil . FirstOrDefault ( ) . sym_info as compiled_type_node ) . compiled_type ) ;
2015-05-14 22:35:07 +03:00
break ;
//case semantic_node_type.compiled_event: return new CompiledScope(null,(si.sym_info as compiled_event).event_info.);
//case semantic_node_type.compiled_event: return new CompiledScope(null,(si.sym_info as compiled_event).
}
return null ;
}
public override string ToString ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetFullTypeName ( this ) ;
}
}
public class CompiledFieldScope : ElementScope , ICompiledFieldScope
{
public FieldInfo fi ;
public bool is_global ;
public List < string > generic_args ;
public CompiledFieldScope ( SymInfo si , FieldInfo fi , CompiledScope declaringType )
{
this . si = si ;
this . fi = fi ;
string [ ] args = declaringType . TemplateArguments ;
if ( args ! = null )
{
generic_args = new List < string > ( ) ;
generic_args . AddRange ( args ) ;
}
if ( generic_args ! = null )
{
//TypeScope ts = declaringType.instances[fi.FieldType.GenericParameterPosition];
this . sc = CompiledScope . get_type_instance ( fi . FieldType , declaringType . instances ) ;
}
else
2016-05-08 20:45:37 +03:00
this . sc = TypeTable . get_compiled_type ( fi . FieldType ) ;
2015-05-14 22:35:07 +03:00
if ( fi . IsLiteral )
this . cnst_val = fi . GetRawConstantValue ( ) ;
if ( si . name = = null )
AssemblyDocCache . AddDescribeToComplete ( this . si , fi ) ;
this . si . name = fi . Name ;
2016-05-01 13:02:40 +03:00
this . si . description = this . ToString ( ) ;
2015-05-14 22:35:07 +03:00
//this.si.describe += "\n"+AssemblyDocCache.GetDocumentation(fi.DeclaringType.Assembly,"F:"+fi.DeclaringType.FullName+"."+fi.Name);
this . topScope = declaringType ;
if ( fi . IsPrivate )
{
this . acc_mod = access_modifer . private_modifer ;
this . si . acc_mod = access_modifer . private_modifer ;
}
else if ( fi . IsFamily | | fi . IsFamilyOrAssembly )
{
this . acc_mod = access_modifer . protected_modifer ;
this . si . acc_mod = access_modifer . protected_modifer ;
}
else if ( fi . IsFamilyAndAssembly | | fi . IsAssembly )
{
this . acc_mod = access_modifer . internal_modifer ;
this . si . acc_mod = access_modifer . internal_modifer ;
}
}
public CompiledFieldScope ( SymInfo si , FieldInfo fi , CompiledScope declaringType , bool is_global )
{
this . si = si ;
this . fi = fi ;
string [ ] args = declaringType . TemplateArguments ;
if ( args ! = null )
{
generic_args = new List < string > ( ) ;
generic_args . AddRange ( args ) ;
}
if ( generic_args ! = null )
{
//TypeScope ts = declaringType.instances[fi.FieldType.GenericParameterPosition];
this . sc = CompiledScope . get_type_instance ( fi . FieldType , declaringType . instances ) ;
}
else
2016-05-08 20:45:37 +03:00
this . sc = TypeTable . get_compiled_type ( fi . FieldType ) ;
2015-05-14 22:35:07 +03:00
if ( fi . IsLiteral )
this . cnst_val = fi . GetRawConstantValue ( ) ;
if ( si . name = = null )
AssemblyDocCache . AddDescribeToComplete ( this . si , fi ) ;
this . si . name = fi . Name ;
this . is_global = is_global ;
2016-05-01 13:02:40 +03:00
this . si . description = this . ToString ( ) ;
2015-05-14 22:35:07 +03:00
//this.si.describe += "\n"+AssemblyDocCache.GetDocumentation(fi.DeclaringType.Assembly,"F:"+fi.DeclaringType.FullName+"."+fi.Name);
this . topScope = declaringType ;
if ( fi . IsPrivate )
{
this . acc_mod = access_modifer . private_modifer ;
this . si . acc_mod = access_modifer . private_modifer ;
}
else if ( fi . IsFamily | | fi . IsFamilyOrAssembly )
{
this . acc_mod = access_modifer . protected_modifer ;
this . si . acc_mod = access_modifer . protected_modifer ;
}
else if ( fi . IsFamilyAndAssembly | | fi . IsAssembly )
{
this . acc_mod = access_modifer . internal_modifer ;
this . si . acc_mod = access_modifer . internal_modifer ;
}
}
public override ScopeKind Kind
{
get
{
return ScopeKind . CompiledField ;
}
}
public bool IsGlobal
{
get
{
return is_global ;
}
}
public List < string > GenericArgs
{
get
{
return generic_args ;
}
}
public FieldInfo CompiledField
{
get
{
return fi ;
}
}
public override bool IsReadOnly
{
get { return fi . IsInitOnly ; }
}
public override bool IsEqual ( SymScope ts )
{
if ( ts is CompiledFieldScope & & ( ts as CompiledFieldScope ) . fi = = this . fi ) return true ;
return false ;
}
public override string ToString ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
public class CompiledEventScope : ElementScope , ICompiledEventScope
{
public EventInfo ei ;
public List < string > generic_args ;
public CompiledEventScope ( SymInfo si , EventInfo ei , CompiledScope declaringType )
{
this . si = si ;
this . ei = ei ;
string [ ] args = declaringType . TemplateArguments ;
if ( args ! = null )
{
generic_args = new List < string > ( ) ;
generic_args . AddRange ( args ) ;
}
if ( generic_args ! = null )
{
//TypeScope ts = declaringType.instances[ei.EventHandlerType.GenericParameterPosition];
this . sc = CompiledScope . get_type_instance ( ei . EventHandlerType , declaringType . instances ) ;
}
else
2016-05-08 20:45:37 +03:00
this . sc = TypeTable . get_compiled_type ( ei . EventHandlerType ) ;
2015-05-14 22:35:07 +03:00
if ( si . name = = null )
AssemblyDocCache . AddDescribeToComplete ( this . si , ei ) ;
this . si . name = ei . Name ;
2016-05-01 13:02:40 +03:00
this . si . description = this . ToString ( ) ;
2015-05-14 22:35:07 +03:00
this . topScope = declaringType ;
MethodInfo acc_mi = ei . GetAddMethod ( true ) ;
is_static = acc_mi . IsStatic ;
if ( acc_mi . IsPrivate )
{
this . acc_mod = access_modifer . private_modifer ;
this . si . acc_mod = access_modifer . private_modifer ;
}
else if ( acc_mi . IsFamily | | acc_mi . IsFamilyOrAssembly )
{
this . acc_mod = access_modifer . protected_modifer ;
this . si . acc_mod = access_modifer . protected_modifer ;
}
else if ( acc_mi . IsFamilyAndAssembly | | acc_mi . IsAssembly )
{
this . acc_mod = access_modifer . internal_modifer ;
this . si . acc_mod = access_modifer . internal_modifer ;
}
//this.si.describe += "\n"+AssemblyDocCache.GetDocumentation(ei.DeclaringType.Assembly,"E:"+ei.DeclaringType.FullName+"."+ei.Name);
}
public override ScopeKind Kind
{
get
{
return ScopeKind . CompiledEvent ;
}
}
public List < string > GenericArgs
{
get
{
return generic_args ;
}
}
public override bool IsStatic
{
get
{
return is_static ;
}
}
public EventInfo CompiledEvent
{
get
{
return ei ;
}
}
public override bool IsEqual ( SymScope ts )
{
if ( ts is CompiledEventScope & & ( ts as CompiledEventScope ) . ei = = this . ei ) return true ;
return false ;
}
public override string ToString ( )
{
//return "event "+ TypeUtility.GetShortTypeName(ei.DeclaringType) +"."+ ei.Name + ": "+sc.ToString();
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
public class CompiledPropertyScope : ElementScope , ICompiledPropertyScope
{
public PropertyInfo pi ;
public List < string > generic_args ;
public CompiledPropertyScope ( SymInfo si , PropertyInfo pi , CompiledScope declaringType )
{
this . si = si ;
this . pi = pi ;
string [ ] args = declaringType . TemplateArguments ;
if ( args ! = null )
{
generic_args = new List < string > ( ) ;
generic_args . AddRange ( args ) ;
}
2016-04-03 13:57:12 +03:00
if ( generic_args ! = null | | declaringType . instances ! = null )
2015-05-14 22:35:07 +03:00
{
//TypeScope ts = declaringType.instances[pi.PropertyType.GenericParameterPosition];
this . sc = CompiledScope . get_type_instance ( pi . PropertyType , declaringType . instances ) ;
}
else
2016-05-08 20:45:37 +03:00
this . sc = TypeTable . get_compiled_type ( pi . PropertyType ) ;
2015-05-14 22:35:07 +03:00
if ( si . name = = null )
AssemblyDocCache . AddDescribeToComplete ( this . si , pi ) ;
this . si . name = pi . Name ;
this . topScope = declaringType ;
//this.si.describe += "\n"+AssemblyDocCache.GetDocumentation(pi.DeclaringType.Assembly,"P:"+pi.DeclaringType.FullName+"."+pi.Name);
MethodInfo acc_mi = PascalABCCompiler . NetHelper . NetHelper . GetAnyAccessor ( pi ) ;
if ( acc_mi ! = null & & acc_mi = = pi . GetGetMethod ( true ) )
{
ParameterInfo [ ] prms = acc_mi . GetParameters ( ) ;
if ( prms . Length > 0 )
{
indexers = new List < TypeScope > ( ) ;
foreach ( ParameterInfo p in prms )
{
2016-05-08 20:45:37 +03:00
indexers . Add ( TypeTable . get_compiled_type ( p . ParameterType ) ) ;
2015-05-14 22:35:07 +03:00
}
Type ret_type = acc_mi . ReturnType ;
2016-05-08 20:45:37 +03:00
elementType = TypeTable . get_compiled_type ( ret_type ) ;
2015-05-14 22:35:07 +03:00
}
}
if ( acc_mi ! = null )
if ( acc_mi . IsPrivate )
{
this . acc_mod = access_modifer . private_modifer ;
this . si . acc_mod = access_modifer . private_modifer ;
}
else if ( acc_mi . IsFamily | | acc_mi . IsFamilyOrAssembly )
{
this . acc_mod = access_modifer . protected_modifer ;
this . si . acc_mod = access_modifer . protected_modifer ;
}
else if ( acc_mi . IsFamilyAndAssembly | | acc_mi . IsAssembly )
{
this . acc_mod = access_modifer . internal_modifer ;
this . si . acc_mod = access_modifer . internal_modifer ;
}
2016-05-01 13:02:40 +03:00
this . si . description = this . ToString ( ) ;
2015-05-14 22:35:07 +03:00
}
public override ScopeKind Kind
{
get
{
return ScopeKind . CompiledProperty ;
}
}
public List < string > GenericArgs
{
get
{
return generic_args ;
}
}
public PropertyInfo CompiledProperty
{
get
{
return pi ;
}
}
public override bool IsReadOnly
{
get { return pi . GetSetMethod ( true ) = = null ; }
}
public override bool IsEqual ( SymScope ts )
{
if ( ts is CompiledPropertyScope & & ( ts as CompiledPropertyScope ) . pi = = this . pi ) return true ;
return false ;
}
public override string ToString ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
public class CompiledParameterScope : ElementScope
{
private ParameterInfo pi ;
public CompiledParameterScope ( SymInfo si , ParameterInfo pi )
{
this . si = si ;
this . pi = pi ;
2016-05-08 20:45:37 +03:00
this . sc = TypeTable . get_compiled_type ( pi . ParameterType ) ;
2015-05-14 22:35:07 +03:00
if ( pi . ParameterType . IsByRef )
this . param_kind = parametr_kind . var_parametr ;
else if ( is_params ( pi ) )
this . param_kind = parametr_kind . params_parametr ;
2017-10-17 21:54:20 +03:00
if ( pi . IsOptional )
this . cnst_val = pi . DefaultValue ;
2015-05-14 22:35:07 +03:00
//MakeDescription();
}
private bool is_params ( ParameterInfo _par )
{
object [ ] objarr = _par . GetCustomAttributes ( typeof ( ParamArrayAttribute ) , true ) ;
if ( ( objarr = = null ) | | ( objarr . Length = = 0 ) )
{
return false ;
}
return true ;
}
}
public class CompiledMethodScope : ProcScope , ICompiledMethodScope
{
public MethodInfo mi ;
public bool is_global ;
//private CompiledScope ret_type;
2018-04-19 22:05:47 +03:00
public CompiledMethodScope ( SymInfo si , MethodInfo mi , TypeScope declaringType )
2015-05-14 22:35:07 +03:00
{
this . si = si ;
this . mi = mi ;
2018-04-19 22:05:47 +03:00
if ( declaringType = = TypeTable . string_type & & mi . GetParameters ( ) . Length > = 1 & & mi . GetParameters ( ) [ 0 ] . ParameterType . Name = = "IEnumerable`1" )
{
List < TypeScope > type_list = new List < TypeScope > ( ) ;
type_list . Add ( TypeTable . char_type ) ;
declaringType = TypeTable . get_compiled_type ( mi . GetParameters ( ) [ 0 ] . ParameterType . GetGenericTypeDefinition ( ) ) . GetInstance ( type_list ) ;
}
2015-05-14 22:35:07 +03:00
string [ ] args = declaringType . TemplateArguments ;
2016-12-04 14:46:04 +03:00
this . declaringType = declaringType ;
2015-05-14 22:35:07 +03:00
if ( args ! = null )
{
generic_args = new List < string > ( ) ;
generic_args . AddRange ( args ) ;
2016-02-07 14:24:18 +03:00
}
if ( mi . GetGenericArguments ( ) . Length > 0 )
{
2016-03-20 16:23:41 +03:00
this . template_parameters = new List < string > ( ) ;
foreach ( Type t in mi . GetGenericArguments ( ) )
this . template_parameters . Add ( t . Name ) ;
2015-05-14 22:35:07 +03:00
}
if ( mi . ReturnType ! = typeof ( void ) )
{
2016-12-04 14:46:04 +03:00
if ( generic_args ! = null )
2015-05-14 22:35:07 +03:00
{
this . return_type = CompiledScope . get_type_instance ( mi . ReturnType , declaringType . instances ) ;
}
else
2016-05-08 20:45:37 +03:00
return_type = TypeTable . get_compiled_type ( mi . ReturnType ) ;
2015-05-14 22:35:07 +03:00
}
parameters = new List < ElementScope > ( ) ;
int i = 0 ;
is_extension = PascalABCCompiler . NetHelper . NetHelper . IsExtensionMethod ( mi ) ;
foreach ( ParameterInfo pi in mi . GetParameters ( ) )
{
parameters . Add ( new CompiledParameterScope ( new SymInfo ( pi . Name , SymbolKind . Parameter , pi . Name ) , pi ) ) ;
}
if ( si . name = = null )
AssemblyDocCache . AddDescribeToComplete ( this . si , mi ) ;
2017-02-12 21:08:13 +03:00
this . si . name = CodeCompletionController . CurrentParser . LanguageInformation . GetShortName ( this ) ;
2016-05-01 13:02:40 +03:00
this . si . description = this . ToString ( ) ;
2015-05-14 22:35:07 +03:00
//this.si.describe += "\n"+AssemblyDocCache.GetDocumentation(mi.DeclaringType.Assembly,"M:"+mi.DeclaringType.FullName+"."+mi.Name+GetParamNames());
this . topScope = declaringType ;
if ( mi . IsPrivate )
{
this . si . acc_mod = access_modifer . private_modifer ;
this . acc_mod = access_modifer . private_modifer ;
}
else if ( mi . IsFamily | | mi . IsFamilyOrAssembly )
{
this . acc_mod = access_modifer . protected_modifer ;
this . si . acc_mod = access_modifer . protected_modifer ;
}
else if ( mi . IsFamilyAndAssembly | | mi . IsAssembly )
{
this . acc_mod = access_modifer . internal_modifer ;
this . si . acc_mod = access_modifer . internal_modifer ;
}
2019-12-24 18:23:34 +03:00
is_constructor = mi . IsConstructor ;
2015-05-14 22:35:07 +03:00
}
public CompiledMethodScope ( SymInfo si , MethodInfo mi , CompiledScope declaringType , bool is_global )
{
this . si = si ;
this . mi = mi ;
2016-12-04 14:46:04 +03:00
this . declaringType = declaringType ;
2015-05-14 22:35:07 +03:00
string [ ] args = declaringType . TemplateArguments ;
if ( args ! = null )
{
generic_args = new List < string > ( ) ;
generic_args . AddRange ( args ) ;
}
if ( mi . ReturnType ! = typeof ( void ) )
2016-05-08 20:45:37 +03:00
return_type = TypeTable . get_compiled_type ( mi . ReturnType ) ;
2015-05-14 22:35:07 +03:00
parameters = new List < ElementScope > ( ) ;
int i = 0 ;
is_extension = PascalABCCompiler . NetHelper . NetHelper . IsExtensionMethod ( mi ) ;
foreach ( ParameterInfo pi in mi . GetParameters ( ) )
{
parameters . Add ( new CompiledParameterScope ( new SymInfo ( pi . Name , SymbolKind . Parameter , pi . Name ) , pi ) ) ;
}
this . is_global = is_global ;
if ( si . name = = null )
AssemblyDocCache . AddDescribeToComplete ( this . si , mi ) ;
2017-02-12 21:08:13 +03:00
this . si . name = CodeCompletionController . CurrentParser . LanguageInformation . GetShortName ( this ) ;
2016-05-01 13:02:40 +03:00
this . si . description = this . ToString ( ) ;
2015-05-14 22:35:07 +03:00
//this.si.describe += "\n"+AssemblyDocCache.GetDocumentation(mi.DeclaringType.Assembly,"M:"+mi.DeclaringType.FullName+"."+mi.Name+GetParamNames());
this . topScope = declaringType ;
if ( mi . IsPrivate )
{
this . si . acc_mod = access_modifer . private_modifer ;
this . acc_mod = access_modifer . private_modifer ;
}
else if ( mi . IsFamily | | mi . IsFamilyOrAssembly )
{
this . acc_mod = access_modifer . protected_modifer ;
this . si . acc_mod = access_modifer . protected_modifer ;
}
else if ( mi . IsFamilyAndAssembly | | mi . IsAssembly )
{
this . acc_mod = access_modifer . internal_modifer ;
this . si . acc_mod = access_modifer . internal_modifer ;
}
2019-12-24 18:23:34 +03:00
is_constructor = mi . IsConstructor ;
2015-05-14 22:35:07 +03:00
}
public override ScopeKind Kind
{
get
{
return ScopeKind . CompiledMethod ;
}
}
public List < string > GenericArgs
{
get
{
return generic_args ;
}
}
public bool IsGlobal
{
get
{
return is_global ;
}
}
public override string Name
{
get { return mi . Name ; }
}
public MethodInfo CompiledMethod
{
get
{
return mi ;
}
}
public override bool IsAbstract
{
get { return mi . IsAbstract & & ! mi . DeclaringType . IsInterface ; }
}
public override bool IsStatic
{
get { return mi . IsStatic & & ! is_extension ; }
}
public override bool IsVirtual
{
2018-05-07 22:15:01 +03:00
get { return mi . IsVirtual & & ! mi . IsFinal ; }
2015-05-14 22:35:07 +03:00
}
public override bool IsConstructor ( )
{
2019-12-24 18:23:34 +03:00
return mi . IsConstructor ;
2015-05-14 22:35:07 +03:00
}
public override int GetParametersCount ( )
{
return mi . GetParameters ( ) . Length ;
}
public override SymInfo [ ] GetNames ( )
{
2017-08-17 22:32:08 +03:00
if ( return_type ! = null )
return return_type . GetNames ( ) ;
else
return new SymInfo [ 0 ] ;
2015-05-14 22:35:07 +03:00
}
// public override SymInfo[] GetNames(ExpressionVisitor ev)
// {
// return return_type.GetNames();
// }
public override SymScope FindName ( string name )
{
2017-08-17 22:32:08 +03:00
if ( return_type ! = null )
return return_type . FindName ( name ) ;
else
return null ;
2015-05-14 22:35:07 +03:00
}
public override SymScope FindNameOnlyInType ( string name )
{
return FindName ( name ) ;
}
public override bool IsEqual ( SymScope ts )
{
CompiledMethodScope cms = ts as CompiledMethodScope ;
if ( cms = = null ) return false ;
if ( cms . mi = = this . mi ) return true ;
if ( cms . nextProc ! = null ) return IsEqual ( cms . nextProc ) ;
return false ;
}
public override bool IsParamsEquals ( ProcScope ps )
{
if ( ps is CompiledMethodScope | | ps is CompiledConstructorScope )
return false ;
try
{
ParameterInfo [ ] prms = this . mi . GetParameters ( ) ;
if ( ps . parameters = = null )
{
if ( prms . Length ! = 0 ) return false ;
if ( ps . return_type = = null )
{
if ( this . mi . ReturnType = = typeof ( void ) )
return true ;
else
return false ;
}
if ( this . mi . ReturnType = = null )
return false ;
2016-05-08 20:45:37 +03:00
return ps . return_type . IsEqual ( TypeTable . get_compiled_type ( this . mi . ReturnType ) ) ;
2015-05-14 22:35:07 +03:00
}
if ( prms . Length ! = ps . parameters . Count )
return false ;
for ( int i = 0 ; i < prms . Length ; i + + )
{
2016-05-08 20:45:37 +03:00
if ( ! ps . parameters [ i ] . sc . IsEqual ( TypeTable . get_compiled_type ( prms [ i ] . ParameterType ) ) )
2015-05-14 22:35:07 +03:00
return false ;
}
if ( ps . return_type = = null )
{
if ( this . mi . ReturnType = = typeof ( void ) )
return true ;
else
return false ;
}
if ( this . mi . ReturnType = = null )
return false ;
2016-05-08 20:45:37 +03:00
return ps . return_type . IsEqual ( TypeTable . get_compiled_type ( this . mi . ReturnType ) ) ;
2015-05-14 22:35:07 +03:00
}
catch
{
return false ;
}
}
public override string ToString ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
public class CompiledConstructorScope : ProcScope , ICompiledConstructorScope
{
public ConstructorInfo mi ;
//private CompiledScope ret_type;
public override bool IsConstructor ( )
{
return true ;
}
public CompiledConstructorScope ( SymInfo si , ConstructorInfo mi , CompiledScope declaringType )
{
this . si = si ;
this . mi = mi ;
//if (mi.ReturnType != typeof(void))
2016-05-08 20:45:37 +03:00
return_type = TypeTable . get_compiled_type ( mi . DeclaringType ) ;
2015-05-14 22:35:07 +03:00
if ( si . name = = null )
AssemblyDocCache . AddDescribeToComplete ( this . si , mi ) ;
parameters = new List < ElementScope > ( ) ;
foreach ( ParameterInfo pi in mi . GetParameters ( ) )
parameters . Add ( new CompiledParameterScope ( new SymInfo ( pi . Name , SymbolKind . Parameter , pi . Name ) , pi ) ) ;
2017-02-12 21:08:13 +03:00
this . si . name = CodeCompletionController . CurrentParser . LanguageInformation . GetShortName ( this ) ;
2016-05-01 13:02:40 +03:00
this . si . description = this . ToString ( ) ; //+"\n"+AssemblyDocCache.GetDocumentation(mi.DeclaringType.Assembly,"M:"+mi.DeclaringType.FullName+".#ctor"+GetParamNames());
2015-05-14 22:35:07 +03:00
this . topScope = declaringType ;
if ( mi . IsPrivate )
{
this . si . acc_mod = access_modifer . private_modifer ;
this . acc_mod = access_modifer . private_modifer ;
}
else if ( mi . IsFamily | | mi . IsFamilyOrAssembly )
{
this . acc_mod = access_modifer . protected_modifer ;
this . si . acc_mod = access_modifer . protected_modifer ;
}
else if ( mi . IsFamilyAndAssembly | | mi . IsAssembly )
{
this . acc_mod = access_modifer . internal_modifer ;
this . si . acc_mod = access_modifer . internal_modifer ;
}
}
public override ScopeKind Kind
{
get
{
return ScopeKind . CompiledConstructor ;
}
}
public ConstructorInfo CompiledConstructor
{
get
{
return mi ;
}
}
public IBaseScope Type
{
get
{
throw new NotImplementedException ( ) ;
}
}
public override int GetParametersCount ( )
{
return mi . GetParameters ( ) . Length ;
}
public override SymInfo [ ] GetNames ( )
{
return return_type . GetNames ( ) ;
}
// public override SymInfo[] GetNames(ExpressionVisitor ev)
// {
// return return_type.GetNames();
// }
public override SymScope FindName ( string name )
{
return return_type . FindName ( name ) ;
}
public override SymScope FindNameOnlyInType ( string name )
{
return FindName ( name ) ;
}
public override bool IsEqual ( SymScope ts )
{
CompiledConstructorScope cms = ts as CompiledConstructorScope ;
if ( cms = = null ) return false ;
if ( cms . mi = = this . mi ) return true ;
if ( cms . nextProc ! = null ) return IsEqual ( cms . nextProc ) ;
return false ;
}
public override bool IsParamsEquals ( ProcScope ps )
{
if ( ps is CompiledMethodScope | | ps is CompiledConstructorScope )
return false ;
if ( ( ps . parameters = = null | | ps . parameters . Count = = 0 ) & & this . mi . GetParameters ( ) . Length = = 0 )
return true ;
return false ;
}
public override string ToString ( )
{
return CodeCompletionController . CurrentParser . LanguageInformation . GetDescription ( this ) ;
}
}
public class WithScope : SymScope
{
class TypeScopeDesc
{
public SymScope ss ;
public bool is_type ;
public TypeScopeDesc ( SymScope ss , bool is_type )
{
this . ss = ss ;
this . is_type = is_type ;
}
}
private List < TypeScopeDesc > with_scopes = new List < TypeScopeDesc > ( ) ;
public WithScope ( SymScope topScope )
{
this . topScope = topScope ;
this . si = new SymInfo ( "$with_block" , SymbolKind . Block , "$with_block" ) ;
}
public void AddWithScope ( SymScope ss , bool is_type )
{
with_scopes . Add ( new TypeScopeDesc ( ss , is_type ) ) ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
for ( int i = 0 ; i < with_scopes . Count ; i + + )
{
SymScope ss = with_scopes [ i ] . ss . FindNameOnlyInType ( name ) ;
if ( ss ! = null ) return ss ;
}
return topScope . FindNameInAnyOrder ( name ) ;
}
public override SymInfo [ ] GetNames ( )
{
List < SymInfo > lst = new List < SymInfo > ( ) ;
for ( int i = 0 ; i < with_scopes . Count ; i + + )
{
lst . AddRange ( with_scopes [ i ] . ss . GetNamesAsInObject ( ) ) ;
}
lst . AddRange ( topScope . GetNames ( ) ) ;
return lst . ToArray ( ) ;
}
// public override SymInfo[] GetNames(ExpressionVisitor ev)
// {
// List<SymInfo> lst = new List<SymInfo>();
// for (int i=0; i<with_scopes.Count; i++)
// {
// if (!with_scopes[i].is_type)
// lst.AddRange(with_scopes[i].ss.GetNamesAsInObject(ev));
// else
// lst.AddRange((with_scopes[i].ss as TypeScope).GetNames(ev,PascalABCCompiler.Parsers.KeywordKind.None));
// }
// lst.AddRange(topScope.GetNames(ev));
// return lst.ToArray();
// }
public override SymInfo [ ] GetNamesInAllTopScopes ( bool all_names , ExpressionVisitor ev , bool is_static )
{
List < SymInfo > lst = new List < SymInfo > ( ) ;
for ( int i = 0 ; i < with_scopes . Count ; i + + )
{
if ( ! with_scopes [ i ] . is_type )
lst . AddRange ( with_scopes [ i ] . ss . GetNamesAsInObject ( ev ) ) ;
else
lst . AddRange ( ( with_scopes [ i ] . ss as TypeScope ) . GetNames ( ev , PascalABCCompiler . Parsers . KeywordKind . None , false ) ) ;
}
lst . AddRange ( topScope . GetNamesInAllTopScopes ( all_names , ev , is_static ) ) ;
return lst . ToArray ( ) ;
}
public override SymScope FindName ( string name )
{
for ( int i = 0 ; i < with_scopes . Count ; i + + )
{
SymScope ss = with_scopes [ i ] . ss . FindNameOnlyInType ( name ) ;
if ( ss ! = null ) return ss ;
}
return topScope . FindName ( name ) ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
List < SymScope > names = new List < SymScope > ( ) ;
for ( int i = 0 ; i < with_scopes . Count ; i + + )
{
names . AddRange ( with_scopes [ i ] . ss . FindOverloadNamesOnlyInType ( name ) ) ;
}
names . AddRange ( topScope . FindOverloadNames ( name ) ) ;
return names ;
}
public override void AddName ( string name , SymScope sc )
{
if ( members = = null ) members = new List < SymScope > ( ) ;
base . AddName ( name , sc ) ;
}
public override SymScope FindNameOnlyInType ( string name )
{
return FindName ( name ) ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return FindOverloadNames ( name ) ;
}
}
public class BlockScope : SymScope , IBlockScope
{
public BlockScope ( SymScope topScope )
{
this . topScope = topScope ;
this . si = new SymInfo ( "$block_scope" , SymbolKind . Block , "$block_scope" ) ;
this . members = new List < SymScope > ( ) ;
}
public override ScopeKind Kind
{
get
{
return ScopeKind . Block ;
}
}
}
public class UnknownScope : TypeScope
{
public UnknownScope ( SymInfo si )
{
this . si = si ;
this . name = si . name ;
}
public override bool IsEqual ( SymScope ts )
{
2017-11-05 19:57:51 +03:00
return ts ! = null & & string . Compare ( this . si . name , ts . si . name , true ) = = 0 ;
2015-05-14 22:35:07 +03:00
}
public override SymScope FindName ( string name )
{
return null ;
}
public override List < SymScope > FindOverloadNames ( string name )
{
return new List < SymScope > ( 0 ) ;
}
2018-05-13 15:02:48 +03:00
public override TypeScope GetInstance ( List < TypeScope > gen_args , bool exact = false )
2015-05-14 22:35:07 +03:00
{
2016-04-03 13:57:12 +03:00
if ( gen_args . Count > 0 )
return gen_args [ 0 ] ;
2015-05-14 22:35:07 +03:00
return this ;
}
public override List < SymScope > FindOverloadNamesOnlyInType ( string name )
{
return new List < SymScope > ( 0 ) ;
}
public override SymScope FindNameInAnyOrder ( string name )
{
return null ;
}
public override SymScope FindNameOnlyInThisType ( string name )
{
return null ;
}
public override SymScope FindNameOnlyInType ( string name )
{
return null ;
}
public override SymInfo [ ] GetNames ( )
{
return new SymInfo [ 0 ] ;
}
// public override SymInfo[] GetNames(ExpressionVisitor ev)
// {
// return new SymInfo[0];
// }
public override SymInfo [ ] GetNamesAsInObject ( )
{
return new SymInfo [ 0 ] ;
}
public override SymInfo [ ] GetNamesAsInObject ( ExpressionVisitor ev )
{
return new SymInfo [ 0 ] ;
}
public override SymInfo [ ] GetNamesInAllTopScopes ( bool all_names , ExpressionVisitor ev , bool is_static )
{
return new SymInfo [ 0 ] ;
}
public override string ToString ( )
{
2016-05-01 13:02:40 +03:00
return si . description ;
2015-05-14 22:35:07 +03:00
}
}
/ * public class ClassScope : BaseScope
{
public override SymInfo [ ] GetName ( string name )
{
}
public override BaseScope FindName ( string name )
{
}
} * /
}