//
using System;
-using System.Collections;
+using System.Collections.Generic;
using System.Reflection.Emit;
namespace Mono.CSharp
//
// A scope type context, it can be inflated for generic types
//
- Type CurrentType { get; }
+ TypeSpec CurrentType { get; }
//
// A scope type parameters either VAR or MVAR
TypeParameter[] CurrentTypeParameters { get; }
//
- // A type definition of the type context. For partial types definition use
+ // A member definition of the context. For partial types definition use
// CurrentTypeDefinition.PartialContainer otherwise the context is local
//
- // TODO: CurrentType.Definition
- //
- TypeContainer CurrentTypeDefinition { get; }
+ MemberCore CurrentMemberDefinition { get; }
bool IsObsolete { get; }
bool IsUnsafe { get; }
bool IsStatic { get; }
+ bool HasUnresolvedConstraints { get; }
string GetSignatureForError ();
- ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc);
- FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104);
+ ExtensionMethodGroupExpr LookupExtensionMethod (TypeSpec extensionType, string name, int arity, Location loc);
+ FullNamedExpression LookupNamespaceOrType (string name, int arity, Location loc, bool ignore_cs0104);
FullNamedExpression LookupNamespaceAlias (string name);
+
+ CompilerContext Compiler { get; }
}
//
public TypeInferenceContext ReturnTypeInference;
- Type return_type;
+ TypeSpec return_type;
/// <summary>
/// The location where return has to jump to return the
/// </summary>
public bool HasReturnLabel;
- public BlockContext (IMemberContext mc, ExplicitBlock block, Type returnType)
+ public BlockContext (IMemberContext mc, ExplicitBlock block, TypeSpec returnType)
: base (mc)
{
if (returnType == null)
HasReturnLabel = true;
}
- public Type ReturnType {
+ public TypeSpec ReturnType {
get { return return_type; }
}
}
//
InferReturnType = 1 << 23,
- OmitDebuggingInfo = 1 << 24
+ OmitDebuggingInfo = 1 << 24,
+
+ ExpressionTreeConversion = 1 << 25,
+
+ InvokeSpecialName = 1 << 26
}
// utility helper for CheckExpr, UnCheckExpr, Checked and Unchecked statements
oldval = ec.flags & mask;
ec.flags = (ec.flags & invmask) | (val & mask);
- if ((mask & Options.ProbingMode) != 0)
- Report.DisableReporting ();
+// if ((mask & Options.ProbingMode) != 0)
+// ec.Report.DisableReporting ();
}
public void Dispose ()
{
- if ((invmask & Options.ProbingMode) == 0)
- Report.EnableReporting ();
+// if ((invmask & Options.ProbingMode) == 0)
+// ec.Report.EnableReporting ();
ec.flags = (ec.flags & invmask) | oldval;
}
public ResolveContext (IMemberContext mc)
{
+ if (mc == null)
+ throw new ArgumentNullException ();
+
MemberContext = mc;
//
flags |= options;
}
+ public CompilerContext Compiler {
+ get { return MemberContext.Compiler; }
+ }
+
public virtual FlowBranching CurrentBranching {
get { return null; }
}
get { return CurrentAnonymousMethod as Iterator; }
}
- public Type CurrentType {
+ public TypeSpec CurrentType {
get { return MemberContext.CurrentType; }
}
get { return MemberContext.CurrentTypeParameters; }
}
- public TypeContainer CurrentTypeDefinition {
- get { return MemberContext.CurrentTypeDefinition; }
+ public MemberCore CurrentMemberDefinition {
+ get { return MemberContext.CurrentMemberDefinition; }
}
public bool ConstantCheckState {
get { return (flags & Options.DoFlowAnalysis) != 0; }
}
+ public bool HasUnresolvedConstraints {
+ get { return false; }
+ }
+
public bool IsInProbingMode {
get { return (flags & Options.ProbingMode) != 0; }
}
return (this.flags & options) != 0;
}
+ public Report Report {
+ get {
+ return Compiler.Report;
+ }
+ }
+
// Temporarily set all the given flags to the given value. Should be used in an 'using' statement
public FlagsHandle Set (Options options)
{
return new FlagsHandle (this, options, enable ? options : 0);
}
- public FlagsHandle WithFlowAnalysis (bool do_flow_analysis, bool omit_struct_analysis)
- {
- Options newflags =
- (do_flow_analysis ? Options.DoFlowAnalysis : 0) |
- (omit_struct_analysis ? Options.OmitStructFlowAnalysis : 0);
- return new FlagsHandle (this, Options.DoFlowAnalysis | Options.OmitStructFlowAnalysis, newflags);
- }
-
#region IMemberContext Members
public string GetSignatureForError ()
get { return HasSet (Options.UnsafeScope) || MemberContext.IsUnsafe; }
}
- public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
+ public ExtensionMethodGroupExpr LookupExtensionMethod (TypeSpec extensionType, string name, int arity, Location loc)
{
- return MemberContext.LookupExtensionMethod (extensionType, name, loc);
+ return MemberContext.LookupExtensionMethod (extensionType, name, arity, loc);
}
- public FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104)
+ public FullNamedExpression LookupNamespaceOrType (string name, int arity, Location loc, bool ignore_cs0104)
{
- return MemberContext.LookupNamespaceOrType (name, loc, ignore_cs0104);
+ return MemberContext.LookupNamespaceOrType (name, arity, loc, ignore_cs0104);
}
public FullNamedExpression LookupNamespaceAlias (string name)
//
public class CloneContext
{
- Hashtable block_map = new Hashtable ();
- Hashtable variable_map;
+ Dictionary<Block, Block> block_map = new Dictionary<Block, Block> ();
+ Dictionary<LocalInfo, LocalInfo> variable_map;
public void AddBlockMap (Block from, Block to)
{
- if (block_map.Contains (from))
+ if (block_map.ContainsKey (from))
return;
block_map[from] = to;
}
public Block LookupBlock (Block from)
{
- Block result = (Block) block_map[from];
-
- if (result == null) {
+ Block result;
+ if (!block_map.TryGetValue (from, out result)) {
result = (Block) from.Clone (this);
- block_map[from] = result;
+ block_map [from] = result;
}
return result;
///
public Block RemapBlockCopy (Block from)
{
- Block mapped_to = (Block) block_map[from];
- if (mapped_to == null)
+ Block mapped_to;
+ if (!block_map.TryGetValue (from, out mapped_to))
return from;
return mapped_to;
public void AddVariableMap (LocalInfo from, LocalInfo to)
{
if (variable_map == null)
- variable_map = new Hashtable ();
-
- if (variable_map.Contains (from))
+ variable_map = new Dictionary<LocalInfo, LocalInfo> ();
+ else if (variable_map.ContainsKey (from))
return;
+
variable_map[from] = to;
}
public LocalInfo LookupVariable (LocalInfo from)
{
- LocalInfo result = (LocalInfo) variable_map[from];
-
- if (result == null)
+ try {
+ return variable_map[from];
+ } catch (KeyNotFoundException) {
throw new Exception ("LookupVariable: looking up a variable that has not been registered yet");
+ }
+ }
+ }
- return result;
+ //
+ // Main compiler context
+ //
+ public class CompilerContext
+ {
+ readonly Report report;
+
+ public CompilerContext (Report report)
+ {
+ this.report = report;
+ }
+
+ public bool IsRuntimeBinder { get; set; }
+
+ public Report Report {
+ get { return report; }
+ }
+
+ //public PredefinedAttributes PredefinedAttributes {
+ // get { throw new NotImplementedException (); }
+ //}
+ }
+
+ //
+ // Generic code emitter context
+ //
+ public class BuilderContext
+ {
+ [Flags]
+ public enum Options
+ {
+ /// <summary>
+ /// This flag tracks the `checked' state of the compilation,
+ /// it controls whether we should generate code that does overflow
+ /// checking, or if we generate code that ignores overflows.
+ ///
+ /// The default setting comes from the command line option to generate
+ /// checked or unchecked code plus any source code changes using the
+ /// checked/unchecked statements or expressions. Contrast this with
+ /// the ConstantCheckState flag.
+ /// </summary>
+ CheckedScope = 1 << 0,
+
+ /// <summary>
+ /// The constant check state is always set to `true' and cant be changed
+ /// from the command line. The source code can change this setting with
+ /// the `checked' and `unchecked' statements and expressions.
+ /// </summary>
+ ConstantCheckState = 1 << 1,
+
+ AllCheckStateFlags = CheckedScope | ConstantCheckState,
+
+ OmitDebugInfo = 1 << 2,
+
+ ConstructorScope = 1 << 3
+ }
+
+ // utility helper for CheckExpr, UnCheckExpr, Checked and Unchecked statements
+ // it's public so that we can use a struct at the callsite
+ public struct FlagsHandle : IDisposable
+ {
+ BuilderContext ec;
+ readonly Options invmask, oldval;
+
+ public FlagsHandle (BuilderContext ec, Options flagsToSet)
+ : this (ec, flagsToSet, flagsToSet)
+ {
+ }
+
+ internal FlagsHandle (BuilderContext ec, Options mask, Options val)
+ {
+ this.ec = ec;
+ invmask = ~mask;
+ oldval = ec.flags & mask;
+ ec.flags = (ec.flags & invmask) | (val & mask);
+ }
+
+ public void Dispose ()
+ {
+ ec.flags = (ec.flags & invmask) | oldval;
+ }
+ }
+
+ Options flags;
+
+ public bool HasSet (Options options)
+ {
+ return (this.flags & options) == options;
+ }
+
+ // Temporarily set all the given flags to the given value. Should be used in an 'using' statement
+ public FlagsHandle With (Options options, bool enable)
+ {
+ return new FlagsHandle (this, options, enable ? options : 0);
}
}
-}
\ No newline at end of file
+}