本文整理汇总了C#中Mono.CSharp.CompilerContext类的典型用法代码示例。如果您正苦于以下问题:C# CompilerContext类的具体用法?C# CompilerContext怎么用?C# CompilerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilerContext类属于Mono.CSharp命名空间,在下文中一共展示了CompilerContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: InitializeEvaluator
private static void InitializeEvaluator()
{
_Interop.VarStorage["ReplVersion"] = typeof(Program).Assembly.GetName().Version;
var settings = new CompilerSettings() {
StdLib = true
};
var reportPrinter = new ConsoleReportPrinter();
var ctx = new CompilerContext(settings, reportPrinter);
evaluator = new Evaluator(ctx);
evaluator.ReferenceAssembly(typeof(_Interop).Assembly);
evaluator.Run(
@"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
");
evaluator.Run("var _v = _Interop.VarStorage;");
evaluator.Run("var _h = _Interop.History;");
evaluator.Run("_Interop.VoidMethod exit = _Interop.Exit;");
evaluator.Run("_Interop.ReturnStringListMethod globals = _Interop.GetGlobals");
}
开发者ID:mkaput,项目名称:csrepl,代码行数:29,代码来源:Program.cs
示例2: FeatureIsNotAvailable
public void FeatureIsNotAvailable (CompilerContext compiler, Location loc, string feature)
{
string version;
switch (compiler.Settings.Version) {
case LanguageVersion.ISO_1:
version = "1.0";
break;
case LanguageVersion.ISO_2:
version = "2.0";
break;
case LanguageVersion.V_3:
version = "3.0";
break;
case LanguageVersion.V_4:
version = "4.0";
break;
case LanguageVersion.V_5:
version = "5.0";
break;
default:
throw new InternalErrorException ("Invalid feature version", compiler.Settings.Version);
}
Error (1644, loc,
"Feature `{0}' cannot be used because it is not part of the C# {1} language specification",
feature, version);
}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:27,代码来源:report.cs
示例3: ScriptingEngine
public ScriptingEngine()
{
tokenSource = new CancellationTokenSource();
taskFactory = new TaskFactory(tokenSource.Token);
context = new CompilerContext(new Mono.CSharp.CompilerSettings(), new ConsoleReportPrinter());
evaluator = new Evaluator(context);
evaluator.InteractiveBaseClass = typeof(ScriptingInteractiveBase);
evaluator.DescribeTypeExpressions = true;
ScriptingInteractiveBase.Evaluator = evaluator;
var errorStream = new GuiStream(TextType.Error, OnConsoleOutput);
var guiOutput = new StreamWriter(errorStream);
guiOutput.AutoFlush = true;
Console.SetError(guiOutput);
ScriptingInteractiveBase.Output = guiOutput;
var stdoutStream = new GuiStream(TextType.Output, OnConsoleOutput);
guiOutput = new StreamWriter(stdoutStream);
guiOutput.AutoFlush = true;
Console.SetOut(guiOutput);
ScriptingInteractiveBase.Error = guiOutput;
codeCompletion = new CSharpCompletion(this);
Evaluate("using System; using System.Linq; using System.Collections; using System.Collections.Generic;");
//init the code completion so that the first character typed is not delayed
//var readOnlyDocument = new ReadOnlyDocument(new StringTextSource(""), "init.csx");
//codeCompletion.GetCompletions(readOnlyDocument, 0);
}
开发者ID:CedarLogic,项目名称:CShell,代码行数:31,代码来源:ScriptingEngine.cs
示例4: Main
static void Main(string[] args)
{
var compilerContext = new CompilerContext(new CompilerSettings(), new ConsoleReportPrinter());
var evaluator = new Evaluator(compilerContext);
// Make it reference our own assembly so it can use IFoo
evaluator.ReferenceAssembly(typeof(IFoo).Assembly);
// Feed it some code
evaluator.Compile(
@"
public class Foo : MonoCompilerDemo.IFoo
{
public string Bar(string s) { return s.ToUpper(); }
}");
for (; ; )
{
string line = Console.ReadLine();
if (line == null) break;
object result;
bool result_set;
evaluator.Evaluate(line, out result, out result_set);
if (result_set) Console.WriteLine(result);
}
}
开发者ID:davidebbo,项目名称:MonoCompilerDemo,代码行数:27,代码来源:Program.cs
示例5: Shell
public Shell(MainWindow container) : base()
{
this.container = container;
WrapMode = WrapMode.Word;
CreateTags ();
Pango.FontDescription font_description = new Pango.FontDescription();
font_description.Family = "Monospace";
ModifyFont(font_description);
TextIter end = Buffer.EndIter;
Buffer.InsertWithTagsByName (ref end, "Mono C# Shell, type 'help;' for help\n\nEnter statements or expressions below.\n", "Comment");
ShowPrompt (false);
context = new CompilerContext (new CompilerSettings (), new ConsoleReportPrinter ());
evaluator = new Evaluator (context);
evaluator.DescribeTypeExpressions = true;
evaluator.InteractiveBaseClass = typeof (InteractiveGraphicsBase);
evaluator.Run ("LoadAssembly (\"System.Drawing\");");
evaluator.Run ("using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Drawing;");
if (!MainClass.Debug){
GuiStream error_stream = new GuiStream ("Error", (x, y) => Output (x, y));
StreamWriter gui_output = new StreamWriter (error_stream);
gui_output.AutoFlush = true;
Console.SetError (gui_output);
GuiStream stdout_stream = new GuiStream ("Stdout", (x, y) => Output (x, y));
gui_output = new StreamWriter (stdout_stream);
gui_output.AutoFlush = true;
Console.SetOut (gui_output);
}
}
开发者ID:FreeBSD-DotNet,项目名称:mono-tools,代码行数:35,代码来源:Shell.cs
示例6: Simple
public void Simple ()
{
//string content = @"class A { }";
string content = @"
class Foo
{
void Bar ()
{
completionList.Add (""delegate"" + sb, ""md-keyword"", GettextCatalog.GetString (""Creates anonymous delegate.""), ""delegate"" + sb + "" {"" + Document.Editor.EolMarker + stateTracker.Engine.ThisLineIndent + TextEditorProperties.IndentString + ""|"" + Document.Editor.EolMarker + stateTracker.Engine.ThisLineIndent +""};"");
}
}"
;
var stream = new MemoryStream (Encoding.UTF8.GetBytes (content));
var ctx = new CompilerContext (new CompilerSettings (), new AssertReportPrinter ());
ModuleContainer module = new ModuleContainer (ctx);
var file = new SourceFile ("test", "asdfas", 0);
CSharpParser parser = new CSharpParser (
new SeekableStreamReader (stream, Encoding.UTF8),
new CompilationSourceFile (module, file),
ctx.Report,
new ParserSession ());
RootContext.ToplevelTypes = module;
Location.Initialize (new List<SourceFile> { file });
parser.parse ();
Assert.AreEqual (0, ctx.Report.Errors);
module.Accept (new TestVisitor ());
}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:35,代码来源:ASTVisitorTest.cs
示例7: LookupTypeReflection
public virtual Type LookupTypeReflection (CompilerContext ctx, string name, Location loc, bool must_be_unique)
{
Type found_type = null;
foreach (Assembly a in referenced_assemblies) {
Type t = GetTypeInAssembly (a, name);
if (t == null)
continue;
if (!must_be_unique)
return t;
if (found_type == null) {
found_type = t;
continue;
}
// When type is forwarded
if (t.Assembly == found_type.Assembly)
continue;
ctx.Report.SymbolRelatedToPreviousError (found_type);
ctx.Report.SymbolRelatedToPreviousError (t);
if (loc.IsNull) {
Error_AmbiguousPredefinedType (ctx, loc, name, found_type);
} else {
ctx.Report.Error (433, loc, "The imported type `{0}' is defined multiple times", name);
}
return found_type;
}
return found_type;
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:34,代码来源:namespace.cs
示例8: tokenize_file
void tokenize_file (CompilationUnit file, CompilerContext ctx)
{
Stream input;
try {
input = File.OpenRead (file.Name);
} catch {
Report.Error (2001, "Source file `" + file.Name + "' could not be found");
return;
}
using (input){
SeekableStreamReader reader = new SeekableStreamReader (input, RootContext.Encoding);
Tokenizer lexer = new Tokenizer (reader, file, ctx);
int token, tokens = 0, errors = 0;
while ((token = lexer.token ()) != Token.EOF){
tokens++;
if (token == Token.ERROR)
errors++;
}
Console.WriteLine ("Tokenized: " + tokens + " found " + errors + " errors");
}
return;
}
开发者ID:nekresh,项目名称:mono,代码行数:26,代码来源:driver.cs
示例9: ModuleCompiled
public ModuleCompiled(CompilerContext context, bool isUnsafe)
: base(null)
{
this.is_unsafe = isUnsafe;
this.context = context;
types = new List<TypeContainer> ();
anonymous_types = new Dictionary<int, List<AnonymousTypeClass>> ();
}
开发者ID:speier,项目名称:shake,代码行数:9,代码来源:roottypes.cs
示例10: ModuleContainer
public ModuleContainer (CompilerContext context, bool isUnsafe)
: base (null, null, MemberName.Null, null, Kind.Root)
{
this.is_unsafe = isUnsafe;
this.context = context;
types = new ArrayList ();
anonymous_types = new Hashtable ();
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:9,代码来源:roottypes.cs
示例11: InitDynamic
//
// Initializes the code generator variables for interactive use (repl)
//
static public void InitDynamic (CompilerContext ctx, string name)
{
current_domain = AppDomain.CurrentDomain;
AssemblyName an = Assembly.GetAssemblyName (name, name);
Assembly.Builder = current_domain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run);
RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
RootContext.ToplevelTypes.Builder = Assembly.Builder.DefineDynamicModule (Basename (name), false);
Assembly.Name = Assembly.Builder.GetName ();
}
开发者ID:afaerber,项目名称:mono,代码行数:13,代码来源:codegen.cs
示例12: Report
public Report (CompilerContext context, ReportPrinter printer)
{
if (context == null)
throw new ArgumentNullException ("settings");
if (printer == null)
throw new ArgumentNullException ("printer");
this.settings = context.Settings;
this.printer = printer;
}
开发者ID:Profit0004,项目名称:mono,代码行数:10,代码来源:report.cs
示例13: Setup
public void Setup()
{
var builder = new StringBuilder();
var writer = new StringWriter(builder);
var printer = new StreamReportPrinter(writer);
var settings = new CompilerSettings();
settings.AssemblyReferences.Add("DbTool.Testing");
var context = new CompilerContext(settings, printer);
_evaluator = new Evaluator(context);
}
开发者ID:pedershk,项目名称:dotnetprograms,代码行数:11,代码来源:EvaluatorTest.cs
示例14: ModuleContainer
public ModuleContainer (CompilerContext context)
: base (null, null, MemberName.Null, null, 0)
{
this.context = context;
caching_flags &= ~(Flags.Obsolete_Undetected | Flags.Excluded_Undetected);
types = new List<TypeContainer> ();
anonymous_types = new Dictionary<int, List<AnonymousTypeClass>> ();
global_ns = new GlobalRootNamespace ();
alias_ns = new Dictionary<string, RootNamespace> ();
}
开发者ID:mpareja,项目名称:mono,代码行数:12,代码来源:roottypes.cs
示例15: Create
public static DynamicContext Create ()
{
if (dc != null)
return dc;
lock (compiler_initializer) {
if (dc != null)
return dc;
var settings = new Compiler.CompilerSettings () {
WarningLevel = 0
};
var cc = new Compiler.CompilerContext (settings, ErrorPrinter.Instance) {
IsRuntimeBinder = true
};
//
// Any later loaded assemblies are handled internally by GetAssemblyDefinition
// domain.AssemblyLoad cannot be used as that would be too destructive as we
// would hold all loaded assemblies even if they can be never visited
//
// TODO: Remove this code and rely on GetAssemblyDefinition only
//
var module = new Compiler.ModuleContainer (cc);
module.HasTypesFullyDefined = true;
// Setup fake assembly, it's used mostly to simplify checks like friend-access
var temp = new Compiler.AssemblyDefinitionDynamic (module, "dynamic");
module.SetDeclaringAssembly (temp);
var importer = new Compiler.ReflectionImporter (module, cc.BuiltinTypes) {
IgnorePrivateMembers = false,
IgnoreCompilerGeneratedField = false
};
// Import all currently loaded assemblies
// TODO: Rewrite this to populate type cache on-demand, that should greatly
// reduce our start-up cost
var domain = AppDomain.CurrentDomain;
foreach (var a in AppDomain.CurrentDomain.GetAssemblies ()) {
importer.ImportAssembly (a, module.GlobalRootNamespace);
}
cc.BuiltinTypes.CheckDefinitions (module);
module.InitializePredefinedTypes ();
dc = new DynamicContext (module, importer);
}
return dc;
}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:52,代码来源:DynamicContext.cs
示例16: Iterator
//
// Our constructor
//
private Iterator(CompilerContext ctx, IMethodData method, TypeContainer host, TypeSpec iterator_type, bool is_enumerable)
: base(new ToplevelBlock (ctx, method.Block, ParametersCompiled.EmptyReadOnlyParameters, method.Block.StartLocation),
TypeManager.bool_type,
method.Location)
{
this.OriginalMethod = method;
this.OriginalIteratorType = iterator_type;
this.IsEnumerable = is_enumerable;
this.Host = host;
this.type = method.ReturnType;
IteratorHost = Block.ChangeToIterator (this, method.Block);
}
开发者ID:speier,项目名称:shake,代码行数:16,代码来源:iterators.cs
示例17: ComputeNamespace
public void ComputeNamespace (CompilerContext ctx, Type extensionType)
{
foreach (Assembly a in referenced_assemblies) {
try {
ComputeNamespaces (a, extensionType);
} catch (TypeLoadException e) {
ctx.Report.Error (11, Location.Null, e.Message);
} catch (System.IO.FileNotFoundException) {
ctx.Report.Error (12, Location.Null, "An assembly `{0}' is used without being referenced",
a.FullName);
}
}
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:13,代码来源:namespace.cs
示例18: ImportTypes
public void ImportTypes (CompilerContext ctx)
{
foreach (Assembly a in referenced_assemblies) {
try {
ctx.MetaImporter.ImportAssembly (a, this);
} catch (TypeLoadException e) {
ctx.Report.Error (11, Location.Null, e.Message);
} catch (System.IO.FileNotFoundException) {
ctx.Report.Error (12, Location.Null, "An assembly `{0}' is used without being referenced",
a.FullName);
}
}
}
开发者ID:cthrax,项目名称:mono,代码行数:13,代码来源:namespace.cs
示例19: Evaluator
public Evaluator (CompilerSettings settings, Report report)
{
ctx = new CompilerContext (settings, report);
module = new ModuleContainer (ctx);
module.Evaluator = this;
// FIXME: Importer needs this assembly for internalsvisibleto
module.SetDeclaringAssembly (new AssemblyDefinitionDynamic (module, "evaluator"));
importer = new ReflectionImporter (module, ctx.BuildinTypes);
InteractiveBaseClass = typeof (InteractiveBase);
fields = new Dictionary<string, Tuple<FieldSpec, FieldInfo>> ();
}
开发者ID:famousthom,项目名称:monodevelop,代码行数:14,代码来源:eval.cs
示例20: Init
public void Init()
{
var printer = new StreamReportPrinter(_stringWriter);
var settings = new CompilerSettings();
settings.AssemblyReferences.AddRange(InitialAssemblies);
var context = new CompilerContext(settings, printer);
_evaluator = new Evaluator(context)
{
InteractiveBaseClass = typeof (DbToolInteractive),
DescribeTypeExpressions = true,
};
ReferenceAssemblies(typeof(Database).Assembly, typeof(DynamicSqlQuery).Assembly);
Using(InitialUsings);
DbToolInteractive.Evaluator = _evaluator;
DbToolInteractive.Output = _stringWriter;
}
开发者ID:pedershk,项目名称:dotnetprograms,代码行数:17,代码来源:MonoCSharpEvaluator.cs
注:本文中的Mono.CSharp.CompilerContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论