本文整理汇总了C#中CompilationContext类的典型用法代码示例。如果您正苦于以下问题:C# CompilationContext类的具体用法?C# CompilationContext怎么用?C# CompilationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilationContext类属于命名空间,在下文中一共展示了CompilationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitCall
public static void EmitCall(
CompilationContext context,
IAstRefOrAddr invocationObject,
MethodInfo methodInfo,
List<IAstStackItem> arguments)
{
if (arguments == null)
{
arguments = new List<IAstStackItem>();
}
if (invocationObject != null)
{
invocationObject.Compile(context);
}
ParameterInfo[] args = methodInfo.GetParameters();
if (args.Length != arguments.Count)
{
throw new Exception("Invalid method parameters count");
}
for (int i = 0; i < args.Length; ++i)
{
arguments[i].Compile(context);
PrepareValueOnStack(context, args[i].ParameterType, arguments[i].itemType);
}
if (methodInfo.IsVirtual)
{
context.EmitCall(OpCodes.Callvirt, methodInfo);
}
else
{
context.EmitCall(OpCodes.Call, methodInfo);
}
}
示例2: Main
static int Main(string[] args)
{
if (args != null && args.Length == 1)
{
if (args[0].Equals("-w", StringComparison.InvariantCultureIgnoreCase) ||
args[0].Equals("-wait", StringComparison.InvariantCultureIgnoreCase))
Console.ReadLine();
else
siteRoot = args[0];
}
if (siteRoot == null)
{
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
siteRoot = baseDirectory.Substring(0, baseDirectory.LastIndexOf("\\bin", StringComparison.InvariantCultureIgnoreCase));
}
Console.WriteLine("Compiling [" + siteRoot + "] ...");
InitializeConfig();
if (!Directory.Exists(siteRoot))
{
PrintHelpMessage(string.Format("The path '{0}' does not exist", siteRoot));
Console.ReadLine();
return -1;
}
OfflineCompiler compiler;
try
{
ICompilationContext compilationContext = new CompilationContext(
new DirectoryInfo(Path.Combine(siteRoot, "bin")),
new DirectoryInfo(siteRoot),
new DirectoryInfo(Path.Combine(siteRoot, "views")),
new DirectoryInfo(options.CompilerOptions.TemporarySourceFilesDirectory));
compiler = new OfflineCompiler(
new CSharpCodeProviderAdapterFactory(),
new PreProcessor(),
compilationContext, options.CompilerOptions, new DefaultFileSystemAdapter());
}
catch
{
PrintHelpMessage("Could not start the compiler.");
return -2;
}
try
{
string path = compiler.Execute();
Console.WriteLine("[{0}] compiled into [{1}].", siteRoot, path);
return 0;
}
catch (Exception ex)
{
PrintHelpMessage("Could not compile." + Environment.NewLine + ex);
return -3;
}
}
示例3: CompileDirectory
private void CompileDirectory(CompilationContext context, string viewDirectory)
{
// Prevent processing of the same directories multiple times (sligh performance optimization,
// as the build manager second call to compile a view is essentially a "no-op".
if (context.ProcessedDirectories.Contains(viewDirectory))
return;
context.ProcessedDirectories.Add(viewDirectory);
var stopwatch = new Stopwatch();
stopwatch.Start();
try {
var firstFile = _virtualPathProvider
.ListFiles(viewDirectory)
.Where(f => context.FileExtensionsToCompile.Any(e => f.EndsWith(e, StringComparison.OrdinalIgnoreCase)))
.FirstOrDefault();
if (firstFile != null)
BuildManager.GetCompiledAssembly(firstFile);
}
catch(Exception e) {
// Some views might not compile, this is ok and harmless in this
// context of pre-compiling views.
Logger.Information(e, "Compilation of directory '{0}' skipped", viewDirectory);
}
stopwatch.Stop();
Logger.Information("Directory '{0}' compiled in {1} msec", viewDirectory, stopwatch.ElapsedMilliseconds);
}
示例4: Compile
public void Compile(CompilationContext context)
{
targetObject.Compile(context);
value.Compile(context);
CompilationHelper.PrepareValueOnStack(context, fieldInfo.FieldType, value.itemType);
context.Emit(OpCodes.Stfld, fieldInfo);
}
示例5: BuildAst
internal override IEnumerable<AssociativeNode> BuildAst(List<AssociativeNode> inputAstNodes, CompilationContext context)
{
var rhs = AstFactory.BuildStringNode(Value);
var assignment = AstFactory.BuildAssignment(GetAstIdentifierForOutputIndex(0), rhs);
return new[] { assignment };
}
示例6: Compile
public override void Compile(CompilationContext context)
{
CompilationHelper.CheckIsValue(itemType);
array.Compile(context);
context.Emit(OpCodes.Ldc_I4, index);
context.Emit(OpCodes.Ldelema, itemType);
}
示例7: Execute
/// <summary>
/// Executes the translation process.
/// </summary>
/// <param name="context">The compilation context.</param>
public void Execute(CompilationContext context)
{
if (context == null || context.Model == null)
return;
if (context.OutputStream == null || !context.OutputStream.CanWrite)
throw new CompilationException("The translation output stream is null or not writable.");
var translationCtx = new TranslationContext();
translationCtx.OutputStream = context.OutputStream;
// write enum declarations
var enumTranslator = new EnumTranslator();
foreach (var item in context.Model.Enums)
enumTranslator.Translate(item, translationCtx);
// write class declarations
var classTranslator = new ClassTranslator();
foreach (var item in ClassSorter.Sort(context.Model.Classes))
classTranslator.Translate(item, translationCtx);
// write global statements
if (context.Model.GlobalStatements.Any())
{
translationCtx.WriteLine();
foreach (var item in context.Model.GlobalStatements)
translationCtx.WriteModel(item);
}
}
示例8: Compile
public void Compile(CompilationContext context)
{
AstBuildHelper.CallMethod(
_setMethod,
_targetObject,
new List<IAstStackItem>() { _value }
).Compile(context);
}
示例9: Compile
public void Compile(CompilationContext context)
{
if(localType.IsValueType)
{
context.Emit(OpCodes.Ldloca, localIndex);
context.Emit(OpCodes.Initobj, localType);
}
}
示例10: Execute
/// <summary>
/// Executes the model validation process.
/// </summary>
/// <param name="context">The compilation context.</param>
public void Execute(CompilationContext context)
{
var provider = new ImportProvider<IModelValidator>();
foreach (var validator in provider.GetImports())
{
validator.Validate(context.Model, context.Result);
}
}
示例11: Compile
public void Compile(CompilationContext context)
{
var endBlock = context.ilGenerator.BeginExceptionBlock();
protectedBlock.Compile(context);
context.ilGenerator.BeginCatchBlock(exceptionType);
context.ilGenerator.Emit(OpCodes.Stloc, eceptionVariable);
handlerBlock.Compile(context);
context.ilGenerator.EndExceptionBlock();
}
示例12: Compile
public void Compile(CompilationContext context)
{
new AstCallMethod(methodInfo, invocationObject, arguments).Compile(context);
if (methodInfo.ReturnType != typeof(void))
{
context.Emit(OpCodes.Pop);
}
}
示例13: Compile
public virtual void Compile(CompilationContext context)
{
AstReadArgument arg = new AstReadArgument()
{
argumentIndex = 0,
argumentType = thisType
};
arg.Compile(context);
}
示例14: Compile
public void Compile(CompilationContext context)
{
value.Compile(context);
if (value.itemType.IsValueType)
{
context.Emit(OpCodes.Box, itemType);
}
}
示例15: IncrementalHighlighter
public IncrementalHighlighter(Highlighter highlighter)
{
highlightingParser = new HighlightingParser(highlighter);
var context = new CompilationContext();
tokenizer = context.CreateTokenizer(
token => highlightingParser.OnToken(token),
() => highlightingParser.OnDone(),
() => {}
);
}