本文整理汇总了C#中Compiler类的典型用法代码示例。如果您正苦于以下问题:C# Compiler类的具体用法?C# Compiler怎么用?C# Compiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Compiler类属于命名空间,在下文中一共展示了Compiler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CompileDereference
protected virtual Expression CompileDereference(Compiler compiler, Frame frame, Expression left, Parse.BinaryExpression expression, System.Type typeHint)
{
left = compiler.MaterializeReference(left);
var local = compiler.AddFrame(frame, expression);
var memberType = left.Type.GenericTypeArguments[0];
var parameters = new List<ParameterExpression>();
var valueParam = compiler.CreateValueParam(expression, local, left, memberType);
parameters.Add(valueParam);
var indexParam = compiler.CreateIndexParam(expression, local);
parameters.Add(indexParam);
var right =
compiler.MaterializeReference
(
compiler.CompileExpression(local, expression.Right, typeHint)
);
var selection = Expression.Lambda(right, parameters);
var select =
typeof(Enumerable).GetMethodExt
(
"Select",
new System.Type[] { typeof(IEnumerable<ReflectionUtility.T>), typeof(Func<ReflectionUtility.T, int, ReflectionUtility.T>) }
);
select = select.MakeGenericMethod(memberType, selection.ReturnType);
return Expression.Call(select, left, selection);
}
开发者ID:jgabb8989,项目名称:DotQL,代码行数:30,代码来源:NaryTypeHandler.cs
示例2: Main
public static void Main(string[] args)
{
InputStream input = new InputStream("source.c");
BytecodeStream output = new BytecodeStream();
Compiler compiler = new Compiler();
compiler.Compile(input, output);
}
开发者ID:possientis,项目名称:Prog,代码行数:7,代码来源:facade.cs
示例3: GLVertoutput
/// <summary>
/// Create OpenGL object. Standard object constructor for ProtoFX.
/// </summary>
/// <param name="block"></param>
/// <param name="scene"></param>
/// <param name="debugging"></param>
public GLVertoutput(Compiler.Block block, Dict scene, bool debugging)
: base(block.Name, block.Anno)
{
var err = new CompileException($"vertoutput '{name}'");
// PARSE ARGUMENTS
Cmds2Fields(block, err);
// CREATE OPENGL OBJECT
glname = GL.GenTransformFeedback();
GL.BindTransformFeedback(TransformFeedbackTarget.TransformFeedback, glname);
// parse commands
int numbindings = 0;
foreach (var cmd in block["buff"])
Attach(numbindings++, cmd, scene, err | $"command '{cmd.Text}'");
// if errors occurred throw exception
if (err.HasErrors())
throw err;
// unbind object and check for errors
GL.BindTransformFeedback(TransformFeedbackTarget.TransformFeedback, 0);
if (HasErrorOrGlError(err, block))
throw err;
}
开发者ID:h3tch,项目名称:ProtoFX,代码行数:32,代码来源:GLVertoutput.cs
示例4: Compile
public override void Compile(Compiler compiler, Node node, NodeParent parent)
{
if (((Literal)node).Value == null)
{
// nil
compiler.AppendLine("$_stack[] = new F_NilClass;");
return;
}
if (((Literal)node).Value is bool)
{
// True or False
compiler.AppendLine("$_stack[] = new F_{0}Class;", ((Literal)node).Value.ToString());
return;
}
if (((Literal)node).Value is string)
{
switch (((Literal)node).Value.ToString())
{
case "self":
compiler.AppendLine("$_stack[] = $_locals->self;", ((Literal)node).Value.ToString());
break;
case "__FILE__":
case "__LINE__":
compiler.AppendLine("$_stack[] = F_String::__from_string({0});", ((Literal)node).Value.ToString());
break;
}
return;
}
compiler.AppendLine("$_stack[] = F_Number::__from_number({0});", ((Literal)node).Value.ToString());
}
开发者ID:rzhw,项目名称:Fructose,代码行数:31,代码来源:Literal.cs
示例5: Compile
public override void Compile(Compiler compiler, Node node, NodeParent parent)
{
var pmethod = parent.OfType<MethodDefinition>().SingleOrDefault();
var isInBlock = pmethod != null && pmethod.Name.Contains("__lambda_");
if (((ReturnStatement)node).Arguments == null || ((ReturnStatement)node).Arguments.Expressions.Count() == 0)
{
compiler.AppendLine("$_stack[] = new F_NilClass;");
}
else if (((ReturnStatement)node).Arguments.Expressions.Count() > 0)
{
compiler.CompileNode(((ReturnStatement)node).Arguments.Expressions.First(), parent.CreateChild(node));
}
else
{
compiler.CompileNode(new ArrayConstructor(((ReturnStatement)node).Arguments, ((ReturnStatement)node).Location), parent.CreateChild(node));
}
if (!isInBlock)
{
compiler.AppendLine("return array_pop($_stack);");
}
else
{
compiler.AppendLine("throw new ReturnFromBlock(array_pop($_stack));");
}
}
开发者ID:rzhw,项目名称:Fructose,代码行数:27,代码来源:Return.cs
示例6: CompileCSharp6
public void CompileCSharp6()
{
// see https://roslyn.codeplex.com/wikipage?title=Language%20Feature%20Status&referringTitle=Documentation
const string code1 = @"
using System;
namespace Whatever
{
public class Something
{
// auto-property initializer
public int Value { get; set; } = 3;
public void DoSomething()
{
Console.WriteLine(""Hello!"");
}
public void DoSomething(string[] args)
{
// conditional access
var len = args?.Length ?? 0;
}
}
}
";
var compiler = new Compiler(LanguageVersion.CSharp6);
compiler.Compile(_tempDir, "Whatever", new Dictionary<string, string> { { "code", code1 } });
Assert.IsTrue(File.Exists(Path.Combine(_tempDir, "Whatever.dll")));
}
开发者ID:nul800sebastiaan,项目名称:Zbu.ModelsBuilder,代码行数:31,代码来源:CompilerTests.cs
示例7: Compile
public override void Compile(Compiler compiler, Node node, NodeParent parent)
{
if (node is IsDefinedExpression)
{
var ide = (IsDefinedExpression)node;
switch(ide.Expression.NodeType)
{
case NodeTypes.MethodCall:
compiler.AppendLine("$_stack[] = F_TrueClass::__from_bool(function_exists('{0}'));", Mangling.RubyMethodToPHP(((MethodCall)ide.Expression).MethodName));
return;
case NodeTypes.ConstantVariable:
compiler.AppendLine("$_stack[] = F_TrueClass::__from_bool(class_exists('{0}'));", Mangling.RubyMethodToPHP(((ConstantVariable)ide.Expression).Name));
return;
case NodeTypes.ClassVariable:
case NodeTypes.GlobalVariable:
case NodeTypes.InstanceVariable:
case NodeTypes.LocalVariable:
compiler.AppendLine("$_stack[] = F_TrueClass::__from_bool(isset({0}));", ((Variable)ide.Expression).ToPHPVariable());
return;
default:
throw new FructoseCompileException("Not supported yet: defined?( " + ide.Expression.NodeType.ToString() + " )", ide.Expression);
}
}
else
throw new FructoseCompileException("Not supported yet: " + node.ToString(), node);
}
开发者ID:rzhw,项目名称:Fructose,代码行数:27,代码来源:DescriptionExpression.cs
示例8: Compile
public override void Compile(Compiler compiler, IronRuby.Compiler.Ast.Node node, NodeParent parent)
{
var sae = (SimpleAssignmentExpression)node;
// substitute a method call of []= rather than the crap that ironruby's parser produces:
switch (sae.Left.NodeType)
{
case NodeTypes.ArrayItemAccess:
var aia = (ArrayItemAccess)sae.Left;
compiler.CompileNode(new MethodCall(aia.Array, "[]=", new Arguments(aia.Arguments.Expressions.Concat(new[] { sae.Right }).ToArray()), sae.Location), parent.CreateChild(node));
return;
case NodeTypes.AttributeAccess:
var aa = (AttributeAccess)sae.Left;
compiler.CompileNode(new MethodCall(aa.Qualifier, aa.Name, new Arguments(sae.Right), aa.Location), parent.CreateChild(node));
return;
}
compiler.CompileNode(sae.Right, parent.CreateChild(node));
if (sae.Operation != null)
{
compiler.AppendLine("$_stack[] = {0};", assignmentVar(sae.Left, parent));
compiler.AppendLine("$_stack[] = array_pop($_stack)->{0}(NULL, array_pop($_stack));", Mangling.RubyMethodToPHP(sae.Operation));
}
compiler.AppendLine("{0} = $_stack[count($_stack)-1];", assignmentVar(sae.Left, parent));
}
开发者ID:rzhw,项目名称:Fructose,代码行数:25,代码来源:Assignment.cs
示例9: CompilerLanguageVersionTest
public void CompilerLanguageVersionTest()
{
const string code = @"
class Test
{
private string GetValue()
{
return ""value"";
}
// this is csharp v6
public string Value => this.GetValue();
}
";
var files = new Dictionary<string, string> { { "source", code } };
SyntaxTree[] trees;
Compiler compiler;
Assert.Throws<Exception>(() =>
{
compiler = new Compiler();
compiler.GetCompilation("Umbraco.ModelsBuilder.Generated", files, out trees);
});
// works
compiler = new Compiler(LanguageVersion.CSharp6);
compiler.GetCompilation("Umbraco.ModelsBuilder.Generated", files, out trees);
}
开发者ID:nul800sebastiaan,项目名称:Zbu.ModelsBuilder,代码行数:28,代码来源:RoslynTests.cs
示例10: Compile
public void Compile(ProgramGraph graph, CompilerOutputInfo info)
{
if (!(info is ShaderOutputInfo))
return;
ShaderOutputInfo outputInfo = info as ShaderOutputInfo;
RegisterDict = new Dictionary<string, int>();
for(int i = 0; i < graph.getMaxDepth(); i++)
{
foreach (Vertex v in graph.getVerticesForLayer(i))
{
foreach (NodeItem outputItem in v.Data.Items.Where(item => item.Output.Enabled))
{
if(outputItem.OutputData is ShaderTypes.sampler2D)
{
ShaderTypes.sampler2D Sampler = (ShaderTypes.sampler2D)outputItem.OutputData;
if (!RegisterDict.ContainsKey(Sampler.path))
RegisterDict.Add(Sampler.path, RegisterDict.Count);
}
}
}
}
mCompiler = new HLSLCompiler(new Dictionary<object, string>(), RegisterDict);
WritePostFxScript(outputInfo);
if (mCompiler == null)
return;
mCompiler.Compile(graph, outputInfo);
}
开发者ID:RichardRanft,项目名称:CGF,代码行数:27,代码来源:T3DPostFxCompiler.cs
示例11: Initialise
public void Initialise(Compiler compiler)
{
if (compiler.m_XEngineLSLCompatabilityModule)
LSL_Converter = new LegacyCSCodeGenerator();
else
LSL_Converter = new CSCodeGenerator(compiler.m_SLCompatabilityMode, null);
}
开发者ID:NickyPerian,项目名称:Aurora,代码行数:7,代码来源:LSLConverter.cs
示例12: EmitDedicatedMethod
bool EmitDedicatedMethod(Compiler.CompilerContext ctx, Compiler.Local valueFrom, bool read)
{
System.Reflection.Emit.MethodBuilder method = ctx.GetDedicatedMethod(key, read);
if (method == null) return false;
using (Compiler.Local token = new ProtoBuf.Compiler.Local(ctx, typeof(SubItemToken)))
{
Type rwType = read ? typeof(ProtoReader) : typeof(ProtoWriter);
ctx.LoadValue(valueFrom);
if (!read) // write requires the object for StartSubItem; read doesn't
{
if (type.IsValueType) { ctx.LoadNullRef(); }
else { ctx.CopyValue(); }
}
ctx.LoadReaderWriter();
ctx.EmitCall(rwType.GetMethod("StartSubItem"));
ctx.StoreValue(token);
// note: value already on the stack
ctx.LoadReaderWriter();
ctx.EmitCall(method);
// handle inheritance (we will be calling the *base* version of things,
// but we expect Read to return the "type" type)
if (read && type != method.ReturnType) ctx.Cast(this.type);
ctx.LoadValue(token);
ctx.LoadReaderWriter();
ctx.EmitCall(rwType.GetMethod("EndSubItem"));
}
return true;
}
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:30,代码来源:SubItemSerializer.cs
示例13: EmitRead
protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
{
using (Compiler.Local oldValue = ctx.GetLocalWithValue(expectedType, valueFrom))
using (Compiler.Local token = new Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
using (Compiler.Local field = new Compiler.Local(ctx, ctx.MapType(typeof(int))))
{
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("StartSubItem"));
ctx.StoreValue(token);
Compiler.CodeLabel next = ctx.DefineLabel(), processField = ctx.DefineLabel(), end = ctx.DefineLabel();
ctx.MarkLabel(next);
ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
ctx.CopyValue();
ctx.StoreValue(field);
ctx.LoadValue(Tag); // = 1 - process
ctx.BranchIfEqual(processField, true);
ctx.LoadValue(field);
ctx.LoadValue(1); // < 1 - exit
ctx.BranchIfLess(end, false);
// default: skip
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
ctx.Branch(next, true);
// process
ctx.MarkLabel(processField);
if (Tail.RequiresOldValue)
{
if (Helpers.IsValueType(expectedType))
{
ctx.LoadAddress(oldValue, expectedType);
ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
}
else
{
ctx.LoadValue(oldValue);
}
}
Tail.EmitRead(ctx, null);
// note we demanded always returns a value
if (Helpers.IsValueType(expectedType))
{
ctx.EmitCtor(expectedType, Tail.ExpectedType); // re-nullable<T> it
}
ctx.StoreValue(oldValue);
ctx.Branch(next, false);
// outro
ctx.MarkLabel(end);
ctx.LoadValue(token);
ctx.LoadReaderWriter();
ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("EndSubItem"));
ctx.LoadValue(oldValue); // load the old value
}
}
开发者ID:gezidan,项目名称:ZYSOCKET,代码行数:60,代码来源:NullDecorator.cs
示例14: EmitBeq
private void EmitBeq(Compiler.CompilerContext ctx, Compiler.CodeLabel label, Type type)
{
switch (Helpers.GetTypeCode(type))
{
case ProtoTypeCode.Boolean:
case ProtoTypeCode.Byte:
case ProtoTypeCode.Char:
case ProtoTypeCode.Double:
case ProtoTypeCode.Int16:
case ProtoTypeCode.Int32:
case ProtoTypeCode.Int64:
case ProtoTypeCode.SByte:
case ProtoTypeCode.Single:
case ProtoTypeCode.UInt16:
case ProtoTypeCode.UInt32:
case ProtoTypeCode.UInt64:
ctx.BranchIfEqual(label, false);
break;
default:
MethodInfo method = type.GetMethod("op_Equality", BindingFlags.Public | BindingFlags.Static,
null, new Type[] { type, type }, null);
if (method == null || method.ReturnType != typeof(bool))
{
throw new InvalidOperationException("No suitable equality operator found for default-values of type: " + type.FullName);
}
ctx.EmitCall(method);
ctx.BranchIfTrue(label, false);
break;
}
}
开发者ID:Ribosome2,项目名称:protobuf-net-1,代码行数:31,代码来源:DefaultValueDecorator.cs
示例15: Emitter
public Emitter(Compiler compiler)
{
Compiler = compiler;
// create assembly object
var name = new AssemblyNameDefinition("MirelleCompiled", new Version(1, 0, 0, 0));
Assembly = AssemblyDefinition.CreateAssembly(name, "MirelleCompiled", ModuleKind.Console);
var attr = typeof(STAThreadAttribute).GetConstructor(new Type[] { } );
// register global method
GlobalBody = new MethodDefinition("main", MethodAttributes.Static | MethodAttributes.Private | MethodAttributes.HideBySig, Assembly.MainModule.TypeSystem.Void);
GlobalBody.CustomAttributes.Add(new CustomAttribute(AssemblyImport(attr)));
RootNode.GlobalMethod = new MethodNode("main", new SignatureNode("void"), true, false, GlobalBody);
RootNode.GlobalMethod.Scope = new Utils.Scope(GlobalBody);
// register global type
GlobalType = new TypeDefinition("MirelleCompiled", ".program", TypeAttributes.AutoClass | TypeAttributes.Public | TypeAttributes.SpecialName | TypeAttributes.BeforeFieldInit, Assembly.MainModule.TypeSystem.Object);
Assembly.MainModule.Types.Add(GlobalType);
GlobalType.Methods.Add(GlobalBody);
Assembly.EntryPoint = GlobalBody;
// register marker interfaces
MirelleTypeInterface = AssemblyImport(typeof(MirelleStdlib.IMirelleType));
MirelleEnumInterface = AssemblyImport(typeof(MirelleStdlib.IMirelleEnum));
}
开发者ID:menozz,项目名称:mirelle,代码行数:26,代码来源:Emitter.cs
示例16: Compile
public void Compile()
{
if (mBytecode != null) throw new InvalidOperationException("Can only compile a script once.");
var compiler = new Compiler(mForeign);
compiler.FunctionStarted = mDebug.StartFunction;
// add the source files
foreach (var sourceFile in GetSourceFiles(mPath))
{
compiler.AddSourceFile(sourceFile);
}
using (var stream = new MemoryStream())
{
// compile the code
mErrors = compiler.Compile(stream);
// bail if there were compile errors
if (mErrors.Count > 0) return;
mBytecode = new Magpie.Interpreter.BytecodeFile(stream.ToArray());
}
}
开发者ID:rwaldron,项目名称:magpie,代码行数:25,代码来源:Script.cs
示例17: EmitWriteArrayLoop
private void EmitWriteArrayLoop(Compiler.CompilerContext ctx, Compiler.Local i, Compiler.Local arr)
{
// i = 0
ctx.LoadValue(0);
ctx.StoreValue(i);
// range test is last (to minimise branches)
Compiler.CodeLabel loopTest = ctx.DefineLabel(), processItem = ctx.DefineLabel();
ctx.Branch(loopTest, false);
ctx.MarkLabel(processItem);
// {...}
ctx.LoadArrayValue(arr, i);
ctx.WriteNullCheckedTail(itemType, Tail, null);
// i++
ctx.LoadValue(i);
ctx.LoadValue(1);
ctx.Add();
ctx.StoreValue(i);
// i < arr.Length
ctx.MarkLabel(loopTest);
ctx.LoadValue(i);
ctx.LoadLength(arr, false);
ctx.BranchIfLess(processItem, false);
}
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:27,代码来源:ArrayDecorator.cs
示例18: Parse
public static string Parse(
Compiler docsCompiler, Folder folder, string fullPath, string trail, string versionUrl)
{
bool convertToHtml = docsCompiler.ConvertToHtml;
if (!File.Exists(fullPath))
throw new FileNotFoundException(string.Format("{0} was not found", fullPath));
var contents = File.ReadAllText(fullPath);
contents = CodeBlockFinder.Replace(
contents, match => GenerateCodeBlock(match.Groups[1].Value.Trim(), match.Groups[2].Value, convertToHtml));
contents = CodeFinder.Replace(
contents,
match =>
GenerateCodeBlockFromFile(match.Groups[1].Value.Trim(), docsCompiler.CodeSamplesPath, convertToHtml));
if (folder != null)
contents = FilesListFinder.Replace(contents, match => GenerateFilesList(folder, false));
if (convertToHtml)
{
contents = contents.ResolveMarkdown(
docsCompiler.Output,
!string.IsNullOrWhiteSpace(docsCompiler.Output.RootUrl) ? trail : string.Empty,
versionUrl);
}
contents = NotesFinder.Replace(
contents, match => InjectNoteBlocks(match.Groups[1].Value.Trim(), match.Groups[2].Value.Trim()));
return contents;
}
开发者ID:AlexZeitler,项目名称:docs,代码行数:31,代码来源:DocumentationParser.cs
示例19: BuildExtensionMethods
public void BuildExtensionMethods(Compiler context)
{
List<MethodInfo> extensionMethods = GetExtensionMethods(InputAssembly).ToList();
ExtensionMethodLookup = new Dictionary<string, MethodInfo>(extensionMethods.Count);
foreach (MethodInfo mi in extensionMethods)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("M:{0}.{1}", mi.DeclaringType.FullName, mi.Name);
if (mi.IsGenericMethodDefinition)
sb.Append("`");
Type[] genericMethodArguments = mi.GetGenericArguments();
if (genericMethodArguments != null && genericMethodArguments.Length > 0)
sb.AppendFormat("`{0}", genericMethodArguments.Length);
ParameterInfo[] parameters = mi.GetParameters();
if (parameters != null && parameters.Length > 0)
{
sb.Append("(");
sb.Append(string.Join(",", parameters.Select(p => p.ParameterType).Select(pt => pt.ToCref()).ToArray()));
sb.Append(")");
}
MethodInfo existingExtensionMethod = null;
if (ExtensionMethodLookup.TryGetValue(sb.ToString(), out existingExtensionMethod))
{
context.LogWarning("Generated Extension Method Cref \"{0}\" is ambiguous\n\tExisting Method: \"{1}\"\n\tNew Method: \"{2}\"", sb.ToString(), existingExtensionMethod, mi);
}
else
{
context.LogVerbose("Found Extension Method \"{0}\"\n\tGenerated Cref:\"{1}\"", mi, sb);
ExtensionMethodLookup.Add(sb.ToString(), mi);
}
}
}
开发者ID:automatonic,项目名称:refraxion,代码行数:34,代码来源:Compiler.RxAssemblyInfo.cs
示例20: Execute
public override void Execute(VirtualMachine vm, Compiler.Nodes.FunctionCallNode node)
{
Variable leftVariable = vm.getVariable(node.Left);
Variable rightVariable = vm.getVariable(node.Right);
if(leftVariable.Type == VariableType.Number && rightVariable.Type == VariableType.Number) //values are parsable as numbers.
{
int left = int.Parse(leftVariable.Value);
int right = int.Parse(rightVariable.Value);
switch(node.Name) {
case "AreEqual":
vm.Return = new Variable(VariableType.Boolean, (left == right).ToString());
break;
case "IsSmaller":
vm.Return = new Variable(VariableType.Boolean, (left < right).ToString());
break;
case "IsLarger":
vm.Return = new Variable(VariableType.Boolean, (left > right).ToString());
break;
case "IsSmallerOrEqual":
vm.Return = new Variable(VariableType.Boolean, (left <= right).ToString());
break;
case "IsLargerOrEqual":
vm.Return = new Variable(VariableType.Boolean, (left <= right).ToString());
break;
}
}
//TODO: compare strings?
}
开发者ID:armed10,项目名称:GeenCompilerOfzo,代码行数:31,代码来源:CompareCommand.cs
注:本文中的Compiler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论