Author: sudha
Date: 2005-04-13 02:57:46 -0400 (Wed, 13 Apr 2005)
New Revision: 42889
Modified:
trunk/mcs/mbas/ChangeLog
trunk/mcs/mbas/expression.cs
trunk/mcs/mbas/statement.cs
Log:
Support for late binding (not yet complete, not tested thoroughly)
Modified: trunk/mcs/mbas/ChangeLog
===================================================================
--- trunk/mcs/mbas/ChangeLog 2005-04-13 06:52:42 UTC (rev 42888)
+++ trunk/mcs/mbas/ChangeLog 2005-04-13 06:57:46 UTC (rev 42889)
@@ -1,3 +1,9 @@
+2005-04-12 Satya Sudha K <[EMAIL PROTECTED]>
+ * statement.cs :
+ Introduced a class 'StatementSequence', to translate a
late-binding call to a block of statements
+ * expression.cs :
+ Support for late binding (Not complete yet. Some basic method
invocations work as of now)
+
2005-04-06 Ritvik Mayank <[EMAIL PROTECTED]>
by Sudharsan V <[EMAIL PROTECTED]>
* class.cs: correction for reflecting the correct Line No. in the Error
message
Modified: trunk/mcs/mbas/expression.cs
===================================================================
--- trunk/mcs/mbas/expression.cs 2005-04-13 06:52:42 UTC (rev 42888)
+++ trunk/mcs/mbas/expression.cs 2005-04-13 06:57:46 UTC (rev 42889)
@@ -3556,6 +3556,7 @@
MethodBase method = null;
bool is_base;
bool is_left_hand; // Needed for late bound calls
+ bool is_retval_required; // Needed for late bound calls
static Hashtable method_parameter_cache;
static MemberFilter CompareName;
@@ -3574,6 +3575,7 @@
public Invocation (Expression expr, ArrayList arguments,
Location l)
{
this.expr = expr;
+ this.is_retval_required = false;
Arguments = arguments;
loc = l;
CompareName = new MemberFilter (compare_name_filter);
@@ -3585,6 +3587,15 @@
}
}
+ public bool IsRetvalRequired {
+ get {
+ return is_retval_required;
+ }
+ set {
+ is_retval_required = value;
+ }
+ }
+
/// <summary>
/// Returns the Parameters (a ParameterData interface) for the
/// Method 'mb'
@@ -4386,22 +4397,38 @@
// trigger the invocation
//
Expression expr_to_return = null;
+ Expression temp = null;
if (expr is BaseAccess)
is_base = true;
+ ResolveFlags flags;
if ((ec.ReturnType != null) && (expr.ToString() ==
ec.BlockName)) {
ec.InvokingOwnOverload = true;
- expr = expr.Resolve (ec,
ResolveFlags.MethodGroup);
+ flags = ResolveFlags.MethodGroup;
+ temp = expr.Resolve (ec, flags);
ec.InvokingOwnOverload = false;
}
else
{
ec.InvokingOwnOverload = false;
- expr = expr.Resolve (ec,
ResolveFlags.VariableOrValue | ResolveFlags.MethodGroup);
+ flags = ResolveFlags.VariableOrValue |
ResolveFlags.MethodGroup;
+ temp = expr.Resolve (ec, flags);
}
- if (expr == null)
+
+ if (temp == null) {
+ if (expr is MemberAccess) {
+ MemberAccess m = expr as MemberAccess;
+ if (m.Expr.Type ==
TypeManager.object_type) {
+ StatementSequence etmp = new
StatementSequence (ec.CurrentBlock, loc, expr, Arguments);
+
etmp.GenerateLateBindingStatements();
+ return etmp.Resolve (ec);
+ }
+ }
return null;
+ }
+
+ expr = temp;
if (expr is Invocation) {
// FIXME Calls which return an Array are not
resolved (here or in the grammar)
@@ -6312,8 +6339,11 @@
expr_type, expr_type, AllMemberTypes,
AllBindingFlags |
BindingFlags.NonPublic, Identifier);
- if (lookup == null)
- Error (30456, "'" + expr_type + "' does
not contain a definition for '" + Identifier + "'");
+ if (lookup == null) {
+ if (expr_type !=
TypeManager.object_type)
+ Error (30456, "'" + expr_type +
"' does not contain a definition for '" + Identifier + "'");
+ return null;
+ }
else
{
if ((expr_type != ec.ContainerType) &&
Modified: trunk/mcs/mbas/statement.cs
===================================================================
--- trunk/mcs/mbas/statement.cs 2005-04-13 06:52:42 UTC (rev 42888)
+++ trunk/mcs/mbas/statement.cs 2005-04-13 06:57:46 UTC (rev 42889)
@@ -6,6 +6,7 @@
// Martin Baulig ([EMAIL PROTECTED])
// Anirban Bhattacharjee ([EMAIL PROTECTED])
// Manjula GHM ([EMAIL PROTECTED])
+// Satya Sudha K ([EMAIL PROTECTED])
//
// (C) 2001, 2002 Ximian, Inc.
//
@@ -2689,6 +2690,13 @@
//
CaseInsensitiveHashtable local_builders;
+ // to hold names of variables required for late binding
+ public const string lateBindingArgs = "1_LBArgs";
+ public const string lateBindingArgNames = "1_LBArgsNames";
+ public const string lateBindingCopyBack = "1_LBCopyBack";
+
+ bool isLateBindingRequired = false;
+
bool used = false;
static int id;
@@ -2725,6 +2733,21 @@
{
if (parent != null)
parent.AddChild (this);
+ else {
+ // Top block
+ // Add variables that may be required for late
binding
+ variables = new CaseInsensitiveHashtable ();
+ ArrayList rank_specifier = new ArrayList ();
+ ArrayList element = new ArrayList ();
+ element.Add (new EmptyExpression ());
+ rank_specifier.Add (element);
+ Expression e =
Mono.MonoBASIC.Parser.DecomposeQI ("System.Object[]", start);
+ AddVariable (e, Block.lateBindingArgs, null,
start);
+ e = Mono.MonoBASIC.Parser.DecomposeQI
("System.String[]", start);
+ AddVariable (e, Block.lateBindingArgNames,
null, start);
+ e = Mono.MonoBASIC.Parser.DecomposeQI
("System.Boolean[]", start);
+ AddVariable (e, Block.lateBindingCopyBack,
null, start);
+ }
this.Parent = parent;
this.Implicit = implicit_block;
@@ -2736,6 +2759,15 @@
statements = new ArrayList ();
}
+ public bool IsLateBindingRequired {
+ get {
+ return isLateBindingRequired;
+ }
+ set {
+ isLateBindingRequired = true;
+ }
+ }
+
public int ID {
get {
return this_id;
@@ -3129,6 +3161,14 @@
foreach (DictionaryEntry de in variables){
string name = (string) de.Key;
+ /*
+ if (!isLateBindingRequired) {
+ if (name.Equals
(Block.lateBindingArgs) ||
+ name.Equals
(Block.lateBindingArgNames) ||
+ name.Equals
(Block.lateBindingCopyBack))
+ continue;
+ }
+ */
VariableInfo vi = (VariableInfo)
de.Value;
if (vi.VariableType == null)
@@ -3210,13 +3250,14 @@
bool ok = true;
ec.CurrentBlock = this;
+
+ if (!variables_initialized)
+ UpdateVariableInfo (ec);
+
ec.StartFlowBranching (this);
Report.Debug (1, "RESOLVE BLOCK", StartLocation,
ec.CurrentBranching);
- if (!variables_initialized)
- UpdateVariableInfo (ec);
-
ArrayList new_statements = new ArrayList ();
bool unreachable = false, warning_shown = false;
@@ -3226,7 +3267,6 @@
warning_shown = true;
Warning_DeadCodeFound (s.loc);
}
-
continue;
}
@@ -3288,6 +3328,128 @@
}
}
+ public class StatementSequence : Expression {
+ Block stmtBlock;
+ ArrayList args;
+ Expression expr;
+
+ public StatementSequence (Block parent, Location loc,
Expression expr)
+ : this (parent, loc, expr, null)
+ { }
+
+ public StatementSequence (Block parent, Location loc,
Expression expr, ArrayList a)
+ {
+ stmtBlock = new Block (parent);
+ args = a;
+ this.expr = expr;
+ stmtBlock.IsLateBindingRequired = true;
+ this.loc = loc;
+ }
+ public Block StmtBlock {
+ get {
+ return stmtBlock;
+ }
+ }
+
+ public override Expression DoResolve (EmitContext ec)
+ {
+ if (!stmtBlock.Resolve (ec))
+ return null;
+ eclass = ExprClass.Value;
+ type = TypeManager.object_type;
+ return this;
+ }
+
+ public void GenerateLateBindingStatements ()
+ {
+ int argCount = 0;
+ // Arguments for call
Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall
+ ArrayList invocationArgs = new ArrayList ();
+ invocationArgs.Add (new Argument
(((MemberAccess)expr).Expr, Argument.AType.Expression));
+ invocationArgs.Add (new Argument (NullLiteral.Null,
Argument.AType.Expression));
+ invocationArgs.Add (new Argument (new StringLiteral
(((MemberAccess)expr).Identifier), Argument.AType.Expression));
+ // __LateBindingArgs = new Object () {arg1, arg2 ...}
+ ArrayList arrayInitializers = new ArrayList ();
+ ArrayList originalArgs = new ArrayList ();
+ if (args != null) {
+ //arrayInitializers = new ArrayList ();
+ argCount = args.Count;
+ foreach (Argument a in args) {
+ arrayInitializers.Add (a.Expr);
+ originalArgs.Add (a.Expr);
+ }
+ }
+
+ ArrayCreation new_expr = new ArrayCreation
(Parser.DecomposeQI ("System.Object", loc), "[]", arrayInitializers, loc);
+ Assign assign_stmt = null;
+
+ LocalVariableReference v1 = new LocalVariableReference
(stmtBlock, Block.lateBindingArgs, loc);
+ assign_stmt = new Assign (v1, new_expr, loc);
+ stmtBlock.AddStatement (new StatementExpression
((ExpressionStatement) assign_stmt, loc));
+ invocationArgs.Add (new Argument (v1,
Argument.AType.Expression));
+
+ // __LateBindingArgNames = nothing
+ //LocalVariableReference v2 = new
LocalVariableReference (stmtBlock, Block.lateBindingArgNames, loc);
+ //assign_stmt = new Assign (v2, NullLiteral.Null, loc);
+ //stmtBlock.AddStatement (new StatementExpression
((ExpressionStatement) assign_stmt, loc));
+
+ invocationArgs.Add (new Argument (NullLiteral.Null,
Argument.AType.Expression));
+
+ // __LateBindingCopyBack = new Boolean (no_of_args) {}
+ bool isCopyBackRequired = false;
+ for (int i = 0; i < argCount; i++) {
+ if (!(((Argument)args[i]).Expr is Constant))
+ isCopyBackRequired = true;
+ }
+
+ LocalVariableReference v3 = new LocalVariableReference
(stmtBlock, Block.lateBindingCopyBack, loc);
+ if (isCopyBackRequired) {
+ ArrayList rank_specifier = new ArrayList ();
+ rank_specifier.Add (new IntLiteral (argCount));
+ arrayInitializers = new ArrayList ();
+ for (int i = 0; i < argCount; i++) {
+ if (((Argument)args[i]).Expr is
Constant)
+ arrayInitializers.Add (new
BoolLiteral (false));
+ else
+ arrayInitializers.Add (new
BoolLiteral (true));
+ }
+
+ new_expr = new ArrayCreation
(Parser.DecomposeQI ("System.Boolean", loc), "[]", arrayInitializers, loc);
+ assign_stmt = new Assign (v3, new_expr, loc);
+ stmtBlock.AddStatement (new StatementExpression
((ExpressionStatement) assign_stmt, loc));
+ invocationArgs.Add (new Argument (v3,
Argument.AType.Expression));
+ } else {
+ invocationArgs.Add (new Argument
(NullLiteral.Null, Argument.AType.Expression));
+ }
+
+ Expression etmp = Parser.DecomposeQI
("Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall", loc);
+ Invocation inv_stmt = new Invocation (etmp,
invocationArgs, Location.Null);
+ stmtBlock.AddStatement (new StatementExpression
((ExpressionStatement) inv_stmt, loc));
+
+ for (int i = 0; i< argCount; i ++) {
+ Expression thisArg = (Expression) originalArgs
[i];
+ if (thisArg is Constant)
+ continue;
+ Expression intExpr = new IntLiteral (i);
+ ArrayList argsLocal = new ArrayList ();
+ argsLocal.Add (new Argument (intExpr,
Argument.AType.Expression));
+ Expression indexExpr = new Invocation (new
SimpleName (Block.lateBindingCopyBack, loc), argsLocal, loc);
+ Expression varRef = (Expression) (originalArgs
[i]);
+ Expression value = new Invocation (new
SimpleName (Block.lateBindingArgs, loc), argsLocal, loc);
+ assign_stmt = new Assign (varRef, value, loc);
+ Expression boolExpr = new Binary
(Binary.Operator.Inequality, indexExpr, new BoolLiteral (false), loc);
+ Statement ifStmt = new If (boolExpr, new
StatementExpression ((ExpressionStatement) assign_stmt, loc), loc);
+ stmtBlock.AddStatement (ifStmt);
+ }
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ stmtBlock.Emit (ec);
+ ec.ig.Emit (OpCodes.Ldloc_0);
+ }
+ }
+
public class SwitchLabel {
Expression label;
object converted;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches