Ejemplo n.º 1
0
 public JSForLoop(JSStatement initializer, JSExpression condition, JSStatement increment, params JSStatement[] body)
 {
     _Initializer = initializer;
     _Condition   = condition;
     _Increment   = increment;
     Statements.AddRange(body);
 }
Ejemplo n.º 2
0
        public override void ReplaceChild(JSNode oldChild, JSNode newChild)
        {
            if (oldChild == null)
            {
                throw new ArgumentNullException("oldChild");
            }

            if (_Condition == oldChild)
            {
                _Condition = (JSExpression)newChild;
            }

            var cse = newChild as JSSwitchCase;

            if (cse != null)
            {
                for (int i = 0, c = Cases.Count; i < c; i++)
                {
                    if (Cases[i] == oldChild)
                    {
                        Cases[i] = cse;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override void ReplaceChild(JSNode oldChild, JSNode newChild)
        {
            if (oldChild == null)
            {
                throw new ArgumentNullException("oldChild");
            }

            if (_Initializer == oldChild)
            {
                _Initializer = (JSStatement)newChild;
            }

            if (_Condition == oldChild)
            {
                _Condition = (JSExpression)newChild;
            }

            if (_Increment == oldChild)
            {
                _Increment = (JSStatement)newChild;
            }

            if (newChild is JSStatement)
            {
                base.ReplaceChild(oldChild, newChild);
            }
        }
Ejemplo n.º 4
0
        static JSNode()
        {
            var tNode         = typeof(JSNode);
            var typesToWalk   = (from t in tNode.Assembly.GetTypes() where tNode.IsAssignableFrom(t) select t).ToArray();
            var nodeTypesById = new List <Type>();

            // Assign a unique ID to all node types in the type hierarchy
            foreach (var nodeType in typesToWalk)
            {
                var type = nodeType;

                while (type != null)
                {
                    if (!TypeIds.ContainsKey(type))
                    {
                        TypeIds.Add(type, nodeTypesById.Count);
                        nodeTypesById.Add(type);
                    }

                    if (type == tNode)
                    {
                        break;
                    }

                    type = type.BaseType;
                }
            }

            NodeTypes = nodeTypesById.ToArray();
            NodeSelfAndBaseTypeIds = new int[NodeTypes.Length][];

            var ids = new List <int>();

            for (var i = 0; i < NodeTypes.Length; i++)
            {
                ids.Clear();

                var type = NodeTypes[i];
                while (type != null)
                {
                    ids.Add(GetTypeId(type));
                    if (type == tNode)
                    {
                        break;
                    }

                    type = type.BaseType;
                }

                NodeSelfAndBaseTypeIds[i] = ids.ToArray();
            }

            JSExpression.Initialize();
            JSNodeTraversalData.Initialize();
        }
Ejemplo n.º 5
0
        public JSLambda(JSFunctionExpression function, JSExpression @this, bool useBind)
            : base(function)
        {
            if (@this == null)
            {
                throw new ArgumentNullException("this");
            }

            This    = @this;
            UseBind = useBind;
        }
Ejemplo n.º 6
0
        public override void ReplaceChild(JSNode oldChild, JSNode newChild)
        {
            if (oldChild == null)
            {
                throw new ArgumentNullException("oldChild");
            }

            if (oldChild == _Expression)
            {
                _Expression = (JSExpression)newChild;
            }
        }
Ejemplo n.º 7
0
        public override void ReplaceChild(JSNode oldChild, JSNode newChild)
        {
            if (newChild == this)
            {
                throw new InvalidOperationException("Direct cycle formed by replacement");
            }

            if (DefaultValue == oldChild)
            {
                DefaultValue = (JSExpression)newChild;
            }
        }
Ejemplo n.º 8
0
        public JSIfStatement(JSExpression condition, JSStatement trueClause, JSStatement falseClause = null)
        {
            _Condition   = condition;
            _TrueClause  = trueClause;
            _FalseClause = falseClause;

            if (_TrueClause != null)
            {
                _TrueClause.IsControlFlow = true;
            }
            if (_FalseClause != null)
            {
                _FalseClause.IsControlFlow = true;
            }
        }
Ejemplo n.º 9
0
        static bool GetValue(JSNode parent, int index, out JSNode node, out string name)
        {
            JSExpression expr   = (JSExpression)parent;
            var          values = expr.Values;

            if (index >= values.Length)
            {
                node = null;
                name = null;
                return(false);
            }
            else
            {
                node = values[index];
                name = expr.GetValueName(index) ?? "Values";

                return(true);
            }
        }
Ejemplo n.º 10
0
        public JSIfStatement(JSExpression condition, JSStatement trueClause, JSStatement falseClause = null)
        {
            _Condition   = condition;
            _TrueClause  = trueClause;
            _FalseClause = falseClause;

            var trueBlock = _TrueClause as JSBlockStatement;

            if (trueBlock != null)
            {
                trueBlock.IsControlFlow = true;
            }

            var falseBlock = _FalseClause as JSBlockStatement;

            if (falseBlock != null)
            {
                falseBlock.IsControlFlow = true;
            }
        }
Ejemplo n.º 11
0
        public override void ReplaceChild(JSNode oldChild, JSNode newChild)
        {
            if (oldChild == null)
            {
                throw new ArgumentNullException("oldChild");
            }

            if (_Condition == oldChild)
            {
                _Condition = (JSExpression)newChild;
            }

            if (_TrueClause == oldChild)
            {
                _TrueClause = (JSStatement)newChild;
            }

            if (_FalseClause == oldChild)
            {
                _FalseClause = (JSStatement)newChild;
            }
        }
Ejemplo n.º 12
0
        public static TypeReference ExtractType(JSExpression expression)
        {
            while (expression != null)
            {
                var pii = expression as JSPublicInterfaceOfExpression;
                var jst = expression as JSType;

                if (pii != null)
                {
                    expression = pii.Inner;
                }
                else if (jst != null)
                {
                    return(jst.Type);
                }
                else
                {
                    return(null);
                }
            }

            return(null);
        }
Ejemplo n.º 13
0
        public JSVariable(string name, TypeReference type, MethodReference function, JSExpression defaultValue = null)
            : base(type)
        {
            Name = name;

            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (type is ByReferenceType)
            {
                type         = ((ByReferenceType)type).ElementType;
                _IsReference = true;
            }
            else
            {
                _IsReference = false;
            }

            Function = function;

            DefaultValue = defaultValue ?? new JSDefaultValueLiteral(type);
        }
Ejemplo n.º 14
0
 public JSExpressionStatement(JSExpression expression)
 {
     _Expression = expression;
 }
Ejemplo n.º 15
0
 public JSTemporaryVariable(string name, TypeReference type, MethodReference function, JSExpression defaultValue = null)
     : base(name, type, function, defaultValue)
 {
 }
Ejemplo n.º 16
0
 internal JSClosureVariable(string name, TypeReference type, MethodReference function, JSExpression defaultValue = null)
     : base(name, type, function, defaultValue)
 {
 }
Ejemplo n.º 17
0
 public JSSwitchStatement(JSExpression condition, params JSSwitchCase[] cases)
 {
     _Condition = condition;
     Cases.AddRange(cases);
 }
Ejemplo n.º 18
0
 private JSAstBuilder(JSExpression expression)
 {
     _expression = expression;
 }
Ejemplo n.º 19
0
 public JSSwitchStatement(JSExpression condition, params JSSwitchCase[] cases)
 {
     IsControlFlow = true;
     _Condition    = condition;
     Cases.AddRange(cases);
 }
Ejemplo n.º 20
0
        public static void EnsureTypeIdsAreAssigned()
        {
            if (AreTypeIdsAssigned)
            {
                return;
            }

            AreTypeIdsAssigned = true;

            var tNode       = typeof(JSNode);
            var typesToWalk = (
                from a in NodeAssemblies
                from t in TypesToWalk(a)
                where tNode.IsAssignableFrom(t)
                select t
                ).ToList();
            var nodeTypesById = new List <Type>();

            // Assign a unique ID to all node types in the type hierarchy
            foreach (var nodeType in typesToWalk)
            {
                var type = nodeType;

                while (type != null)
                {
                    if (!TypeIds.ContainsKey(type))
                    {
                        TypeIds.Add(type, nodeTypesById.Count);
                        nodeTypesById.Add(type);
                    }

                    if (type == tNode)
                    {
                        break;
                    }

                    type = type.BaseType;
                }
            }

            _NodeTypes = nodeTypesById.ToArray();
            _NodeSelfAndBaseTypeIds = new int[_NodeTypes.Length][];

            var ids = new List <int>();

            for (var i = 0; i < _NodeTypes.Length; i++)
            {
                ids.Clear();

                var type = _NodeTypes[i];
                while (type != null)
                {
                    ids.Add(GetTypeId(type));
                    if (type == tNode)
                    {
                        break;
                    }

                    type = type.BaseType;
                }

                _NodeSelfAndBaseTypeIds[i] = ids.ToArray();
            }

            JSExpression.Initialize();
            JSNodeTraversalData.Initialize();
        }
Ejemplo n.º 21
0
 public NoExpectedTypeException(JSExpression node)
     : base(String.Format("Node of type {0} has no expected type: {1}", node.GetType().Name, node))
 {
 }
Ejemplo n.º 22
0
 public JSDoLoop(JSExpression condition, params JSStatement[] body)
 {
     _Condition = condition;
     Statements.AddRange(body);
 }