*.cs: Moving to generics world.
cs-parser.jay: Removed current_array_type.
svn path=/trunk/mcs/; revision=147840
+2009-12-08 Marek Safar <marek.safar@gmail.com>
+
+ *.cs: Moving to generics world.
+
+ cs-parser.jay: Removed current_array_type.
+
2009-12-07 Marek Safar <marek.safar@gmail.com>
*.cs: Moving to generics world.
using System;
using System.Reflection;
using System.Reflection.Emit;
-using System.Collections;
using System.Collections.Generic;
namespace Mono.CSharp
this.args.AddRange (args.args);
}
- public ArrayList CreateDynamicBinderArguments (ResolveContext rc)
+ public ArrayInitializer CreateDynamicBinderArguments (ResolveContext rc)
{
- var all = new ArrayList (args.Count);
Location loc = Location.Null;
+ var all = new ArrayInitializer (args.Count, loc);
MemberAccess binder = DynamicExpressionStatement.GetBinderNamespace (loc);
//
using System;
-using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
List<MemberCore> operators;
// Holds the compiler generated classes
- ArrayList compiler_generated;
+ List<CompilerGeneratedClass> compiler_generated;
//
// Pointers to the default constructor and the default static constructor
Report.Debug (64, "ADD COMPILER GENERATED CLASS", this, c);
if (compiler_generated == null)
- compiler_generated = new ArrayList ();
+ compiler_generated = new List<CompilerGeneratedClass> ();
compiler_generated.Add (c);
}
TypeExpr[] GetNormalPartialBases (ref TypeExpr base_class)
{
- ArrayList ifaces = new ArrayList (0);
+ var ifaces = new List<TypeExpr> (0);
if (iface_exprs != null)
ifaces.AddRange (iface_exprs);
if (ifaces.Count == 0)
return null;
- return (TypeExpr[])ifaces.ToArray (typeof (TypeExpr));
+ return ifaces.ToArray ();
}
//
bool CheckGenericInterfaces (Type[] ifaces)
{
- ArrayList already_checked = new ArrayList ();
+ var already_checked = new List<Type> ();
for (int i = 0; i < ifaces.Length; i++) {
Type iface = ifaces [i];
return true;
}
- protected virtual void DefineContainerMembers (IList mcal) // IList<MemberCore>
+ protected virtual void DefineContainerMembers (System.Collections.IList mcal) // IList<MemberCore>
{
if (mcal != null) {
foreach (MemberCore mc in mcal) {
public MethodInfo[] GetMethods ()
{
- ArrayList members = new ArrayList ();
+ var members = new List<MethodInfo> ();
Define ();
}
}
- MethodInfo[] retMethods = new MethodInfo [members.Count];
- members.CopyTo (retMethods, 0);
- return retMethods;
+ return members.ToArray ();
}
// Indicated whether container has StructLayout attribute set Explicit
/// </summary>
void VerifyClsName ()
{
- Hashtable base_members = base_cache == null ?
- new Hashtable () :
+ Dictionary<string, object> base_members = base_cache == null ?
+ new Dictionary<string, object> () :
base_cache.GetPublicMembers ();
- Hashtable this_members = new Hashtable ();
+ var this_members = new Dictionary<string, object> ();
foreach (var entry in defined_names) {
MemberCore mc = entry.Value;
string basename = name.Substring (name.LastIndexOf ('.') + 1);
string lcase = basename.ToLower (System.Globalization.CultureInfo.InvariantCulture);
- object found = base_members [lcase];
- if (found == null) {
- found = this_members [lcase];
- if (found == null) {
+ object found;
+ if (!base_members.TryGetValue (lcase, out found)) {
+ if (!this_members.TryGetValue (lcase, out found)) {
this_members.Add (lcase, mc);
continue;
}
while (top_level.Parent != null)
top_level = top_level.Parent;
- ArrayList candidates = NamespaceEntry.NS.LookupExtensionMethod (extensionType, this, name);
+ var candidates = NamespaceEntry.NS.LookupExtensionMethod (extensionType, this, name);
if (candidates != null)
return new ExtensionMethodGroupExpr (candidates, NamespaceEntry, extensionType, loc);
}
}
}
- protected override void DefineContainerMembers (IList list)
+ protected override void DefineContainerMembers (System.Collections.IList list)
{
if (list == null)
return;
return false;
if (!Parameters.IsEmpty) {
- ArrayList al = (ArrayList)Parent.PartialContainer.MemberCache.Members [Name];
+ var al = Parent.PartialContainer.MemberCache.Members [Name];
if (al.Count > 1)
MemberCache.VerifyClsParameterConflict (al, this, MethodBuilder, Report);
}
}
if (!Parameters.IsEmpty) {
- ArrayList al = (ArrayList)Parent.MemberCache.Members [ConstructorInfo.ConstructorName];
+ var al = Parent.MemberCache.Members [ConstructorInfo.ConstructorName];
if (al.Count > 2)
MemberCache.VerifyClsParameterConflict (al, this, ConstructorBuilder, Report);
//
namespace Mono.CSharp {
using System;
- using System.Collections;
+ using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
this.Prefix = prefix;
}
- public static void AppendResults (ArrayList results, string prefix, IEnumerable names)
+ public static void AppendResults (List<string> results, string prefix, IEnumerable<string> names)
{
foreach (string name in names){
if (name == null)
protected override Expression DoResolve (ResolveContext ec)
{
- ArrayList results = new ArrayList ();
+ var results = new List<string> ();
AppendResults (results, Prefix, Evaluator.GetVarNames ());
AppendResults (results, Prefix, ec.CurrentTypeDefinition.NamespaceEntry.CompletionGetTypesStartingWith (Prefix));
AppendResults (results, Prefix, Evaluator.GetUsingList ());
- throw new CompletionResult (Prefix, (string []) results.ToArray (typeof (string)));
+ throw new CompletionResult (Prefix, results.ToArray ());
}
protected override void CloneTo (CloneContext clonectx, Expression t)
return null;
}
- ArrayList results = new ArrayList ();
+ var results = new List<string> ();
if (expr_resolved is Namespace){
Namespace nexpr = expr_resolved as Namespace;
string namespaced_partial;
}
}
- throw new CompletionResult (partial_name == null ? "" : partial_name, (string []) results.ToArray (typeof (string)));
+ throw new CompletionResult (partial_name == null ? "" : partial_name, results.ToArray ());
}
protected override void CloneTo (CloneContext clonectx, Expression t)
// great spot to put an `error' because you can reproduce it with this input:
// "public X { }"
//
-// Possible optimization:
-// Run memory profiler with parsing only, and consider dropping
-// arraylists where not needed. Some pieces can use linked lists.
-
using System.Text;
using System.IO;
using System;
-using System.Collections;
using System.Collections.Generic;
namespace Mono.CSharp
FullNamedExpression implicit_value_parameter_type;
ParametersCompiled indexer_parameters;
- /// <summary>
- /// Hack to help create non-typed array initializer
- /// </summary>
- public static FullNamedExpression current_array_type;
- FullNamedExpression pushed_current_array_type;
-
/// <summary>
/// Used to determine if we are parsing the get/set pair
/// of an indexer or a property
///
/// An out-of-band stack.
///
- static Stack oob_stack;
+ static Stack<object> oob_stack;
///
/// Switch stack.
///
- Stack switch_stack;
+ Stack<Block> switch_stack;
///
/// Controls the verbosity of the errors produced by the parser
//
public Undo undo;
- // Stack<ToplevelBlock>
- Stack linq_clause_blocks;
+ Stack<Block> linq_clause_blocks;
// A counter to create new class names in interactive mode
static int class_count;
// share the bucket for very common constructs which can never
// be recursive
//
- static ArrayList parameters_bucket = new ArrayList (6);
- static ArrayList variables_bucket = new ArrayList (6);
+ static List<Parameter> parameters_bucket = new List<Parameter> (6);
+ static List<object> variables_bucket = new List<object> (6);
%}
%token EOF
SEMICOLON
{
int modflags = (int) $2;
- foreach (VariableDeclaration constant in (ArrayList) $5){
+ foreach (VariableDeclaration constant in (List<object>) $5){
Location l = constant.Location;
if ((modflags & Modifiers.STATIC) != 0) {
Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + "." + (string) constant.identifier);
Const c = new Const (
current_class, (FullNamedExpression) $4, (string) constant.identifier,
- (Expression) constant.expression_or_array_initializer, modflags,
+ constant.GetInitializer ((FullNamedExpression) $4), modflags,
(Attributes) $1, l);
if (RootContext.Documentation != null) {
| constant_declarators COMMA constant_declarator
{
if ($3 != null) {
- ArrayList constants = (ArrayList) $1;
+ var constants = (List<object>) $1;
constants.Add ($3);
}
}
constant_initializer
{
--lexer.parsing_block;
- $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, $4);
+ $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $4);
}
| IDENTIFIER
{
int mod = (int) $2;
- current_array_type = null;
-
- foreach (VariableMemberDeclaration var in (ArrayList) $4){
+ foreach (VariableMemberDeclaration var in (List<object>) $4){
Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1);
- field.Initializer = var.expression_or_array_initializer;
+ field.Initializer = var.GetInitializer (type);
if (RootContext.Documentation != null) {
field.DocComment = Lexer.consume_doc_comment ();
int mod = (int) $2;
- current_array_type = null;
-
- foreach (VariableDeclaration var in (ArrayList) $5) {
+ foreach (VariableDeclaration var in (List<VariableDeclaration>) $5) {
FixedField field = new FixedField (current_class, type, mod, var.identifier,
- (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
+ var.GetInitializer (type), (Attributes) $1, var.Location);
if (RootContext.Documentation != null) {
field.DocComment = Lexer.consume_doc_comment ();
fixed_variable_declarators
: fixed_variable_declarator
{
- ArrayList decl = new ArrayList (2);
- decl.Add ($1);
+ var decl = new List<VariableDeclaration> (2);
+ decl.Add ((VariableDeclaration)$1);
$$ = decl;
}
| fixed_variable_declarators COMMA fixed_variable_declarator
{
- ArrayList decls = (ArrayList) $1;
- decls.Add ($3);
+ var decls = (List<VariableDeclaration>) $1;
+ decls.Add ((VariableDeclaration)$3);
$$ = $1;
}
;
fixed_variable_declarator
: IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
{
- $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, $3);
+ $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
}
| IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
{
}
| local_variable_declarators COMMA local_variable_declarator
{
- ArrayList decls = (ArrayList) $1;
+ var decls = (List<object>) $1;
decls.Add ($3);
$$ = $1;
}
local_variable_declarator
: IDENTIFIER ASSIGN local_variable_initializer
{
- $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, $3);
+ $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3);
}
| IDENTIFIER
{
}
| variable_declarators COMMA variable_declarator
{
- ArrayList decls = (ArrayList) $1;
+ var decls = (List<object>) $1;
decls.Add ($3);
$$ = $1;
}
variable_initializer
{
--lexer.parsing_block;
- $$ = new VariableMemberDeclaration ((MemberName) $1, $4);
+ $$ = new VariableMemberDeclaration ((MemberName) $1, (Expression) $4);
}
| member_declaration_name
{
formal_parameter_list
: fixed_parameters
{
- ArrayList pars_list = (ArrayList) $1;
-
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
-
- $$ = new ParametersCompiled (compiler, pars);
+ var pars_list = (List<Parameter>) $1;
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
}
| fixed_parameters COMMA parameter_array
{
- ArrayList pars_list = (ArrayList) $1;
- pars_list.Add ($3);
+ var pars_list = (List<Parameter>) $1;
+ pars_list.Add ((Parameter) $3);
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
-
- $$ = new ParametersCompiled (compiler, pars);
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
}
| fixed_parameters COMMA arglist_modifier
{
- ArrayList pars_list = (ArrayList) $1;
+ var pars_list = (List<Parameter>) $1;
pars_list.Add (new ArglistParameter (GetLocation ($3)));
-
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
-
- $$ = new ParametersCompiled (compiler, pars, true);
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
}
| parameter_array COMMA error
{
{
if ($3 != null)
Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
-
- ArrayList pars_list = (ArrayList) $1;
- pars_list.Add (new ArglistParameter (GetLocation ($3)));
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
+ var pars_list = (List<Parameter>) $1;
+ pars_list.Add (new ArglistParameter (GetLocation ($3)));
- $$ = new ParametersCompiled (compiler, pars, true);
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
}
| arglist_modifier COMMA error
{
| fixed_parameters COMMA ARGLIST COMMA error
{
Report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list");
-
- ArrayList pars_list = (ArrayList) $1;
- pars_list.Add (new ArglistParameter (GetLocation ($3)));
- Parameter [] pars = new Parameter [pars_list.Count];
- pars_list.CopyTo (pars);
+ var pars_list = (List<Parameter>) $1;
+ pars_list.Add (new ArglistParameter (GetLocation ($3)));
- $$ = new ParametersCompiled (compiler, pars, true);
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true);
}
| parameter_array
{
}
| fixed_parameters COMMA fixed_parameter
{
- ArrayList pars = (ArrayList) $1;
+ var pars = (List<Parameter>) $1;
Parameter p = (Parameter) $3;
if (p != null) {
if (p.HasExtensionMethodModifier)
opt_modifiers
EVENT type variable_declarators SEMICOLON
{
- current_array_type = null;
- foreach (VariableMemberDeclaration var in (ArrayList) $5) {
+ foreach (VariableMemberDeclaration var in (List<object>) $5) {
EventField e = new EventField (
current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1);
- if (var.expression_or_array_initializer != null) {
- if (current_container.Kind == Kind.Interface) {
- Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
- }
-
- e.Initializer = var.expression_or_array_initializer;
+ e.Initializer = var.GetInitializer ((FullNamedExpression) $4);
+ if (current_container.Kind == Kind.Interface && e.Initializer != null) {
+ Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ());
}
if (var.MemberName.Left != null) {
EnumMember em = null;
- foreach (VariableDeclaration ev in (ArrayList) $7) {
+ foreach (VariableDeclaration ev in (IList<VariableDeclaration>) $7) {
em = new EnumMember (
- e, em, ev.identifier, (Expression) ev.expression_or_array_initializer,
+ e, em, ev.identifier, ev.GetInitializer ((FullNamedExpression) $5),
ev.OptAttributes, ev.Location);
// if (RootContext.Documentation != null)
;
opt_enum_member_declarations
- : /* empty */ { $$ = new ArrayList (0); }
+ : /* empty */ { $$ = new VariableDeclaration [0]; }
| enum_member_declarations opt_comma { $$ = $1; }
;
enum_member_declarations
: enum_member_declaration
{
- ArrayList l = new ArrayList (4);
-
- l.Add ($1);
+ var l = new List<VariableDeclaration> (4);
+ l.Add ((VariableDeclaration) $1);
$$ = l;
}
| enum_member_declarations COMMA enum_member_declaration
{
- ArrayList l = (ArrayList) $1;
-
- l.Add ($3);
-
+ var l = (List<VariableDeclaration>) $1;
+ l.Add ((VariableDeclaration) $3);
$$ = l;
}
;
{
--lexer.parsing_block;
VariableDeclaration vd = new VariableDeclaration (
- (Tokenizer.LocatedToken) $2, $5, (Attributes) $1);
+ (Tokenizer.LocatedToken) $2, (Expression) $5, (Attributes) $1);
if (RootContext.Documentation != null)
vd.DocComment = ConsumeStoredComment ();
| type_expression rank_specifiers
{
string rank_specifiers = (string) $2;
- $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
+ $$ = new ComposedCast ((FullNamedExpression) $1, rank_specifiers);
}
;
$$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
} else {
if (name.Left == null && name.Name == "var")
- $$ = current_array_type = new VarExpr (name.Location);
+ $$ = new VarExpr (name.Location);
else
$$ = name.GetTypeExpression ();
}
}
| OPEN_BRACE expression_list CLOSE_BRACE
{
- $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1));
+ $$ = new CollectionElementInitializer ((List<Expression>)$2, GetLocation ($1));
}
| OPEN_BRACE CLOSE_BRACE
{
Error_ExpectingTypeName (expr);
$$ = TypeManager.system_object_expr;
}
-
- current_array_type = (FullNamedExpression)$$;
}
;
expression_list
: expression
{
- ArrayList list = new ArrayList (4);
- list.Add ($1);
+ var list = new List<Expression> (4);
+ list.Add ((Expression) $1);
$$ = list;
}
| expression_list COMMA expression
{
- ArrayList list = (ArrayList) $1;
- list.Add ($3);
+ var list = (List<Expression>) $1;
+ list.Add ((Expression) $3);
$$ = list;
}
;
opt_rank_specifier // shift/reduce on OPEN_BRACE
opt_array_initializer
{
- $$ = new ArrayCreation ((FullNamedExpression) $1, (ArrayList) $3, (string) $5, (ArrayList) $6, GetLocation ($1));
+ $$ = new ArrayCreation ((FullNamedExpression) $1, (List<Expression>) $3, (string) $5, (ArrayInitializer) $6, GetLocation ($1));
}
| new_expr_start rank_specifiers opt_array_initializer
{
if ($3 == null)
Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer");
- $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayList) $3, GetLocation ($1));
+ $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayInitializer) $3, GetLocation ($1));
}
| NEW rank_specifiers array_initializer
{
if (RootContext.Version <= LanguageVersion.ISO_2)
Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays");
- $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, GetLocation ($1));
+ $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayInitializer) $3, GetLocation ($1));
}
| new_expr_start error
{
array_initializer
: OPEN_BRACE CLOSE_BRACE
{
- $$ = new ArrayList (0);
+ $$ = new ArrayInitializer (0, GetLocation ($1));
}
| OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE
{
- $$ = $2;
+ $$ = new ArrayInitializer ((List<Expression>) $2, GetLocation ($1));
}
;
variable_initializer_list
: variable_initializer
{
- ArrayList list = new ArrayList (4);
- list.Add ($1);
+ var list = new List<Expression> (4);
+ list.Add ((Expression) $1);
$$ = list;
}
| variable_initializer_list COMMA variable_initializer
{
- ArrayList list = (ArrayList) $1;
- list.Add ($3);
+ var list = (List<Expression>) $1;
+ list.Add ((Expression) $3);
$$ = list;
}
| error
{
Error_SyntaxError (yyToken);
- $$ = new ArrayList ();
+ $$ = new List<Expression> ();
}
;
typeof_expression
: TYPEOF
{
- pushed_current_array_type = current_array_type;
lexer.TypeOfParsing = true;
}
open_parens_any typeof_type_expression CLOSE_PARENS
$$ = new TypeOfVoid (GetLocation ($1));
else
$$ = new TypeOf (type, GetLocation ($1));
- current_array_type = pushed_current_array_type;
}
;
lambda_parameter_list
: lambda_parameter
{
- ArrayList pars = new ArrayList (4);
- pars.Add ($1);
+ var pars = new List<Parameter> (4);
+ pars.Add ((Parameter) $1);
$$ = pars;
}
| lambda_parameter_list COMMA lambda_parameter
{
- ArrayList pars = (ArrayList) $1;
+ var pars = (List<Parameter>) $1;
Parameter p = (Parameter)$3;
if (pars[0].GetType () != p.GetType ()) {
Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly");
opt_lambda_parameter_list
: /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; }
| lambda_parameter_list {
- ArrayList pars_list = (ArrayList) $1;
- $$ = new ParametersCompiled (compiler, (Parameter[])pars_list.ToArray (typeof (Parameter)));
+ var pars_list = (List<Parameter>) $1;
+ $$ = new ParametersCompiled (compiler, pars_list.ToArray ());
}
;
declaration_statement
: local_variable_declaration SEMICOLON
{
- current_array_type = null;
if ($1 != null){
- DictionaryEntry de = (DictionaryEntry) $1;
- Expression e = (Expression) de.Key;
-
- $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location);
+ var de = (Tuple<FullNamedExpression, List<object>>) $1;
+ $$ = declare_local_variables (de.Item1, de.Item2, de.Item1.Location);
}
}
| local_constant_declaration SEMICOLON
{
- current_array_type = null;
if ($1 != null){
- DictionaryEntry de = (DictionaryEntry) $1;
+ var de = (Tuple<FullNamedExpression, List<object>>) $1;
- $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value);
+ $$ = declare_local_constants (de.Item1, de.Item2);
}
}
;
if (rank_or_nullable.Length == 0) {
SimpleName sn = expr as SimpleName;
if (sn != null && sn.Name == "var")
- $$ = current_array_type = new VarExpr (sn.Location);
+ $$ = new VarExpr (sn.Location);
else
$$ = $1;
} else {
if ((string) $2 == "")
$$ = $1;
else
- $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
+ $$ = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location);
}
| VOID opt_rank_specifier
{
if (rank == "")
$$ = $1;
else
- $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank);
+ $$ = new ComposedCast ((FullNamedExpression) $1, rank);
} else {
$$ = null;
}
if ($1 != null) {
VarExpr ve = $1 as VarExpr;
if (ve != null) {
- if (((VariableDeclaration)((ArrayList)$2) [0]).expression_or_array_initializer == null)
+ if (!((VariableDeclaration) ((List<object>)$2) [0]).HasInitializer)
ve.VariableInitializersCount = 0;
else
- ve.VariableInitializersCount = ((ArrayList)$2).Count;
+ ve.VariableInitializersCount = ((List<object>)$2).Count;
}
- $$ = new DictionaryEntry ($1, $2);
+ $$ = new Tuple<FullNamedExpression, List<object>> ((FullNamedExpression) $1, (List<object>) $2);
} else
$$ = null;
}
: CONST variable_type constant_declarators
{
if ($2 != null)
- $$ = new DictionaryEntry ($2, $3);
+ $$ = new Tuple<FullNamedExpression, List<object>> ((FullNamedExpression) $2, (List<object>) $3);
else
$$ = null;
}
: SWITCH open_parens_any
{
if (switch_stack == null)
- switch_stack = new Stack (2);
+ switch_stack = new Stack<Block> (2);
switch_stack.Push (current_block);
}
expression CLOSE_PARENS
start_block (l);
Block assign_block = current_block;
- if ($3 is DictionaryEntry){
- DictionaryEntry de = (DictionaryEntry) $3;
+ if ($3 is Tuple<FullNamedExpression, List<object>>){
+ var de = (Tuple<FullNamedExpression, List<object>>) $3;
- Expression type = (Expression) de.Key;
- ArrayList var_declarators = (ArrayList) de.Value;
+ var type = de.Item1;
- foreach (VariableDeclaration decl in var_declarators){
+ foreach (VariableDeclaration decl in de.Item2){
LocalInfo vi;
if (vi == null)
continue;
- Expression expr = decl.expression_or_array_initializer;
+ Expression expr = decl.GetInitializer (type);
LocalVariableReference var;
var = new LocalVariableReference (assign_block, decl.identifier, l);
catch_clause
: CATCH opt_catch_args
{
- Expression type = null;
-
if ($2 != null) {
- DictionaryEntry cc = (DictionaryEntry) $2;
- type = (Expression) cc.Key;
- var lt = (Tokenizer.LocatedToken) cc.Value;
+ var cc = (Tuple<FullNamedExpression, Tokenizer.LocatedToken>) $2;
+ var lt = cc.Item2;
if (lt != null){
- ArrayList one = new ArrayList (2);
+ List<object> one = new List<object> (1);
one.Add (new VariableDeclaration (lt, null));
start_block (lexer.Location);
- current_block = declare_local_variables (type, one, lt.Location);
+ current_block = declare_local_variables (cc.Item1, one, lt.Location);
}
}
} block {
Block var_block = null;
if ($2 != null){
- DictionaryEntry cc = (DictionaryEntry) $2;
- type = (Expression) cc.Key;
- var lt = (Tokenizer.LocatedToken) cc.Value;
+ var cc = (Tuple<FullNamedExpression, Tokenizer.LocatedToken>) $2;
+ type = cc.Item1;
+ var lt = cc.Item2;
if (lt != null){
id = lt.Value;
catch_args
: open_parens_any type opt_identifier CLOSE_PARENS
{
- $$ = new DictionaryEntry ($2, $3);
+ $$ = new Tuple<FullNamedExpression, Tokenizer.LocatedToken> ((FullNamedExpression)$2, (Tokenizer.LocatedToken) $3);
}
| open_parens_any CLOSE_PARENS
{
start_block (lexer.Location);
Block assign_block = current_block;
- DictionaryEntry de = (DictionaryEntry) $3;
+ var de = (Tuple<FullNamedExpression, List<object>>) $3;
Location l = GetLocation ($1);
- Expression type = (Expression) de.Key;
- ArrayList var_declarators = (ArrayList) de.Value;
+ var vars = new Stack<Tuple<LocalVariableReference, Expression>> ();
- Stack vars = new Stack ();
-
- foreach (VariableDeclaration decl in var_declarators) {
- LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
+ foreach (VariableDeclaration decl in de.Item2) {
+ LocalInfo vi = current_block.AddVariable (de.Item1, decl.identifier, decl.Location);
if (vi == null)
continue;
vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
- Expression expr = decl.expression_or_array_initializer;
+ Expression expr = decl.GetInitializer (de.Item1);
if (expr == null) {
Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration");
continue;
// This is so that it is not a warning on using variables
vi.Used = true;
- vars.Push (new DictionaryEntry (var, expr));
+ vars.Push (new Tuple<LocalVariableReference, Expression> (var, expr));
// Assign a = new SimpleAssign (var, expr, decl.Location);
// assign_block.AddStatement (new StatementExpression (a));
embedded_statement
{
Statement stmt = (Statement) $6;
- Stack vars = (Stack) $5;
+ var vars = (Stack<Tuple<LocalVariableReference, Expression>>) $5;
Location l = GetLocation ($1);
while (vars.Count > 0) {
- DictionaryEntry de = (DictionaryEntry) vars.Pop ();
- stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l);
+ var de = vars.Pop ();
+ stmt = new Using (de.Item1, de.Item2, stmt, l);
}
current_block.AddStatement (stmt);
$$ = end_block (lexer.Location);
| GROUP
{
if (linq_clause_blocks == null)
- linq_clause_blocks = new Stack ();
+ linq_clause_blocks = new Stack<Block> ();
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
linq_clause_blocks.Push (current_block);
: JOIN IDENTIFIER IN
{
if (linq_clause_blocks == null)
- linq_clause_blocks = new Stack ();
+ linq_clause_blocks = new Stack<Block> ();
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
linq_clause_blocks.Push (current_block);
| JOIN type IDENTIFIER IN
{
if (linq_clause_blocks == null)
- linq_clause_blocks = new Stack ();
+ linq_clause_blocks = new Stack<Block> ();
current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location);
linq_clause_blocks.Push (current_block);
// </summary>
class VariableDeclaration {
public string identifier;
- public Expression expression_or_array_initializer;
+ Expression initializer;
public Location Location;
public Attributes OptAttributes;
public string DocComment;
- public VariableDeclaration (Tokenizer.LocatedToken lt, object eoai, Attributes opt_attrs)
+ public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer, Attributes opt_attrs)
{
this.identifier = lt.Value;
- if (eoai is ArrayList) {
- this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location);
- } else {
- this.expression_or_array_initializer = (Expression)eoai;
- }
+ this.initializer = initializer;
this.Location = lt.Location;
this.OptAttributes = opt_attrs;
}
- public VariableDeclaration (Tokenizer.LocatedToken lt, object eoai) : this (lt, eoai, null)
+ public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer)
+ : this (lt, initializer, null)
+ {
+ }
+
+ public Expression GetInitializer (FullNamedExpression type)
{
+ if (initializer is ArrayInitializer)
+ return new ArrayCreation (type, "", (ArrayInitializer)initializer, Location);
+
+ return initializer;
+ }
+
+ public bool HasInitializer {
+ get { return initializer != null; }
}
}
class VariableMemberDeclaration
{
public readonly MemberName MemberName;
- public Expression expression_or_array_initializer;
+ Expression initializer;
- public VariableMemberDeclaration (MemberName mn, object initializer)
+ public VariableMemberDeclaration (MemberName mn, Expression initializer)
{
MemberName = mn;
-
- if (initializer is ArrayList) {
- this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location);
- } else {
- this.expression_or_array_initializer = (Expression)initializer;
- }
+ this.initializer = initializer;
+ }
+
+ public Expression GetInitializer (FullNamedExpression type)
+ {
+ if (initializer is ArrayInitializer)
+ return new ArrayCreation (type, "", (ArrayInitializer)initializer, MemberName.Location);
+
+ return initializer;
}
}
}
}
-Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
+Block declare_local_variables (FullNamedExpression type, List<object> variable_declarators, Location loc)
{
Block implicit_block;
foreach (VariableDeclaration decl in variable_declarators){
// We can not use the super-handy f.Initializer, because
// multiple lines would force code to be executed out of sync
- if (decl.expression_or_array_initializer != null){
+ var init = decl.GetInitializer (type);
+ if (init != null){
string id = "$" + decl.identifier;
LocalInfo vi = current_block.AddVariable (type, id, decl.Location);
LocalVariableReference var;
var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, vi, decl.Location);
- Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location);
+ Assign assign = new SimpleAssign (var, init, decl.Location);
current_block.AddStatement (new StatementExpression (assign));
assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var);
current_block.AddStatement (new StatementExpression (assign));
foreach (VariableDeclaration decl in variable_declarators){
if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
- if (decl.expression_or_array_initializer != null){
+ if (decl.HasInitializer){
Assign assign;
- Expression expr = decl.expression_or_array_initializer;
var lvr = new LocalVariableReference (implicit_block, decl.identifier, loc);
- assign = new SimpleAssign (lvr, expr, decl.Location);
+ assign = new SimpleAssign (lvr, decl.GetInitializer (type), decl.Location);
implicit_block.AddStatement (new StatementExpression (assign));
}
return implicit_block;
}
-Block declare_local_constants (Expression type, ArrayList declarators)
+Block declare_local_constants (FullNamedExpression type, List<object> declarators)
{
Block implicit_block;
implicit_block = current_block;
foreach (VariableDeclaration decl in declarators){
- implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
+ implicit_block.AddConstant (type, decl.identifier, decl.GetInitializer (type), decl.Location);
}
return implicit_block;
static CSharpParser ()
{
- oob_stack = new Stack ();
+ oob_stack = new Stack<object> ();
}
public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx)
string GetExpecting ()
{
int [] tokens = yyExpectingTokens (yyExpectingState);
- ArrayList names = new ArrayList (tokens.Length);
+ var names = new List<string> (tokens.Length);
bool has_type = false;
bool has_identifier = false;
for (int i = 0; i < tokens.Length; i++){
using System;
using System.Text;
-using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection.Emit;
if (this is GenericMethod)
the_parent = null;
- ArrayList list = new ArrayList ();
+ var list = new List<TypeParameter> ();
if (the_parent != null && the_parent.IsGeneric) {
// FIXME: move generics info out of DeclSpace
TypeParameter[] parent_params = the_parent.TypeParameters;
}
}
- IDictionary cache = TypeManager.AllClsTopLevelTypes;
+ var cache = TypeManager.AllClsTopLevelTypes;
if (cache == null)
return true;
string lcase = Name.ToLower (System.Globalization.CultureInfo.InvariantCulture);
- if (!cache.Contains (lcase)) {
+ if (!cache.ContainsKey (lcase)) {
cache.Add (lcase, this);
return true;
}
return List.GetEnumerator ();
}
- IEnumerator IEnumerable.GetEnumerator ()
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
{
return List.GetEnumerator ();
}
/// </summary>
public class MemberCache {
public readonly IMemberContainer Container;
- protected Hashtable member_hash;
- protected Hashtable method_hash;
+ protected Dictionary<string, List<CacheEntry>> member_hash;
+ protected Dictionary<string, List<CacheEntry>> method_hash;
+
+ Dictionary<string, object> locase_table;
+
+ static List<MethodInfo> overrides = new List<MethodInfo> ();
/// <summary>
/// Create a new MemberCache for the given IMemberContainer `container'.
if (Container.BaseCache != null)
member_hash = SetupCache (Container.BaseCache);
else
- member_hash = new Hashtable ();
+ member_hash = new Dictionary<string, List<CacheEntry>> ();
// If this is neither a dynamic type nor an interface, create a special
// method cache with all declared and inherited methods.
// !(type.IsGenericType && (type.GetGenericTypeDefinition () is TypeBuilder)) &&
!TypeManager.IsGenericType (type) && !TypeManager.IsGenericParameter (type) &&
(Container.BaseCache == null || Container.BaseCache.method_hash != null)) {
- method_hash = new Hashtable ();
- AddMethods (type);
+ method_hash = new Dictionary<string, List<CacheEntry>> ();
+ AddMethods (type);
}
// Add all members from the current class.
{
this.Container = container;
if (baseType == null)
- this.member_hash = new Hashtable ();
+ this.member_hash = new Dictionary<string, List<CacheEntry>> ();
else
this.member_hash = SetupCache (TypeManager.LookupMemberCache (baseType));
}
//
this.Container = null;
- member_hash = new Hashtable ();
+ member_hash = new Dictionary<string, List<CacheEntry>> ();
if (ifaces == null)
return;
if (Container.BaseCache != null)
member_hash = SetupCache (Container.BaseCache);
else
- member_hash = new Hashtable ();
+ member_hash = new Dictionary<string, List<CacheEntry>> ();
if (base_class != null)
AddCacheContents (TypeManager.LookupMemberCache (base_class));
/// <summary>
/// Bootstrap this member cache by doing a deep-copy of our base.
/// </summary>
- static Hashtable SetupCache (MemberCache base_class)
+ static Dictionary<string, List<CacheEntry>> SetupCache (MemberCache base_class)
{
if (base_class == null)
- return new Hashtable ();
+ return new Dictionary<string, List<CacheEntry>> ();
- Hashtable hash = new Hashtable (base_class.member_hash.Count);
- IDictionaryEnumerator it = base_class.member_hash.GetEnumerator ();
+ var hash = new Dictionary<string, List<CacheEntry>> (base_class.member_hash.Count);
+ var it = base_class.member_hash.GetEnumerator ();
while (it.MoveNext ()) {
- hash.Add (it.Key, ((ArrayList) it.Value).Clone ());
- }
+ hash.Add (it.Current.Key, new List<CacheEntry> (it.Current.Value));
+ }
return hash;
}
/// </summary>
void AddCacheContents (MemberCache cache)
{
- IDictionaryEnumerator it = cache.member_hash.GetEnumerator ();
+ var it = cache.member_hash.GetEnumerator ();
while (it.MoveNext ()) {
- ArrayList list = (ArrayList) member_hash [it.Key];
- if (list == null)
- member_hash [it.Key] = list = new ArrayList ();
+ List<CacheEntry> list;
+ if (!member_hash.TryGetValue (it.Current.Key, out list))
+ member_hash [it.Current.Key] = list = new List<CacheEntry> ();
- ArrayList entries = (ArrayList) it.Value;
+ var entries = it.Current.Value;
for (int i = entries.Count-1; i >= 0; i--) {
- CacheEntry entry = (CacheEntry) entries [i];
+ var entry = entries [i];
if (entry.Container != cache.Container)
break;
string name, MemberInfo member)
{
// We use a name-based hash table of ArrayList's.
- ArrayList list = (ArrayList) member_hash [name];
- if (list == null) {
- list = new ArrayList (1);
+ List<CacheEntry> list;
+ if (!member_hash.TryGetValue (name, out list)) {
+ list = new List<CacheEntry> (1);
member_hash.Add (name, list);
}
AddMethods (BindingFlags.Instance | BindingFlags.NonPublic, type);
}
- static ArrayList overrides = new ArrayList ();
-
void AddMethods (BindingFlags bf, Type type)
{
MethodBase [] members = type.GetMethods (bf);
string name = member.Name;
// We use a name-based hash table of ArrayList's.
- ArrayList list = (ArrayList) method_hash [name];
- if (list == null) {
- list = new ArrayList (1);
+ List<CacheEntry> list;
+ if (!method_hash.TryGetValue (name, out list)) {
+ list = new List<CacheEntry> (1);
method_hash.Add (name, list);
}
/// number to speed up the searching process.
/// </summary>
[Flags]
- protected enum EntryType {
+ public enum EntryType {
None = 0x000,
Instance = 0x001,
MaskType = Constructor|Event|Field|Method|Property|NestedType
}
- protected class CacheEntry {
+ public class CacheEntry {
public readonly IMemberContainer Container;
public EntryType EntryType;
public readonly MemberInfo Member;
/// and checks whether we can abort the search since we've already found what
/// we were looking for.
/// </summary>
- protected bool DoneSearching (ArrayList list)
+ protected bool DoneSearching (IList<MemberInfo> list)
{
//
// We've found exactly one member in the current class and it's not
/// The lookup process will automatically restart itself in method-only
/// search mode if it discovers that it's about to return methods.
/// </summary>
- ArrayList global = new ArrayList ();
- bool using_global = false;
+ List<MemberInfo> global = new List<MemberInfo> ();
+ bool using_global;
static MemberInfo [] emptyMemberInfo = new MemberInfo [0];
// then we restart a method search if the first match is a method.
bool do_method_search = !method_search && (method_hash != null);
- ArrayList applicable;
+ List<CacheEntry> applicable;
// If this is a method-only search, we try to use the method cache if
// possible; a lookup in the method cache will return a MemberInfo with
// the correct ReflectedType for inherited methods.
if (method_search && (method_hash != null))
- applicable = (ArrayList) method_hash [name];
+ method_hash.TryGetValue (name, out applicable);
else
- applicable = (ArrayList) member_hash [name];
+ member_hash.TryGetValue (name, out applicable);
if (applicable == null)
return emptyMemberInfo;
// find the nested type @name in @this.
public Type FindNestedType (string name)
{
- ArrayList applicable = (ArrayList) member_hash [name];
- if (applicable == null)
+ List<CacheEntry> applicable;
+ if (!member_hash.TryGetValue (name, out applicable))
return null;
for (int i = applicable.Count-1; i >= 0; i--) {
- CacheEntry entry = (CacheEntry) applicable [i];
+ CacheEntry entry = applicable [i];
if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
return (Type) entry.Member;
}
public MemberInfo FindBaseEvent (Type invocation_type, string name)
{
- ArrayList applicable = (ArrayList) member_hash [name];
- if (applicable == null)
+ List<CacheEntry> applicable;
+ if (!member_hash.TryGetValue (name, out applicable))
return null;
//
//
for (int i = applicable.Count - 1; i >= 0; i--)
{
- CacheEntry entry = (CacheEntry) applicable [i];
+ CacheEntry entry = applicable [i];
if ((entry.EntryType & EntryType.Event) == 0)
continue;
//
// Looks for extension methods with defined name and extension type
//
- public ArrayList FindExtensionMethods (Assembly thisAssembly, Type extensionType, string name, bool publicOnly)
+ public List<MethodBase> FindExtensionMethods (Assembly thisAssembly, Type extensionType, string name, bool publicOnly)
{
- ArrayList entries;
+ List<CacheEntry> entries;
if (method_hash != null)
- entries = (ArrayList)method_hash [name];
- else
- entries = (ArrayList)member_hash [name];
+ method_hash.TryGetValue (name, out entries);
+ else {
+ member_hash.TryGetValue (name, out entries);
+ }
if (entries == null)
return null;
EntryType entry_type = EntryType.Static | EntryType.Method | EntryType.NotExtensionMethod;
EntryType found_entry_type = entry_type & ~EntryType.NotExtensionMethod;
- ArrayList candidates = null;
+ List<MethodBase> candidates = null;
foreach (CacheEntry entry in entries) {
if ((entry.EntryType & entry_type) == found_entry_type) {
MethodBase mb = (MethodBase)entry.Member;
//if (implicit conversion between ex_type and extensionType exist) {
if (candidates == null)
- candidates = new ArrayList (2);
+ candidates = new List<MethodBase> (2);
candidates.Add (mb);
//}
}
//
public MemberInfo FindMemberToOverride (Type invocation_type, string name, AParametersCollection parameters, GenericMethod generic_method, bool is_property)
{
- ArrayList applicable;
+ List<CacheEntry> applicable;
if (method_hash != null && !is_property)
- applicable = (ArrayList) method_hash [name];
+ method_hash.TryGetValue (name, out applicable);
else
- applicable = (ArrayList) member_hash [name];
+ member_hash.TryGetValue (name, out applicable);
if (applicable == null)
return null;
// Walk the chain of methods, starting from the top.
//
for (int i = applicable.Count - 1; i >= 0; i--) {
- CacheEntry entry = (CacheEntry) applicable [i];
+ CacheEntry entry = applicable [i];
if ((entry.EntryType & (is_property ? (EntryType.Property | EntryType.Field) : EntryType.Method)) == 0)
continue;
/// </summary>
public MemberInfo FindMemberWithSameName (string name, bool ignore_complex_types, MemberInfo ignore_member)
{
- ArrayList applicable = null;
+ List<CacheEntry> applicable = null;
if (method_hash != null)
- applicable = (ArrayList) method_hash [name];
+ method_hash.TryGetValue (name, out applicable);
if (applicable != null) {
for (int i = applicable.Count - 1; i >= 0; i--) {
if (member_hash == null)
return null;
- applicable = (ArrayList) member_hash [name];
-
- if (applicable != null) {
+
+ if (member_hash.TryGetValue (name, out applicable)) {
for (int i = applicable.Count - 1; i >= 0; i--) {
CacheEntry entry = (CacheEntry) applicable [i];
if ((entry.EntryType & EntryType.Public) != 0 & entry.Member != ignore_member) {
return null;
}
- Hashtable locase_table;
-
+
/// <summary>
/// Builds low-case table for CLS Compliance test
/// </summary>
- public Hashtable GetPublicMembers ()
+ public Dictionary<string, object> GetPublicMembers ()
{
if (locase_table != null)
return locase_table;
-
- locase_table = new Hashtable ();
- foreach (DictionaryEntry entry in member_hash) {
- ArrayList members = (ArrayList)entry.Value;
+
+ locase_table = new Dictionary<string, object> ();
+ foreach (var entry in member_hash) {
+ var members = entry.Value;
for (int ii = 0; ii < members.Count; ++ii) {
- CacheEntry member_entry = (CacheEntry) members [ii];
+ CacheEntry member_entry = members [ii];
if ((member_entry.EntryType & EntryType.Public) == 0)
continue;
return locase_table;
}
- public Hashtable Members {
+ public IDictionary<string, List<CacheEntry>> Members {
get {
return member_hash;
}
/// </summary>
///
// TODO: refactor as method is always 'this'
- public static void VerifyClsParameterConflict (ArrayList al, MethodCore method, MemberInfo this_builder, Report Report)
+ public static void VerifyClsParameterConflict (IList<CacheEntry> al, MethodCore method, MemberInfo this_builder, Report Report)
{
EntryType tested_type = (method is Constructor ? EntryType.Constructor : EntryType.Method) | EntryType.Public;
for (int i = 0; i < al.Count; ++i) {
- MemberCache.CacheEntry entry = (MemberCache.CacheEntry) al [i];
+ var entry = al [i];
// skip itself
if (entry.Member == this_builder)
public bool CheckExistingMembersOverloads (MemberCore member, string name, ParametersCompiled parameters, Report Report)
{
- ArrayList entries = (ArrayList)member_hash [name];
- if (entries == null)
+ List<CacheEntry> entries;
+ if (!member_hash.TryGetValue (name, out entries))
return true;
int method_param_count = parameters.Count;
//
using System;
-using System.Collections;
using System.Reflection.Emit;
#if NET_4_0
if (member != null && member.HasTypeArguments) {
TypeArguments ta = member.TypeArguments;
if (ta.Resolve (ec)) {
- ArrayList targs = new ArrayList (ta.Count);
+ var targs = new ArrayInitializer (ta.Count, loc);
foreach (Type t in ta.Arguments)
targs.Add (new TypeOf (new TypeExpression (t, loc), loc));
Expression real_args;
if (args == null) {
// Cannot be null because .NET trips over
- real_args = new ArrayCreation (new MemberAccess (GetBinderNamespace (loc), "CSharpArgumentInfo", loc), "[]", new ArrayList (0), loc);
+ real_args = new ArrayCreation (
+ new MemberAccess (GetBinderNamespace (loc), "CSharpArgumentInfo", loc), "[]",
+ new ArrayInitializer (0, loc), loc);
} else {
real_args = new ImplicitlyTypedArrayCreation ("[]", args.CreateDynamicBinderArguments (ec), loc);
}
namespace Mono.CSharp {
using System;
- using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
if (mi.Length > 1) {
bool is_interface = qualifier_type != null && qualifier_type.IsInterface;
- ArrayList methods = new ArrayList (2);
- ArrayList non_methods = null;
+ var methods = new List<MethodBase> (2);
+ List<MemberInfo> non_methods = null;
foreach (MemberInfo m in mi) {
if (m is MethodBase) {
- methods.Add (m);
+ methods.Add ((MethodBase) m);
continue;
}
if (non_methods == null)
- non_methods = new ArrayList (2);
+ non_methods = new List<MemberInfo> (2);
bool is_candidate = true;
for (int i = 0; i < non_methods.Count; ++i) {
- MemberInfo n_m = (MemberInfo) non_methods [i];
+ MemberInfo n_m = non_methods [i];
if (n_m.DeclaringType.IsInterface && TypeManager.ImplementsInterface (m.DeclaringType, n_m.DeclaringType)) {
non_methods.Remove (n_m);
--i;
}
if (methods.Count == 0 && non_methods != null && non_methods.Count > 1) {
- ctx.Report.SymbolRelatedToPreviousError ((MemberInfo)non_methods [1]);
- ctx.Report.SymbolRelatedToPreviousError ((MemberInfo)non_methods [0]);
+ ctx.Report.SymbolRelatedToPreviousError (non_methods [1]);
+ ctx.Report.SymbolRelatedToPreviousError (non_methods [0]);
ctx.Report.Error (229, loc, "Ambiguity between `{0}' and `{1}'",
- TypeManager.GetFullNameSignature ((MemberInfo)non_methods [1]),
- TypeManager.GetFullNameSignature ((MemberInfo)non_methods [0]));
+ TypeManager.GetFullNameSignature (non_methods [1]),
+ TypeManager.GetFullNameSignature (non_methods [0]));
return null;
}
/// </summary>
public class CastFromDecimal : TypeCast
{
- static IDictionary operators;
+ static Dictionary<Type, MethodInfo> operators;
public CastFromDecimal (Expression child, Type return_type)
: base (child, return_type)
public Expression Resolve ()
{
if (operators == null) {
- MemberInfo[] all_oper = TypeManager.MemberLookup (TypeManager.decimal_type,
- TypeManager.decimal_type, TypeManager.decimal_type, MemberTypes.Method,
- BindingFlags.Static | BindingFlags.Public, "op_Explicit", null);
+ MemberInfo[] all_oper = TypeManager.MemberLookup (TypeManager.decimal_type,
+ TypeManager.decimal_type, TypeManager.decimal_type, MemberTypes.Method,
+ BindingFlags.Static | BindingFlags.Public, "op_Explicit", null);
- operators = new System.Collections.Specialized.HybridDictionary ();
+ operators = new Dictionary<Type, MethodInfo> (ReferenceEquality<Type>.Default);
foreach (MethodInfo oper in all_oper) {
AParametersCollection pd = TypeManager.GetParameterData (oper);
if (pd.Types [0] == TypeManager.decimal_type)
}
}
- return operators.Contains (type) ? this : null;
+ return operators.ContainsKey (type) ? this : null;
}
public override void Emit (EmitContext ec)
ILGenerator ig = ec.ig;
child.Emit (ec);
- ig.Emit (OpCodes.Call, (MethodInfo)operators [type]);
+ ig.Emit (OpCodes.Call, operators [type]);
}
}
public Expression ExtensionExpression;
Argument extension_argument;
- public ExtensionMethodGroupExpr (ArrayList list, NamespaceEntry n, Type extensionType, Location l)
+ public ExtensionMethodGroupExpr (List<MethodBase> list, NamespaceEntry n, Type extensionType, Location l)
: base (list, extensionType, l)
{
this.namespace_entry = n;
has_inaccessible_candidates_only = inacessibleCandidatesOnly;
}
- public MethodGroupExpr (ArrayList list, Type type, Location l)
+ public MethodGroupExpr (List<MethodBase> list, Type type, Location l)
: this (type, l)
{
try {
- Methods = (MethodBase[])list.ToArray (typeof (MethodBase));
+ Methods = list.ToArray ();
} catch {
foreach (MemberInfo m in list){
if (!(m is MethodBase)){
if (mg2 == null)
return mg1;
-
- ArrayList all = new ArrayList (mg1.Methods);
+
+ var all = new List<MethodBase> (mg1.Methods);
foreach (MethodBase m in mg2.Methods){
if (!TypeManager.ArrayContainsMethod (mg1.Methods, m, false))
all.Add (m);
{
bool method_params = false;
Type applicable_type = null;
- ArrayList candidates = new ArrayList (2);
- ArrayList candidate_overrides = null;
+ var candidates = new List<MethodBase> (2);
+ List<MethodBase> candidate_overrides = null;
//
// Used to keep a map between the candidate
MethodBase m = Methods [i];
if (TypeManager.IsOverride (m)) {
if (candidate_overrides == null)
- candidate_overrides = new ArrayList ();
+ candidate_overrides = new List<MethodBase> ();
candidate_overrides.Add (m);
m = TypeManager.TryGetBaseDefinition (m);
}
int j = finalized; // where to put the next finalized candidate
int k = finalized; // where to put the next undiscarded candidate
for (int i = finalized; i < candidate_top; ++i) {
- MethodBase candidate = (MethodBase) candidates [i];
+ MethodBase candidate = candidates [i];
Type decl_type = candidate.DeclaringType;
if (decl_type == applicable_type) {
// Now we actually find the best method
//
- best_candidate = (MethodBase) candidates [0];
+ best_candidate = candidates [0];
method_params = candidate_to_form != null && candidate_to_form.ContainsKey (best_candidate);
//
//
MethodBase ambiguous = null;
for (int ix = 1; ix < candidate_top; ix++) {
- MethodBase candidate = (MethodBase) candidates [ix];
+ MethodBase candidate = candidates [ix];
if (candidate == best_candidate)
continue;
Type pt = null;
int a_idx = 0, a_pos = 0;
Argument a = null;
- ArrayList params_initializers = null;
+ ArrayInitializer params_initializers = null;
bool has_unsafe_arg = method is MethodInfo ? ((MethodInfo) method).ReturnType.IsPointer : false;
for (; a_idx < arg_count; a_idx++, ++a_pos) {
if (p_mod == Parameter.Modifier.PARAMS) {
if (chose_params_expanded) {
- params_initializers = new ArrayList (arg_count - a_idx);
+ params_initializers = new ArrayInitializer (arg_count - a_idx, a.Expr.Location);
pt = TypeManager.GetElementType (pt);
}
}
pt = pd.Types [param_count - 1];
pt = TypeManager.GetElementType (pt);
has_unsafe_arg |= pt.IsPointer;
- params_initializers = new ArrayList (0);
+ params_initializers = new ArrayInitializer (0, loc);
}
//
//
if (params_initializers != null) {
arguments.Add (new Argument (
- new ArrayCreation (new TypeExpression (pt, loc), "[]",
- params_initializers, loc).Resolve (ec)));
+ new ArrayCreation (new TypeExpression (pt, loc), "[]", params_initializers, loc).Resolve (ec)));
arg_count++;
}
//
using System;
using System.Threading;
-using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
static string current_debug_name;
static int count;
static Thread invoke_thread;
-
- static ArrayList using_alias_list = new ArrayList ();
- internal static ArrayList using_list = new ArrayList ();
- static Hashtable fields = new Hashtable ();
+
+ static List<NamespaceEntry.UsingAliasEntry> using_alias_list = new List<NamespaceEntry.UsingAliasEntry> ();
+ internal static List<NamespaceEntry.UsingEntry> using_list = new List<NamespaceEntry.UsingEntry> ();
+ static Dictionary<string, FieldInfo> fields = new Dictionary<string, FieldInfo> ();
static Type interactive_base_class = typeof (InteractiveBase);
static Driver driver;
driver.ProcessDefaultConfig ();
- ArrayList startup_files = new ArrayList ();
+ var startup_files = new List<string> ();
foreach (CompilationUnit file in Location.SourceFiles)
startup_files.Add (file.Path);
RootContext.EvalMode = true;
inited = true;
- return (string []) startup_files.ToArray (typeof (string));
+ return startup_files.ToArray ();
}
}
// or reflection gets confused (it basically gets confused, and variables override each
// other).
//
- static ArrayList queued_fields = new ArrayList ();
+ static List<Field> queued_fields = new List<Field> ();
//static ArrayList types = new ArrayList ();
foreach (Field field in queued_fields){
FieldInfo fi = tt.GetField (field.Name);
- FieldInfo old = (FieldInfo) fields [field.Name];
+ FieldInfo old;
// If a previous value was set, nullify it, so that we do
// not leak memory
- if (old != null){
+ if (fields.TryGetValue (field.Name, out old)){
if (TypeManager.IsStruct (old.FieldType)){
//
// TODO: Clear fields for structs
}
}
- static internal ICollection GetUsingList ()
+ static internal ICollection<string> GetUsingList ()
{
- ArrayList res = new ArrayList (using_list.Count);
+ var res = new List<string> (using_list.Count);
foreach (object ue in using_list)
res.Add (ue.ToString ());
return res;
static internal string [] GetVarNames ()
{
lock (evaluator_lock){
- return (string []) new ArrayList (fields.Keys).ToArray (typeof (string));
+ return new List<string> (fields.Keys).ToArray ();
}
}
lock (evaluator_lock){
StringBuilder sb = new StringBuilder ();
- foreach (DictionaryEntry de in fields){
- FieldInfo fi = LookupField ((string) de.Key);
+ foreach (var de in fields){
+ FieldInfo fi = LookupField (de.Key);
object value = null;
bool error = false;
namespace Mono.CSharp {
using System;
- using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
static void CreatePointerOperatorsTable ()
{
- ArrayList temp = new ArrayList ();
+ var temp = new List<PredefinedPointerOperator> ();
//
// Pointer arithmetic:
//
temp.Add (new PredefinedPointerOperator (null, Operator.SubtractionMask, TypeManager.int64_type));
- pointer_operators = (PredefinedOperator []) temp.ToArray (typeof (PredefinedOperator));
+ pointer_operators = temp.ToArray ();
}
static void CreateStandardOperatorsTable ()
{
- ArrayList temp = new ArrayList ();
+ var temp = new List<PredefinedOperator> ();
Type bool_type = TypeManager.bool_type;
temp.Add (new PredefinedOperator (TypeManager.int32_type, Operator.ArithmeticMask | Operator.BitwiseMask));
temp.Add (new PredefinedShiftOperator (TypeManager.int64_type, Operator.ShiftMask));
temp.Add (new PredefinedShiftOperator (TypeManager.uint64_type, Operator.ShiftMask));
- standard_operators = (PredefinedOperator []) temp.ToArray (typeof (PredefinedOperator));
+ standard_operators = temp.ToArray ();
}
//
}
}
+ public class ArrayInitializer : ShimExpression
+ {
+ List<Expression> elements;
+
+ public ArrayInitializer (List<Expression> init, Location loc)
+ : base (null)
+ {
+ elements = init;
+ }
+
+ public ArrayInitializer (int count, Location loc)
+ : base (null)
+ {
+ elements = new List<Expression> (count);
+ }
+
+ public ArrayInitializer (Location loc)
+ : this (4, loc)
+ {
+ }
+
+ public void Add (Expression expr)
+ {
+ elements.Add (expr);
+ }
+
+ protected override void CloneTo (CloneContext clonectx, Expression t)
+ {
+ var target = (ArrayInitializer) t;
+
+ target.elements = new List<Expression> (elements.Count);
+ foreach (var element in elements)
+ target.elements.Add (element.Clone (clonectx));
+
+ base.CloneTo (clonectx, t);
+ }
+
+ public int Count {
+ get { return elements.Count; }
+ }
+
+ protected override Expression DoResolve (ResolveContext rc)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public Expression this [int index] {
+ get { return elements [index]; }
+ }
+ }
+
/// <summary>
/// 14.5.10.2: Represents an array creation expression.
/// </summary>
/// initialization data and the other which does not need dimensions
/// specified but where initialization data is mandatory.
/// </remarks>
- public class ArrayCreation : Expression {
+ class ArrayCreation : Expression
+ {
FullNamedExpression requested_base_type;
- ArrayList initializers;
+ ArrayInitializer initializers;
//
// The list of Argument types.
// This is used to construct the `newarray' or constructor signature
//
- protected ArrayList arguments;
+ protected List<Expression> arguments;
protected Type array_element_type;
bool expect_initializers = false;
protected List<Expression> array_data;
- IDictionary bounds;
+ Dictionary<int, int> bounds;
// The number of constants in array initializers
int const_initializers_count;
bool only_constant_initializers;
-
- public ArrayCreation (FullNamedExpression requested_base_type, ArrayList exprs, string rank, ArrayList initializers, Location l)
+
+ public ArrayCreation (FullNamedExpression requested_base_type, List<Expression> exprs, string rank, ArrayInitializer initializers, Location l)
{
this.requested_base_type = requested_base_type;
this.initializers = initializers;
this.rank = rank;
loc = l;
- arguments = new ArrayList (exprs.Count);
-
- foreach (Expression e in exprs) {
- arguments.Add (e);
- num_arguments++;
- }
+ arguments = new List<Expression> (exprs);
+ num_arguments = arguments.Count;
}
- public ArrayCreation (FullNamedExpression requested_base_type, string rank, ArrayList initializers, Location l)
+ public ArrayCreation (FullNamedExpression requested_base_type, string rank, ArrayInitializer initializers, Location l)
{
this.requested_base_type = requested_base_type;
this.initializers = initializers;
ec.Report.Error (248, loc, "Cannot create an array with a negative size");
}
- bool CheckIndices (ResolveContext ec, ArrayList probe, int idx, bool specified_dims, int child_bounds)
+ bool CheckIndices (ResolveContext ec, ArrayInitializer probe, int idx, bool specified_dims, int child_bounds)
{
if (specified_dims) {
- Expression a = (Expression) arguments [idx];
+ Expression a = arguments [idx];
a = a.Resolve (ec);
if (a == null)
return false;
only_constant_initializers = true;
for (int i = 0; i < probe.Count; ++i) {
- object o = probe [i];
- if (o is ArrayList) {
- ArrayList sub_probe = o as ArrayList;
+ var o = probe [i];
+ if (o is ArrayInitializer) {
+ var sub_probe = o as ArrayInitializer;
if (idx + 1 >= dimensions){
ec.Report.Error (623, loc, "Array initializers can only be used in a variable or field initializer. Try using a new expression instead");
return false;
if (!ret)
return false;
} else if (child_bounds > 1) {
- ec.Report.Error (846, ((Expression) o).Location, "A nested array initializer was expected");
+ ec.Report.Error (846, o.Location, "A nested array initializer was expected");
} else {
- Expression element = ResolveArrayElement (ec, (Expression) o);
+ Expression element = ResolveArrayElement (ec, o);
if (element == null)
continue;
for (int i = 0; i < array_data.Count; ++i) {
Expression e = array_data [i];
if (e == null)
- e = Convert.ImplicitConversion (ec, (Expression) initializers [i], array_element_type, loc);
+ e = Convert.ImplicitConversion (ec, initializers [i], array_element_type, loc);
args.Add (new Argument (e.CreateExpressionTree (ec)));
}
public void UpdateIndices ()
{
int i = 0;
- for (ArrayList probe = initializers; probe != null;) {
- if (probe.Count > 0 && probe [0] is ArrayList) {
+ for (var probe = initializers; probe != null;) {
+ if (probe.Count > 0 && probe [0] is ArrayInitializer) {
Expression e = new IntConstant (probe.Count, Location.Null);
arguments.Add (e);
- bounds [i++] = probe.Count;
-
- probe = (ArrayList) probe [0];
+ bounds [i++] = probe.Count;
+
+ probe = (ArrayInitializer) probe[0];
} else {
Expression e = new IntConstant (probe.Count, Location.Null);
// will need to store them in the byte blob later
//
array_data = new List<Expression> ();
- bounds = new System.Collections.Specialized.HybridDictionary ();
+ bounds = new Dictionary<int, int> ();
if (arguments != null)
return CheckIndices (ec, initializers, 0, true, dimensions);
- arguments = new ArrayList ();
+ arguments = new List<Expression> ();
if (!CheckIndices (ec, initializers, 0, false, dimensions))
return false;
//
bool ResolveArrayType (ResolveContext ec)
{
- if (requested_base_type == null) {
- ec.Report.Error (622, loc, "Can only use array initializer expressions to assign to array types. Try using a new expression instead");
- return false;
- }
-
if (requested_base_type is VarExpr) {
ec.Report.Error (820, loc, "An implicitly typed local variable declarator cannot use an array initializer");
return false;
return false;
type = array_type_expr.Type;
+ if (!type.IsArray) {
+ ec.Report.Error (622, loc, "Can only use array initializer expressions to assign to array types. Try using a new expression instead");
+ return false;
+ }
+
array_element_type = TypeManager.GetElementType (type);
dimensions = type.GetArrayRank ();
return null;
for (int i = 0; i < arguments.Count; ++i) {
- Expression e = ((Expression) arguments[i]).Resolve (ec);
+ Expression e = arguments[i].Resolve (ec);
if (e == null)
continue;
for (int i = 0; i < array_data.Count; i++){
- Expression e = (Expression)array_data [i];
+ Expression e = array_data [i];
// Constant can be initialized via StaticInitializer
if (e != null && !(!emitConstants && e is Constant)) {
//
for (int j = dims - 1; j >= 0; j--){
current_pos [j]++;
- if (current_pos [j] < (int) bounds [j])
+ if (current_pos [j] < bounds [j])
break;
current_pos [j] = 0;
}
}
if (array_data == null) {
- Expression arg = (Expression) arguments[0];
+ Expression arg = arguments [0];
object arg_value;
if (arg.GetAttributableValue (ec, arg.Type, out arg_value) && arg_value is int && (int)arg_value == 0) {
value = Array.CreateInstance (array_element_type, 0);
object element_value;
for (int i = 0; i < ret.Length; ++i)
{
- Expression e = (Expression)array_data [i];
+ Expression e = array_data [i];
// Is null when an initializer is optimized (value == predefined value)
if (e == null)
target.requested_base_type = (FullNamedExpression)requested_base_type.Clone (clonectx);
if (arguments != null){
- target.arguments = new ArrayList (arguments.Count);
+ target.arguments = new List<Expression> (arguments.Count);
foreach (Expression e in arguments)
target.arguments.Add (e.Clone (clonectx));
}
- if (initializers != null){
- target.initializers = new ArrayList (initializers.Count);
- foreach (object initializer in initializers)
- if (initializer is ArrayList) {
- ArrayList this_al = (ArrayList)initializer;
- ArrayList al = new ArrayList (this_al.Count);
- target.initializers.Add (al);
- foreach (Expression e in this_al)
- al.Add (e.Clone (clonectx));
- } else {
- target.initializers.Add (((Expression)initializer).Clone (clonectx));
- }
- }
+ if (initializers != null)
+ target.initializers = (ArrayInitializer) initializers.Clone (clonectx);
}
}
//
// Represents an implicitly typed array epxression
//
- public class ImplicitlyTypedArrayCreation : ArrayCreation
+ class ImplicitlyTypedArrayCreation : ArrayCreation
{
- public ImplicitlyTypedArrayCreation (string rank, ArrayList initializers, Location loc)
+ public ImplicitlyTypedArrayCreation (string rank, ArrayInitializer initializers, Location loc)
: base (null, rank, initializers, loc)
{
if (rank.Length > 2) {
public IndexerMethodGroupExpr (Indexers indexers, Location loc)
: base (null, loc)
{
- Methods = (MethodBase []) indexers.Methods.ToArray (typeof (MethodBase));
+ Methods = indexers.Methods.ToArray ();
}
public override string Name {
class Indexers
{
// Contains either property getter or setter
- public ArrayList Methods;
- public ArrayList Properties;
+ public List<MethodBase> Methods;
+ public List<PropertyInfo> Properties;
Indexers ()
{
accessor = property.GetSetMethod (true);
if (Methods == null) {
- Methods = new ArrayList ();
- Properties = new ArrayList ();
+ Methods = new List<MethodBase> ();
+ Properties = new List<PropertyInfo> ();
}
Methods.Add (accessor);
this.loc = argument.Location;
}
- public CollectionElementInitializer (ArrayList arguments, Location loc)
+ public CollectionElementInitializer (List<Expression> arguments, Location loc)
: base (null, new Arguments (arguments.Count))
{
foreach (Expression e in arguments)
Arguments args = new Arguments (2);
args.Add (new Argument (mg.CreateExpressionTree (ec)));
- ArrayList expr_initializers = new ArrayList (arguments.Count);
+ var expr_initializers = new ArrayInitializer (arguments.Count, loc);
foreach (Argument a in arguments)
expr_initializers.Add (a.CreateExpressionTree (ec));
public override Expression CreateExpressionTree (ResolveContext ec)
{
- var expr_initializers = new ArrayList (initializers.Count);
+ var expr_initializers = new ArrayInitializer (initializers.Count, loc);
foreach (Expression e in initializers) {
Expression expr = e.CreateExpressionTree (ec);
if (expr != null)
protected override Expression DoResolve (ResolveContext ec)
{
- ArrayList element_names = null;
+ List<string> element_names = null;
for (int i = 0; i < initializers.Count; ++i) {
Expression initializer = (Expression) initializers [i];
ElementInitializer element_initializer = initializer as ElementInitializer;
if (i == 0) {
if (element_initializer != null) {
- element_names = new ArrayList (initializers.Count);
+ element_names = new List<string> (initializers.Count);
element_names.Add (element_initializer.Name);
} else if (initializer is CompletingExpression){
initializer.Resolve (ec);
if (parameters == null)
return base.CreateExpressionTree (ec);
- var init = new ArrayList (parameters.Count);
+ var init = new ArrayInitializer (parameters.Count, loc);
foreach (Property p in anonymous_type.Properties)
init.Add (new TypeOfMethod (TypeBuilder.GetMethod (type, p.GetBuilder), loc));
- var ctor_args = new ArrayList (Arguments.Count);
+ var ctor_args = new ArrayInitializer (Arguments.Count, loc);
foreach (Argument a in Arguments)
ctor_args.Add (a.CreateExpressionTree (ec));
using System.Reflection;
using System.Reflection.Emit;
using System.Globalization;
-using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
}
}
- public partial class TypeManager
+ partial class TypeManager
{
- static public Type activator_type;
-
public static TypeContainer LookupGenericTypeContainer (Type t)
{
t = DropGenericTypeArguments (t);
// Copyright 2003-2008 Novell, Inc.
//
using System;
-using System.Collections;
using System.Collections.Generic;
using System.Reflection;
//
// Returns the types starting with the given prefix
//
- public ICollection CompletionGetTypesStartingWith (string prefix)
+ public ICollection<string> CompletionGetTypesStartingWith (string prefix)
{
- Hashtable result = null;
+ Dictionary<string, string> result = null;
foreach (Assembly a in referenced_assemblies){
Type [] mtypes = a.GetTypes ();
foreach (Type t in mtypes){
string f = t.FullName;
- if (f.StartsWith (prefix) && (result == null || !result.Contains (f))){
+ if (f.StartsWith (prefix) && (result == null || !result.ContainsKey (f))){
if (result == null)
- result = new Hashtable ();
+ result = new Dictionary<string, string> ();
result [f] = f;
}
}
}
- return result == null ? result : result.Keys;
+ return result == null ? null : result.Keys;
}
protected static void Error_AmbiguousPredefinedType (CompilerContext ctx, Location loc, string name, Type type)
//
// Completes types with the given `prefix' and stores the results in `result'
//
- public void CompletionGetTypesStartingWith (string prefix, Hashtable result)
+ public void CompletionGetTypesStartingWith (string prefix, Dictionary<string, string> result)
{
int l = fullname.Length + 1;
- ICollection res = root.CompletionGetTypesStartingWith (fullname + "." + prefix);
+ var res = root.CompletionGetTypesStartingWith (fullname + "." + prefix);
if (res == null)
return;
if (p != -1)
x = x.Substring (0, p) + "<";
- if (!result.Contains (x))
+ if (!result.ContainsKey (x))
result [x] = x;
}
}
///
/// Looks for extension method in this namespace
///
- public ArrayList LookupExtensionMethod (Type extensionType, ClassOrStruct currentClass, string name)
+ public List<MethodBase> LookupExtensionMethod (Type extensionType, ClassOrStruct currentClass, string name)
{
- ArrayList found = null;
+ List<MethodBase> found = null;
// TODO: problematic
var invocation_assembly = CodeGen.Assembly.Builder;
if (declspaces != null) {
- IEnumerator e = declspaces.Values.GetEnumerator ();
- e.Reset ();
+ var e = declspaces.Values.GetEnumerator ();
while (e.MoveNext ()) {
Class c = e.Current as Class;
if (c == null)
if ((c.ModFlags & Modifiers.METHOD_EXTENSION) == 0)
continue;
- ArrayList res = c.MemberCache.FindExtensionMethods (invocation_assembly, extensionType, name, c != currentClass);
+ var res = c.MemberCache.FindExtensionMethods (invocation_assembly, extensionType, name, c != currentClass);
if (res == null)
continue;
foreach (Type t in external_exmethod_classes) {
MemberCache m = TypeHandle.GetMemberCache (t);
- ArrayList res = m.FindExtensionMethods (invocation_assembly, extensionType, name, true);
+ var res = m.FindExtensionMethods (invocation_assembly, extensionType, name, true);
if (res == null)
continue;
//
public class NamespaceEntry : IMemberContext {
- class UsingEntry {
+ public class UsingEntry {
readonly MemberName name;
Namespace resolved;
}
}
- class UsingAliasEntry {
+ public class UsingAliasEntry {
public readonly string Alias;
public Location Location;
// Namespace using import block
List<UsingAliasEntry> using_aliases;
- ArrayList using_clauses;
+ List<UsingEntry> using_clauses;
public bool DeclarationFound;
// End
static readonly Namespace [] empty_namespaces = new Namespace [0];
Namespace [] namespace_using_table;
- static ArrayList entries = new ArrayList ();
+ static List<NamespaceEntry> entries = new List<NamespaceEntry> ();
public static void Reset ()
{
- entries = new ArrayList ();
+ entries = new List<NamespaceEntry> ();
}
public NamespaceEntry (NamespaceEntry parent, CompilationUnit file, string name)
// Populates the Namespace with some using declarations, used by the
// eval mode.
//
- public void Populate (ArrayList source_using_aliases, ArrayList source_using_clauses)
+ public void Populate (List<UsingAliasEntry> source_using_aliases, List<UsingEntry> source_using_clauses)
{
foreach (UsingAliasEntry uae in source_using_aliases){
if (using_aliases == null)
foreach (UsingEntry ue in source_using_clauses){
if (using_clauses == null)
- using_clauses = new ArrayList ();
+ using_clauses = new List<UsingEntry> ();
using_clauses.Add (ue);
}
// arrays that might already have the same information; Used by the
// C# Eval mode.
//
- public void Extract (ArrayList out_using_aliases, ArrayList out_using_clauses)
+ public void Extract (List<UsingAliasEntry> out_using_aliases, List<UsingEntry> out_using_clauses)
{
if (using_aliases != null){
foreach (UsingAliasEntry uae in using_aliases){
}
if (using_clauses == null) {
- using_clauses = new ArrayList ();
+ using_clauses = new List<UsingEntry> ();
} else {
foreach (UsingEntry old_entry in using_clauses) {
if (name.Equals (old_entry.MemberName)) {
///
public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
{
- ArrayList candidates = null;
+ List<MethodBase> candidates = null;
foreach (Namespace n in GetUsingTable ()) {
- ArrayList a = n.LookupExtensionMethod (extensionType, null, name);
+ var a = n.LookupExtensionMethod (extensionType, null, name);
if (a == null)
continue;
return resolved;
}
- public ICollection CompletionGetTypesStartingWith (string prefix)
+ public ICollection<string> CompletionGetTypesStartingWith (string prefix)
{
- Hashtable result = new Hashtable ();
+ var result = new Dictionary<string, string> ();
for (NamespaceEntry curr_ns = this; curr_ns != null; curr_ns = curr_ns.ImplicitParent){
foreach (Namespace using_ns in GetUsingTable ()){
return namespace_using_table;
}
- ArrayList list = new ArrayList (using_clauses.Count);
+ var list = new List<Namespace> (using_clauses.Count);
foreach (UsingEntry ue in using_clauses) {
Namespace using_ns = ue.Resolve (Doppelganger);
list.Add (using_ns);
}
- namespace_using_table = (Namespace[])list.ToArray (typeof (Namespace));
+ namespace_using_table = list.ToArray ();
return namespace_using_table;
}
using System;
using System.Reflection;
using System.Reflection.Emit;
-using System.Collections;
using System.Text;
namespace Mono.CSharp {
public Expression CreateExpressionTree (BlockContext ec, Location loc)
{
- var initializers = new ArrayList (Count);
+ var initializers = new ArrayInitializer (Count, loc);
foreach (Parameter p in FixedParameters) {
//
// Each parameter expression is stored to local variable
using System.Reflection;
using System.Reflection.Emit;
using System.Diagnostics;
-using System.Collections;
using System.Collections.Generic;
namespace Mono.CSharp {
continue;
value = (string) sl.Converted;
- ArrayList init_args = new ArrayList (2);
+ var init_args = new List<Expression> (2);
init_args.Add (new StringLiteral (value, sl.Location));
init_args.Add (new IntConstant (counter, loc));
init.Add (new CollectionElementInitializer (init_args, loc));
}
}
+ class Tuple<T1, T2>
+ {
+ public Tuple (T1 item1, T2 item2)
+ {
+ Item1 = item1;
+ Item2 = item2;
+ }
+
+ public T1 Item1 { get; private set; }
+ public T2 Item2 { get; private set; }
+ }
+
public class Accessors {
public Accessor get_or_add;
public Accessor set_or_remove;
//
using System;
-using System.Collections;
using System.Reflection;
using System.Reflection.Emit;
/// <summary>
/// There is exactly one instance of this class per type.
/// </summary>
-public sealed class TypeHandle : IMemberContainer {
+sealed class TypeHandle : IMemberContainer {
public readonly IMemberContainer BaseType;
readonly int id = ++next_id;