+2005-01-27 Marek Safar <marek.safar@seznam.cz>
+
+ * expression.cs (Indirection): Implemented IVariable interface
+ to support indirection in AddressOf operator.
+ (PointerArithmetic.Emit): Add optimalization for case where
+ result can be precomputed.
+
2005-01-26 Martin Baulig <martin@ximian.com>
* class.cs (TypeContainer.AttributeTargets): Return the correct
}
IVariable variable = Expr as IVariable;
- if (!ec.InFixedInitializer && ((variable == null) || !variable.VerifyFixed (false))) {
+ bool is_fixed = variable != null && variable.VerifyFixed (false);
+
+ if (!ec.InFixedInitializer && !is_fixed) {
Error (212, "You can only take the address of an unfixed expression inside " +
"of a fixed statement initializer");
return null;
}
- if (ec.InFixedInitializer && ((variable != null) && variable.VerifyFixed (false))) {
+ if (ec.InFixedInitializer && is_fixed) {
Error (213, "You can not fix an already fixed expression");
return null;
}
// after semantic analysis (this is so we can take the address
// of an indirection).
//
- public class Indirection : Expression, IMemoryLocation, IAssignMethod {
+ public class Indirection : Expression, IMemoryLocation, IAssignMethod, IVariable {
Expression expr;
LocalTemporary temporary;
bool prepared;
{
return "*(" + expr + ")";
}
+
+ #region IVariable Members
+
+ public VariableInfo VariableInfo {
+ get {
+ return null;
+ }
+ }
+
+ public bool VerifyFixed (bool is_expression)
+ {
+ return true;
+ }
+
+ #endregion
}
/// <summary>
//
left.Emit (ec);
ig.Emit (OpCodes.Conv_I);
- right.Emit (ec);
- if (size != 1){
- if (size == 0)
- ig.Emit (OpCodes.Sizeof, element);
- else
- IntLiteral.EmitInt (ig, size);
- if (rtype == TypeManager.int64_type)
- ig.Emit (OpCodes.Conv_I8);
- else if (rtype == TypeManager.uint64_type)
- ig.Emit (OpCodes.Conv_U8);
- ig.Emit (OpCodes.Mul);
+
+ Constant right_const = right as Constant;
+ if (right_const != null && size != 0) {
+ Expression ex = ConstantFold.BinaryFold (ec, Binary.Operator.Multiply, new IntConstant (size), right_const, loc);
+ if (ex == null)
+ return;
+ ex.Emit (ec);
+ } else {
+ right.Emit (ec);
+ if (size != 1){
+ if (size == 0)
+ ig.Emit (OpCodes.Sizeof, element);
+ else
+ IntLiteral.EmitInt (ig, size);
+ if (rtype == TypeManager.int64_type)
+ ig.Emit (OpCodes.Conv_I8);
+ else if (rtype == TypeManager.uint64_type)
+ ig.Emit (OpCodes.Conv_U8);
+ ig.Emit (OpCodes.Mul);
+ }
}
if (rtype == TypeManager.int64_type || rtype == TypeManager.uint64_type)