Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs/mbas
diff options
context:
space:
mode:
authorRafael Teixeira <monoman@gmail.com>2005-08-05 00:55:16 +0400
committerRafael Teixeira <monoman@gmail.com>2005-08-05 00:55:16 +0400
commit113658ab64e452b87435309f61893c273320c221 (patch)
treefbc630563de0a4aa57dd99055b12e8ab75673591 /mcs/mbas
parent7c102be407dfe063b8aee3b448ac91f9dd640b2f (diff)
2005-08-04 Rafael Teixeira <rafaelteixeirabr@hotmail.com>
* statement.cs: Refactored code/fields from Redim to RedimClause so that it works for multiple arrays being redimensioned in the same statement * mb-parser.jay: redim_clauses rule was losing additional items 2005-08-04 Aldo Monteiro <aldo@psl-pr.softwarelivre.org>, Renato Suga <renato@psl-pr.softwarelivre.org> * mb-parser.jay: treatment of opt_type_spec in redim_clause * statement.cs: changed constructor in class RedimClause so that it gets an Expression. Report.Error now emits the line number too for ReDim errors. New attribute in RedimClause: Expression ExprAs svn path=/trunk/mcs/; revision=48020
Diffstat (limited to 'mcs/mbas')
-rw-r--r--mcs/mbas/ChangeLog12
-rw-r--r--mcs/mbas/Test/misc/RedimPreserve.vb49
-rw-r--r--mcs/mbas/mb-parser.jay11
-rw-r--r--mcs/mbas/statement.cs141
4 files changed, 124 insertions, 89 deletions
diff --git a/mcs/mbas/ChangeLog b/mcs/mbas/ChangeLog
index a29b2037eb8..636a65ff659 100644
--- a/mcs/mbas/ChangeLog
+++ b/mcs/mbas/ChangeLog
@@ -1,3 +1,15 @@
+2005-08-04 Rafael Teixeira <rafaelteixeirabr@hotmail.com>
+ * statement.cs: Refactored code/fields from Redim to RedimClause
+ so that it works for multiple arrays being redimensioned in the same statement
+ * mb-parser.jay: redim_clauses rule was losing additional items
+
+2005-08-04 Aldo Monteiro <aldo@psl-pr.softwarelivre.org>,
+ Renato Suga <renato@psl-pr.softwarelivre.org>
+ * mb-parser.jay: treatment of opt_type_spec in redim_clause
+ * statement.cs: changed constructor in class RedimClause so that it gets
+ an Expression. Report.Error now emits the line number too for ReDim
+ errors. New attribute in RedimClause: Expression ExprAs
+
2005-08-04 Maverson Eduardo Schulze Rosa <maverson@gmail.com>
* mb-parser.jay: Fix local static variables initialization
diff --git a/mcs/mbas/Test/misc/RedimPreserve.vb b/mcs/mbas/Test/misc/RedimPreserve.vb
index ca3e93b3b77..52769c5b5b6 100644
--- a/mcs/mbas/Test/misc/RedimPreserve.vb
+++ b/mcs/mbas/Test/misc/RedimPreserve.vb
@@ -5,39 +5,46 @@ Option Compare Text
Imports System
Module RedimPreserve
-
+
Sub DoTest ()
- Dim IntArray(10) As Integer
+ Dim A(10) As Integer
+ Dim B(10) As Integer
Dim I As Integer
Console.WriteLine("Array Size = 10 (Dim)")
For I = 0 To 10
- IntArray(I) = 10 - I
- Console.Write(I)
- Console.Write(" : ")
- Console.WriteLine(IntArray(I))
- Next I
+ A(I) = 10 - I
+ B(I) = I*3
+ Next I
+
+ PrintArrays(A, B)
Console.WriteLine("Array Size = 15 (ReDim Preserve)")
- ReDim Preserve IntArray(15)
+ ReDim Preserve A(15), B(15)
+
+ PrintArrays(A, B)
- For I = 0 To 15
- Console.Write(I)
- Console.Write(" : ")
- Console.WriteLine(IntArray(I))
- Next I
- Console.WriteLine("Array Size = 5 (ReDim Preserve")
+ Console.WriteLine("Array Size = 5 (ReDim Preserve)")
- ReDim Preserve IntArray(5)
-
- For I = 0 To 5
- Console.Write(I)
- Console.Write(" : ")
- Console.WriteLine(IntArray(I))
- Next I
+ ReDim Preserve A(5), B(5)
+
+ PrintArrays(A, B)
+
+ Console.WriteLine("Array Size = 3 (ReDim)")
+
+ ReDim A(3), B(3)
+
+ PrintArrays(A, B)
End Sub
+ Sub PrintArrays(ArrayA() as Integer, ArrayB() as Integer)
+ Dim I As Integer
+ For I = 0 To ArrayA.Length - 1
+ Console.WriteLine("{0} : {1} {2}", I, ArrayA(I), ArrayB(I) )
+ Next I
+ End Sub
+
End Module
diff --git a/mcs/mbas/mb-parser.jay b/mcs/mbas/mb-parser.jay
index c22bfea64c8..a97a2ae03c8 100644
--- a/mcs/mbas/mb-parser.jay
+++ b/mcs/mbas/mb-parser.jay
@@ -2824,12 +2824,11 @@ array_handling_statement
;
redim_statement
- : REDIM opt_preserve redim_clauses
+ : REDIM _mark_ opt_preserve redim_clauses
{
- ArrayList list = (ArrayList) $3;
- ReDim r = new ReDim (list, (bool) $2, lexer.Location);
+ ArrayList list = (ArrayList) $4;
+ ReDim r = new ReDim (list, (bool) $3, (Location)$2);
$$ = r;
-
}
;
@@ -2849,7 +2848,7 @@ redim_clauses
| redim_clauses COMMA redim_clause
{
ArrayList clauses = (ArrayList) ($1);
- clauses.Add ($2);
+ clauses.Add ($3);
$$ = clauses;
}
@@ -2859,7 +2858,7 @@ redim_clause
: invocation_expression opt_type_spec
{
Invocation i = (Invocation) $1;
- RedimClause rc = new RedimClause (i.expr, i.Arguments);
+ RedimClause rc = new RedimClause (i.expr, i.Arguments, (Expression) $2);
$$ = rc;
}
;
diff --git a/mcs/mbas/statement.cs b/mcs/mbas/statement.cs
index 9b669826f1d..3377925d193 100644
--- a/mcs/mbas/statement.cs
+++ b/mcs/mbas/statement.cs
@@ -5459,29 +5459,95 @@ namespace Mono.MonoBASIC {
}
public class RedimClause {
- public Expression Expr;
- public ArrayList NewIndexes;
+ private Expression RedimTarget;
+ private ArrayList NewIndexes;
+ private Expression AsType;
- public RedimClause (Expression e, ArrayList args)
+ private LocalTemporary localTmp = null;
+ private Expression origRedimTarget = null;
+ private StatementExpression ReDimExpr;
+
+ public RedimClause (Expression e, ArrayList args, Expression e_as)
{
if (e is SimpleName)
((SimpleName) e).IsInvocation = false;
if (e is MemberAccess)
((MemberAccess) e).IsInvocation = false;
- Expr = e;
+ RedimTarget = e;
+ NewIndexes = args;
+ AsType = e_as;
+ }
+
+ public void Resolve (EmitContext ec, bool Preserve, Location loc)
+ {
+ RedimTarget = RedimTarget.Resolve (ec);
+
+ if (AsType != null) {
+ Report.Error (30811, "'ReDim' statements can no longer be used to declare array variables");
+ return;
+ }
+
+ if (!RedimTarget.Type.IsArray) {
+ Report.Error (49, "'ReDim' statement requires an array");
+ return;
+ }
+
+ ArrayList args = new ArrayList();
+ foreach (Argument a in NewIndexes) {
+ if (a.Resolve(ec, loc))
+ args.Add (a.Expr);
+ }
+
+ for (int x = 0; x < args.Count; x++) {
+ args[x] = new Binary (Binary.Operator.Addition,
+ (Expression) args[x], new IntLiteral (1), Location.Null);
+ }
+
NewIndexes = args;
+ if (RedimTarget.Type.GetArrayRank() != NewIndexes.Count) {
+ Report.Error (30415, "'ReDim' cannot change the number of dimensions of an array.");
+ return;
+ }
+
+ Type BaseType = RedimTarget.Type.GetElementType();
+ Expression BaseTypeExpr = MonoBASIC.Parser.DecomposeQI(BaseType.FullName.ToString(), Location.Null);
+ ArrayCreation acExpr = new ArrayCreation (BaseTypeExpr, NewIndexes, "", null, Location.Null);
+ if (Preserve)
+ {
+ ExpressionStatement PreserveExpr = null;
+ if (RedimTarget is PropertyGroupExpr) {
+ localTmp = new LocalTemporary (ec, RedimTarget.Type);
+ PropertyGroupExpr pe = RedimTarget as PropertyGroupExpr;
+ origRedimTarget = new PropertyGroupExpr (pe.Properties, pe.Arguments, pe.InstanceExpression, loc);
+ if ((origRedimTarget = origRedimTarget.Resolve (ec)) == null) {
+ Report.Error (-1, "'ReDim' vs PropertyGroup");
+ return;
+ }
+ PreserveExpr = (ExpressionStatement) new Preserve(localTmp, acExpr, loc);
+ } else
+ PreserveExpr = (ExpressionStatement) new Preserve(RedimTarget, acExpr, loc);
+ ReDimExpr = (StatementExpression) new StatementExpression ((ExpressionStatement) new Assign (RedimTarget, PreserveExpr, loc), loc);
+ }
+ else
+ ReDimExpr = (StatementExpression) new StatementExpression ((ExpressionStatement) new Assign (RedimTarget, acExpr, loc), loc);
+ ReDimExpr.Resolve(ec);
}
+
+ public void DoEmit (EmitContext ec)
+ {
+ if (localTmp != null) {
+ origRedimTarget.Emit (ec);
+ localTmp.Store (ec);
+ }
+ ReDimExpr.Emit(ec);
+ }
+
}
public class ReDim : Statement {
ArrayList RedimTargets;
- Type BaseType;
bool Preserve;
- LocalTemporary localTmp = null;
- Expression origRedimTarget = null;
-
- private StatementExpression ReDimExpr;
public ReDim (ArrayList targets, bool opt_preserve, Location l)
{
@@ -5492,64 +5558,15 @@ namespace Mono.MonoBASIC {
public override bool Resolve (EmitContext ec)
{
- Expression RedimTarget;
- ArrayList NewIndexes;
-
- foreach (RedimClause rc in RedimTargets) {
- RedimTarget = rc.Expr;
- NewIndexes = rc.NewIndexes;
- RedimTarget = RedimTarget.Resolve (ec);
-
- if (!RedimTarget.Type.IsArray)
- Report.Error (49, "'ReDim' statement requires an array");
-
- ArrayList args = new ArrayList();
- foreach (Argument a in NewIndexes) {
- if (a.Resolve(ec, loc))
- args.Add (a.Expr);
- }
-
- for (int x = 0; x < args.Count; x++) {
- args[x] = new Binary (Binary.Operator.Addition,
- (Expression) args[x], new IntLiteral (1), Location.Null);
- }
-
- NewIndexes = args;
- if (RedimTarget.Type.GetArrayRank() != args.Count)
- Report.Error (30415, "'ReDim' cannot change the number of dimensions of an array.");
-
- BaseType = RedimTarget.Type.GetElementType();
- Expression BaseTypeExpr = MonoBASIC.Parser.DecomposeQI(BaseType.FullName.ToString(), Location.Null);
- ArrayCreation acExpr = new ArrayCreation (BaseTypeExpr, NewIndexes, "", null, Location.Null);
- // TODO: we are in a foreach we probably can't reuse ReDimExpr, must turn it into an array(list)
- if (Preserve)
- {
- ExpressionStatement PreserveExpr = null;
- if (RedimTarget is PropertyGroupExpr) {
- localTmp = new LocalTemporary (ec, RedimTarget.Type);
- PropertyGroupExpr pe = RedimTarget as PropertyGroupExpr;
- origRedimTarget = new PropertyGroupExpr (pe.Properties, pe.Arguments, pe.InstanceExpression, loc);
- if ((origRedimTarget = origRedimTarget.Resolve (ec)) == null)
- return false;
- PreserveExpr = (ExpressionStatement) new Preserve(localTmp, acExpr, loc);
- } else
- PreserveExpr = (ExpressionStatement) new Preserve(RedimTarget, acExpr, loc);
- ReDimExpr = (StatementExpression) new StatementExpression ((ExpressionStatement) new Assign (RedimTarget, PreserveExpr, loc), loc);
- }
- else
- ReDimExpr = (StatementExpression) new StatementExpression ((ExpressionStatement) new Assign (RedimTarget, acExpr, loc), loc);
- ReDimExpr.Resolve(ec);
- }
+ foreach (RedimClause rc in RedimTargets)
+ rc.Resolve(ec, Preserve, loc);
return true;
}
protected override bool DoEmit (EmitContext ec)
{
- if (localTmp != null) {
- origRedimTarget.Emit (ec);
- localTmp.Store (ec);
- }
- ReDimExpr.Emit(ec);
+ foreach (RedimClause rc in RedimTargets)
+ rc.DoEmit(ec);
return false;
}