public TypeDecl( Text.Span span, Text.Span headingSpan, bool isConditional, PhpMemberAttributes memberAttributes, bool isPartial, List <FormalTypeParam> /*!*/ genericParams, INamedTypeRef baseClass, List <INamedTypeRef> /*!*/ implementsList, List <TypeMemberDecl> /*!*/ elements, Text.Span bodySpan, List <CustomAttribute> attributes) : base(span) { Debug.Assert(genericParams != null && implementsList != null && elements != null); Debug.Assert((memberAttributes & PhpMemberAttributes.Trait) == 0 || (memberAttributes & PhpMemberAttributes.Interface) == 0, "Interface cannot be a trait"); this.typeSignature = new TypeSignature(genericParams); this.baseClass = baseClass; this.MemberAttributes = memberAttributes; this.IsConditional = isConditional; this.ImplementsList = implementsList.AsArray(); this.members = elements; this.members.TrimExcess(); if (attributes != null && attributes.Count != 0) { this.Attributes = new CustomAttributes(attributes); } this.headingSpan = headingSpan; this.bodySpan = bodySpan; this.partialKeyword = isPartial; }
public TryStmt(Text.Span p, BlockStmt /*!*/ body, List <CatchItem> catches, FinallyItem finallyItem) : base(p) { Debug.Assert(body != null); this.body = body; this.catches = catches.AsArray(); this.finallyItem = finallyItem; }
public TryStmt(Text.Span p, IList<Statement>/*!*/ statements, List<CatchItem> catches, FinallyItem finallyItem) : base(p) { Debug.Assert(statements != null); this.statements = statements.AsArray(); this.catches = catches.AsArray(); this.finallyItem = finallyItem; }
public TryStmt(Text.Span p, IList <Statement> /*!*/ statements, List <CatchItem> catches, FinallyItem finallyItem) : base(p) { Debug.Assert(statements != null); this.statements = statements.AsArray(); this.catches = catches.AsArray(); this.finallyItem = finallyItem; }
public void ConvertListToArray() { IEnumerable <int> enumerable = new List <int> { 1, 2 }; int[] result = enumerable.AsArray(); Assert.AreEqual(2, result.Length); }
private static object[] GetExpressionArguments(MethodCallExpression expression) { IList <object> results = new List <object>(); foreach (Expression argumentExpression in expression.Arguments) { if (argumentExpression.NodeType == ExpressionType.Constant) { object result = ((ConstantExpression)argumentExpression).Value; results.Add(result); } } return(results.AsArray()); }
public static AstNode ReplaceMeWith(this AstNode old, Func<AstNode> newf) { var parset = typeof(AstNode).GetProperty("Parent").GetSetMethod(true); var chiset = typeof(AstNode).GetProperty("Children").GetSetMethod(true); var chiiset = typeof(AstNode).GetProperty("ChildIndex").GetSetMethod(true); var parent = old.Parent; var chiindex = old.ChildIndex; // if you uncomment this, something will crash, namely Extract fx for a direct child of a root expression // parset.Invoke(old, new object[] { null }); // chiiset.Invoke(old, ((object)-1).AsArray()); var @new = newf(); var head = parent.Children.Take(chiindex); var tail = parent.Children.Skip(chiindex + 1); var newchi = new List<AstNode>(head.Concat(@new.AsArray()).Concat(tail)).AsReadOnly(); chiset.Invoke(parent, newchi.AsArray()); parset.Invoke(@new, parent.AsArray()); chiiset.Invoke(@new, ((object)chiindex).AsArray()); return @new; }
private ISourceToken[] FilterTokens(IList <ISourceToken> tokens) { var filtered = tokens.Where(t => t.Token != Tokens.T_WHITESPACE && // whitespaces t.Token != Tokens.T_COMMENT && // comments t.Token != Tokens.T_DOC_COMMENT && // comments t.Token != Tokens.T_PUBLIC && // default public t.Token != Tokens.T_VAR && // var replaced by default public t.Token != Tokens.END // empty end token ).AsArray(); var result = new List <ISourceToken>(); for (int i = 0; i < filtered.Length; i++) { if (i + 2 < filtered.Length && filtered[i].Token == Tokens.T_LBRACE && filtered[i + 1].Token == Tokens.T_SEMI && filtered[i + 2].Token == Tokens.T_CASE) { // leading empty semicolon in switch result.Add(filtered[i]); result.Add(filtered[i + 2]); i += 2; } else if (i + 2 < filtered.Length && filtered[i].Token == Tokens.T_RPAREN && filtered[i + 1].Token == Tokens.T_COLON && filtered[i + 2].Token == Tokens.T_CASE) { // switch with colon result.Add(filtered[i]); result.Add(new SourceToken(Tokens.T_LBRACE, Span.Invalid)); result.Add(filtered[i + 2]); i += 2; } else if (i + 3 < filtered.Length && filtered[i].Token == Tokens.T_RPAREN && filtered[i + 1].Token == Tokens.T_COLON && filtered[i + 2].Token == Tokens.T_SEMI && filtered[i + 3].Token == Tokens.T_CASE) { // leading empty semicolon in switch with colon result.Add(filtered[i]); result.Add(new SourceToken(Tokens.T_LBRACE, Span.Invalid)); result.Add(filtered[i + 3]); i += 3; } else if (i + 2 < filtered.Length && filtered[i].Token == Tokens.T_EXIT && filtered[i + 1].Token == Tokens.T_LPAREN && filtered[i + 2].Token == Tokens.T_RPAREN) { // empty exit with parentheses result.Add(filtered[i]); i += 2; } else if (i + 1 < filtered.Length && filtered[i].Token == Tokens.T_ENDSWITCH && filtered[i + 1].Token == Tokens.T_SEMI) { // endswitch result.Add(new SourceToken(Tokens.T_RBRACE, Span.Invalid)); i++; } else if (i + 1 < filtered.Length && filtered[i].Token == Tokens.T_SEMI && filtered[i + 1].Token == Tokens.T_CLOSE_TAG) { // semicolon before close tag result.Add(new SourceToken(Tokens.T_CLOSE_TAG, Span.Invalid)); i++; } else if (i + 1 < filtered.Length && filtered[i].Token == Tokens.T_OPEN_TAG && filtered[i + 1].Token == Tokens.T_CLOSE_TAG) { // empty php block i++; } else if (i == filtered.Length - 1 && filtered[i].Token == Tokens.T_OPEN_TAG) { // empty open php block i++; } else if (i == filtered.Length - 1 && filtered[i].Token == Tokens.T_SEMI) { // closing semicolon and close tag result.Add(new SourceToken(Tokens.T_CLOSE_TAG, Span.Invalid)); i++; } else if (filtered[i].Token == Tokens.T_OPEN_TAG_WITH_ECHO) { // open tag with echo repalced by open tag and echo result.Add(new SourceToken(Tokens.T_OPEN_TAG, Span.Invalid)); result.Add(new SourceToken(Tokens.T_ECHO, Span.Invalid)); } else { result.Add(filtered[i]); } } if (result.Count != 0 && result.Last().Token == Tokens.T_CLOSE_TAG) { result.RemoveLast(); } return(result.AsArray()); }