/// <summary>
/// Compiles the input string and returns a delegate that represents the compiled code.
/// </summary>
/// <remarks>
///
/// Compiles the input string as a C# expression or
/// statement, unlike the Evaluate method, the
/// resulting delegate can be invoked multiple times
/// without incurring in the compilation overhead.
///
/// If the return value of this function is null,
/// this indicates that the parsing was complete.
/// If the return value is a string it indicates
/// that the input string was partial and that the
/// invoking code should provide more code before
/// the code can be successfully compiled.
///
/// If you know that you will always get full expressions or
/// statements and do not care about partial input, you can use
/// the other Compile overload.
///
/// On success, in addition to returning null, the
/// compiled parameter will be set to the delegate
/// that can be invoked to execute the code.
///
/// </remarks>
static public string Compile(string input, out CompiledMethod compiled)
{
if (input == null || input.Length == 0)
{
compiled = null;
return(null);
}
lock (evaluator_lock)
{
if (!inited)
{
Init();
}
else
{
ctx.Report.Printer.Reset();
}
// RootContext.ToplevelTypes = new ModuleContainer (ctx);
bool partial_input;
CSharpParser parser = ParseString(ParseMode.Silent, input, out partial_input);
if (parser == null)
{
compiled = null;
if (partial_input)
{
return(input);
}
ParseString(ParseMode.ReportErrors, input, out partial_input);
return(null);
}
object parser_result = parser.InteractiveResult;
if (!(parser_result is Class))
{
int errors = ctx.Report.Errors;
NamespaceEntry.VerifyAllUsing();
if (errors == ctx.Report.Errors)
{
parser.CurrentNamespace.Extract(using_alias_list, using_list);
}
else
{
NamespaceEntry.Reset();
}
}
#if STATIC
throw new NotSupportedException();
#else
compiled = CompileBlock(parser_result as Class, parser.undo, ctx.Report);
return(null);
#endif
}
}