예제 #1
0
 public JSForLoop(JSStatement initializer, JSExpression condition, JSStatement increment, params JSStatement[] body)
 {
     _Initializer = initializer;
     _Condition   = condition;
     _Increment   = increment;
     Statements.AddRange(body);
 }
예제 #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;
                    }
                }
            }
        }
예제 #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);
            }
        }
예제 #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();
        }
예제 #5
0
파일: JSLiteralTypes.cs 프로젝트: xen2/JSIL
        public JSLambda(JSFunctionExpression function, JSExpression @this, bool useBind)
            : base(function)
        {
            if (@this == null)
            {
                throw new ArgumentNullException("this");
            }

            This    = @this;
            UseBind = useBind;
        }
예제 #6
0
        public override void ReplaceChild(JSNode oldChild, JSNode newChild)
        {
            if (oldChild == null)
            {
                throw new ArgumentNullException("oldChild");
            }

            if (oldChild == _Expression)
            {
                _Expression = (JSExpression)newChild;
            }
        }
예제 #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;
            }
        }
예제 #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;
            }
        }
예제 #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);
            }
        }
예제 #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;
            }
        }
예제 #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;
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #14
0
 public JSExpressionStatement(JSExpression expression)
 {
     _Expression = expression;
 }
예제 #15
0
 public JSTemporaryVariable(string name, TypeReference type, MethodReference function, JSExpression defaultValue = null)
     : base(name, type, function, defaultValue)
 {
 }
예제 #16
0
 internal JSClosureVariable(string name, TypeReference type, MethodReference function, JSExpression defaultValue = null)
     : base(name, type, function, defaultValue)
 {
 }
예제 #17
0
 public JSSwitchStatement(JSExpression condition, params JSSwitchCase[] cases)
 {
     _Condition = condition;
     Cases.AddRange(cases);
 }
예제 #18
0
 private JSAstBuilder(JSExpression expression)
 {
     _expression = expression;
 }
예제 #19
0
 public JSSwitchStatement(JSExpression condition, params JSSwitchCase[] cases)
 {
     IsControlFlow = true;
     _Condition    = condition;
     Cases.AddRange(cases);
 }
예제 #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();
        }
예제 #21
0
 public NoExpectedTypeException(JSExpression node)
     : base(String.Format("Node of type {0} has no expected type: {1}", node.GetType().Name, node))
 {
 }
예제 #22
0
 public JSDoLoop(JSExpression condition, params JSStatement[] body)
 {
     _Condition = condition;
     Statements.AddRange(body);
 }