コード例 #1
0
ファイル: Parser.cs プロジェクト: dbremner/specsharp
 private void ProcessOptions(SpecSharpCompilerOptions options){
   if (options == null) return;
   this.insideCheckedBlock = options.CheckedArithmetic;
   this.insideUncheckedBlock = false;
   this.compatibilityOn = options.Compatibility;
   this.allowUnsafeCode = options.AllowUnsafeCode;
   this.parsingContractAssembly = options.IsContractAssembly;
   if (this.parsingContractAssembly) {
     this.omitBodies = true;
   }
   this.options = options;
 }
コード例 #2
0
ファイル: MsBuildTask.cs プロジェクト: hesam/SketchSharp
 private void LogRunSpecSharp(SpecSharpCompilerOptions options)
 {
   /* Show the commandline invokation in the build output pane */
   StringBuilder message = new StringBuilder();
   String[] sources = GetSourceFilePaths();
   message.Append("Ssc <options>");
   message.Append(" /out:");
   message.Append(options.OutputAssembly);
   if( this.OnlyTypeChecks )
     message.Append(" /onlychecks");
   foreach (String refassem in options.ReferencedAssemblies) {
     message.Append(" /r:");
     message.Append(refassem);
   }
   foreach (String source in sources) {
     message.Append(" ");
     message.Append(source);
   }
   LogMessage(message.ToString());
 }
コード例 #3
0
ファイル: MsBuildTask.cs プロジェクト: hesam/SketchSharp
 /// <summary>
 /// Populates the ReferencedAssemblies collection on the given options object with strings
 /// corresponding to the paths of the referenced assemblies. TODO: also populate a still to be 
 /// defined collection of aliases for the assemblies. (AliasesForReferencedAssemblies)
 /// </summary>
 private void PopulateReferencesCollection(SpecSharpCompilerOptions/*!*/ options)
 {
   ITaskItem[] taskItems = this.References;
   if (taskItems == null || taskItems.Length == 0) return;
   StringCollection referencedAssemblies = options.ReferencedAssemblies;
   //^ assume referencedAssemblies != null;
   StringCollection aliasesForReferencedAssemblies = options.AliasesForReferencedAssemblies;
   if (aliasesForReferencedAssemblies == null)
     aliasesForReferencedAssemblies = options.AliasesForReferencedAssemblies = new StringCollection();
   foreach (ITaskItem taskItem in taskItems) {
     if (taskItem == null) continue;
     string referencedAssemblyPath = taskItem.ItemSpec;
     referencedAssemblies.Add(referencedAssemblyPath);
     string aliases = taskItem.GetMetadata("Aliases");
     aliasesForReferencedAssemblies.Add(aliases);
   }
 }
コード例 #4
0
ファイル: MsBuildTask.cs プロジェクト: hesam/SketchSharp
 private void DisableContractFeatures(SpecSharpCompilerOptions options, string p) {
   if (p == null) return;
   string[] disabledFeatures = p.Split(';');
   foreach (string feature in disabledFeatures) {
     switch (feature) {
       case "ac":
       case "assumechecks":
         options.DisableAssumeChecks = true;
         break;
       case "dc":
       case "defensivechecks":
         options.DisableDefensiveChecks = true;
         break;
       case "gcc":
       case "guardedclasseschecks":
         options.DisableGuardedClassesChecks = true;
         break;
       case "ic":
       case "internalchecks":
         options.DisableInternalChecks = true;
         break;
       case "icm":
       case "internalcontractsmetadata":
         options.DisableInternalContractsMetadata = true;
         break;
       case "pcm":
       case "publiccontractsmetadata":
         options.DisablePublicContractsMetadata = true;
         break;
       default:
         break;
     }
   }
 }
コード例 #5
0
ファイル: MsBuildTask.cs プロジェクト: hesam/SketchSharp
    /// <summary>
    /// Allocates new SpecSharpCompilerOptions object and initializes it using the values of the properties that were initialized
    /// by MsBuild. The resulting object is used to present a parsed command line to the compiler. The compiler itself is used
    /// to parse any response files.
    /// </summary>
    /// <returns></returns>
    private SpecSharpCompilerOptions/*!*/ GetCompilerOptions(Compiler/*!*/ specSharpCompiler)
    {
      SpecSharpCompilerOptions options = new SpecSharpCompilerOptions();
      if (this.AdditionalLibPaths != null)
        options.AdditionalSearchPaths = new Cci.StringList(this.AdditionalLibPaths);
      options.AllowUnsafeCode = this.AllowUnsafeBlocks;
      options.AssemblyKeyFile = this.KeyFile;
      options.AssemblyKeyName = this.KeyContainer;
      options.BaseAddress = this.GetBaseAddress(specSharpCompiler);
      if (this.ProgramVerifierCommandLineOptions == null)
        options.ProgramVerifierCommandLineOptions = new System.Compiler.StringList(0);
      else
        options.ProgramVerifierCommandLineOptions = new System.Compiler.StringList(this.ProgramVerifierCommandLineOptions.Split(' '));
      options.BugReportFileName = this.ErrorReport;
      options.CheckedArithmetic = this.CheckForOverflowUnderflow;
      options.OnlyTypeChecks = this.OnlyTypeChecks;
      options.CodePage = this.CodePage;
#if NoVS
      options.Site = new BuildSite(this.Log);
#else    
      options.Site = new BuildSite(this.taskManager, this.Log);
#endif
      options.DefinedPreProcessorSymbols = this.GetDefinedPreProcessorSymbols(specSharpCompiler);
      options.DelaySign = this.DelaySign;
      this.DisableContractFeatures(options, this.DisabledContractFeatures);
      this.PopulateResourceStringCollection(options.EmbeddedResources, this.Resources);
      options.EmitManifest = string.Compare(this.TargetType, "module", true, CultureInfo.InvariantCulture) != 0;
      options.EncodeOutputInUTF8 = this.Utf8Output;
      options.FileAlignment = this.FileAlignment;
      options.FullyQualifyPaths = this.GenerateFullPaths;
      options.GenerateExecutable = options.EmitManifest && string.Compare(this.TargetType, "library", true, CultureInfo.InvariantCulture) != 0;
      options.IncludeDebugInformation = this.EmitDebugInformation;
      options.LanguageVersion = this.GetLanguageVersion(specSharpCompiler);
      this.PopulateResourceStringCollection(options.LinkedResources, this.LinkResources);
      options.MainClass = this.MainEntryPoint;
      options.ModuleKind = this.GetModuleKind();
      options.UseStandardConfigFile = !this.NoConfig;
      options.NoStandardLibrary = this.NoStandardLib;
      options.Optimize = this.Optimize;
      options.ShadowedAssembly = this.OriginalAssembly;
      if (options.ShadowedAssembly != null && options.ShadowedAssembly.Length > 0)
        options.IsContractAssembly = true;
      string outputAssembly = this.OutputAssembly;
      if (outputAssembly != null && outputAssembly.Length > 0) {
        options.ExplicitOutputExtension = Path.GetExtension(this.OutputAssembly);
        options.OutputAssembly = Path.GetFileName(this.OutputAssembly);
        options.OutputPath = Path.GetDirectoryName(this.OutputAssembly);
        if (this.ProduceContractAssembly) {
          options.IsContractAssembly = false;
          options.ShadowedAssembly = Path.Combine(options.OutputPath, options.OutputAssembly);
          options.OutputAssembly = Path.GetFileNameWithoutExtension(this.OutputAssembly) + ".Contracts" + Path.GetExtension(this.OutputAssembly);
          this.OutputAssembly = Path.Combine(options.OutputPath, options.OutputAssembly);
        }
      }
      options.PDBOnly = string.Compare(this.DebugType, "pdbonly", true, CultureInfo.InvariantCulture) == 0;
      this.PopulateReferencesCollection(options);
      if (this.AddModules != null)
        options.ReferencedModules = new Cci.StringList(this.AddModules);
      options.ReferenceTypesAreNonNullByDefault = this.ReferenceTypesAreNonNullByDefault;
      options.CheckContractAdmissibility = this.CheckContractAdmissibility;
      options.CheckPurity = this.CheckPurity;
      options.RootNamespace = null;
      options.RunProgramVerifier = this.Verify;
      options.SpecificWarningsToTreatAsErrors = this.GetIntList(this.WarningsAsErrors);
      options.SpecificWarningsNotToTreatAsErrors = this.GetIntList(this.WarningsNotAsErrors);
      options.StandardLibraryLocation = this.StandardLibraryLocation;
      options.SuppressedWarnings = this.GetIntList(this.DisabledWarnings);
      options.SuppressLogo = this.NoLogo;
      options.TargetPlatform = this.GetRuntimeType();
      options.TargetPlatformLocation = this.TargetRuntimeLocation;
      options.TargetProcessor = this.GetProcessorType(specSharpCompiler);
      options.TreatWarningsAsErrors = this.TreatWarningsAsErrors;
      options.UserToken = IntPtr.Zero;
      options.WarningLevel = this.WarningLevel;
      options.Win32Icon = this.Win32Icon;
      options.Win32Resource = this.Win32Resource;
      options.XMLDocFileName = this.DocumentationFile;

      //TODO: deal with response files. Use the compiler object passed in as parameter.
      //TODO: what about the standard response files?
      return options;
    }
コード例 #6
0
ファイル: MsBuildTask.cs プロジェクト: hesam/SketchSharp
 private bool CompilationOutputIsUpToDate(SpecSharpCompilerOptions options, string[] sourceFilePaths) {
   string targetPath = Path.Combine(options.OutputPath, options.OutputAssembly);
   if (!File.Exists(targetPath) || !File.Exists(options.ShadowedAssembly)) return false;
   DateTime outputTimeStamp = File.GetLastWriteTime(targetPath);
   if (File.GetLastWriteTime(options.ShadowedAssembly) > outputTimeStamp) return false;
   foreach (string sourceFilePath in sourceFilePaths) {
     if (!File.Exists(sourceFilePath)) return false;
     if (File.GetLastWriteTime(sourceFilePath) > outputTimeStamp) return false;
   }
   if (options.ReferencedAssemblies != null) {
     foreach (string refPath in options.ReferencedAssemblies) {
       if (!File.Exists(refPath)) return false;
       if (File.GetLastWriteTime(refPath) > outputTimeStamp) return false;
     }
   }
   if (options.ReferencedModules != null) {
     foreach (string refPath in options.ReferencedModules) {
       if (!File.Exists(refPath)) return false;
       if (File.GetLastWriteTime(refPath) > outputTimeStamp) return false;
     }
   }
   return true;
 }
コード例 #7
0
ファイル: MsBuildTask.cs プロジェクト: hesam/SketchSharp
 private int GetLevelAtWhichWarningsAreSuppressed(Cci.ErrorNode/*!*/ error, SpecSharpCompilerOptions/*!*/ options)
 {
   int severity = error.Severity;
   int errorCode = error.Code;
   Cci.Int32List suppressedWarnings = options.SuppressedWarnings;
   for (int i = 0, n = suppressedWarnings == null ? 0 : suppressedWarnings.Count; i < n; i++) {
     if (suppressedWarnings[i] == errorCode) return severity;
   }
   return options.WarningLevel + 1;
 }
コード例 #8
0
ファイル: MsBuildTask.cs プロジェクト: hesam/SketchSharp
 private int GetSeverityAtWhichWarningsBecomeErrors(Cci.ErrorNode/*!*/ error, SpecSharpCompilerOptions/*!*/ options)
 {
   int severity = error.Severity;
   if (severity == 0 || options.TreatWarningsAsErrors) return severity;
   int errorCode = error.Code;
   Cci.Int32List severeWarnings = options.SpecificWarningsToTreatAsErrors;
   for (int i = 0, n = severeWarnings == null ? 0 : severeWarnings.Count; i < n; i++) {
     if (severeWarnings[i] == errorCode) return severity;
   }
   return 0;
 }
コード例 #9
0
ファイル: MsBuildTask.cs プロジェクト: hesam/SketchSharp
 private void LogErrorsAndWarnings(Cci.ErrorNodeList/*!*/ errors, SpecSharpCompilerOptions/*!*/ options)
 {
   int errorCount = 0;
   int warningCount = 0;
   int prevSev = 0;
   int n = errors.Count;
   if (n > 100) n = 100;
   for (int i = 0; i < n; i++) {
     Cci.ErrorNode error = errors[i];
     if (error != null) {
       int suppressedWarningSeverity = this.GetLevelAtWhichWarningsAreSuppressed(error, options);
       int errorSeverity = (options.TreatWarningsAsErrors ?
                             suppressedWarningSeverity - 1 :
                             this.GetSeverityAtWhichWarningsBecomeErrors(error, options));
       int severity = error.Severity;
       if (severity < 0)
         severity = prevSev;
       else
         prevSev = severity;
       bool isWarning = severity > errorSeverity;        
       bool isSpecSharpSpecific = error.Code >= 2500 && error.Code < 3000;
       if (!isWarning || severity < suppressedWarningSeverity) {
         LogTaskError("CS", error.Code, null,
           this.GetRelativePath(error.SourceContext.Document),
           this.GetFullPath(error.SourceContext.Document),
           error.SourceContext.StartLine, error.SourceContext.StartColumn,
           error.SourceContext.EndLine, error.SourceContext.EndColumn,
           error.GetMessage(CultureInfo.CurrentCulture), 
           isWarning, isSpecSharpSpecific );
       }
       if (isWarning)
         warningCount++;
       else
         errorCount++;
     }
   }
   LogMessage("Compile complete -- " + 
              errorCount.ToString() + " errors, " +
              warningCount.ToString() + " warnings\n" 
             ); 
 }
コード例 #10
0
ファイル: Parser.cs プロジェクト: dbremner/specsharp
 public Parser(Document document, ErrorNodeList errors, Module symbolTable, SpecSharpCompilerOptions options){
   this.scanner = new Scanner(document, errors, options);
   this.ProcessOptions(options);
   this.errors = errors;
   this.module = symbolTable;
 }
コード例 #11
0
ファイル: LanguageService.cs プロジェクト: hesam/SketchSharp
 public override System.CodeDom.Compiler.CompilerParameters GetDummyCompilerParameters(){
   SpecSharpCompilerOptions options = new SpecSharpCompilerOptions();
   options.DummyCompilation = true;
   return options;
 }
コード例 #12
0
 internal VsScanner(SpecSharpCompilerOptions options){
   this.scanner = new Scanner(false, false, false, true, false);
   this.scanner.SetOptions(options);
 }  
コード例 #13
0
 internal Cci.CompilerOptions GetCompilerOptions(){
   SpecSharpCompilerOptions coptions = new SpecSharpCompilerOptions(new Microsoft.VisualStudio.IntegrationHelper.CompilerOptions(this));
   coptions.Compatibility = this.Compatibility;
   coptions.ReferenceTypesAreNonNullByDefault = this.ReferenceTypesAreNonNullByDefault;
   coptions.RunProgramVerifier = this.RunProgramVerifier;
   coptions.RunProgramVerifierWhileEditing = this.RunProgramVerifierWhileEditing;
   string s = this.ProgramVerifierCommandLineOptions;
   if (s == null){
     coptions.ProgramVerifierCommandLineOptions = new System.Compiler.StringList();
   } else {
     coptions.ProgramVerifierCommandLineOptions = new System.Compiler.StringList(s.Split(' '));
   }
   // begin change by drunje
   coptions.AllowPointersToManagedStructures = this.AllowPointersToManagedStructures;
   // end change by drunje
   coptions.CheckContractAdmissibility = this.CheckContractAccessibility;
   coptions.CheckPurity = this.CheckPurity;
   return coptions;
 }
コード例 #14
0
ファイル: Scanner.cs プロジェクト: hesam/SketchSharp
 public void SetOptions(SpecSharpCompilerOptions options){
   if (options == null) return;
   this.inCompatibilityMode = options.Compatibility;
   if (options.XMLDocFileName != null && options.XMLDocFileName.Length > 0)
     this.ignoreDocComments = false;
   this.PreprocessorDefinedSymbols = new Hashtable();
   StringList syms = options.DefinedPreProcessorSymbols;
   for (int i = 0, n = syms == null ? 0 : syms.Count; i < n; i++){
     string sym = syms[i];
     if (sym == null) continue;
     sym.Trim();
     this.PreprocessorDefinedSymbols[sym] = sym;
   }
   this.PreprocessorDefinedSymbols["true"] = "true";
   this.PreprocessorDefinedSymbols["false"] = null;
 }
コード例 #15
0
ファイル: Scanner.cs プロジェクト: hesam/SketchSharp
 internal Scanner(Document document, ErrorNodeList errors, SpecSharpCompilerOptions options){
   this.document = document;
   this.originalDocument = document;
   this.sourceText = document.Text;
   if (document.Text != null) this.sourceString = document.Text.Source;
   this.endPos = 0;
   this.maxPos = document.Text.Length;
   this.errors = errors;
   this.ignoreDocComments = true;
   this.SetOptions(options);
 }