using System.Reflection.Emit;
using System.Diagnostics.SymbolStore;
-namespace Mono.CSharp {
+namespace Mono.MonoBASIC {
/// <summary>
/// Code generator class.
/// Whether we are inside an unsafe block
/// </summary>
public bool InUnsafe;
+
+ /// <summary>
+ /// Whether we are inside an unsafe block
+ /// </summary>
+ public bool InvokingOwnOverload;
/// <summary>
/// Location for this EmitContext
/// we relax the rules
/// </summary>
public bool InEnumContext;
+
+ public string BlockName;
protected Stack FlowStack;
ReturnType = return_type;
IsConstructor = is_constructor;
CurrentBlock = null;
+ BlockName = "";
+ InvokingOwnOverload = false;
if (parent != null){
// Can only be null for the ResolveType contexts.
CurrentBranching.SetParameterAssigned (number);
}
+ // These are two overloaded methods for EmitTopBlock
+ // since in MonoBasic functions we need the Function name
+ // along with its top block, in order to be able to
+ // retrieve the return value when there is no explicit
+ // 'Return' statement
public void EmitTopBlock (Block block, InternalParameters ip, Location loc)
{
- bool has_ret = false;
+ EmitTopBlock (block, "", ip, loc);
+ }
-// Console.WriteLine ("Emitting: " + loc);
+ public void EmitTopBlock (Block block, string bname, InternalParameters ip, Location loc)
+ {
+ bool has_ret = false;
+ //Console.WriteLine ("Emitting: '{0}", bname);
+ BlockName = bname;
if (CodeGen.SymbolWriter != null)
Mark (loc);
if (ReturnType != null && !has_ret){
//
- // FIXME: we need full flow analysis to implement this
- // correctly and emit an error instead of a warning.
+ // mcs here would report an error (and justly so), but functions without
+ // an explicit return value are perfectly legal in MonoBasic
//
- //
- Report.Error (161, loc, "Not all code paths return a value");
+
+ VariableInfo vi = block.GetVariableInfo (bname);
+ if (vi != null)
+ {
+ ig.Emit (OpCodes.Ldloc, vi.LocalBuilder);
+ ig.Emit (OpCodes.Ret);
+ }
+ else
+ Report.Error (-200, "This is not supposed to happen !");
return;
}