示例#1
0
        public IEnumerable <BeliefValueSubsPair> AskPossibleProperties(Name property, Name perspective, IEnumerable <SubstitutionSet> constraints)
        {
            if (constraints == null)
            {
                constraints = new[] { new SubstitutionSet() }
            }
            ;

            if (property.IsPrimitive)
            {
                if (property == Name.SELF_SYMBOL)
                {
                    var p = AssertPerspective(perspective, nameof(perspective)).Last();
                    if (p == Name.SELF_SYMBOL)
                    {
                        p = Perspective;
                    }
                    property = p;
                }

                return(new[] { Tuples.Create(new ComplexValue(property), constraints) });
            }

            var ToMList = AssertPerspective(perspective, nameof(perspective));

            return(internal_AskPossibleProperties(property, ToMList, constraints));
        }
示例#2
0
        private static ITrwDiff DiffArray(Context context, IList <object> a1, IList <object> a2)
        {
            var permutation       = BuildArrayPermutation(context, a1, a2);
            var addedIndices      = Enumerable.Range(0, a2.Count).Where(x => !permutation.Any(y => y.Second == x)).Select(x => Tuples.Pair(x, a2[x])).ToArray();
            var removedIndices    = Enumerable.Range(0, a1.Count).Where(x => !permutation.Any(y => y.First == x)).Select(x => Tuples.Pair(x, a1[x])).ToArray();
            var itemsMoved        = new List <Pair <int> >();
            var itemsDiffed       = new List <Pair <Pair <int>, ITrwDiff> >();
            var unaffectedIndices = new List <int>();

            foreach (var indexPair in permutation)
            {
                var oldValue = a1[indexPair.First];
                var newValue = a2[indexPair.Second];
                var diff     = Diff(context, oldValue, newValue);
                if (diff != null)
                {
                    itemsDiffed.Add(Tuples.Pair(indexPair, diff));
                }
                else if (indexPair.First != indexPair.Second)
                {
                    itemsMoved.Add(indexPair);
                }
                else
                {
                    unaffectedIndices.Add(indexPair.First);
                }
            }
            return(addedIndices.Any() || removedIndices.Any() || itemsMoved.Any() || itemsDiffed.Any()
                ? new MutateArrayTrwDiff(addedIndices, removedIndices, itemsMoved, itemsDiffed, unaffectedIndices)
                : null);
        }
示例#3
0
        public void TestGetFirstName_Should_return_a_valid_Tuple(string firstName, string middleName, string familyName)
        {
            var actualTuple = Tuples.ConvertToTuple(firstName, middleName, familyName);
            var actualName  = Tuples.GetFirstName(firstName, middleName, familyName);

            actualName.Should().Be(actualTuple.FirstName, $"The first name '{firstName}' was converted to {actualTuple.FirstName}, which did not match the expected value of {actualName}");
        }
示例#4
0
文件: Expression.cs 项目: xcorail/ql
        private void PopulateArgument(ArgumentSyntax arg, int child)
        {
            var expr = Create(cx, arg.Expression, this, child);
            int mode;

            switch (arg.RefOrOutKeyword.Kind())
            {
            case SyntaxKind.RefKeyword:
                mode = 1;
                break;

            case SyntaxKind.OutKeyword:
                mode = 2;
                break;

            case SyntaxKind.None:
                mode = 0;
                break;

            case SyntaxKind.InKeyword:
                mode = 3;
                break;

            default:
                throw new InternalError(arg, "Unknown argument type");
            }
            cx.Emit(Tuples.expr_argument(expr, mode));

            if (arg.NameColon != null)
            {
                cx.Emit(Tuples.expr_argument_name(expr, arg.NameColon.Name.Identifier.Text));
            }
        }
示例#5
0
        public IEnumerable <Tuple3 <int> > EnumerateTriangles()
        {
            switch (Topology)
            {
            case ExplicitModelPrimitiveTopology.PointList:
            case ExplicitModelPrimitiveTopology.LineList:
            case ExplicitModelPrimitiveTopology.LineStrip:
                throw new InvalidOperationException("Trying to enumerate triangles of a non-triangle model.");

            case ExplicitModelPrimitiveTopology.TriangleList:
                for (var i = 0; i < Indices.Length; i += 3)
                {
                    yield return(Tuples.SameTypeTuple(Indices[i], Indices[i + 1], Indices[i + 2]));
                }
                break;

            case ExplicitModelPrimitiveTopology.TriangleStrip:
                var odd = 0;
                for (var i = 0; i < Indices.Length - 2; i++)
                {
                    yield return(Tuples.SameTypeTuple(Indices[i], Indices[i + 1 + odd], Indices[i + 2 - odd]));

                    odd ^= 1;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#6
0
        private IEnumerable <Pair <PrimitiveValue, SubstitutionSet> > EventIdPropertyCalculator(KB kb, Name perspective, IDictionary <string, Name> args, IEnumerable <SubstitutionSet> constraints)
        {
            List <Pair <PrimitiveValue, SubstitutionSet> > results = new List <Pair <PrimitiveValue, SubstitutionSet> >();

            if (!perspective.Match(Name.SELF_SYMBOL))
            {
                return(results);
            }

            Name type    = GetArgument(args, "type");
            Name subject = GetArgument(args, "subject");
            Name def     = GetArgument(args, "def");
            Name target  = GetArgument(args, "target");

            var key = Name.BuildName(EVT_NAME, type, subject, def, target);

            foreach (var c in constraints)
            {
                foreach (var pair in m_typeIndexes.Unify(key, c))
                {
                    foreach (var id in pair.Item1)
                    {
                        results.Add(Tuples.Create((PrimitiveValue)id, new SubstitutionSet(pair.Item2)));
                    }
                }
            }
            return(results);
        }
示例#7
0
        public Compilation(Context cx, string cwd, string[] args) : base(cx)
        {
            Extraction.Entities.Assembly.CreateOutputAssembly(cx);

            cx.Emit(Tuples.compilations(this, Extraction.Entities.File.PathAsDatabaseString(cwd)));

            // Arguments
            int index = 0;

            foreach (var arg in args)
            {
                cx.Emit(Tuples.compilation_args(this, index++, arg));
            }

            // Files
            index = 0;
            foreach (var file in cx.Compilation.SyntaxTrees.Select(tree => Extraction.Entities.File.Create(cx, tree.FilePath)))
            {
                cx.Emit(Tuples.compilation_compiling_files(this, index++, file));
            }

            // References
            index = 0;
            foreach (var file in cx.Compilation.References.OfType <PortableExecutableReference>().Select(r => Extraction.Entities.File.Create(cx, r.FilePath)))
            {
                cx.Emit(Tuples.compilation_referencing_files(this, index++, file));
            }

            // Diagnostics
            index = 0;
            foreach (var diag in cx.Compilation.GetDiagnostics().Select(d => new Diagnostic(cx, d)))
            {
                cx.Emit(Tuples.diagnostic_for(diag, this, 0, index++));
            }
        }
示例#8
0
        void ExtractAttribute(AttributeSyntax syntax, ITypeSymbol attributeClass, IEntity entity)
        {
            var type = Type.Create(cx, attributeClass);

            cx.Emit(Tuples.attributes(this, type.TypeRef, entity));

            cx.Emit(Tuples.attribute_location(this, cx.Create(syntax.Name.GetLocation())));

            if (cx.Extractor.OutputPath != null)
            {
                cx.Emit(Tuples.attribute_location(this, Assembly.CreateOutputAssembly(cx)));
            }

            TypeMention.Create(cx, syntax.Name, this, type);

            if (syntax.ArgumentList != null)
            {
                cx.PopulateLater(() =>
                {
                    int child = 0;
                    foreach (var arg in syntax.ArgumentList.Arguments)
                    {
                        var expr = Expression.Create(cx, arg.Expression, this, child++);
                        if (!(arg.NameEquals is null))
                        {
                            cx.Emit(Tuples.expr_argument_name(expr, arg.NameEquals.Name.Identifier.Text));
                        }
                    }
                });
            }
        }
示例#9
0
    static public void Main()
    {
        var tuple    = Tuple.Create(10u, 20u);
        var newTuple = Tuples.FlipThingsAround(tuple);

        Console.WriteLine($"({newTuple.Item1},{newTuple.Item2})");
    }
示例#10
0
        private IEnumerable <Pair <PrimitiveValue, SubstitutionSet> > GetEmotionsForEntity(IEmotionalState state,
                                                                                           Name emotionName, KB kb, Name perspective, IEnumerable <SubstitutionSet> constraints)
        {
            if (emotionName.IsVariable)
            {
                foreach (var emotion in state.GetAllEmotions())
                {
                    var sub = new Substitution(emotionName, (Name)emotion.EmotionType);
                    foreach (var c in constraints)
                    {
                        if (c.Conflicts(sub))
                        {
                            continue;
                        }

                        var newConstraints = new SubstitutionSet(c);
                        newConstraints.AddSubstitution(sub);
                        yield return(Tuples.Create((PrimitiveValue)emotion.Intensity, newConstraints));
                    }
                }
            }
            else
            {
                foreach (var resultPair in kb.AskPossibleProperties(emotionName, perspective, constraints))
                {
                    string         emotionKey = resultPair.Item1.ToString();
                    var            emotion    = state.GetEmotionsByType(emotionKey).OrderByDescending(e => e.Intensity).FirstOrDefault();
                    PrimitiveValue value      = emotion == null ? 0 : emotion.Intensity;
                    foreach (var c in resultPair.Item2)
                    {
                        yield return(Tuples.Create(value, c));
                    }
                }
            }
        }
示例#11
0
        private IEnumerable <Pair <PrimitiveValue, SubstitutionSet> > MoodPropertyCalculator(KB kb, Name perspective, IDictionary <string, Name> args, IEnumerable <SubstitutionSet> constraints)
        {
            if (perspective != Name.SELF_SYMBOL)
            {
                yield break;
            }

            Name arg = args["x"];

            if (arg.IsVariable)
            {
                var sub = new Substitution(arg, kb.Perspective);
                foreach (var c in constraints)
                {
                    if (c.AddSubstitution(sub))
                    {
                        yield return(Tuples.Create((PrimitiveValue)m_emotionalState.Mood, c));
                    }
                }
            }
            else
            {
                foreach (var resultPair in kb.AskPossibleProperties(arg, perspective, constraints))
                {
                    var v = (PrimitiveValue)m_emotionalState.Mood;
                    foreach (var c in resultPair.Item2)
                    {
                        yield return(Tuples.Create(v, c));
                    }
                }
            }
        }
示例#12
0
文件: Expression.cs 项目: xcorail/ql
        internal Expression(IExpressionInfo info)
            : base(info.Context)
        {
            Location = info.Location;
            Kind     = info.Kind;
            Type     = info.Type;

            if (Type.Type is null)
            {
                Type = NullType.Create(cx);
            }

            cx.Emit(Tuples.expressions(this, Kind, Type.Type.TypeRef));
            if (info.Parent.IsTopLevelParent)
            {
                cx.Emit(Tuples.expr_parent_top_level(this, info.Child, info.Parent));
            }
            else
            {
                cx.Emit(Tuples.expr_parent(this, info.Child, info.Parent));
            }
            cx.Emit(Tuples.expr_location(this, Location));

            if (info.IsCompilerGenerated)
            {
                cx.Emit(Tuples.expr_compiler_generated(this));
            }

            if (info.ExprValue is string value)
            {
                cx.Emit(Tuples.expr_value(this, value));
            }

            Type.Type.ExtractGenerics();
        }
示例#13
0
 protected void ExtractCompilerGenerated()
 {
     if (symbol.IsImplicitlyDeclared)
     {
         Context.Emit(Tuples.compiler_generated(this));
     }
 }
示例#14
0
        public void Tuples2Test1()
        {
            var tuple = Tuples.Tuples2("str3", 3);

            tuple.first.Should().Be("str3");
            tuple.second.Should().Be(3);
        }
示例#15
0
 private static bool AreEqual(Context context, object v1, object v2)
 {
     if (v1 is IDictionary <string, object> o1 && v2 is IDictionary <string, object> o2)
     {
         return(context.EqualityCache.GetOrAdd(Tuples.SameTypePair(v1, v2),
                                               x => o1.Keys.Count == o2.Count && o1.Keys.All(y => AreEqual(context, o1[y], o2[y]))));
     }
     if (v1 is IList <object> a1 && v2 is IList <object> a2)
     {
         return(context.EqualityCache.GetOrAdd(Tuples.SameTypePair(v1, v2),
                                               x => a1.Count == a2.Count && Enumerable.Range(0, a1.Count).All(y => AreEqual(context, a1[y], a2[y]))));
     }
     if (v1 is string s1 && v2 is string s2)
     {
         return(s1 == s2);
     }
     if (v1 is double d1 && v2 is double d2)
     {
         return(d1 == d2);
     }
     if (v1 is int i1 && v2 is int i2)
     {
         return(i1 == i2);
     }
     if (v1 is bool b1 && v2 is bool b2)
     {
         return(b1 == b2);
     }
     if (v1 == null && v2 == null)
     {
         return(true);
     }
     return(false);
 }
示例#16
0
        public void TestTuples()
        {
            var tpls = new Tuples();

            Desharp.Debug.Dump(tpls);
            Desharp.Debug.Log(tpls, Desharp.Level.DEBUG);
        }
        // Main function for where instructions are placed for computer to execute.
        static void Main()
        {
            // Creating a tuple option #1. Tuple is declared, defined, and outputted in the main function. Defined using Tuple.Create() function.
            Console.WriteLine("Option #1:");
            var tuple1 = Tuple.Create(234, "Hello", new List <double>()
            {
                3.2, 3.3
            });

            Console.WriteLine($"Item 1: {tuple1.Item1}, Item 2: {tuple1.Item2}, Item 3: {tuple1.Item3[0]}\r\n");

            // Creating a tuple option #2. Tuple is declared, defined and outputted in main function. Defined differently than option #1.
            Console.WriteLine("Option #2:");
            var tuple2 = new Tuple <int, string, string>(456, "Hello", "What's Up");

            Console.WriteLine($"Item 1: {tuple2.Item1}, Item 2: {tuple2.Item2}, Item 3: {tuple2.Item3}\r\n");

            // Creating a tuple option #3. Tuple is defined in main function, values are passed into class, and outputted there.
            Console.WriteLine("Option #3:");
            Tuples.TupleClassCreation1(88, "Yo mama", new List <double>()
            {
                3.2, 3.3
            });

            // Creating a tuple option #4. Tuple is declared, defined, and outputted withn class.
            Console.WriteLine("Option #4:");
            Tuples.TupleClassCreation2();

            Console.ReadLine();
        }
示例#18
0
        public static VariableDeclaration CreateDeclarator(Context cx, VariableDeclaratorSyntax d, Type type, bool isVar, IExpressionParentEntity parent, int child)
        {
            var ret = Create(cx, d, type, isVar, parent, child);

            cx.Try(d, null, () =>
            {
                var id         = d.Identifier;
                var declSymbol = cx.Model(d).GetDeclaredSymbol(d);
                var location   = cx.Create(id.GetLocation());
                var localVar   = LocalVariable.Create(cx, declSymbol, ret, isVar, location);

                if (d.Initializer != null)
                {
                    Create(cx, d.Initializer.Value, ret, 0);

                    // Create an access
                    var access = new Expression(new ExpressionInfo(cx, type, location, ExprKind.LOCAL_VARIABLE_ACCESS, ret, 1, false, null));
                    cx.Emit(Tuples.expr_access(access, localVar));
                }

                var decl = d.Parent as VariableDeclarationSyntax;
                if (decl != null)
                {
                    TypeMention.Create(cx, decl.Type, ret, type);
                }
            });
            return(ret);
        }
示例#19
0
文件: Method.cs 项目: xcorail/ql
        protected void ExtractGenerics()
        {
            var isFullyConstructed = IsBoundGeneric;

            if (IsGeneric)
            {
                int child = 0;

                if (isFullyConstructed)
                {
                    Context.Emit(Tuples.is_constructed(this));
                    Context.Emit(Tuples.constructed_generic(this, Method.Create(Context, ConstructedFromSymbol)));
                    foreach (var tp in symbol.GetAnnotatedTypeArguments())
                    {
                        Context.Emit(Tuples.type_arguments(Type.Create(Context, tp.Symbol), child, this));
                        var ta = tp.Nullability.GetTypeAnnotation();
                        if (ta != Kinds.TypeAnnotation.None)
                        {
                            Context.Emit(Tuples.type_argument_annotation(this, child, ta));
                        }
                        child++;
                    }
                }
                else
                {
                    Context.Emit(Tuples.is_generic(this));
                    foreach (var typeParam in symbol.TypeParameters.Select(tp => TypeParameter.Create(Context, tp)))
                    {
                        Context.Emit(Tuples.type_parameters(typeParam, child, this));
                        child++;
                    }
                }
            }
        }
示例#20
0
        public override void Populate()
        {
            PopulateMethod();
            ExtractModifiers();
            ContainingType.ExtractGenerics();

            var returnType = Type.Create(Context, symbol.ReturnType);

            Context.Emit(Tuples.methods(this, Name, ContainingType, returnType.TypeRef, OriginalDefinition));

            if (IsSourceDeclaration)
            {
                foreach (var declaration in symbol.DeclaringSyntaxReferences.Select(s => s.GetSyntax()).OfType <MethodDeclarationSyntax>())
                {
                    Context.BindComments(this, declaration.Identifier.GetLocation());
                    TypeMention.Create(Context, declaration.ReturnType, this, returnType);
                }
            }

            foreach (var l in Locations)
            {
                Context.Emit(Tuples.method_location(this, l));
            }

            ExtractGenerics();
            Overrides();
            ExtractRefReturn();
            ExtractCompilerGenerated();
        }
示例#21
0
        internal static IEnumerable <IExtractionProduct> GetParameterExtractionProducts(IEnumerable <Type> parameterTypes, IParameterizable parameterizable, ICustomModifierReceiver receiver, Context cx, int firstChildIndex)
        {
            var i = firstChildIndex;

            foreach (var p in parameterTypes)
            {
                var t = p;
                if (t is ModifiedType mt)
                {
                    t = mt.Unmodified;
                    yield return(Tuples.cil_custom_modifiers(receiver, mt.Modifier, mt.IsRequired));
                }
                if (t is ByRefType brt)
                {
                    t = brt.ElementType;
                    var parameter = cx.Populate(new Parameter(cx, parameterizable, i++, t));
                    yield return(parameter);

                    yield return(Tuples.cil_type_annotation(parameter, TypeAnnotation.Ref));
                }
                else
                {
                    yield return(cx.Populate(new Parameter(cx, parameterizable, i++, t)));
                }
            }
        }
示例#22
0
        protected void ExtractGenerics()
        {
            var isFullyConstructed = IsBoundGeneric;

            if (IsGeneric)
            {
                int child = 0;

                if (isFullyConstructed)
                {
                    Context.Emit(Tuples.is_constructed(this));
                    Context.Emit(Tuples.constructed_generic(this, Method.Create(Context, ConstructedFromSymbol)));
                    foreach (var tp in symbol.TypeArguments)
                    {
                        Context.Emit(Tuples.type_arguments(Type.Create(Context, tp), child++, this));
                    }
                }
                else
                {
                    Context.Emit(Tuples.is_generic(this));
                    foreach (var typeParam in symbol.TypeParameters.Select(tp => TypeParameter.Create(Context, tp)))
                    {
                        Context.Emit(Tuples.type_parameters(typeParam, child++, this));
                    }
                }
            }
        }
示例#23
0
文件: Attribute.cs 项目: safl/ql
        void ExtractAttribute(AttributeSyntax syntax, ITypeSymbol attributeClass, IEntity entity)
        {
            var type = Type.Create(cx, attributeClass);

            cx.Emit(Tuples.attributes(this, type.TypeRef, entity));

            cx.Emit(Tuples.attribute_location(this, cx.Create(syntax.Name.GetLocation())));

            if (cx.Extractor.OutputPath != null)
            {
                cx.Emit(Tuples.attribute_location(this, Assembly.CreateOutputAssembly(cx)));
            }

            TypeMention.Create(cx, syntax.Name, this, type);

            if (syntax.ArgumentList != null)
            {
                cx.PopulateLater(() =>
                {
                    int child = 0;
                    foreach (var arg in syntax.ArgumentList.Arguments)
                    {
                        Expression.Create(cx, arg.Expression, this, child++);
                    }
                    // !! Handle named arguments
                });
            }
        }
示例#24
0
        protected override void Populate()
        {
            if (Kind == ExprKind.POINTER_INDIRECTION)
            {
                var qualifierInfo = new ExpressionNodeInfo(cx, Qualifier, this, 0);
                var add           = new Expression(new ExpressionInfo(cx, qualifierInfo.Type, Location, ExprKind.ADD, this, 0, false, null));
                qualifierInfo.SetParent(add, 0);
                CreateFromNode(qualifierInfo);
                PopulateArguments(ArgumentList, 1);
            }
            else
            {
                var child = -1;
                Create(cx, Qualifier, this, child++);
                foreach (var a in ArgumentList.Arguments)
                {
                    cx.Extract(a, this, child++);
                }

                var symbolInfo = cx.GetSymbolInfo(base.Syntax);

                var indexer = symbolInfo.Symbol as IPropertySymbol;
                if (indexer != null)
                {
                    cx.Emit(Tuples.expr_access(this, Indexer.Create(cx, indexer)));
                }
            }
        }
示例#25
0
 public override void Populate()
 {
     Position   = symbol.GetLineSpan();
     FileEntity = File.Create(Context, Position.Path);
     Context.Emit(Tuples.locations_default(this, FileEntity, Position.Span.Start.Line + 1, Position.Span.Start.Character + 1,
                                           Position.Span.End.Line + 1, Position.Span.End.Character));
 }
示例#26
0
        public override void Populate()
        {
            PopulateMethod();
            ExtractModifiers();

            var returnType = Type.Create(Context, symbol.ReturnType);

            Context.Emit(Tuples.operators(this,
                                          symbol.Name,
                                          OperatorSymbol(Context, symbol.Name),
                                          ContainingType,
                                          returnType.TypeRef,
                                          (UserOperator)OriginalDefinition));

            foreach (var l in Locations)
            {
                Context.Emit(Tuples.operator_location(this, l));
            }

            if (IsSourceDeclaration)
            {
                var declSyntaxReferences = symbol.DeclaringSyntaxReferences.Select(s => s.GetSyntax()).ToArray();
                foreach (var declaration in declSyntaxReferences.OfType <OperatorDeclarationSyntax>())
                {
                    TypeMention.Create(Context, declaration.ReturnType, this, returnType);
                }
                foreach (var declaration in declSyntaxReferences.OfType <ConversionOperatorDeclarationSyntax>())
                {
                    TypeMention.Create(Context, declaration.Type, this, returnType);
                }
            }

            ContainingType.ExtractGenerics();
        }
示例#27
0
        protected override void Populate()
        {
            var target = cx.GetSymbolInfo(Syntax);
            var method = (IMethodSymbol)target.Symbol;

            if (method != null)
            {
                cx.Emit(Tuples.expr_call(this, Method.Create(cx, method)));
            }
            var child = 0;

            Expression objectInitializer = Syntax.Initializers.Any() ?
                                           new Expression(new ExpressionInfo(cx, Type, Location, ExprKind.OBJECT_INIT, this, -1, false, null)) :
                                           null;

            foreach (var init in Syntax.Initializers)
            {
                // Create an "assignment"
                var property   = cx.Model(init).GetDeclaredSymbol(init);
                var propEntity = Property.Create(cx, property);
                var type       = Type.Create(cx, property.Type);
                var loc        = cx.Create(init.GetLocation());

                var assignment = new Expression(new ExpressionInfo(cx, type, loc, ExprKind.SIMPLE_ASSIGN, objectInitializer, child++, false, null));
                Create(cx, init.Expression, assignment, 0);
                Property.Create(cx, property);

                var access = new Expression(new ExpressionInfo(cx, type, loc, ExprKind.PROPERTY_ACCESS, assignment, 1, false, null));
                cx.Emit(Tuples.expr_access(access, propEntity));
            }
        }
示例#28
0
        protected override void Populate()
        {
            bool isSpecificCatchClause  = Stmt.Declaration != null;
            bool hasVariableDeclaration = isSpecificCatchClause && Stmt.Declaration.Identifier.RawKind != 0;

            if (hasVariableDeclaration) // A catch clause of the form 'catch(Ex ex) { ... }'
            {
                var decl = Expressions.VariableDeclaration.Create(cx, Stmt.Declaration, false, this, 0);
                cx.Emit(Tuples.catch_type(this, decl.Type.Type.TypeRef, true));
            }
            else if (isSpecificCatchClause) // A catch clause of the form 'catch(Ex) { ... }'
            {
                cx.Emit(Tuples.catch_type(this, Type.Create(cx, cx.GetType(Stmt.Declaration.Type)).Type.TypeRef, true));
            }
            else // A catch clause of the form 'catch { ... }'
            {
                var exception = Type.Create(cx, cx.Compilation.GetTypeByMetadataName(SystemExceptionName));
                cx.Emit(Tuples.catch_type(this, exception, false));
            }

            if (Stmt.Filter != null)
            {
                // For backward compatibility, the catch filter clause is child number 2.
                Expression.Create(cx, Stmt.Filter.FilterExpression, this, 2);
            }

            Create(cx, Stmt.Block, this, 1);
        }
示例#29
0
        public override void Populate()
        {
            var typeKey = Type.Create(Context, ConstructedType);

            Context.Emit(Tuples.@params(this, Original.symbol.Name, typeKey.TypeRef, 0, Kind.This, Parent, Original));
            Context.Emit(Tuples.param_location(this, Original.Location));
        }
示例#30
0
        private IEnumerable <IExtractionProduct> Decode(byte[]?ilbytes, Dictionary <int, Instruction> jump_table)
        {
            // Sequence points are stored in order of offset.
            // We use an enumerator to locate the correct sequence point for each instruction.
            // The sequence point gives the location of each instruction.
            // The location of an instruction is given by the sequence point *after* the
            // instruction.
            IEnumerator <PDB.SequencePoint>?nextSequencePoint = null;
            PdbSourceLocation?instructionLocation             = null;

            if (methodDebugInformation != null)
            {
                nextSequencePoint = methodDebugInformation.SequencePoints.GetEnumerator();
                if (nextSequencePoint.MoveNext())
                {
                    instructionLocation = Cx.CreateSourceLocation(nextSequencePoint.Current.Location);
                    yield return(instructionLocation);
                }
                else
                {
                    nextSequencePoint = null;
                }
            }

            var child = 0;

            for (var offset = 0; offset < (ilbytes?.Length ?? 0);)
            {
                var instruction = new Instruction(Cx, this, ilbytes !, offset, child++);
                yield return(instruction);

                if (nextSequencePoint != null && offset >= nextSequencePoint.Current.Offset)
                {
                    instructionLocation = Cx.CreateSourceLocation(nextSequencePoint.Current.Location);
                    yield return(instructionLocation);

                    if (!nextSequencePoint.MoveNext())
                    {
                        nextSequencePoint = null;
                    }
                }

                if (instructionLocation != null)
                {
                    yield return(Tuples.cil_instruction_location(instruction, instructionLocation));
                }

                jump_table.Add(instruction.Offset, instruction);
                offset += instruction.Width;
            }

            foreach (var i in jump_table)
            {
                foreach (var t in i.Value.JumpContents(jump_table))
                {
                    yield return(t);
                }
            }
        }
示例#31
0
        internal void FromTuples(Tuples tpls)
        {
            this.SetAllNull();

            if (tpls.MemberNameCount != null) this.MemberNameCount = tpls.MemberNameCount.Value;

            SLTuple t;
            using (OpenXmlReader oxr = OpenXmlReader.Create(tpls))
            {
                while (oxr.Read())
                {
                    if (oxr.ElementType == typeof(Tuple))
                    {
                        t = new SLTuple();
                        t.FromTuple((Tuple)oxr.LoadCurrentElement());
                        this.Tuples.Add(t);
                    }
                }
            }
        }
示例#32
0
        internal Tuples ToTuples()
        {
            Tuples tpls = new Tuples();
            if (this.MemberNameCount != null) tpls.MemberNameCount = this.MemberNameCount.Value;

            foreach (SLTuple t in this.Tuples)
            {
                tpls.Append(t.ToTuple());
            }

            return tpls;
        }
示例#33
0
 /// <summary>
 /// Returns all keys being read or written in a transaction
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public List<Tuples<string, string, string, long, TransactionStates>> getAll(string key)
 {
     List<Tuples<string, string, string, long, TransactionStates>> ret = new List<Tuples<string, string, string, long, TransactionStates>>();
     if (mTransactions.Count > 0)
     {
         foreach (long txID in mTransactions.Keys)
         {
             TransactionContext tc = mTransactions[txID];
             foreach (string tKey in tc.ValuesOfKey.Keys)
             {
                 if (tKey.CompareTo(key) == 0)
                 {
                     System.Console.WriteLine("PASSED COMPARISION " + key);
                     foreach (Pair<string, long> p in tc.ValuesOfKey[key])
                     {
                         Tuples<string, string, string, long, TransactionStates> t = new Tuples<string, string, string, long, TransactionStates>(key, mServer.URL, p.Value, p.Timestamp, tc.TransactionState);
                         ret.Add(t);
                     }
                 }
             }
         }
     }
     if (ret.Count > 0) { return ret; }
     return null;
 }