本文整理汇总了C#中ErrorNodeList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ErrorNodeList.Add方法的具体用法?C# ErrorNodeList.Add怎么用?C# ErrorNodeList.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ErrorNodeList
的用法示例。
在下文中一共展示了ErrorNodeList.Add方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseOptionBatchFile
public string[] ParseOptionBatchFile(CompilerParameters options, string batchFileName, ErrorNodeList errors, Hashtable alreadySeenResponseFiles){
try{
batchFileName = System.IO.Path.GetFullPath(batchFileName);
if (alreadySeenResponseFiles[batchFileName] != null){
errors.Add(this.CreateErrorNode(Error.DuplicateResponseFile, batchFileName));
return null;
}else
alreadySeenResponseFiles[batchFileName] = batchFileName;
string optionBatch = this.ReadSourceText(batchFileName, options, errors);
StringCollection opts = new StringCollection();
bool insideQuotedString = false;
bool insideComment = false;
for (int i = 0, j = 0, n = optionBatch.Length; j < n; j++){
switch(optionBatch[j]){
case (char)0x0A:
case (char)0x0D:
insideQuotedString = false;
if (insideComment){
insideComment = false;
i = j+1;
break;
}
goto case ' ';
case ' ':
case '\t':
if (insideQuotedString || insideComment) break;
if (i < j)
opts.Add(optionBatch.Substring(i, j-i));
i = j+1;
break;
case '"':
if (insideQuotedString){
if (!insideComment)
opts.Add(optionBatch.Substring(i, j-i));
insideQuotedString = false;
}else
insideQuotedString = true;
i = j+1;
break;
case '#':
insideComment = true;
break;
default:
if (j == n-1 && i < j)
opts.Add(optionBatch.Substring(i, n-i));
break;
}
}
int c = opts.Count;
string[] args = new string[c];
opts.CopyTo(args, 0);
return this.ParseCompilerParameters(options, args, errors, false);
}catch(ArgumentException){
}catch(System.IO.IOException){
}catch(NotSupportedException){
}catch(System.Security.SecurityException){
}catch(UnauthorizedAccessException){
}
errors.Add(this.CreateErrorNode(Error.BatchFileNotRead, batchFileName, this.CreateErrorNode(Error.NoSuchFile, batchFileName).GetMessage()));
return null;
}
示例2: ParseCompilerOption
public virtual bool ParseCompilerOption(CompilerParameters options, string arg, ErrorNodeList errors){
CompilerOptions coptions = options as CompilerOptions;
int n = arg.Length;
if (n <= 1) return false;
char ch = arg[0];
if (ch != '/' && ch != '-') return false;
ch = arg[1];
switch(Char.ToLower(ch)){
case 'a':
if (coptions == null) return false;
StringCollection referencedModules = this.ParseNamedArgumentList(arg, "addmodule", "addmodule");
if (referencedModules != null){
if (coptions.ReferencedModules == null) coptions.ReferencedModules = new StringList(referencedModules.Count);
foreach (string referencedModule in referencedModules)
coptions.ReferencedModules.Add(referencedModule);
return true;
}
return false;
case 'b':
if (coptions == null) return false;
string baseAddress = this.ParseNamedArgument(arg, "baseaddress", "baseaddress");
if (baseAddress != null){
try{
coptions.BaseAddress = long.Parse(baseAddress, null); //TODO: figure out acceptable formats
return true;
}catch{}
}
string bugReportFileName = this.ParseNamedArgument(arg, "bugreport", "bugreport");
if (bugReportFileName != null){
coptions.BugReportFileName = bugReportFileName;
return true;
}
if (this.ParseName(arg, "break", "break")) {
System.Diagnostics.Debugger.Break();
return true;
}
return false;
case 'c':
if (coptions == null) return false;
string codePage = this.ParseNamedArgument(arg, "codepage", "codepage");
if (codePage != null){
try{
coptions.CodePage = int.Parse(codePage, null); //TODO: figure out acceptable formats
return true;
}catch{}
}
object checkedOn = this.ParseNamedBoolean(arg, "checked", "checked");
if (checkedOn != null){
coptions.CheckedArithmetic = (bool)checkedOn;
return true;
}
if (this.ParseName(arg, "compile", "c")){
coptions.CompileAndExecute = false;
return true;
}
return false;
case 'd':
if (coptions != null){
string debugOption = this.ParseNamedArgument(arg, "debug", "debug");
if (debugOption != null){
if (debugOption == "pdbonly"){
coptions.PDBOnly = true;
return true;
}else if (debugOption == "full"){
coptions.PDBOnly = false;
return true;
}else
return false;
}
}
object debugOn = this.ParseNamedBoolean(arg, "debug", "debug");
if (debugOn != null){
options.IncludeDebugInformation = (bool)debugOn;
return true;
}
if (coptions != null){
object delaySign = this.ParseNamedBoolean(arg, "delaysign", "delay");
if (delaySign != null){
coptions.DelaySign = (bool)delaySign;
return true;
}
string xmlDocFileName = this.ParseNamedArgument(arg, "doc", "doc");
if (xmlDocFileName != null){
coptions.XMLDocFileName = xmlDocFileName;
return true;
}
StringCollection definedSymbols = this.ParseNamedArgumentList(arg, "define", "d");
if (definedSymbols != null){
if (coptions.DefinedPreProcessorSymbols == null)
coptions.DefinedPreProcessorSymbols = new StringList(definedSymbols.Count);
foreach (string definedSymbol in definedSymbols)
coptions.DefinedPreProcessorSymbols.Add(definedSymbol);
return true;
}
StringCollection disabledFeatures = this.ParseNamedArgumentList(arg, "disable", "disable");
if (disabledFeatures != null){
foreach (string feature in disabledFeatures){
switch (feature){
case "ac":
case "assumechecks":
//.........这里部分代码省略.........
示例3: ParseOptionBatch
public virtual string[] ParseOptionBatch(CompilerParameters options, string arg, ErrorNodeList errors, Hashtable alreadySeenResponseFiles){
Debug.Assert(arg != null);
if (arg.Length < 2){
errors.Add(this.CreateErrorNode(Error.InvalidCompilerOption, arg));
return null;
}
return ParseOptionBatchFile(options, arg.Substring(1), errors, alreadySeenResponseFiles);
}
示例4: CreateDocumentText
public virtual DocumentText CreateDocumentText(string fileName, CompilerResults results, CompilerParameters options, ErrorNodeList errorNodes, bool canUseMemoryMap){
#if !ROTOR
if (canUseMemoryMap){
int applicableCodePage = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ANSICodePage;
CompilerOptions coptions = options as CompilerOptions;
if (coptions != null && coptions.CodePage != null) applicableCodePage = (int)coptions.CodePage;
int asciiCodePage = System.Globalization.CultureInfo.InvariantCulture.TextInfo.ANSICodePage;
if (applicableCodePage == asciiCodePage){
//If there is no unicode signature at the start of the file, it seems reasonably safe to assume that 1 byte == 1 char
//In that case we can bypass the overhead of BCL file classes and use a memory mapped file instead.
unsafe{
try{
MemoryMappedFile mmFile = new MemoryMappedFile(fileName);
try{
byte b0 = *mmFile.Buffer;
if (b0 == 'M' && *(mmFile.Buffer+1) == 'Z'){
//This is a binary file. Give an appropriate error.
errorNodes.Add(this.CreateErrorNode(Error.IsBinaryFile, System.IO.Path.GetFullPath(fileName)));
this.ProcessErrors(options, results, errorNodes);
mmFile.Dispose();
return null;
}else if (b0 != 0xff && b0 != 0xfe && b0 != 0xef){
// No unicode signature, it seems. Go ahead and compile using the memory mapped file.
return new DocumentText(mmFile);
}
}catch(Exception e){
errorNodes.Add(this.CreateErrorNode(Error.InternalCompilerError, e.Message));
this.ProcessErrors(options, results, errorNodes);
return new DocumentText("");
}
}catch{}
}
}
}
#endif
return new DocumentText(this.ReadSourceText(fileName, options, errorNodes));
}
示例5: ParseCompilerParameters
public virtual string[] ParseCompilerParameters(CompilerParameters options, string[] arguments, ErrorNodeList errors, bool checkSourceFiles){
StringCollection filesToCompile = new StringCollection();
Hashtable alreadySeenResponseFiles = null;
bool gaveFileNotFoundError = false;
foreach (string arg in arguments){
if (arg == null || arg.Length == 0) continue;
char ch = arg[0];
if (ch == '@'){
if (alreadySeenResponseFiles == null) alreadySeenResponseFiles = new Hashtable();
string[] fileNames = this.ParseOptionBatch(options, arg, errors, alreadySeenResponseFiles);
if (fileNames != null) filesToCompile.AddRange(fileNames);
}else if (ch == '/' || ch == '-'){
if (!this.ParseCompilerOption(options, arg, errors))
errors.Add(this.CreateErrorNode(Error.InvalidCompilerOption, arg));
}else {
// allow URL syntax
string s = arg.Replace('/', Path.DirectorySeparatorChar);
// allow wildcards
string path = (arg.IndexOf("\\")<0) ? ".\\" : Path.GetDirectoryName(arg);
string pattern = Path.GetFileName(arg);
string extension = Path.HasExtension(pattern) ? Path.GetExtension(pattern) : "";
bool notAFile = true;
if (path != null && Directory.Exists(path)){
foreach (string file in Directory.GetFiles(path, pattern)){
string ext = Path.HasExtension(file) ? Path.GetExtension(file) : "";
if (string.Compare(extension, ext, true, System.Globalization.CultureInfo.InvariantCulture) != 0) continue;
filesToCompile.Add(file);
notAFile = false;
}
}
if (notAFile && checkSourceFiles){
errors.Add(this.CreateErrorNode(Error.SourceFileNotRead, arg, this.CreateErrorNode(Error.NoSuchFile, arg).GetMessage()));
gaveFileNotFoundError = true;
}
}
}
if (checkSourceFiles && filesToCompile.Count == 0 && !gaveFileNotFoundError)
errors.Add(this.CreateErrorNode(Error.NoSourceFiles));
string[] result = new string[filesToCompile.Count];
filesToCompile.CopyTo(result, 0);
return result;
}
示例6: SetEntryPoint
public void SetEntryPoint(Compilation compilation, CompilerResults results){
Method mainMethod = null;
string mainClassOrFileName = null;
if (compilation.CompilerParameters.MainClass != null && compilation.CompilerParameters.MainClass.Length > 0){
mainClassOrFileName = compilation.CompilerParameters.MainClass;
int nsSeparatorPos = mainClassOrFileName.LastIndexOf('.');
Identifier ns = Identifier.For(mainClassOrFileName.Substring(0, nsSeparatorPos == -1 ? 0 : nsSeparatorPos));
Identifier id = Identifier.For(mainClassOrFileName.Substring(nsSeparatorPos+1));
TypeNode mainClass = compilation.TargetModule.GetType(ns, id);
if (mainClass != null)
mainMethod = this.GetMainMethod(mainClass, compilation.CompilerParameters, results);
}else{
TypeNodeList types = compilation.TargetModule.Types;
bool firstTime = true;
for (int i = 0, n = types.Count; i < n; i++){
TypeNode t = types[i];
if (t == null) continue;
Method m = this.GetMainMethod(t, compilation.CompilerParameters, results);
if (m != null){
if (compilation.CompilerParameters.OutputAssembly == null || compilation.CompilerParameters.OutputAssembly.Length == 0){
Debug.Assert(compilation.CompilerParameters.GenerateExecutable);
if (m.SourceContext.Document != null)
this.SetOutputFileName(compilation.CompilerParameters, m.SourceContext.Document.Name);
}
if (mainMethod == null)
mainMethod = m;
else if (compilation.CompilerParameters.GenerateExecutable){
if (firstTime){
this.HandleMultipleMainMethodError(mainMethod, compilation.CompilerParameters, results);
firstTime = false;
}
this.HandleMultipleMainMethodError(m, compilation.CompilerParameters, results);
}
}
}
}
if (!compilation.CompilerParameters.GenerateExecutable) return;
if (mainMethod == null){
ErrorNodeList errorNodes = new ErrorNodeList(1);
if (mainClassOrFileName == null) mainClassOrFileName = compilation.CompilerParameters.OutputAssembly;
if (mainClassOrFileName == null){
for (int i = 0, n = compilation.CompilationUnits == null ? 0 : compilation.CompilationUnits.Count; i < n; i++){
CompilationUnit cu = compilation.CompilationUnits[i];
if (cu == null || cu.Name == null) continue;
this.SetOutputFileName(compilation.CompilerParameters, cu.Name.ToString());
break;
}
mainClassOrFileName = compilation.CompilerParameters.OutputAssembly;
}
errorNodes.Add(this.CreateErrorNode(Error.NoMainMethod, mainClassOrFileName == null ? "" : mainClassOrFileName));
this.ProcessErrors(compilation.CompilerParameters, results, errorNodes);
}
compilation.TargetModule.EntryPoint = mainMethod;
if (mainMethod != null && mainMethod.SourceContext.Document != null &&
(compilation.CompilerParameters.OutputAssembly == null || compilation.CompilerParameters.OutputAssembly.Length == 0)){
this.SetOutputFileName(compilation.CompilerParameters, mainMethod.SourceContext.Document.Name);
}
}
示例7: SaveOrLoadAssembly
public virtual void SaveOrLoadAssembly(AssemblyNode assem, CompilerParameters options, CompilerResults results, ErrorNodeList errorNodes){
if (assem == null) return;
AssemblyReferenceList arefs = assem.AssemblyReferences;
//TODO: give the error in the context of the member that made the reference
for (int i = 0, n = arefs == null ? 0 : arefs.Count; i < n; i++){
AssemblyReference aref = arefs[i];
if (aref == null || aref.Assembly == null) continue;
ArrayList metadataErrors = aref.Assembly.MetadataImportErrors;
if (metadataErrors == null) continue;
foreach (Exception mdErr in metadataErrors)
if (mdErr.Message.StartsWith("Assembly reference not resolved"))
results.Errors.Add(new CompilerError(aref.Assembly.Name+".dll", 0, 0, "0", mdErr.Message));
}
if (results.NativeCompilerReturnValue != 0) return; //TODO: allow option to override this
if (options.GenerateInMemory){
System.Security.Policy.Evidence evidence = options.Evidence;
CompilerOptions cOptions = options as CompilerOptions;
System.AppDomain targetDomain = cOptions == null ? null : cOptions.TargetAppDomain;
if (targetDomain == null) targetDomain = AppDomain.CurrentDomain;
for (int i = 0, n = arefs == null ? 0 : arefs.Count; i < n; i++){
AssemblyReference aref = arefs[i];
if (aref == null || aref.Assembly == null) continue;
aref.Assembly.GetRuntimeAssembly(evidence, targetDomain);
}
results.CompiledAssembly = assem.GetRuntimeAssembly(evidence, targetDomain);
}else{
ErrorNodeList errors = new ErrorNodeList(0);
string fileName = this.GetTargetFileName(options, errors);
this.AddResourcesAndIcons(assem, options, errors);
if (errors.Count == 0){
try{
assem.WriteModule(fileName, options);
}catch(KeyFileNotFoundException){
ErrorNode keyFileMissing = this.CreateErrorNode(Error.AssemblyKeyFileMissing, ((CompilerOptions)options).AssemblyKeyFile);
errors.Add(this.CreateErrorNode(Error.AssemblyCouldNotBeSigned, assem.Location, keyFileMissing.GetMessage()));
errorNodes.Add(errors[0]);
this.ProcessErrors(options, results, errors);
}catch(AssemblyCouldNotBeSignedException){
ErrorNode unknownCryptoFailure = this.CreateErrorNode(Error.UnknownCryptoFailure);
errors.Add(this.CreateErrorNode(Error.AssemblyCouldNotBeSigned, assem.Location, unknownCryptoFailure.GetMessage()));
errorNodes.Add(errors[0]);
this.ProcessErrors(options, results, errors);
}catch(Exception e){
errors.Add(this.CreateErrorNode(Error.InternalCompilerError, e.Message));
errorNodes.Add(errors[0]);
this.ProcessErrors(options, results, errors);
}
CompilerOptions coptions = options as CompilerOptions;
if (coptions != null && coptions.XMLDocFileName != null && coptions.XMLDocFileName.Length > 0)
assem.WriteDocumentation(new StreamWriter(coptions.XMLDocFileName));
results.PathToAssembly = fileName;
}else{
this.ProcessErrors(options, results, errors);
for (int i = 0, n = errors.Count; i < n; i++)
errorNodes.Add(errors[i]);
}
}
}
示例8: ReadSourceText
public virtual string ReadSourceText(string fileName, CompilerParameters options, ErrorNodeList errorNodes){
CompilerOptions coptions = options as CompilerOptions;
try{
using (System.IO.FileStream inputStream = new System.IO.FileStream(fileName,
System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)){
// get the file size
long size = inputStream.Seek(0, System.IO.SeekOrigin.End);
if (size > int.MaxValue){
errorNodes.Add(this.CreateErrorNode(Error.SourceFileTooLarge, fileName));
return "";
}
inputStream.Seek(0, System.IO.SeekOrigin.Begin);
int b1 = inputStream.ReadByte();
int b2 = inputStream.ReadByte();
if (b1 == 'M' && b2 == 'Z'){
errorNodes.Add(this.CreateErrorNode(Error.IsBinaryFile, System.IO.Path.GetFullPath(fileName)));
return "";
}
inputStream.Seek(0, System.IO.SeekOrigin.Begin);
Encoding encoding = Encoding.Default;
if (coptions != null && coptions.CodePage != null){
try{
encoding = Encoding.GetEncoding((int)coptions.CodePage);
}catch(System.ArgumentException){
errorNodes.Add(this.CreateErrorNode(Error.InvalidCodePage, coptions.CodePage.ToString()));
return "";
}
}
System.IO.StreamReader reader = new System.IO.StreamReader(inputStream, encoding, true); //last param allows markers to override encoding
//Read the contents of the file into an array of char and return as a string
char[] sourceText = new char[(int)size];
int length = reader.Read(sourceText, 0, (int)size);
return new String(sourceText, 0, length);
}
}catch(Exception e){
errorNodes.Add(this.CreateErrorNode(Error.SourceFileNotRead, fileName, e.Message));
return "";
}
}
示例9: AddResourcesAndIcons
public virtual void AddResourcesAndIcons(Module module, CompilerParameters options, ErrorNodeList errors){
if (options == null) return;
CompilerOptions coptions = options as CompilerOptions;
string win32ResourceFilePath = options.Win32Resource;
if (win32ResourceFilePath != null && win32ResourceFilePath.Length > 0){
if (!File.Exists(win32ResourceFilePath) && options.OutputAssembly != null)
win32ResourceFilePath = PathWrapper.Combine(Path.GetDirectoryName(options.OutputAssembly), win32ResourceFilePath);
try{
module.AddWin32ResourceFile(win32ResourceFilePath);
}catch(OutOfMemoryException){
errors.Add(this.CreateErrorNode(Error.InvalidWin32ResourceFileContent, win32ResourceFilePath));
}catch(NullReferenceException){
errors.Add(this.CreateErrorNode(Error.InvalidWin32ResourceFileContent, win32ResourceFilePath));
}catch(Exception e){
errors.Add(this.CreateErrorNode(Error.Win32ResourceFileNotRead, win32ResourceFilePath, e.Message));
}
}
if (coptions != null && coptions.Win32Icon != null && coptions.Win32Icon.Length > 0){
string win32iconFilePath = coptions.Win32Icon;
if (!File.Exists(win32iconFilePath) && options.OutputAssembly != null)
win32iconFilePath = PathWrapper.Combine(Path.GetDirectoryName(options.OutputAssembly), win32iconFilePath);
try{
module.AddWin32Icon(win32iconFilePath);
}catch(OutOfMemoryException){
errors.Add(this.CreateErrorNode(Error.AutoWin32ResGenFailed,
this.CreateErrorNode(Error.Win32IconFileNotRead, win32iconFilePath,
this.CreateErrorNode(Error.InvalidData).GetMessage()).GetMessage()));
}catch(NullReferenceException){
errors.Add(this.CreateErrorNode(Error.AutoWin32ResGenFailed,
this.CreateErrorNode(Error.Win32IconFileNotRead, win32iconFilePath,
this.CreateErrorNode(Error.InvalidData).GetMessage()).GetMessage()));
}catch(Exception e){
errors.Add(this.CreateErrorNode(Error.AutoWin32ResGenFailed,
this.CreateErrorNode(Error.Win32IconFileNotRead, win32iconFilePath, e.Message).GetMessage()));
}
}
if (coptions != null && (win32ResourceFilePath == null || win32ResourceFilePath.Length == 0))
module.AddWin32VersionInfo(coptions);
if (coptions != null && coptions.EmbeddedResources != null && coptions.EmbeddedResources.Count > 0){
if (module.Resources == null) module.Resources = new ResourceList();
for (int i = 0, n = coptions.EmbeddedResources.Count; i < n; i++){
string resource = coptions.EmbeddedResources[i];
if (resource == null) continue;
string resourceFileName = resource;
string resourceName = Path.GetFileName(resource);
int firstComma = resource.IndexOf(',');
if (firstComma > 0){
resourceFileName = resource.Substring(0, firstComma);
resourceName = resource.Substring(firstComma+1);
}else if (coptions.RootNamespace != null && coptions.RootNamespace.Length > 0){
resourceName = coptions.RootNamespace + "." + resourceName;
}
byte[] resourceContents = null;
resourceFileName = PathWrapper.Combine(Path.GetDirectoryName(options.OutputAssembly), resourceFileName);
try{
using (System.IO.FileStream resStream = File.OpenRead(resourceFileName)){
long size = resStream.Length;
if (size > int.MaxValue) continue; //TODO: error message
int len = (int)size;
resourceContents = new byte[len];
resStream.Read(resourceContents, 0, len);
}
}catch(Exception e){
errors.Add(this.CreateErrorNode(Error.CannotReadResource, Path.GetFileName(resourceFileName), e.Message));
}
Resource res = new Resource();
res.Name = resourceName;
res.IsPublic = true; //TODO: get this value from the resource string
res.DefiningModule = module;
res.Data = resourceContents;
module.Resources.Add(res);
}
}
if (coptions != null && coptions.LinkedResources != null && coptions.LinkedResources.Count > 0){
if (module.Resources == null) module.Resources = new ResourceList();
for (int i = 0, n = coptions.LinkedResources.Count; i < n; i++){
string resource = coptions.LinkedResources[i];
if (resource == null) continue;
string resourceFileName = resource;
string resourceName = resource;
int firstComma = resource.IndexOf(',');
if (firstComma > 0){
resourceFileName = resource.Substring(0, firstComma);
resourceName = resource.Substring(firstComma+1);
}
Resource res = new Resource();
res.Name = resourceName;
res.IsPublic = true;
res.DefiningModule = new Module();
res.DefiningModule.Kind = ModuleKindFlags.ManifestResourceFile;
res.DefiningModule.Name = resourceFileName;
res.DefiningModule.Location = PathWrapper.Combine(Path.GetDirectoryName(options.OutputAssembly), resourceFileName); ;
res.Data = null;
module.Resources.Add(res);
}
}
}
示例10: GetMainMethod
public virtual Method GetMainMethod(TypeNode type, CompilerParameters options, CompilerResults results){
MemberList members = type.Members;
Method mainMethod = null;
bool multipleMainMethods = false;
for (int i = 0, n = members.Count; i < n; i++){
Member mem = members[i];
Method m = mem as Method;
if (m == null){
TypeNode nt = mem as TypeNode;
if (nt == null) continue;
m = this.GetMainMethod(nt, options, results);
if (m == null) continue;
if (type.IsGeneric || m.IsGeneric){
this.HandleGenericMainMethodError(m, options, results);
continue;
}
if (mainMethod != null){
multipleMainMethods = true;
this.HandleMultipleMainMethodError(mainMethod, options, results);
}
mainMethod = m;
continue;
}
if (m.Name.UniqueIdKey != StandardIds.Main.UniqueIdKey || !m.IsStatic) continue;
if (m.ReturnType != SystemTypes.Void && m.ReturnType != SystemTypes.Int32) goto warning;
int np = m.Parameters == null ? 0 : m.Parameters.Count;
if (np > 1) goto warning;
if (np == 1){
TypeNode t = m.Parameters[0].Type;
OptionalModifier om = t as OptionalModifier;
if (om != null && om.Modifier == SystemTypes.NonNullType){
t = om.ModifiedType;
}
ArrayType pt =t as ArrayType;
if (pt == null) goto warning;
if (pt.Rank != 1 || TypeNode.StripModifier(pt.ElementType, SystemTypes.NonNullType) != SystemTypes.String) goto warning;
if (pt.ElementType != SystemTypes.String)
m.Parameters[0].Type = SystemTypes.String.GetArrayType(1);
}
if (type.IsGeneric || m.IsGeneric) {
this.HandleGenericMainMethodError(m, options, results);
continue;
}
if (mainMethod != null && !mainMethod.ParametersMatch(m.Parameters)) { //second condition avoid redundant message
multipleMainMethods = true;
this.HandleMultipleMainMethodError(mainMethod, options, results);
}
mainMethod = m;
continue;
warning:
ErrorNodeList errorNodes = new ErrorNodeList(1);
errorNodes.Add(this.CreateErrorNode(Error.InvalidMainMethodSignature, m));
this.ProcessErrors(options, results, errorNodes);
}
if (multipleMainMethods)
this.HandleMultipleMainMethodError(mainMethod, options, results);
return mainMethod;
}
示例11: AddReferenceToModule
protected virtual void AddReferenceToModule(CompilerOptions options, Module module, string name, string aliases, ErrorNodeList errorNodes, TrivialHashtable previousReferences,
bool giveErrorsForDuplicateReferences, bool assemblyReference){
this.AllocateAssemblyCacheIfNeeded();
Error e = assemblyReference ? Error.NotAnAssembly : Error.NotAModule;
string aname = name;
string fname = System.IO.Path.GetFileName(aname);
string ext = System.IO.Path.GetExtension(fname);
bool providedDefaultExtension = false;
if (assemblyReference){
if (ext.ToLower(CultureInfo.InvariantCulture) != ".dll" && ext.ToLower(CultureInfo.InvariantCulture) != ".exe"){
aname = aname+".dll";
fname = fname+".dll";
providedDefaultExtension = true;
}
}else{
if (ext.ToLower(CultureInfo.InvariantCulture) != ".netmodule"){
aname = aname+".netmodule";
fname = fname+".netmodule";
providedDefaultExtension = true;
}
}
Module rModule = null;
if (providedDefaultExtension)
rModule = this.GetModuleFromReferencedCompilation(name);
if (rModule == null)
rModule = this.GetModuleFromReferencedCompilation(aname);
if (rModule == null){
e = Error.NoSuchFile;
if (fname == aname){//Simple name, let compiler probe for it
if (providedDefaultExtension) {
aname = this.GetFullyQualifiedNameForReferencedLibrary(options, name);
if (aname == null)
aname = this.GetFullyQualifiedNameForReferencedLibrary(options, aname);
}else
aname = this.GetFullyQualifiedNameForReferencedLibrary(options, aname);
if (aname == null) goto error;
}else{
if (!System.IO.File.Exists(aname)){
if (!System.IO.File.Exists(name)) goto error;
aname = name;
}
}
rModule = Module.GetModule(aname, this.AssemblyCache, !options.MayLockFiles, options.LoadDebugSymbolsForReferencedAssemblies, true);
if (rModule == null) goto error;
e = assemblyReference ? Error.NotAnAssembly : Error.NotAModule;
}
AssemblyNode rAssem = rModule as AssemblyNode;
if (rAssem != null){
if (!assemblyReference) goto error;
}else{
if (assemblyReference) goto error;
}
Node prevRef = previousReferences[rModule.UniqueKey] as Node;
AssemblyReference aref = prevRef as AssemblyReference;
if (prevRef != null) {
if (aref == null || aliases == null || aliases.Length == 0){
if (!giveErrorsForDuplicateReferences) return;
e = assemblyReference ? Error.DuplicateAssemblyReference : Error.DuplicateModuleReference;
goto error;
}
}
if (assemblyReference){
if (aref == null) aref = new AssemblyReference(rAssem);
if (aliases != null && aliases.Length > 0){
if (aref.Aliases == null) aref.Aliases = new IdentifierList();
string[] aliasArr = aliases.Split(',');
foreach (string alias in aliasArr)
if (alias != null && alias.Length > 0) aref.Aliases.Add(Identifier.For(alias));
}
module.AssemblyReferences.Add(aref);
previousReferences[rModule.UniqueKey] = aref;
}else{
ModuleReference mref = new ModuleReference(name, rModule);
module.ModuleReferences.Add(mref);
previousReferences[rModule.UniqueKey] = mref;
}
return;
error:
errorNodes.Add(this.CreateErrorNode(e, name));
}
示例12: HandleMultipleMainMethodError
public virtual void HandleMultipleMainMethodError(Method mainMethod, CompilerParameters options, CompilerResults results) {
ErrorNode enode = this.CreateErrorNode(Error.MultipleMainMethods, mainMethod);
string[] mpars = new String[2];
mpars[0] = enode.MessageParameters[0];
mpars[1] = options.OutputAssembly;
enode.MessageParameters = mpars;
ErrorNodeList errorNodes = new ErrorNodeList(1);
errorNodes.Add(enode);
this.ProcessErrors(options, results, errorNodes);
}
示例13: HandleGenericMainMethodError
public virtual void HandleGenericMainMethodError(Method mainMethod, CompilerParameters options, CompilerResults results) {
ErrorNode enode = this.CreateErrorNode(Error.MainCantBeGeneric, mainMethod);
ErrorNodeList errorNodes = new ErrorNodeList(1);
errorNodes.Add(enode);
this.ProcessErrors(options, results, errorNodes);
}
示例14: GetMainMethod
public virtual Method GetMainMethod(TypeNode type, CompilerParameters options, CompilerResults results){
MemberList members = type.Members;
Method mainMethod = null;
bool multipleMainMethods = false;
for (int i = 0, n = members.Count; i < n; i++){
Member mem = members[i];
Method m = mem as Method;
if (m == null){
TypeNode nt = mem as TypeNode;
if (nt == null) continue;
m = this.GetMainMethod(nt, options, results);
if (m == null) continue;
if (type.IsGeneric || m.IsGeneric){
this.HandleGenericMainMethodError(m, options, results);
continue;
}
if (mainMethod != null){
multipleMainMethods = true;
this.HandleMultipleMainMethodError(mainMethod, options, results);
}
mainMethod = m;
continue;
}
if (m.Name.UniqueIdKey != StandardIds.Main.UniqueIdKey || !m.IsStatic) continue;
if (m.ReturnType != SystemTypes.Void && m.ReturnType != SystemTypes.Int32) goto warning;
int np = m.Parameters == null ? 0 : m.Parameters.Count;
if (np > 1) goto warning;
if (np == 1){
bool nonNullParameter;
TypeNode t = m.Parameters[0].Type.StripOptionalModifiers(out nonNullParameter);
ArrayType pt = t as ArrayType;
if (pt == null) goto warning;
if (pt.Rank != 1 || TypeNode.StripModifier(pt.ElementType, SystemTypes.NonNullType) != SystemTypes.String) goto warning;
m.Parameters[0].Type = SystemTypes.String.GetArrayType(1); // set it just in case it was string![] or string![]!
if (pt.ElementType != SystemTypes.String) {
// then it was "non-null string" because of call to StripModifier above
// so stick an attribute on so type can be reconstructed
InstanceInitializer nnAECtor = SystemTypes.NotNullArrayElementsAttribute.GetConstructor();
if (m.Parameters[0].Attributes == null)
m.Parameters[0].Attributes = new AttributeList(1);
m.Parameters[0].Attributes.Add(new AttributeNode(new MemberBinding(null, nnAECtor), null, AttributeTargets.Parameter));
}
if (nonNullParameter) {
// stick an attribute on so type can be reconstructed
InstanceInitializer nnCtor = SystemTypes.NotNullAttribute.GetConstructor();
if (m.Parameters[0].Attributes == null)
m.Parameters[0].Attributes = new AttributeList(1);
m.Parameters[0].Attributes.Add(new AttributeNode(new MemberBinding(null, nnCtor), null, AttributeTargets.Parameter));
}
}
if (type.IsGeneric || m.IsGeneric) {
this.HandleGenericMainMethodError(m, options, results);
continue;
}
if (mainMethod != null && !mainMethod.ParametersMatch(m.Parameters)) { //second condition avoid redundant message
multipleMainMethods = true;
this.HandleMultipleMainMethodError(mainMethod, options, results);
}
mainMethod = m;
continue;
warning:
ErrorNodeList errorNodes = new ErrorNodeList(1);
errorNodes.Add(this.CreateErrorNode(Error.InvalidMainMethodSignature, m));
this.ProcessErrors(options, results, errorNodes);
}
if (multipleMainMethods)
this.HandleMultipleMainMethodError(mainMethod, options, results);
return mainMethod;
}