Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public override void DetermineIfNonNullCheckingIsDesired(CompilationUnit cUnit)
        {
            SpecSharpCompilerOptions soptions = this.currentOptions as SpecSharpCompilerOptions;

            if (soptions != null && soptions.Compatibility)
            {
                return;
            }
            this.NonNullChecking = !(this.currentPreprocessorDefinedSymbols != null && this.currentPreprocessorDefinedSymbols.ContainsKey("NONONNULLTYPECHECK"));
        }
Exemplo n.º 3
0
        public Analyzer(TypeSystem t, Compilation c)
            : base(t, c)
        {
            if (c != null)
            {
                SpecSharpCompilerOptions ssco = c.CompilerParameters as SpecSharpCompilerOptions;
                if (ssco != null)
                {
                    if (ssco.Compatibility)
                    {
                        this.NonNullChecking = false; // i.e., turn it off if we need to be compatible
                    }
                    this.WeakPurityAnalysis = ssco.CheckPurity;
                    // Diego said it is important that the same instance of the purity analysis is used across all
                    // methods in the compilation unit. So create it here and just call it for each method in
                    // the override for language specific analysis.
                    // PointsToAnalysis.verbose = true;
                    if (this.WeakPurityAnalysis)
                    {
                        // InterProcedural bottom up traversal with fixpoint
                        //this.WeakPurityAnalyzer = new WeakPurityAndWriteEffectsAnalysis(this,typeSystem, c,true,true);

                        // Only Intraprocedural (in this mode doesnot support delegates...)
                        //this.WeakPurityAnalyzer = new WeakPurityAndWriteEffectsAnalysis(this, typeSystem, c, false);

                        // Interprocedural top-down inlining simulation (with max-depth)
                        this.WeakPurityAnalyzer = new WeakPurityAndWriteEffectsAnalysis(this, typeSystem, c, true, false, 2);

                        this.WeakPurityAnalyzer.StandAloneApp = false;
                        this.WeakPurityAnalyzer.BoogieMode    = true;
                    }

                    /// Reentrancy ANALYSIS

                    this.ObjectExposureAnalysis       = false;
                    ObjectConsistencyAnalysis.verbose = false;
                    if (ObjectExposureAnalysis)
                    {
                        this.ObjectExposureAnalyzer = new ObjectExposureAnalysis(this, typeSystem, c, true, false, 4);
                    }
                    this.ReentrancyAnalysis = false;
                    if (ReentrancyAnalysis)
                    {
                        this.ReentrancyAnalyzer = new ReentrancyAnalysis(this, typeSystem, c, true, false, 4);
                    }
                }
            }
        }
Exemplo n.º 4
0
 public override CompilationUnit VisitCompilationUnit(CompilationUnit cUnit)
 {
     if (cUnit == null)
     {
         return(null);
     }
     if (cUnit.Compilation != null)
     {
         SpecSharpCompilerOptions coptions = cUnit.Compilation.CompilerParameters as SpecSharpCompilerOptions;
         if (coptions != null)
         {
             this.inCompatibilityMode = coptions.Compatibility;
         }
     }
     return(base.VisitCompilationUnit(cUnit));
 }
Exemplo n.º 5
0
        public override TypeNode AddNonNullWrapperIfNeeded(TypeNode typeNode)
        {
            if (typeNode == null || typeNode is ITypeParameter)
            {
                return(typeNode);
            }
            SpecSharpCompilerOptions options = this.currentOptions as SpecSharpCompilerOptions;

            if (options != null && !options.Compatibility && options.ReferenceTypesAreNonNullByDefault && !typeNode.IsValueType)
            {
                if (this.typeSystem != null && !this.typeSystem.IsNonNullType(typeNode))
                {
                    typeNode = OptionalModifier.For(SystemTypes.NonNullType, typeNode);
                }
            }
            return(typeNode);
        }
Exemplo n.º 6
0
        private void PrepareGuardedClass(TypeNode typeNode)
        {
            SpecSharpCompilerOptions options = this.currentOptions as SpecSharpCompilerOptions;

            if (!(options != null && (options.DisableGuardedClassesChecks || options.Compatibility)))
            {
                if (typeNode is Class && typeNode.Contract != null && (typeNode.Contract.InvariantCount > 0 || typeNode.Contract.ModelfieldContractCount > 0) ||
                    typeNode is Class && this.currentPreprocessorDefinedSymbols != null && this.currentPreprocessorDefinedSymbols.ContainsKey("GuardAllClasses"))
                {
                    if (typeNode.Interfaces == null)
                    {
                        typeNode.Interfaces = new InterfaceList();
                    }
                    if (typeNode.Template == null) //we have to be careful when we are passed a typeNode of a specialized generic type as it shares the contract of the 'real' generic typeNode
                    {
                        #region Add the field "frame" to the class.
                        Field frameField = new Field(typeNode, null, FieldFlags.Public, Identifier.For("SpecSharp::frameGuard"), SystemTypes.Guard, null);
                        frameField.CciKind           = CciMemberKind.Auxiliary;
                        typeNode.Contract.FrameField = frameField;
                        typeNode.Members.Add(frameField);
                        This   thisParameter = new This(typeNode);
                        Method frameGetter   = new Method(typeNode, NoDefaultExpose(), Identifier.For("get_SpecSharp::FrameGuard"), null, OptionalModifier.For(SystemTypes.NonNullType, SystemTypes.Guard),
                                                          new Block(new StatementList(new Return(new BinaryExpression(new MemberBinding(thisParameter, frameField), new Literal(SystemTypes.NonNullType, SystemTypes.Type), System.Compiler.NodeType.ExplicitCoercion, OptionalModifier.For(SystemTypes.NonNullType, SystemTypes.Guard))))));
                        // Pretend this method is [Delayed] so that we can call it from a delayed constructor.
                        frameGetter.Attributes.Add(new AttributeNode(new Literal(ExtendedRuntimeTypes.DelayedAttribute, SystemTypes.Type), null, AttributeTargets.Method));
                        frameGetter.CciKind = CciMemberKind.FrameGuardGetter;
                        frameGetter.Attributes.Add(new AttributeNode(new Literal(SystemTypes.PureAttribute, SystemTypes.Type), null, AttributeTargets.Method));
                        frameGetter.Flags                     = MethodFlags.Public | MethodFlags.HideBySig | MethodFlags.SpecialName;
                        frameGetter.CallingConvention         = CallingConventionFlags.HasThis;
                        frameGetter.ThisParameter             = thisParameter;
                        typeNode.Contract.FramePropertyGetter = frameGetter;
                        typeNode.Members.Add(frameGetter);
                        Property frameProperty = new Property(typeNode, null, PropertyFlags.None, Identifier.For("SpecSharp::FrameGuard"), frameGetter, null);
                        typeNode.Members.Add(frameProperty);
                        typeNode.Contract.FrameProperty = frameProperty;
                        #endregion
                        typeNode.Contract.InitFrameSetsMethod         = new Method(typeNode, NoDefaultExpose(), Identifier.For("SpecSharp::InitGuardSets"), null, SystemTypes.Void, null);
                        typeNode.Contract.InitFrameSetsMethod.CciKind = CciMemberKind.Auxiliary;
                        typeNode.Contract.InitFrameSetsMethod.Flags   = MethodFlags.Public | MethodFlags.HideBySig | MethodFlags.SpecialName;
                    }
                }
            }
        }
Exemplo n.º 7
0
 internal VsScanner(SpecSharpCompilerOptions options)
 {
     this.scanner = new Scanner(false, false, false, true, false);
     this.scanner.SetOptions(options);
 }