Search Results for

    Show / Hide Table of Contents

    Class CodeRecognizer

    Helper class for recognizing patterns in code which is to be transformed.

    Inheritance
    Object
    CodeRecognizer
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: Microsoft.ML.Probabilistic.Compiler
    Assembly: Microsoft.ML.Probabilistic.Compiler.dll
    Syntax
    public class CodeRecognizer

    Fields

    Instance

    Declaration
    public static readonly CodeRecognizer Instance
    Field Value
    Type Description
    CodeRecognizer

    Methods

    AddIndexers(BasicTransformContext, List<IVariableDeclaration[]>, IExpression)

    Add the declarations of all loop variables in expr to indVars.

    Declaration
    public void AddIndexers(BasicTransformContext context, List<IVariableDeclaration[]> indVars, IExpression expr)
    Parameters
    Type Name Description
    BasicTransformContext context
    List<IVariableDeclaration[]> indVars
    IExpression expr

    AddLoopBounds(Dictionary<IVariableDeclaration, CodeRecognizer.Bounds>, IStatement)

    Declaration
    public void AddLoopBounds(Dictionary<IVariableDeclaration, CodeRecognizer.Bounds> bounds, IStatement ist)
    Parameters
    Type Name Description
    Dictionary<IVariableDeclaration, CodeRecognizer.Bounds> bounds
    IStatement ist

    FirstExpressionStatement(IStatement)

    Declaration
    public IExpressionStatement FirstExpressionStatement(IStatement ist)
    Parameters
    Type Name Description
    IStatement ist
    Returns
    Type Description
    IExpressionStatement

    ForLoopDepth(IStatement)

    Returns the number of nested for loops in the deepest part of the statement.

    Declaration
    public int ForLoopDepth(IStatement ist)
    Parameters
    Type Name Description
    IStatement ist
    Returns
    Type Description
    Int32

    GetAllPrefixes(IExpression)

    Get a list of prefixes of the given expression, starting from the innermost target, up to and including the given expression.

    Declaration
    public List<IExpression> GetAllPrefixes(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    List<IExpression>

    GetAncestorIndexOfLoopBeingInitialized(BasicTransformContext)

    Declaration
    public int GetAncestorIndexOfLoopBeingInitialized(BasicTransformContext context)
    Parameters
    Type Name Description
    BasicTransformContext context
    Returns
    Type Description
    Int32

    GetArgumentReferenceExpressions(IExpression)

    Declaration
    public IEnumerable<IArgumentReferenceExpression> GetArgumentReferenceExpressions(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    IEnumerable<IArgumentReferenceExpression>

    GetArrayDeclaration(IExpression)

    Declaration
    public object GetArrayDeclaration(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    Object

    GetBounds(IExpression, IReadOnlyDictionary<IVariableDeclaration, CodeRecognizer.Bounds>)

    Declaration
    public CodeRecognizer.Bounds GetBounds(IExpression expr, IReadOnlyDictionary<IVariableDeclaration, CodeRecognizer.Bounds> bounds)
    Parameters
    Type Name Description
    IExpression expr
    IReadOnlyDictionary<IVariableDeclaration, CodeRecognizer.Bounds> bounds
    Returns
    Type Description
    CodeRecognizer.Bounds

    GetConditionAndTargetIndexExpressions(IStatement)

    Declaration
    public IEnumerable<IExpression> GetConditionAndTargetIndexExpressions(IStatement stmt)
    Parameters
    Type Name Description
    IStatement stmt
    Returns
    Type Description
    IEnumerable<IExpression>

    GetDeclaration(IExpression)

    Extracts the variable or parameter declaration from a, possibly indexed, reference or declaration expression. Returns null if the expression is not either of these.

    Declaration
    public object GetDeclaration(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    Object

    GetFieldReference(IExpression)

    Extracts the field reference from a, possibly indexed, field reference expression. Returns null if the expression is not either of these.

    Declaration
    public IFieldReference GetFieldReference(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    IFieldReference

    GetIndexingDepth(IExpression)

    Returns the number of indexing brackets at the end of expr (zero if none)

    Declaration
    public int GetIndexingDepth(IExpression iexpr)
    Parameters
    Type Name Description
    IExpression iexpr
    Returns
    Type Description
    Int32

    GetIndices(IExpression)

    Get a list of all index expressions at the end of expr, innermost first.

    Declaration
    public List<IList<IExpression>> GetIndices(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    List<IList<IExpression>>

    A list of indexing brackets, where each bracket is a collection of index expressions

    GetIndices(IExpression, out IExpression)

    Get a list of all index expressions at the end of expr, innermost first.

    Declaration
    public List<IList<IExpression>> GetIndices(IExpression expr, out IExpression target)
    Parameters
    Type Name Description
    IExpression expr
    IExpression target

    On exit, the innermost expression being indexed, i.e. the array variable

    Returns
    Type Description
    List<IList<IExpression>>

    A list of indexing brackets, where each bracket is a collection of index expressions

    GetLiteral<T>(IExpression)

    Declaration
    public T GetLiteral<T>(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    GetMethodReference(IExpression)

    Declaration
    public IMethodReference GetMethodReference(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    IMethodReference

    GetParameterDeclaration(IExpression)

    Extracts the declaration of the parameter reference from a, possibly indexed, argument reference expression. Returns null if the expression is not either of these.

    Declaration
    public IParameterDeclaration GetParameterDeclaration(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    IParameterDeclaration

    GetStaticMethodOfType(IExpression, Type)

    Declaration
    public string GetStaticMethodOfType(IExpression expr, Type type)
    Parameters
    Type Name Description
    IExpression expr
    Type type
    Returns
    Type Description
    String

    GetStaticMethodType(IExpression)

    Declaration
    public ITypeReference GetStaticMethodType(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    ITypeReference

    GetTarget(IExpression)

    Get the innermost target of an expression, e.g. x[0].field[1].method(y) returns 'x'

    Declaration
    public IExpression GetTarget(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    IExpression

    GetTargets(IStatement)

    Get every expression on the lhs of an assignment.

    Declaration
    public IEnumerable<IExpression> GetTargets(IStatement ist)
    Parameters
    Type Name Description
    IStatement ist
    Returns
    Type Description
    IEnumerable<IExpression>

    GetTargetVariables(IStatement)

    Apply action to every variable on the lhs of an assignment.

    Declaration
    public IEnumerable<IVariableDeclaration> GetTargetVariables(IStatement ist)
    Parameters
    Type Name Description
    IStatement ist
    Returns
    Type Description
    IEnumerable<IVariableDeclaration>

    GetVariableDeclaration(IExpression)

    Extracts the variable declaration from a, possibly indexed, reference or declaration expression. Returns null if the expression is not either of these.

    Declaration
    public IVariableDeclaration GetVariableDeclaration(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    IVariableDeclaration

    GetVariableDeclaration(IStatement)

    Extracts the variable declaration from a declaration statement. Returns null if the statement is not a declaration statement.

    Declaration
    public IVariableDeclaration GetVariableDeclaration(IStatement ist)
    Parameters
    Type Name Description
    IStatement ist
    Returns
    Type Description
    IVariableDeclaration

    GetVariables(IExpression)

    Get all variable references in an expression. The same variable may appear more than once.

    Declaration
    public IEnumerable<IVariableDeclaration> GetVariables(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr

    Any expression

    Returns
    Type Description
    IEnumerable<IVariableDeclaration>

    GetVariablesAndParameters(IExpression)

    Get all variable and parameter references in an expression. The same variable may appear more than once.

    Declaration
    public IEnumerable<object> GetVariablesAndParameters(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr

    Any expression

    Returns
    Type Description
    IEnumerable<Object>

    IsBeingAllocated(BasicTransformContext, IExpression)

    Declaration
    public bool IsBeingAllocated(BasicTransformContext context, IExpression expr)
    Parameters
    Type Name Description
    BasicTransformContext context
    IExpression expr
    Returns
    Type Description
    Boolean

    IsBeingDeclared(BasicTransformContext)

    Declaration
    public bool IsBeingDeclared(BasicTransformContext context)
    Parameters
    Type Name Description
    BasicTransformContext context
    Returns
    Type Description
    Boolean

    IsBeingIndexed(BasicTransformContext)

    Declaration
    public bool IsBeingIndexed(BasicTransformContext context)
    Parameters
    Type Name Description
    BasicTransformContext context
    Returns
    Type Description
    Boolean

    IsBeingMutated(BasicTransformContext, IExpression)

    Returns true if the expression is being mutated in the given context. For example, this will be true if the expression is the LHS of an assignment, or the argument to an 'out' parameter.

    Declaration
    public bool IsBeingMutated(BasicTransformContext context, IExpression expr)
    Parameters
    Type Name Description
    BasicTransformContext context
    IExpression expr
    Returns
    Type Description
    Boolean

    IsForwardLoop(IForStatement)

    Declaration
    public bool IsForwardLoop(IForStatement ifs)
    Parameters
    Type Name Description
    IForStatement ifs
    Returns
    Type Description
    Boolean

    IsIndexedBy(List<IVariableReferenceExpression>, IVariableDeclaration)

    Returns true if any of the reference expressions refer to the specified index variable.

    Declaration
    public bool IsIndexedBy(List<IVariableReferenceExpression> refs, IVariableDeclaration indexVar)
    Parameters
    Type Name Description
    List<IVariableReferenceExpression> refs
    IVariableDeclaration indexVar
    Returns
    Type Description
    Boolean

    IsLiteral(IExpression, Object)

    Declaration
    public bool IsLiteral(IExpression expr, object val)
    Parameters
    Type Name Description
    IExpression expr
    Object val
    Returns
    Type Description
    Boolean

    IsNewObject(IExpression, Type)

    Declaration
    public bool IsNewObject(IExpression expr, Type type)
    Parameters
    Type Name Description
    IExpression expr
    Type type
    Returns
    Type Description
    Boolean

    IsOnLHSOfAssignment(BasicTransformContext, IExpression)

    Returns true if expr is on the left hand side of the innermost assignment statement in the context stack.

    Declaration
    public bool IsOnLHSOfAssignment(BasicTransformContext context, IExpression expr)
    Parameters
    Type Name Description
    BasicTransformContext context
    IExpression expr
    Returns
    Type Description
    Boolean

    IsPartOf(IExpression, IExpression)

    Returns true if the first expression is equal to, or a subarray or element of the second expression. For example, x, x[0], x[0][0] are all subarrays of x, but x[1] is not part of x[0].

    Declaration
    public bool IsPartOf(IExpression expr, IExpression arrayExpr)
    Parameters
    Type Name Description
    IExpression expr
    IExpression arrayExpr
    Returns
    Type Description
    Boolean

    IsStaticGenericMethod(IExpression, Delegate)

    Declaration
    public bool IsStaticGenericMethod(IExpression expr, Delegate method)
    Parameters
    Type Name Description
    IExpression expr
    Delegate method
    Returns
    Type Description
    Boolean

    IsStaticGenericMethod(IExpression, Type, String)

    True if imie is a MethodInvokeExpression on any overload of the named static generic method of type.

    Declaration
    public bool IsStaticGenericMethod(IExpression expr, Type type, string methodName)
    Parameters
    Type Name Description
    IExpression expr
    Type type
    String methodName
    Returns
    Type Description
    Boolean

    IsStaticMethod(IExpression, Delegate)

    Declaration
    public bool IsStaticMethod(IExpression expr, Delegate method)
    Parameters
    Type Name Description
    IExpression expr
    Delegate method
    Returns
    Type Description
    Boolean

    IsStaticMethod(IExpression, MethodInfo)

    Declaration
    public bool IsStaticMethod(IExpression expr, MethodInfo method)
    Parameters
    Type Name Description
    IExpression expr
    MethodInfo method
    Returns
    Type Description
    Boolean

    IsStaticMethod(IExpression, Type)

    True if expr is a MethodInvokeExpression on any static method of type.

    Declaration
    public bool IsStaticMethod(IExpression expr, Type type)
    Parameters
    Type Name Description
    IExpression expr
    Type type
    Returns
    Type Description
    Boolean

    IsStaticMethod(IExpression, Type, String)

    True if expr is a MethodInvokeExpression on any overload of the named static method of type.

    Declaration
    public bool IsStaticMethod(IExpression expr, Type type, string methodName)
    Parameters
    Type Name Description
    IExpression expr
    Type type
    String methodName
    Returns
    Type Description
    Boolean

    IsTypeReferenceTo(ITypeReferenceExpression, Type)

    Declaration
    public bool IsTypeReferenceTo(ITypeReferenceExpression itre, Type type)
    Parameters
    Type Name Description
    ITypeReferenceExpression itre
    Type type
    Returns
    Type Description
    Boolean

    LoopBreakStatement(IForStatement)

    Declaration
    public IStatement LoopBreakStatement(IForStatement loop)
    Parameters
    Type Name Description
    IForStatement loop
    Returns
    Type Description
    IStatement

    LoopSizeExpression(IForStatement)

    Declaration
    public IExpression LoopSizeExpression(IForStatement loop)
    Parameters
    Type Name Description
    IForStatement loop
    Returns
    Type Description
    IExpression

    LoopStartExpression(IForStatement)

    Declaration
    public IExpression LoopStartExpression(IForStatement loop)
    Parameters
    Type Name Description
    IForStatement loop
    Returns
    Type Description
    IExpression

    LoopVariable(IForStatement)

    Declaration
    public IVariableDeclaration LoopVariable(IForStatement ifs)
    Parameters
    Type Name Description
    IForStatement ifs
    Returns
    Type Description
    IVariableDeclaration

    RemoveLastIndex(IExpression)

    Remove the last index from an expression

    Declaration
    public IExpression RemoveLastIndex(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    IExpression

    ReverseLoopDirection(IForStatement)

    Declaration
    public void ReverseLoopDirection(IForStatement loop)
    Parameters
    Type Name Description
    IForStatement loop

    StripFieldsAndProperties(IExpression)

    Declaration
    public IExpression StripFieldsAndProperties(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    IExpression

    StripIndexers(IExpression)

    Declaration
    public IExpression StripIndexers(IExpression expr)
    Parameters
    Type Name Description
    IExpression expr
    Returns
    Type Description
    IExpression

    StripIndexers(IExpression, Boolean)

    Declaration
    public IExpression StripIndexers(IExpression expr, bool varsOnly)
    Parameters
    Type Name Description
    IExpression expr
    Boolean varsOnly
    Returns
    Type Description
    IExpression

    TryEvaluate<T>(IExpression, IDictionary<IVariableDeclaration, T>, out T)

    Declaration
    public bool TryEvaluate<T>(IExpression expr, IDictionary<IVariableDeclaration, T> bindings, out T value)
    Parameters
    Type Name Description
    IExpression expr
    IDictionary<IVariableDeclaration, T> bindings
    T value
    Returns
    Type Description
    Boolean
    Type Parameters
    Name Description
    T

    TryNegateOperator(BinaryOperator, out BinaryOperator)

    Declaration
    public bool TryNegateOperator(BinaryOperator op, out BinaryOperator negatedOp)
    Parameters
    Type Name Description
    BinaryOperator op
    BinaryOperator negatedOp
    Returns
    Type Description
    Boolean
    In This Article
    Back to top Copyright © .NET Foundation. All rights reserved.