public JSForLoop(JSStatement initializer, JSExpression condition, JSStatement increment, params JSStatement[] body) { _Initializer = initializer; _Condition = condition; _Increment = increment; Statements.AddRange(body); }
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; } } } }
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); } }
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(); }
public JSLambda(JSFunctionExpression function, JSExpression @this, bool useBind) : base(function) { if (@this == null) { throw new ArgumentNullException("this"); } This = @this; UseBind = useBind; }
public override void ReplaceChild(JSNode oldChild, JSNode newChild) { if (oldChild == null) { throw new ArgumentNullException("oldChild"); } if (oldChild == _Expression) { _Expression = (JSExpression)newChild; } }
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; } }
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; } }
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); } }
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; } }
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; } }
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); }
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); }
public JSExpressionStatement(JSExpression expression) { _Expression = expression; }
public JSTemporaryVariable(string name, TypeReference type, MethodReference function, JSExpression defaultValue = null) : base(name, type, function, defaultValue) { }
internal JSClosureVariable(string name, TypeReference type, MethodReference function, JSExpression defaultValue = null) : base(name, type, function, defaultValue) { }
public JSSwitchStatement(JSExpression condition, params JSSwitchCase[] cases) { _Condition = condition; Cases.AddRange(cases); }
private JSAstBuilder(JSExpression expression) { _expression = expression; }
public JSSwitchStatement(JSExpression condition, params JSSwitchCase[] cases) { IsControlFlow = true; _Condition = condition; Cases.AddRange(cases); }
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(); }
public NoExpectedTypeException(JSExpression node) : base(String.Format("Node of type {0} has no expected type: {1}", node.GetType().Name, node)) { }
public JSDoLoop(JSExpression condition, params JSStatement[] body) { _Condition = condition; Statements.AddRange(body); }