Example #1
0
        public CallContext(CompilationEnvironment outerCompEnv, CompilationEnvironment inlinedCompEnv, IImSeq <Expression> arguments)
        {
            var paramMap = new Map <JST.Identifier, int>();

            for (var i = 0; i < inlinedCompEnv.Method.Arity; i++)
            {
                paramMap.Add(inlinedCompEnv.ValueParameterIds[i], i);
            }
            Parameters = paramMap;
            var argumentEffects = new Seq <JST.Effects>(inlinedCompEnv.Method.Arity);

            SeenParameters     = new Seq <bool?>(inlinedCompEnv.Method.Arity);
            AllArgumentEffects = JST.Effects.Bottom;
            var allReadOnly = true;

            foreach (var e in arguments)
            {
                var fxCtxt = new JST.EffectsContext(null);
                e.AccumEffects(fxCtxt, null, null);
                argumentEffects.Add(fxCtxt.AccumEffects);
                AllArgumentEffects = AllArgumentEffects.Lub(fxCtxt.AccumEffects);
                if (!fxCtxt.AccumEffects.IsReadOnly)
                {
                    allReadOnly = false;
                }
                SeenParameters.Add(e.IsValue(outerCompEnv) ? default(bool?) : false);
            }
            ArgumentEffects = argumentEffects;
            AllReadOnly     = allReadOnly;
            IsOk            = true;
        }
Example #2
0
        public CallContext(IImSeq <Identifier> parameters, IImSeq <Expression> arguments, Func <Expression, bool> isValue)
        {
            var paramMap = new Map <Identifier, int>();

            for (var i = 0; i < parameters.Count; i++)
            {
                paramMap.Add(parameters[i], i);
            }
            Parameters = paramMap;
            var argumentEffects = new Seq <Effects>(parameters.Count);

            SeenParameters = new Seq <bool>(parameters.Count);
            var allReadOnly = true;

            AllArgumentEffects = Effects.Bottom;
            foreach (var e in arguments)
            {
                var fxCtxt = new EffectsContext(isValue);
                e.AccumEffects(fxCtxt, null, null);
                argumentEffects.Add(fxCtxt.AccumEffects);
                AllArgumentEffects = AllArgumentEffects.Lub(fxCtxt.AccumEffects);
                if (!fxCtxt.AccumEffects.IsReadOnly)
                {
                    allReadOnly = false;
                }
                SeenParameters.Add(false);
            }
            ArgumentEffects = argumentEffects;
            AllReadOnly     = allReadOnly;
            IsOk            = true;
        }
Example #3
0
 public Map(IImMap <K, V> dict)
     : this(dict.Count)
 {
     foreach (var kv in dict)
     {
         Add(kv.Key, kv.Value);
     }
 }
Example #4
0
            protected TranslationContext(TranslationContext parent, int start)
            {
                Parent = parent;
                Start = start;

                ResultType = parent.ResultType;
                Instructions = parent.Instructions;
                OffsetToIndex = parent.OffsetToIndex;
                TryOffsets = parent.TryOffsets;
                IndexToHandler = parent.IndexToHandler;
                IndexToFilter = parent.IndexToFilter;
                Handlers = parent.Handlers;
            }
Example #5
0
 public bool DisjointKeys(IImMap <K, V> other)
 {
     if (entries == null || other.Count == 0)
     {
         return(true);
     }
     foreach (var e in entries)
     {
         if (e != null)
         {
             if (other.ContainsKey(e.Key))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Example #6
0
            public TranslationContext(TypeRef resultType, PE.Instruction[] instructions, IImSeq<PE.ExceptionHandlingClause> handlers)
            {
                Parent = null;
                Start = 0;

                ResultType = resultType;
                Instructions = instructions;
                Handlers = handlers;

                var offsetToIndex = new Map<int, int>();
                for (var i = 0; i < instructions.Length; i++)
                {
                    if (offsetToIndex.ContainsKey(instructions[i].Offset))
                        throw new InvalidOperationException("instructions share same offset");
                    offsetToIndex.Add(instructions[i].Offset, i);
                }
                OffsetToIndex = offsetToIndex;

                var tryOffsets = new Set<int>();
                var indexToHandler = new Map<int, PE.ExceptionHandlingClause>();
                var indexToFilter = new Map<int, PE.ExceptionHandlingClause>();
                foreach (var ehc in handlers)
                {
                    if (!tryOffsets.Contains(ehc.TryOffset))
                        tryOffsets.Add(ehc.TryOffset);
                    var i = OffsetToIndex[ehc.HandlerOffset];
                    indexToHandler.Add(i, ehc);
                    if (ehc.Flags == PE.CorILExceptionClause.Filter)
                    {
                        var j = OffsetToIndex[ehc.FilterOffset];
                        indexToHandler.Add(j, ehc);
                    }
                }
                TryOffsets = tryOffsets;
                IndexToHandler = indexToHandler;
                IndexToFilter = indexToFilter;
            }
Example #7
0
 public CallContext(CompilationEnvironment outerCompEnv, CompilationEnvironment inlinedCompEnv, IImSeq<Expression> arguments)
 {
     var paramMap = new Map<JST.Identifier, int>();
     for (var i = 0; i < inlinedCompEnv.Method.Arity; i++)
         paramMap.Add(inlinedCompEnv.ValueParameterIds[i], i);
     Parameters = paramMap;
     var argumentEffects = new Seq<JST.Effects>(inlinedCompEnv.Method.Arity);
     SeenParameters = new Seq<bool?>(inlinedCompEnv.Method.Arity);
     AllArgumentEffects = JST.Effects.Bottom;
     var allReadOnly = true;
     foreach (var e in arguments)
     {
         var fxCtxt = new JST.EffectsContext(null);
         e.AccumEffects(fxCtxt, null, null);
         argumentEffects.Add(fxCtxt.AccumEffects);
         AllArgumentEffects = AllArgumentEffects.Lub(fxCtxt.AccumEffects);
         if (!fxCtxt.AccumEffects.IsReadOnly)
             allReadOnly = false;
         SeenParameters.Add(e.IsValue(outerCompEnv) ? default(bool?) : false);
     }
     ArgumentEffects = argumentEffects;
     AllReadOnly = allReadOnly;
     IsOk = true;
 }
Example #8
0
 public CallContext(IImSeq<Identifier> parameters, IImSeq<Expression> arguments, Func<Expression, bool> isValue)
 {
     var paramMap = new Map<Identifier, int>();
     for (var i = 0; i < parameters.Count; i++)
         paramMap.Add(parameters[i], i);
     Parameters = paramMap;
     var argumentEffects = new Seq<Effects>(parameters.Count);
     SeenParameters = new Seq<bool>(parameters.Count);
     var allReadOnly = true;
     AllArgumentEffects = Effects.Bottom;
     foreach (var e in arguments)
     {
         var fxCtxt = new EffectsContext(isValue);
         e.AccumEffects(fxCtxt, null, null);
         argumentEffects.Add(fxCtxt.AccumEffects);
         AllArgumentEffects = AllArgumentEffects.Lub(fxCtxt.AccumEffects);
         if (!fxCtxt.AccumEffects.IsReadOnly)
             allReadOnly = false;
         SeenParameters.Add(false);
     }
     ArgumentEffects = argumentEffects;
     AllReadOnly = allReadOnly;
     IsOk = true;
 }
Example #9
0
 public MapDebugView(IImMap <K, V> map)
 {
     this.map = map;
 }
Example #10
0
 public void Read(IImSeq<CustomAttributePropertyType> fixedArgTypes, BlobReader reader, Func<string, CustomAttributePropertyType> resolveType)
 {
     var fieldArgs = default(Map<string, CustomAttributeProperty>);
     var propertyArgs = default(Map<string, CustomAttributeProperty>);
     if (reader.AtEndOfBlob)
     {
         if (fixedArgTypes.Count > 0)
             throw new PEException("expected fixed arguments in custom attribute");
         FixedArgs = Constants.EmptyCustomAttributeProperties;
         FieldArgs = Constants.EmptyNamedCustomAttributueProperties;
         PropertyArgs = Constants.EmptyNamedCustomAttributueProperties;
     }
     else
     {
         if (reader.ReadUInt16() != prolog)
             throw new PEException("invalid custom attribute");
         if (fixedArgTypes.Count > 0)
         {
             var fixedArgs = new Seq<CustomAttributeProperty>(fixedArgTypes.Count);
             for (var i = 0; i < fixedArgTypes.Count; i++)
             {
                 var type = fixedArgTypes[i];
                 fixedArgs.Add
                     (new CustomAttributeProperty { Type = type, Value = type.ReadValue(reader, resolveType) });
             }
             FixedArgs = fixedArgs;
         }
         else
             FixedArgs = Constants.EmptyCustomAttributeProperties;
         var numNamed = reader.ReadUInt16();
         for (var i = 0; i < numNamed; i++)
         {
             var tag = (TypeSigTag)reader.ReadByte();
             var type = CustomAttributePropertyType.Read(reader, resolveType);
             var nm = reader.ReadUTF8SizedString();
             var prop = new CustomAttributeProperty { Type = type, Value = type.ReadValue(reader, resolveType) };
             if (tag == TypeSigTag.CUSTOM_ATTRIBUTE_FIELD)
             {
                 if (fieldArgs == null)
                     fieldArgs = new Map<string, CustomAttributeProperty>();
                 if (fieldArgs.ContainsKey(nm))
                     throw new PEException("duplicate named field in custom attribute");
                 fieldArgs.Add(nm, prop);
             }
             else if (tag == TypeSigTag.CUSTOM_ATTRIBUTE_PROPERTY)
             {
                 if (propertyArgs == null)
                     propertyArgs = new Map<string, CustomAttributeProperty>();
                 if (propertyArgs.ContainsKey(nm))
                     throw new PEException("duplicate named property in custom attribute");
                 propertyArgs.Add(nm, prop);
             }
             else
                 throw new PEException("invalid custom attribute");
         }
         FieldArgs = fieldArgs ?? Constants.EmptyNamedCustomAttributueProperties;
         PropertyArgs = propertyArgs ?? Constants.EmptyNamedCustomAttributueProperties;
     }
 }
Example #11
0
 public VariableEffects(IImMap <Identifier, ReadWriteDomain> vars)
 {
     this.vars = vars;
 }
Example #12
0
 public VariableEffects()
 {
     vars = new Map <Identifier, ReadWriteDomain>();
 }