本文整理汇总了C#中IAstVisitor类的典型用法代码示例。如果您正苦于以下问题:C# IAstVisitor类的具体用法?C# IAstVisitor怎么用?C# IAstVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IAstVisitor类属于命名空间,在下文中一共展示了IAstVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoEvaluate
/// <summary>
/// Evaluate the aggregate expression.
/// </summary>
/// <returns></returns>
public override object DoEvaluate(IAstVisitor visitor)
{
var dataSource = _source.Evaluate(visitor) as LObject;
ExceptionHelper.NotNull(this, dataSource, "aggregation(min/max)");
List<object> items = null;
// Check 1: Could have supplied a single number e.g. sum(2) so just return 2
if (dataSource.Type == LTypes.Number)
return dataSource.Clone();
// Check 2: Expect array
if (dataSource.Type != LTypes.Array)
throw new NotSupportedException(_aggregateType + " not supported for list type of " + dataSource.GetType());
items = dataSource.GetValue() as List<object>;
var val = 0.0;
if (_aggregateType == "sum")
val = items.Sum(item => GetValue(item));
else if (_aggregateType == "avg")
val = items.Average(item => GetValue(item));
else if (_aggregateType == "min")
val = items.Min(item => GetValue(item));
else if (_aggregateType == "max")
val = items.Max(item => GetValue(item));
else if (_aggregateType == "count" || _aggregateType == "number")
val = items.Count;
return new LNumber(val);
}
示例2: Call
/// <summary>
/// Calls the custom function.
/// </summary>
/// <param name="name">Name of the function</param>
/// <param name="exp"></param>
/// <returns></returns>
public object Call(string name, FunctionCallExpr exp, IAstVisitor visitor)
{
var objectName = name;
var method = string.Empty;
Func<string, string, FunctionCallExpr, object> callback = null;
// Contains callback for full function name ? e.g. CreateUser
if (_customCallbacks.ContainsKey(name))
callback = _customCallbacks[name];
// Contains callback that handles multiple methods on a "object".
// e.g. Blog.Create, Blog.Delete etc.
if (name.Contains("."))
{
var ndxDot = name.IndexOf(".");
objectName = name.Substring(0, ndxDot);
method = name.Substring(ndxDot + 1);
if (_customCallbacks.ContainsKey(objectName + ".*"))
callback = _customCallbacks[objectName + ".*"];
}
if (callback == null)
return LObjects.Null;
// 1. Resolve parameter froms expressions into Lang values.
ParamHelper.ResolveParametersToHostLangValues(exp.ParamListExpressions, exp.ParamList, visitor);
object result = callback(objectName, method, exp);
return result;
}
示例3: AcceptChildren
public static void AcceptChildren(this AstNode node, IAstVisitor visitor)
{
foreach (AstNode child in node.Children)
{
child.AcceptVisitor(visitor);
}
}
示例4: FieldReferenceReflectionEmitter
internal FieldReferenceReflectionEmitter(MemberReferenceExpression memberReferenceExpression,
Type target,
MemberInfo member,
ILGenerator ilGenerator,
IOpCodeIndexer instructionsIndexer,
IAstVisitor<ILGenerator, AstNode> visitor,
List<LocalBuilder> locals,
bool isSetter = false)
: base(memberReferenceExpression, target, member, ilGenerator, instructionsIndexer, visitor, locals) {
FieldReference = MemberReference.Annotation<FieldReference>();
IsByRef = MemberReference.Parent is DirectionExpression;
Type = FieldReference.FieldType.GetActualType();
FieldInfo = FieldReference.GetActualField();
NonPublic = !((FieldInfo.Attributes & (_publicFieldAttributes)) == _publicFieldAttributes);
if (isSetter) {
_emitAction = EmitStoreFieldReference;
_emitPrivateAction = EmitPrivateStoreFieldReference;
}
else {
_emitAction = EmitLoadFieldReference;
_emitPrivateAction = EmitPrivateLoadFieldReference;
}
}
示例5: SetVariableValue
/// <summary>
/// Sets a value on a member of a basic type.
/// </summary>
/// <param name="ctx">The context of the runtime</param>
/// <param name="node">The assignment ast node</param>
/// <param name="isDeclaration">Whether or not this is a declaration</param>
/// <param name="varExp">The expression representing the index of the instance to set</param>
/// <param name="valExp">The expression representing the value to set</param>
public static void SetVariableValue(Context ctx, IAstVisitor visitor, AstNode node, bool isDeclaration, Expr varExp, Expr valExp)
{
string varname = ((VariableExpr)varExp).Name;
// Case 1: var result;
if (valExp == null)
{
ctx.Memory.SetValue(varname, LObjects.Null, isDeclaration);
}
// Case 2: var result = <expression>;
else
{
var result = valExp.Evaluate(visitor);
// Check for type: e.g. LFunction ? when using Lambda?
if (result != null && result != LObjects.Null)
{
var lobj = result as LObject;
if (lobj != null && lobj.Type.TypeVal == TypeConstants.Function)
{
// 1. Define the function in global symbol scope
SymbolHelper.ResetSymbolAsFunction(varExp.SymScope, varname, lobj);
}
}
// CHECK_LIMIT:
ctx.Limits.CheckStringLength(node, result);
ctx.Memory.SetValue(varname, result, isDeclaration);
}
// LIMIT CHECK
ctx.Limits.CheckScopeCount(varExp);
ctx.Limits.CheckScopeStringLength(varExp);
}
示例6: SetIndexValue
/// <summary>
/// Sets a value on a member of a basic type.
/// </summary>
/// <param name="ctx">The context of the runtime</param>
/// <param name="varExp">The expression representing the index of the instance to set</param>
/// <param name="valExp">The expression representing the value to set</param>
/// <param name="node">The assignment ast node</param>
public static void SetIndexValue(Context ctx, IAstVisitor visitor, AstNode node, Expr varExp, Expr valExp)
{
// 1. Get the value that is being assigned.
var val = valExp.Evaluate(visitor) as LObject;
// 2. Check the limit if string.
ctx.Limits.CheckStringLength(node, val);
// 3. Evaluate expression to get index info.
var indexExp = varExp.Evaluate(visitor) as IndexAccess;
if (indexExp == null)
throw ComLib.Lang.Helpers.ExceptionHelper.BuildRunTimeException(node, "Value to assign is null");
// 4. Get the target of the index access and the name / number to set.
var target = indexExp.Instance;
var memberNameOrIndex = indexExp.MemberName;
// Get methods associated with type.
var methods = ctx.Methods.Get(target.Type);
// Case 1: users[0] = 'kishore'
if (target.Type == LTypes.Array)
{
var index = Convert.ToInt32(((LNumber)memberNameOrIndex).Value);
methods.SetByNumericIndex(target, index, val);
}
// Case 2: users['total'] = 20
else if (target.Type == LTypes.Map)
{
var name = ((LString)memberNameOrIndex).Value;
methods.SetByStringMember(target, name, val);
}
}
示例7: PropertyReferenceReflectionEmitter
public PropertyReferenceReflectionEmitter(MemberReferenceExpression memberReferenceExpression,
Type target,
MemberInfo member,
ILGenerator ilGenerator,
IOpCodeIndexer instructionsIndexer,
IAstVisitor<ILGenerator, AstNode> visitor,
List<LocalBuilder> locals,
bool isSetter = false)
: base(memberReferenceExpression, target, member, ilGenerator, instructionsIndexer, visitor, locals) {
var propertyInfo = Member as PropertyInfo;
_isSetter = isSetter;
_propertyDefinition = MemberReference.Annotation<Cecil.PropertyDefinition>();
NonPublic = !_propertyDefinition.GetMethod.IsPublic;
Type = _propertyDefinition.PropertyType.GetActualType();
if (isSetter) {
_propertyMethod = propertyInfo.GetSetMethod(NonPublic);
_emitPrivateAction = EmitPrivateStorePropertyReference;
}
else {
_propertyMethod = propertyInfo.GetGetMethod(NonPublic);
_emitPrivateAction = EmitPrivateLoadPropertyReference;
}
}
示例8: RunTraversal
public object RunTraversal(IAstVisitor visitor, ITraversalStrategy strategy)
{
visitor.StartSession(Expression);
object traversalResult;
try
{
strategy.Initialize(Expression);
while (strategy.HasNext())
{
try
{
var current = strategy.Next();
current.Accept(visitor);
}
catch (RestartTraversalException rte)
{
// Expression.Analyze(new TreeDumper());
strategy.Restart(rte.Root);
}
}
}
finally
{
traversalResult = visitor.FinishSession();
}
return traversalResult;
}
示例9: AbstractReflectionEmitter
internal AbstractReflectionEmitter(ILGenerator ilGenerator,
IOpCodeIndexer instructionsIndexer,
IAstVisitor<ILGenerator, AstNode> visitor,
List<LocalBuilder> locals)
: base(ilGenerator, instructionsIndexer) {
Visitor = visitor;
Locals = locals;
}
示例10: EventReferenceReflectionEmitter
internal EventReferenceReflectionEmitter(MemberReferenceExpression memberReferenceExpression,
Type target,
MemberInfo member,
ILGenerator ilGenerator,
IOpCodeIndexer instructionsIndexer,
IAstVisitor<ILGenerator, AstNode> visitor,
List<LocalBuilder> locals)
: base(memberReferenceExpression, target, member, ilGenerator, instructionsIndexer, visitor, locals) { }
示例11: AcceptVisitor
public virtual void AcceptVisitor(IAstVisitor visitor)
{
visitor.BeginVisit(this);
if (ChildNodes.Count > 0)
foreach (AstNode node in ChildNodes)
node.AcceptVisitor(visitor);
visitor.EndVisit(this);
}
示例12: AcceptChildren
public virtual object AcceptChildren(IAstVisitor visitor, object data)
{
foreach (INode child in children) {
Debug.Assert(child != null);
child.AcceptVisitor(visitor, data);
}
return data;
}
示例13: DecoratedOutputFormatter
public DecoratedOutputFormatter(IOutputFormatter formatter, IAstVisitor visitor)
{
if (formatter == null)
throw new ArgumentNullException(nameof(formatter));
if (visitor == null)
throw new ArgumentNullException(nameof(visitor));
_formatter = formatter;
_visitor = visitor;
}
示例14: MultipuleAssignmentEmitter
internal MultipuleAssignmentEmitter(MemberReferenceExpression memberReferenceExpression,
Expression assignor,
ILGenerator ilGenerator,
IOpCodeIndexer instructionsIndexer,
IAstVisitor<ILGenerator, AstNode> visitor,
List<LocalBuilder> locals)
: base(memberReferenceExpression, ilGenerator, instructionsIndexer, visitor, locals) {
_assignorExpression = assignor;
}
示例15: GetMemberAccess
/// <summary>
/// Gets a member access object representing the a member access.
/// </summary>
/// <param name="node"></param>
/// <param name="ctx"></param>
/// <param name="varExp"></param>
/// <param name="memberName"></param>
/// <returns></returns>
public static MemberAccess GetMemberAccess(AstNode node, Context ctx, Expr varExp, string memberName, IAstVisitor visitor)
{
var isVariableExp = varExp.IsNodeType(NodeTypes.SysVariable);
var variableName = isVariableExp ? ((VariableExpr) varExp).Name : string.Empty;
// CASE 1: External function call "user.create"
if (isVariableExp && FunctionHelper.IsExternalFunction(ctx.ExternalFunctions, variableName, memberName))
return new MemberAccess(MemberMode.FunctionExternal) {Name = variableName, MemberName = memberName};
// CASE 2. Static method call: "Person.Create"
if (isVariableExp)
{
var result = MemberHelper.IsExternalTypeName(ctx.Memory, ctx.Types, variableName);
if (result.Success)
return MemberHelper.GetExternalTypeMember(node, (Type) result.Item, variableName, null, memberName, true);
}
// CASE 3: Module
if (varExp.IsNodeType(NodeTypes.SysVariable))
{
var name = varExp.ToQualifiedName();
if (!ctx.Memory.Contains(name))
{
var modresult = ResolveSymbol(varExp.SymScope, name);
if (modresult != null) return modresult;
}
}
// CASE 4: Nested member.
var res = varExp.Visit(visitor);
if (res is MemberAccess )
{
return res as MemberAccess;
}
var obj = res as LObject;
// Check for empty objects.
ExceptionHelper.NotNull(node, obj, "member access");
var type = obj.Type;
// Case 3: Method / Property on FluentScript type
bool isCoreType = obj.Type.IsBuiltInType();
if (isCoreType)
{
var result = MemberHelper.GetLangBasicTypeMember(node, ctx.Methods, obj, memberName);
return result;
}
// CASE 4: Method / Property on External/Host language type (C#)
var lclass = obj as LClass;
var lclassType = lclass.Type as LClassType;
var member = MemberHelper.GetExternalTypeMember(node, lclassType.DataType, variableName, lclass.Value, memberName, false);
return member;
}