当前位置: 首页>>代码示例>>C#>>正文


C# IAstVisitor类代码示例

本文整理汇总了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);
        }
开发者ID:shuxingliu,项目名称:SambaPOS-3,代码行数:38,代码来源:AggregatePlugin.cs

示例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;
        }
开发者ID:shuxingliu,项目名称:SambaPOS-3,代码行数:35,代码来源:ExternalFunctions.cs

示例3: AcceptChildren

 public static void AcceptChildren(this AstNode node, IAstVisitor visitor)
 {
     foreach (AstNode child in node.Children)
     {
         child.AcceptVisitor(visitor);
     }
 }
开发者ID:txdv,项目名称:Builder,代码行数:7,代码来源:Helpers.cs

示例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;
            }
        }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:25,代码来源:FieldReferenceReflectionEmitter.cs

示例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);
        }
开发者ID:GHLabs,项目名称:SambaPOS-3,代码行数:41,代码来源:AssignHelper.cs

示例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);
            }
        }
开发者ID:shuxingliu,项目名称:SambaPOS-3,代码行数:40,代码来源:AssignHelper.cs

示例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;
            }
        }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:26,代码来源:PropertyReferenceReflectionEmitter.cs

示例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;
        }
开发者ID:xeno-by,项目名称:rapt,代码行数:30,代码来源:AstTraverser.cs

示例9: AbstractReflectionEmitter

 internal AbstractReflectionEmitter(ILGenerator ilGenerator,
                                    IOpCodeIndexer instructionsIndexer,
                                    IAstVisitor<ILGenerator, AstNode> visitor,
                                    List<LocalBuilder> locals)
     : base(ilGenerator, instructionsIndexer) {
     Visitor = visitor;
     Locals = locals;
 }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:8,代码来源:AbstractReflectionEmitter.cs

示例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) { }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:8,代码来源:EventReferenceReflectionEmitter.cs

示例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);
 }
开发者ID:eightrivers,项目名称:SSharp,代码行数:8,代码来源:AstNode.cs

示例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;
		}
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:8,代码来源:AbstractNode.cs

示例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;
 }
开发者ID:JerreS,项目名称:AbstractCode,代码行数:9,代码来源:DecoratedOutputFormatter.cs

示例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;
 }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:9,代码来源:MultipuleAssignmentEmitter.cs

示例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;
        }
开发者ID:GHLabs,项目名称:SambaPOS-3,代码行数:63,代码来源:MemberHelper.cs


注:本文中的IAstVisitor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。