本文整理汇总了C#中Mono.CSharp.SourceFile类的典型用法代码示例。如果您正苦于以下问题:C# SourceFile类的具体用法?C# SourceFile怎么用?C# SourceFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SourceFile类属于Mono.CSharp命名空间,在下文中一共展示了SourceFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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
示例2: Parse
public static void Parse(SeekableStreamReader reader, SourceFile sourceFile, ModuleContainer module, ParserSession session, Report report)
{
var file = new CompilationSourceFile(module, sourceFile);
module.AddTypeContainer(file);
CSharpParser parser = new CSharpParser(reader, file, report, session);
parser.parse();
}
开发者ID:Nystul-the-Magician,项目名称:daggerfall-unity,代码行数:8,代码来源:CustomDynamicDriver.cs
示例3: AddFile
public void AddFile (SourceFile file)
{
if (include_files == null)
include_files = new Hashtable ();
if (!include_files.Contains (file.Path))
include_files.Add (file.Path, file);
}
开发者ID:lewurm,项目名称:benchmarker,代码行数:8,代码来源:location.cs
示例4: tokenize_file
void tokenize_file (SourceFile sourceFile, ModuleContainer module, ParserSession session)
{
Stream input;
try {
input = File.OpenRead (sourceFile.Name);
} catch {
Report.Error (2001, "Source file `" + sourceFile.Name + "' could not be found");
return;
}
using (input) {
SeekableStreamReader reader = new SeekableStreamReader (input, ctx.Settings.Encoding);
var file = new CompilationSourceFile (module, sourceFile);
if (sourceFile.FileType == SourceFileType.CSharp) {
Tokenizer lexer = new Tokenizer (reader, file, session);
int token, tokens = 0, errors = 0;
while ((token = lexer.token ()) != Token.EOF){
tokens++;
if (token == Token.ERROR)
errors++;
}
} else {
Mono.PlayScript.Tokenizer lexer = new Mono.PlayScript.Tokenizer (reader, file, session);
lexer.ParsingPlayScript = sourceFile.PsExtended;
int token, tokens = 0, errors = 0;
while ((token = lexer.token ()) != Mono.PlayScript.Token.EOF){
tokens++;
if (token == Mono.PlayScript.Token.ERROR)
errors++;
}
}
}
return;
}
开发者ID:robterrell,项目名称:playscript-mono,代码行数:39,代码来源:driver.cs
示例5: CompileAssemblyFromSourceBatch
// Summary:
// Compiles an assembly from the specified array of strings containing source code,
// using the specified compiler settings.
//
// Parameters:
// options:
// A System.CodeDom.Compiler.CompilerParameters object that indicates the settings
// for compilation.
//
// sources:
// The source code strings to compile.
//
// Returns:
// A System.CodeDom.Compiler.CompilerResults object that indicates the results of
// compilation.
public CompilerResults CompileAssemblyFromSourceBatch(CompilerParameters options, string[] sources)
{
var settings = ParamsToSettings(options);
int i = 0;
foreach (var _source in sources)
{
var source = _source;
Func<Stream> getStream = () => { return new MemoryStream(Encoding.UTF8.GetBytes(source ?? "")); };
var fileName = i.ToString();
var unit = new SourceFile(fileName, fileName, settings.SourceFiles.Count + 1, getStream);
settings.SourceFiles.Add(unit);
i++;
}
return CompileFromCompilerSettings(settings, options.GenerateInMemory);
}
开发者ID:aeroson,项目名称:mcs-ICodeCompiler,代码行数:32,代码来源:CodeCompiler.cs
示例6: Parse
public void Parse (SourceFile file, ModuleContainer module, ParserSession session, Report report)
{
Stream input;
try {
input = File.OpenRead (file.Name);
} catch {
report.Error (2001, "Source file `{0}' could not be found", file.Name);
return;
}
// Check 'MZ' header
if (input.ReadByte () == 77 && input.ReadByte () == 90) {
report.Error (2015, "Source file `{0}' is a binary file and not a text file", file.Name);
input.Close ();
return;
}
input.Position = 0;
SeekableStreamReader reader = new SeekableStreamReader (input, ctx.Settings.Encoding, session.StreamReaderBuffer);
Parse (reader, file, module, session, report);
if (ctx.Settings.GenerateDebugInfo && report.Errors == 0 && !file.HasChecksum) {
input.Position = 0;
var checksum = session.GetChecksumAlgorithm ();
file.SetChecksum (checksum.ComputeHash (input));
}
reader.Dispose ();
input.Close ();
}
开发者ID:Profit0004,项目名称:mono,代码行数:33,代码来源:driver.cs
示例7: GenerateDynamicPartialClasses
public static void GenerateDynamicPartialClasses(ModuleContainer module, ParserSession session, Report report)
{
List<Class> classes = new List<Class>();
FindDynamicClasses(module, classes);
if (classes.Count == 0)
return;
var os = new StringWriter();
os.Write (@"
// Generated dynamic class partial classes
");
foreach (var cl in classes) {
os.Write (@"
namespace {1} {{
partial class {2} : PlayScript.IDynamicClass {{
private PlayScript.IDynamicClass __dynamicProps;
dynamic PlayScript.IDynamicClass.__GetDynamicValue(string name) {{
object value = null;
if (__dynamicProps != null) {{
value = __dynamicProps.__GetDynamicValue(name);
}}
return value;
}}
bool PlayScript.IDynamicClass.__TryGetDynamicValue(string name, out object value) {{
if (__dynamicProps != null) {{
return __dynamicProps.__TryGetDynamicValue(name, out value);
}} else {{
value = null;
return false;
}}
}}
void PlayScript.IDynamicClass.__SetDynamicValue(string name, object value) {{
if (__dynamicProps == null) {{
__dynamicProps = new PlayScript.DynamicProperties(this);
}}
__dynamicProps.__SetDynamicValue(name, value);
}}
bool PlayScript.IDynamicClass.__DeleteDynamicValue(object name) {{
if (__dynamicProps != null) {{
return __dynamicProps.__DeleteDynamicValue(name);
}}
return false;
}}
bool PlayScript.IDynamicClass.__HasDynamicValue(string name) {{
if (__dynamicProps != null) {{
return __dynamicProps.__HasDynamicValue(name);
}}
return false;
}}
System.Collections.IEnumerable PlayScript.IDynamicClass.__GetDynamicNames() {{
if (__dynamicProps != null) {{
return __dynamicProps.__GetDynamicNames();
}}
return null;
}}
}}
}}
", PsConsts.PsRootNamespace, ((ITypeDefinition)cl).Namespace, cl.MemberName.Basename);
}
string fileStr = os.ToString();
var path = System.IO.Path.Combine (System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(module.Compiler.Settings.OutputFile)), "dynamic.g.cs");
System.IO.File.WriteAllText(path, fileStr);
byte[] byteArray = Encoding.ASCII.GetBytes( fileStr );
var input = new MemoryStream( byteArray, false );
var reader = new SeekableStreamReader (input, System.Text.Encoding.UTF8);
SourceFile file = new SourceFile(path, path, 0);
file.FileType = SourceFileType.CSharp;
Driver.Parse (reader, file, module, session, report);
}
开发者ID:rlfqudxo,项目名称:playscript-mono,代码行数:87,代码来源:ps-codegen.cs
示例8: GenerateEmbedClasses
public static void GenerateEmbedClasses(ModuleContainer module, ParserSession session, Report report)
{
List<EmbedData> embeds = new List<EmbedData>();
FindEmbedClasses(module, module, embeds);
if (embeds.Count == 0)
return;
var os = new StringWriter();
os.Write (@"
// Generated embed loader classes
");
foreach (var e in embeds) {
var loc = e._field.Location;
e._field.Initializer = new TypeOf(new MemberAccess(new SimpleName("_embed_loaders", loc), e._className), loc);
os.Write (@"
namespace _embed_loaders {{
internal class {1} : PlayScript.EmbedLoader {{
public {1}() : base({2}, {3}, {4}, {5}, {6}) {{
}}
}}
}}
", PsConsts.PsRootNamespace, e._className, e.source, e.mimeType, e.embedAsCFF, e.fontFamily, e.symbol);
}
string fileStr = os.ToString();
var path = System.IO.Path.Combine (System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(module.Compiler.Settings.OutputFile)), "embed.g.cs");
System.IO.File.WriteAllText(path, fileStr);
byte[] byteArray = Encoding.ASCII.GetBytes( fileStr );
var input = new MemoryStream( byteArray, false );
var reader = new SeekableStreamReader (input, System.Text.Encoding.UTF8);
SourceFile file = new SourceFile(path, path, 0);
file.FileType = SourceFileType.CSharp;
Driver.Parse (reader, file, module, session, report);
}
开发者ID:rlfqudxo,项目名称:playscript-mono,代码行数:46,代码来源:ps-codegen.cs
示例9: LookupFile
// <remarks>
// This is used when we encounter a #line preprocessing directive.
// </remarks>
static public SourceFile LookupFile (CompilationUnit comp_unit, string name)
{
string path;
if (!Path.IsPathRooted (name)) {
string root = Path.GetDirectoryName (comp_unit.Path);
path = Path.Combine (root, name);
} else
path = name;
if (!source_files.ContainsKey (path)) {
if (source_count >= (1 << checkpoint_bits))
return new SourceFile (name, path, 0, true);
source_files.Add (path, ++source_count);
SourceFile retval = new SourceFile (name, path, source_count, true);
source_list.Add (retval);
return retval;
}
int index = (int) source_files [path];
return (SourceFile) source_list [index - 1];
}
开发者ID:afaerber,项目名称:mono,代码行数:25,代码来源:location.cs
示例10: CompileAssemblyFromFileBatch
// Summary:
// Compiles an assembly from the source code contained within the specified files,
// using the specified compiler settings.
//
// Parameters:
// options:
// A System.CodeDom.Compiler.CompilerParameters object that indicates the settings
// for compilation.
//
// fileNames:
// The file names of the files to compile.
//
// Returns:
// A System.CodeDom.Compiler.CompilerResults object that indicates the results of
// compilation.
public CompilerResults CompileAssemblyFromFileBatch(CompilerParameters options, string[] fileNames)
{
var settings = ParamsToSettings(options);
foreach (var fileName in fileNames)
{
string path = Path.GetFullPath(fileName);
var unit = new SourceFile(fileName, path, settings.SourceFiles.Count + 1);
settings.SourceFiles.Add(unit);
}
return CompileFromCompilerSettings(settings, options.GenerateInMemory);
}
开发者ID:aeroson,项目名称:mcs-ICodeCompiler,代码行数:28,代码来源:CodeCompiler.cs
示例11: AddFile
public void AddFile (SourceFile file)
{
if (file == this)
return;
if (include_files == null)
include_files = new Dictionary<string, SourceFile> ();
if (!include_files.ContainsKey (file.Path))
include_files.Add (file.Path, file);
}
开发者ID:afaerber,项目名称:mono,代码行数:11,代码来源:location.cs
示例12: Parse
SyntaxTree Parse(ITextSource program, string fileName, int initialLine, int initialColumn)
{
lock (parseLock) {
errorReportPrinter = new ErrorReportPrinter("");
var ctx = new CompilerContext(compilerSettings.ToMono(), errorReportPrinter);
ctx.Settings.TabSize = 1;
var reader = new SeekableStreamReader(program);
var file = new SourceFile(fileName, fileName, 0);
Location.Initialize(new List<SourceFile>(new [] { file }));
var module = new ModuleContainer(ctx);
var session = new ParserSession();
session.LocationsBag = new LocationsBag();
var report = new Report(ctx, errorReportPrinter);
var parser = Driver.Parse(reader, file, module, session, report, initialLine - 1, initialColumn - 1);
var top = new CompilerCompilationUnit {
ModuleCompiled = module,
LocationsBag = session.LocationsBag,
SpecialsBag = parser.Lexer.sbag,
Conditionals = parser.Lexer.SourceFile.Conditionals
};
var unit = Parse(top, fileName);
unit.Errors.AddRange(errorReportPrinter.Errors);
CompilerCallableEntryPoint.Reset();
return unit;
}
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:26,代码来源:CSharpParser.cs
示例13: CompilationSourceFile
public CompilationSourceFile(ModuleContainer parent, SourceFile sourceFile)
: this(parent)
{
this.file = sourceFile;
}
开发者ID:exodrifter,项目名称:mcs-ICodeCompiler,代码行数:5,代码来源:namespace.cs
示例14: Parse
public void Parse (SourceFile file, ModuleContainer module)
{
Stream input;
try {
input = File.OpenRead (file.Name);
} catch {
Report.Error (2001, "Source file `{0}' could not be found", file.Name);
return;
}
// Check 'MZ' header
if (input.ReadByte () == 77 && input.ReadByte () == 90) {
Report.Error (2015, "Source file `{0}' is a binary file and not a text file", file.Name);
input.Close ();
return;
}
input.Position = 0;
SeekableStreamReader reader = new SeekableStreamReader (input, ctx.Settings.Encoding);
Parse (reader, file, module);
reader.Dispose ();
input.Close ();
}
开发者ID:nestalk,项目名称:mono,代码行数:26,代码来源:driver.cs
示例15: Parse
public static void Parse (SeekableStreamReader reader, SourceFile sourceFile, ModuleContainer module, ParserSession session, Report report)
{
var file = new CompilationSourceFile (module, sourceFile);
module.AddTypeContainer (file);
if (sourceFile.FileType == SourceFileType.CSharp) {
CSharpParser parser = new CSharpParser (reader, file, session);
parser.parse ();
} else {
PlayScriptParser parser = new PlayScriptParser (reader, file, session);
parser.parsing_playscript = sourceFile.PsExtended;
parser.parse ();
}
}
开发者ID:robterrell,项目名称:playscript-mono,代码行数:14,代码来源:driver.cs
示例16: Parse
public CSharpParser Parse (SeekableStreamReader reader, SourceFile sourceFile, ModuleContainer module)
{
var file = new CompilationSourceFile (module, sourceFile);
module.AddTypeContainer (file);
CSharpParser parser = new CSharpParser (reader, file);
parser.Lexer.sbag = new SpecialsBag ();
parser.parse ();
return parser;
}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:10,代码来源:driver.cs
示例17: LookupFile
//
// This is used when we encounter a #line preprocessing directive during parsing
// to register additional source file names
//
public SourceFile LookupFile (CompilationSourceFile comp_unit, string name)
{
if (all_source_files == null) {
all_source_files = new Dictionary<string, SourceFile> ();
foreach (var source in SourceFiles)
all_source_files[source.FullPathName] = source;
}
string path;
if (!Path.IsPathRooted (name)) {
string root = Path.GetDirectoryName (comp_unit.SourceFile.FullPathName);
path = Path.Combine (root, name);
} else
path = name;
SourceFile retval;
if (all_source_files.TryGetValue (path, out retval))
return retval;
retval = new SourceFile (name, path, all_source_files.Count + 1);
Location.AddFile (retval);
all_source_files.Add (path, retval);
return retval;
}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:28,代码来源:context.cs
示例18: Parse
public CompilationUnit Parse(Stream stream, string fileName, int lineModifier = 0)
{
lock (parseLock) {
errorReportPrinter = new ErrorReportPrinter ("");
var ctx = new CompilerContext (CompilerSettings, errorReportPrinter);
ctx.Settings.TabSize = 1;
var reader = new SeekableStreamReader (stream, Encoding.UTF8);
var file = new SourceFile (fileName, fileName, 0);
Location.Initialize (new List<SourceFile> (new [] { file }));
var module = new ModuleContainer (ctx);
var parser = Driver.Parse (reader, file, module, lineModifier);
var top = new CompilerCompilationUnit () {
ModuleCompiled = module,
LocationsBag = parser.LocationsBag,
SpecialsBag = parser.Lexer.sbag
};
var unit = Parse (top, fileName, lineModifier);
unit.Errors.AddRange (errorReportPrinter.Errors);
CompilerCallableEntryPoint.Reset ();
return unit;
}
}
开发者ID:head-thrash,项目名称:monodevelop,代码行数:23,代码来源:CSharpParser.cs
示例19: Push
static public void Push (CompilationUnit compile_unit, SourceFile file)
{
current_source = file != null ? file.Index : -1;
current_compile_unit = compile_unit != null ? compile_unit.Index : -1;
// File is always pushed before being changed.
}
开发者ID:afaerber,项目名称:mono,代码行数:6,代码来源:location.cs
示例20: AddIncludeFile
public void AddIncludeFile(SourceFile file)
{
if (file == this.file)
return;
if (include_files == null)
include_files = new Dictionary<string, SourceFile> ();
if (!include_files.ContainsKey (file.FullPathName))
include_files.Add (file.FullPathName, file);
}
开发者ID:exodrifter,项目名称:mcs-ICodeCompiler,代码行数:11,代码来源:namespace.cs
注:本文中的Mono.CSharp.SourceFile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论