Exemple #1
0
        /// <summary>
        /// Tries to get constant value from FlowOutputSet
        /// </summary>
        /// <param name="outset">FlowOutputSet which contains values</param>
        /// <param name="name">Constant name</param>
        /// <param name="entry">Memory entry of possible values</param>
        /// <returns><c>true</c> if constant is never defined, otherwise <c>true</c></returns>
        public static bool TryGetConstant(FlowOutputSet outset, QualifiedName name,
                                          out MemoryEntry entry)
        {
            var context = outset.Snapshot;
            var values  = new HashSet <Value>();

            var constantArrays = outset.ReadControlVariable(constantVariable);

            Debug.Assert(constantArrays.IsDefined(context), "Internal array of constants is always defined");

            var caseInsensitiveConstant = constantArrays.ReadIndex(context, new MemberIdentifier("." + name.Name.LowercaseValue));

            if (caseInsensitiveConstant.IsDefined(context))
            {
                entry = caseInsensitiveConstant.ReadMemory(context);
                return(false);
            }

            //else there can be case sensitive constant

            var caseSensitiveConstant = constantArrays.ReadIndex(context, new MemberIdentifier("#" + name.Name.Value));

            if (caseSensitiveConstant.IsDefined(context))
            {
                entry = caseSensitiveConstant.ReadMemory(context);
                return(false);
            }

            // Undefined constant is interpreted as a string
            var stringValue = outset.CreateString(name.Name.Value);

            entry = new MemoryEntry(stringValue);

            return(true);
        }
Exemple #2
0
        public override IEnumerable <ThrowInfo> Throw(FlowController flow, FlowOutputSet outSet, ThrowStmt throwStmt, MemoryEntry throwedValue)
        {
            //TODO this is only simple implementation
            var exceptionObj = (ObjectValue)throwedValue.PossibleValues.First();

            var catchBlocks = outSet.ReadControlVariable(CatchBlocks_Storage).ReadMemory(outSet.Snapshot);

            var throwBranches = new List <ThrowInfo>();

            //find catch blocks with valid scope and matching catch condition
            foreach (InfoValue <CatchBlockDescription> blockInfo in catchBlocks.PossibleValues)
            {
                var throwedType = outSet.ObjectType(exceptionObj).QualifiedName;

                //check catch condition
                if (blockInfo.Data.CatchedType.QualifiedName != throwedType)
                {
                    continue;
                }

                var branch = new ThrowInfo(blockInfo.Data, throwedValue);
                throwBranches.Add(branch);
            }

            return(throwBranches);
        }
Exemple #3
0
        /// <summary>
        /// Inserts new constant into FlowOutputSet.
        /// </summary>
        /// <param name="outset">FlowOutputSet, where to insert the values.</param>
        /// <param name="name">Constant name.</param>
        /// <param name="value">Constant value</param>
        /// <param name="caseInsensitive">Determines if the constant is case sensitive of insensitive</param>
        public static void insertConstant(FlowOutputSet outset, QualifiedName name,
                                          MemoryEntry value, bool caseInsensitive = false)
        {
            ReadWriteSnapshotEntryBase constant;
            var constantArrays = outset.ReadControlVariable(constantVariable);

            if (caseInsensitive == true)
            {
                constant = constantArrays.ReadIndex(outset.Snapshot, new MemberIdentifier("." + name.Name.LowercaseValue));
            }
            else
            {
                constant = constantArrays.ReadIndex(outset.Snapshot, new MemberIdentifier("#" + name.Name.Value));
            }
            if (!constant.IsDefined(outset.Snapshot))
            {
                constant.WriteMemory(outset.Snapshot, value);
            }
        }