Class CodeRecognizer
Helper class for recognizing patterns in code which is to be transformed.
Inheritance
CodeRecognizer
Assembly: Microsoft.ML.Probabilistic.Compiler.dll
Syntax
public class CodeRecognizer
Fields
Instance
Declaration
public static readonly CodeRecognizer Instance
Field Value
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
AddLoopBounds(Dictionary<IVariableDeclaration, CodeRecognizer.Bounds>, IStatement)
Declaration
public void AddLoopBounds(Dictionary<IVariableDeclaration, CodeRecognizer.Bounds> bounds, IStatement ist)
Parameters
FirstExpressionStatement(IStatement)
Declaration
public IExpressionStatement FirstExpressionStatement(IStatement ist)
Parameters
Returns
ForLoopDepth(IStatement)
Returns the number of nested for loops in the deepest part of the statement.
Declaration
public int ForLoopDepth(IStatement ist)
Parameters
Returns
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
Returns
GetAncestorIndexOfLoopBeingInitialized(BasicTransformContext)
Declaration
public int GetAncestorIndexOfLoopBeingInitialized(BasicTransformContext context)
Parameters
Returns
GetArgumentReferenceExpressions(IExpression)
Declaration
public IEnumerable<IArgumentReferenceExpression> GetArgumentReferenceExpressions(IExpression expr)
Parameters
Returns
GetArrayDeclaration(IExpression)
Declaration
public object GetArrayDeclaration(IExpression expr)
Parameters
Returns
GetBounds(IExpression, IReadOnlyDictionary<IVariableDeclaration, CodeRecognizer.Bounds>)
Declaration
public CodeRecognizer.Bounds GetBounds(IExpression expr, IReadOnlyDictionary<IVariableDeclaration, CodeRecognizer.Bounds> bounds)
Parameters
Returns
GetConditionAndTargetIndexExpressions(IStatement)
Declaration
public IEnumerable<IExpression> GetConditionAndTargetIndexExpressions(IStatement stmt)
Parameters
Returns
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
Returns
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
Returns
GetIndexingDepth(IExpression)
Returns the number of indexing brackets at the end of expr (zero if none)
Declaration
public int GetIndexingDepth(IExpression iexpr)
Parameters
Returns
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
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
Returns
Type Parameters
GetMethodReference(IExpression)
Declaration
public IMethodReference GetMethodReference(IExpression expr)
Parameters
Returns
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
Returns
GetStaticMethodOfType(IExpression, Type)
Declaration
public string GetStaticMethodOfType(IExpression expr, Type type)
Parameters
Returns
GetStaticMethodType(IExpression)
Declaration
public ITypeReference GetStaticMethodType(IExpression expr)
Parameters
Returns
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
Returns
GetTargets(IStatement)
Get every expression on the lhs of an assignment.
Declaration
public IEnumerable<IExpression> GetTargets(IStatement ist)
Parameters
Returns
GetTargetVariables(IStatement)
Apply action to every variable on the lhs of an assignment.
Declaration
public IEnumerable<IVariableDeclaration> GetTargetVariables(IStatement ist)
Parameters
Returns
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
Returns
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
Returns
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
Returns
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
Returns
IsBeingAllocated(BasicTransformContext, IExpression)
Declaration
public bool IsBeingAllocated(BasicTransformContext context, IExpression expr)
Parameters
Returns
IsBeingDeclared(BasicTransformContext)
Declaration
public bool IsBeingDeclared(BasicTransformContext context)
Parameters
Returns
IsBeingIndexed(BasicTransformContext)
Declaration
public bool IsBeingIndexed(BasicTransformContext context)
Parameters
Returns
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
Returns
IsForwardLoop(IForStatement)
Declaration
public bool IsForwardLoop(IForStatement ifs)
Parameters
Returns
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
Returns
IsLiteral(IExpression, Object)
Declaration
public bool IsLiteral(IExpression expr, object val)
Parameters
Returns
IsNewObject(IExpression, Type)
Declaration
public bool IsNewObject(IExpression expr, Type type)
Parameters
Returns
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
Returns
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
Returns
IsStaticGenericMethod(IExpression, Delegate)
Declaration
public bool IsStaticGenericMethod(IExpression expr, Delegate method)
Parameters
Returns
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
Returns
IsStaticMethod(IExpression, Delegate)
Declaration
public bool IsStaticMethod(IExpression expr, Delegate method)
Parameters
Returns
IsStaticMethod(IExpression, MethodInfo)
Declaration
public bool IsStaticMethod(IExpression expr, MethodInfo method)
Parameters
Returns
IsStaticMethod(IExpression, Type)
True if expr is a MethodInvokeExpression on any static method of type.
Declaration
public bool IsStaticMethod(IExpression expr, Type type)
Parameters
Returns
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
Returns
IsTypeReferenceTo(ITypeReferenceExpression, Type)
Declaration
public bool IsTypeReferenceTo(ITypeReferenceExpression itre, Type type)
Parameters
Returns
LoopBreakStatement(IForStatement)
Declaration
public IStatement LoopBreakStatement(IForStatement loop)
Parameters
Returns
LoopSizeExpression(IForStatement)
Declaration
public IExpression LoopSizeExpression(IForStatement loop)
Parameters
Returns
LoopStartExpression(IForStatement)
Declaration
public IExpression LoopStartExpression(IForStatement loop)
Parameters
Returns
LoopVariable(IForStatement)
Declaration
public IVariableDeclaration LoopVariable(IForStatement ifs)
Parameters
Returns
RemoveLastIndex(IExpression)
Remove the last index from an expression
Declaration
public IExpression RemoveLastIndex(IExpression expr)
Parameters
Returns
ReverseLoopDirection(IForStatement)
Declaration
public void ReverseLoopDirection(IForStatement loop)
Parameters
StripFieldsAndProperties(IExpression)
Declaration
public IExpression StripFieldsAndProperties(IExpression expr)
Parameters
Returns
StripIndexers(IExpression)
Declaration
public IExpression StripIndexers(IExpression expr)
Parameters
Returns
StripIndexers(IExpression, Boolean)
Declaration
public IExpression StripIndexers(IExpression expr, bool varsOnly)
Parameters
Returns
TryEvaluate<T>(IExpression, IDictionary<IVariableDeclaration, T>, out T)
Declaration
public bool TryEvaluate<T>(IExpression expr, IDictionary<IVariableDeclaration, T> bindings, out T value)
Parameters
Returns
Type Parameters
TryNegateOperator(BinaryOperator, out BinaryOperator)
Declaration
public bool TryNegateOperator(BinaryOperator op, out BinaryOperator negatedOp)
Parameters
Returns