From 8d510ba7f34bbe25a5c6df1046b15bf94ead6acb Mon Sep 17 00:00:00 2001 From: Ravi Pratap M Date: Sun, 18 Nov 2001 10:17:16 +0000 Subject: [PATCH] 2001-11-18 Ravi Pratap * expression.cs (ArrayCreation::ValidateInitializers): Update to perform some type checking etc. 2001-11-17 Ravi Pratap * expression.cs (ArrayCreation::ValidateInitializers): Implement bits to provide dimension info is user skips doing that. Update second constructor to store the rank correctly. 2001-11-16 Ravi Pratap * expression.cs (ArrayCreation::ValidateInitializers): Poke around and try to implement. * ../errors/cs0150.cs : Add. * ../errors/cs0178.cs : Add. svn path=/trunk/mcs/; revision=1377 --- mcs/mcs/ChangeLog | 21 ++++++++ mcs/mcs/enum.cs | 1 + mcs/mcs/expression.cs | 110 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 130 insertions(+), 2 deletions(-) diff --git a/mcs/mcs/ChangeLog b/mcs/mcs/ChangeLog index 8aa7f30ccb3..13911a43142 100755 --- a/mcs/mcs/ChangeLog +++ b/mcs/mcs/ChangeLog @@ -1,3 +1,24 @@ +2001-11-18 Ravi Pratap + + * expression.cs (ArrayCreation::ValidateInitializers): Update to perform + some type checking etc. + +2001-11-17 Ravi Pratap + + * expression.cs (ArrayCreation::ValidateInitializers): Implement + bits to provide dimension info is user skips doing that. + + Update second constructor to store the rank correctly. + +2001-11-16 Ravi Pratap + + * expression.cs (ArrayCreation::ValidateInitializers): Poke around + and try to implement. + + * ../errors/cs0150.cs : Add. + + * ../errors/cs0178.cs : Add. + 2001-11-16 Miguel de Icaza * statement.cs: Implement foreach on multi-dimensional arrays. diff --git a/mcs/mcs/enum.cs b/mcs/mcs/enum.cs index bf7a3b1de34..5d7f2509619 100755 --- a/mcs/mcs/enum.cs +++ b/mcs/mcs/enum.cs @@ -2,6 +2,7 @@ // enum.cs: Enum handling. // // Author: Miguel de Icaza (miguel@gnu.org) +// Ravi Pratap (ravi@ximian.com) // // Licensed under the terms of the GNU GPL // diff --git a/mcs/mcs/expression.cs b/mcs/mcs/expression.cs index b59a31da999..5cf7fdb8654 100755 --- a/mcs/mcs/expression.cs +++ b/mcs/mcs/expression.cs @@ -2891,6 +2891,8 @@ namespace CIR { bool IsBuiltinType = false; + int dimensions = 0; + public ArrayCreation (string requested_type, ArrayList exprs, string rank, ArrayList initializers, Location l) { @@ -2909,9 +2911,14 @@ namespace CIR { public ArrayCreation (string requested_type, string rank, ArrayList initializers, Location l) { RequestedType = requested_type; - Rank = rank; Initializers = initializers; loc = l; + + Rank = rank.Substring (0, rank.LastIndexOf ("[")); + + string tmp = rank.Substring (rank.LastIndexOf ("[")); + + dimensions = tmp.Length - 1; } public static string FormArrayType (string base_type, int idx_count, string rank) @@ -2943,12 +2950,111 @@ namespace CIR { return val.Substring (0, val.LastIndexOf ("[")); } + + void error178 () + { + Report.Error (178, loc, "Incorrectly structured array initializer"); + } + + bool ValidateInitializers (EmitContext ec) + { + if (Initializers == null) + return true; + + Type underlying_type = ec.TypeContainer.LookupType (RequestedType, false); + + ArrayList probe = Initializers; + + if (Arguments != null) { + for (int i = 0; i < Arguments.Count; i++) { + Argument a = (Argument) Arguments [i]; + + Expression e = Expression.Reduce (ec, a.Expr); + + if (!(e is Literal)) { + Report.Error (150, loc, "A constant value is expected"); + return false; + } + + int value = (int) ((Literal) e).GetValue (); + if (probe == null) { + error178 (); + return false; + } + + if (value != probe.Count) { + error178 (); + return false; + } + + if (probe [0] is ArrayList) + probe = (ArrayList) probe [0]; + else { + for (int j = 0; j < probe.Count; ++j) { + Expression tmp = (Expression) probe [j]; + + tmp = tmp.Resolve (ec); + + Expression conv = ConvertImplicitRequired (ec, tmp, + underlying_type, loc); + + if (conv == null) + return false; + } + + probe = null; + } + } + + } else { + // + // Here is where we update dimension info in the case + // that the user skips doing that + // + + Arguments = new ArrayList (); + + for (probe = Initializers; probe != null; ) { + Expression e = new IntLiteral (probe.Count); + + Arguments.Add (new Argument (e, Argument.AType.Expression)); + + if (probe [0] is ArrayList) + probe = (ArrayList) probe [0]; + else { + for (int j = 0; j < probe.Count; ++j) { + Expression tmp = (Expression) probe [j]; + + tmp = tmp.Resolve (ec); + + Expression conv = ConvertImplicitRequired (ec, tmp, + underlying_type, loc); + + if (conv == null) + return false; + } + + probe = null; + } + } + + if (Arguments.Count != dimensions) { + error178 (); + return false; + } + } + return true; + } + public override Expression DoResolve (EmitContext ec) { int arg_count; - + + if (!ValidateInitializers (ec)) + return null; + if (Arguments == null) arg_count = 0; else -- 2.25.1