// Marek Safar (marek.safar@seznam.cz)
//
// Copyright 2001 Ximian, Inc.
+// Copyright 2011 Xamarin Inc
//
//
// Notice that during parsing we create objects of type Literal, but the
using System.Reflection.Emit;
#endif
-namespace Mono.CSharp {
+namespace Mono.CSharp
+{
+ public interface ILiteralConstant
+ {
+#if FULL_AST
+ char[] ParsedValue { get; set; }
+#endif
+ }
//
// The null literal
{
}
- public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec t, bool expl)
+ public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec t, bool expl)
{
if (t.IsGenericParameter) {
ec.Report.Error(403, loc,
return;
}
- if (TypeManager.IsValueType (t)) {
+ if (TypeSpec.IsValueType (t)) {
ec.Report.Error(37, loc, "Cannot convert null to `{0}' because it is a value type",
- TypeManager.CSharpName(t));
+ t.GetSignatureForError ());
return;
}
- base.Error_ValueCannotBeConverted (ec, loc, t, expl);
+ base.Error_ValueCannotBeConverted (ec, t, expl);
}
public override string GetValueAsLiteral ()
}
}
- //
- // A null literal in a pointer context
- //
- class NullPointer : NullLiteral {
- public NullPointer (Location loc):
- base (loc)
- {
- type = TypeManager.object_type;
- }
-
- public override void Emit (EmitContext ec)
- {
- //
- // Emits null pointer
- //
- ec.Emit (OpCodes.Ldc_I4_0);
- ec.Emit (OpCodes.Conv_U);
- }
- }
-
- public class BoolLiteral : BoolConstant {
- public BoolLiteral (BuildinTypes types, bool val, Location loc)
+ public class BoolLiteral : BoolConstant, ILiteralConstant
+ {
+ public BoolLiteral (BuiltinTypes types, bool val, Location loc)
: base (types, val, loc)
{
}
public override bool IsLiteral {
get { return true; }
}
+
+#if FULL_AST
+ public char[] ParsedValue { get; set; }
+#endif
+
+ public override object Accept (StructuralVisitor visitor)
+ {
+ return visitor.Visit (this);
+ }
}
- public class CharLiteral : CharConstant {
- public CharLiteral (BuildinTypes types, char c, Location loc)
+ public class CharLiteral : CharConstant, ILiteralConstant
+ {
+ public CharLiteral (BuiltinTypes types, char c, Location loc)
: base (types, c, loc)
{
}
public override bool IsLiteral {
get { return true; }
}
+
+#if FULL_AST
+ public char[] ParsedValue { get; set; }
+#endif
+
+ public override object Accept (StructuralVisitor visitor)
+ {
+ return visitor.Visit (this);
+ }
}
- public class IntLiteral : IntConstant {
- public IntLiteral (BuildinTypes types, int l, Location loc)
+ public class IntLiteral : IntConstant, ILiteralConstant
+ {
+ public IntLiteral (BuiltinTypes types, int l, Location loc)
: base (types, l, loc)
{
}
//
// The 0 literal can be converted to an enum value
//
- if (Value == 0 && TypeManager.IsEnumType (type)) {
+ if (Value == 0 && type.IsEnum) {
Constant c = ConvertImplicitly (EnumSpec.GetUnderlyingType (type));
if (c == null)
return null;
public override bool IsLiteral {
get { return true; }
}
+
+#if FULL_AST
+ public char[] ParsedValue { get; set; }
+#endif
+
+ public override object Accept (StructuralVisitor visitor)
+ {
+ return visitor.Visit (this);
+ }
}
- public class UIntLiteral : UIntConstant {
- public UIntLiteral (BuildinTypes types, uint l, Location loc)
+ public class UIntLiteral : UIntConstant, ILiteralConstant
+ {
+ public UIntLiteral (BuiltinTypes types, uint l, Location loc)
: base (types, l, loc)
{
}
public override bool IsLiteral {
get { return true; }
}
+
+#if FULL_AST
+ public char[] ParsedValue { get; set; }
+#endif
+
+ public override object Accept (StructuralVisitor visitor)
+ {
+ return visitor.Visit (this);
+ }
}
-
- public class LongLiteral : LongConstant {
- public LongLiteral (BuildinTypes types, long l, Location loc)
+
+ public class LongLiteral : LongConstant, ILiteralConstant
+ {
+ public LongLiteral (BuiltinTypes types, long l, Location loc)
: base (types, l, loc)
{
}
public override bool IsLiteral {
get { return true; }
}
+
+#if FULL_AST
+ public char[] ParsedValue { get; set; }
+#endif
+
+ public override object Accept (StructuralVisitor visitor)
+ {
+ return visitor.Visit (this);
+ }
}
- public class ULongLiteral : ULongConstant {
- public ULongLiteral (BuildinTypes types, ulong l, Location loc)
+ public class ULongLiteral : ULongConstant, ILiteralConstant
+ {
+ public ULongLiteral (BuiltinTypes types, ulong l, Location loc)
: base (types, l, loc)
{
}
public override bool IsLiteral {
get { return true; }
}
+
+#if FULL_AST
+ public char[] ParsedValue { get; set; }
+#endif
+
+ public override object Accept (StructuralVisitor visitor)
+ {
+ return visitor.Visit (this);
+ }
}
-
- public class FloatLiteral : FloatConstant {
- public FloatLiteral (BuildinTypes types, float f, Location loc)
+ public class FloatLiteral : FloatConstant, ILiteralConstant
+ {
+ public FloatLiteral (BuiltinTypes types, float f, Location loc)
: base (types, f, loc)
{
}
get { return true; }
}
+#if FULL_AST
+ public char[] ParsedValue { get; set; }
+#endif
+
+ public override object Accept (StructuralVisitor visitor)
+ {
+ return visitor.Visit (this);
+ }
}
- public class DoubleLiteral : DoubleConstant {
- public DoubleLiteral (BuildinTypes types, double d, Location loc)
+ public class DoubleLiteral : DoubleConstant, ILiteralConstant
+ {
+ public DoubleLiteral (BuiltinTypes types, double d, Location loc)
: base (types, d, loc)
{
}
- public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl)
+ public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec target, bool expl)
{
- if (target.BuildinType == BuildinTypeSpec.Type.Float) {
+ if (target.BuiltinType == BuiltinTypeSpec.Type.Float) {
Error_664 (ec, loc, "float", "f");
return;
}
- if (target.BuildinType == BuildinTypeSpec.Type.Decimal) {
+ if (target.BuiltinType == BuiltinTypeSpec.Type.Decimal) {
Error_664 (ec, loc, "decimal", "m");
return;
}
- base.Error_ValueCannotBeConverted (ec, loc, target, expl);
+ base.Error_ValueCannotBeConverted (ec, target, expl);
}
static void Error_664 (ResolveContext ec, Location loc, string type, string suffix)
get { return true; }
}
+#if FULL_AST
+ public char[] ParsedValue { get; set; }
+#endif
+
+ public override object Accept (StructuralVisitor visitor)
+ {
+ return visitor.Visit (this);
+ }
}
- public class DecimalLiteral : DecimalConstant {
- public DecimalLiteral (BuildinTypes types, decimal d, Location loc)
+ public class DecimalLiteral : DecimalConstant, ILiteralConstant
+ {
+ public DecimalLiteral (BuiltinTypes types, decimal d, Location loc)
: base (types, d, loc)
{
}
public override bool IsLiteral {
get { return true; }
}
+
+#if FULL_AST
+ public char[] ParsedValue { get; set; }
+#endif
+
+ public override object Accept (StructuralVisitor visitor)
+ {
+ return visitor.Visit (this);
+ }
}
- public class StringLiteral : StringConstant {
- public StringLiteral (BuildinTypes types, string s, Location loc)
+ public class StringLiteral : StringConstant, ILiteralConstant
+ {
+ public StringLiteral (BuiltinTypes types, string s, Location loc)
: base (types, s, loc)
{
}
get { return true; }
}
+#if FULL_AST
+ public char[] ParsedValue { get; set; }
+#endif
+
+ public override object Accept (StructuralVisitor visitor)
+ {
+ return visitor.Visit (this);
+ }
}
}