progress
This commit is contained in:
parent
16e76d6b31
commit
484dbfc9d9
529 changed files with 113694 additions and 0 deletions
163
AspClassic.Scripting/Hosting/ScriptSource.cs
Normal file
163
AspClassic.Scripting/Hosting/ScriptSource.cs
Normal file
|
@ -0,0 +1,163 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.Remoting;
|
||||
using System.Security.Permissions;
|
||||
using System.Text;
|
||||
using AspClassic.Scripting.Utils;
|
||||
|
||||
namespace AspClassic.Scripting.Hosting;
|
||||
|
||||
[DebuggerDisplay("{Path ?? \"<anonymous>\"}")]
|
||||
public sealed class ScriptSource : MarshalByRefObject
|
||||
{
|
||||
private readonly ScriptEngine _engine;
|
||||
|
||||
private readonly SourceUnit _unit;
|
||||
|
||||
internal SourceUnit SourceUnit => _unit;
|
||||
|
||||
public string Path => _unit.Path;
|
||||
|
||||
public SourceCodeKind Kind => _unit.Kind;
|
||||
|
||||
public ScriptEngine Engine => _engine;
|
||||
|
||||
internal ScriptSource(ScriptEngine engine, SourceUnit sourceUnit)
|
||||
{
|
||||
_unit = sourceUnit;
|
||||
_engine = engine;
|
||||
}
|
||||
|
||||
public CompiledCode Compile()
|
||||
{
|
||||
return CompileInternal(null, null);
|
||||
}
|
||||
|
||||
public CompiledCode Compile(ErrorListener errorListener)
|
||||
{
|
||||
ContractUtils.RequiresNotNull(errorListener, "errorListener");
|
||||
return CompileInternal(null, errorListener);
|
||||
}
|
||||
|
||||
public CompiledCode Compile(CompilerOptions compilerOptions)
|
||||
{
|
||||
ContractUtils.RequiresNotNull(compilerOptions, "compilerOptions");
|
||||
return CompileInternal(compilerOptions, null);
|
||||
}
|
||||
|
||||
public CompiledCode Compile(CompilerOptions compilerOptions, ErrorListener errorListener)
|
||||
{
|
||||
ContractUtils.RequiresNotNull(errorListener, "errorListener");
|
||||
ContractUtils.RequiresNotNull(compilerOptions, "compilerOptions");
|
||||
return CompileInternal(compilerOptions, errorListener);
|
||||
}
|
||||
|
||||
private CompiledCode CompileInternal(CompilerOptions compilerOptions, ErrorListener errorListener)
|
||||
{
|
||||
ErrorSink errorSink = new ErrorListenerProxySink(this, errorListener);
|
||||
ScriptCode scriptCode = ((compilerOptions != null) ? _unit.Compile(compilerOptions, errorSink) : _unit.Compile(errorSink));
|
||||
if (scriptCode == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new CompiledCode(_engine, scriptCode);
|
||||
}
|
||||
|
||||
public dynamic Execute(ScriptScope scope)
|
||||
{
|
||||
ContractUtils.RequiresNotNull(scope, "scope");
|
||||
return _unit.Execute(scope.Scope);
|
||||
}
|
||||
|
||||
public dynamic Execute()
|
||||
{
|
||||
return _unit.Execute();
|
||||
}
|
||||
|
||||
public T Execute<T>(ScriptScope scope)
|
||||
{
|
||||
return _engine.Operations.ConvertTo<T>((object)Execute(scope));
|
||||
}
|
||||
|
||||
public T Execute<T>()
|
||||
{
|
||||
return _engine.Operations.ConvertTo<T>((object)Execute());
|
||||
}
|
||||
|
||||
public ObjectHandle ExecuteAndWrap(ScriptScope scope)
|
||||
{
|
||||
return new ObjectHandle((object)Execute(scope));
|
||||
}
|
||||
|
||||
public ObjectHandle ExecuteAndWrap()
|
||||
{
|
||||
return new ObjectHandle((object)Execute());
|
||||
}
|
||||
|
||||
public int ExecuteProgram()
|
||||
{
|
||||
return _unit.LanguageContext.ExecuteProgram(_unit);
|
||||
}
|
||||
|
||||
public ScriptCodeParseResult GetCodeProperties()
|
||||
{
|
||||
return _unit.GetCodeProperties();
|
||||
}
|
||||
|
||||
public ScriptCodeParseResult GetCodeProperties(CompilerOptions options)
|
||||
{
|
||||
return _unit.GetCodeProperties(options);
|
||||
}
|
||||
|
||||
public SourceCodeReader GetReader()
|
||||
{
|
||||
return _unit.GetReader();
|
||||
}
|
||||
|
||||
public Encoding DetectEncoding()
|
||||
{
|
||||
using SourceCodeReader sourceCodeReader = _unit.GetReader();
|
||||
return sourceCodeReader.Encoding;
|
||||
}
|
||||
|
||||
public string[] GetCodeLines(int start, int count)
|
||||
{
|
||||
return _unit.GetCodeLines(start, count);
|
||||
}
|
||||
|
||||
public string GetCodeLine(int line)
|
||||
{
|
||||
return _unit.GetCodeLine(line);
|
||||
}
|
||||
|
||||
public string GetCode()
|
||||
{
|
||||
return _unit.GetCode();
|
||||
}
|
||||
|
||||
public int MapLine(int line)
|
||||
{
|
||||
return _unit.MapLine(line);
|
||||
}
|
||||
|
||||
public SourceSpan MapLine(SourceSpan span)
|
||||
{
|
||||
return new SourceSpan(_unit.MakeLocation(span.Start), _unit.MakeLocation(span.End));
|
||||
}
|
||||
|
||||
public SourceLocation MapLine(SourceLocation location)
|
||||
{
|
||||
return _unit.MakeLocation(location);
|
||||
}
|
||||
|
||||
public string MapLinetoFile(int line)
|
||||
{
|
||||
return _unit.Path;
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
|
||||
public override object InitializeLifetimeService()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue