aspclassic-core/AspClassic.Parser/TreeXmlSerializer.cs
Jelle Luteijn 484dbfc9d9 progress
2022-05-15 11:19:49 +02:00

1624 lines
54 KiB
C#

#define DEBUG
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Xml;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
namespace AspClassic.Parser;
public class TreeXmlSerializer
{
private readonly XmlWriter Writer;
[SpecialName]
private Dictionary<TypeCharacter, string> _0024STATIC_0024SerializeTypeCharacter_002420111182E4_0024TypeCharacterTable;
public TreeXmlSerializer(XmlWriter Writer)
{
this.Writer = Writer;
}
private static TokenType GetOperatorToken(OperatorType type)
{
switch (type)
{
case OperatorType.Concatenate:
return TokenType.Ampersand;
case OperatorType.Multiply:
return TokenType.Star;
case OperatorType.Divide:
return TokenType.ForwardSlash;
case OperatorType.IntegralDivide:
return TokenType.BackwardSlash;
case OperatorType.Power:
return TokenType.Caret;
case OperatorType.UnaryPlus:
case OperatorType.Plus:
return TokenType.Plus;
case OperatorType.Negate:
case OperatorType.Minus:
return TokenType.Minus;
case OperatorType.LessThan:
return TokenType.LessThan;
case OperatorType.LessThanEquals:
return TokenType.LessThanEquals;
case OperatorType.Equals:
return TokenType.Equals;
case OperatorType.NotEquals:
return TokenType.NotEquals;
case OperatorType.GreaterThan:
return TokenType.GreaterThan;
case OperatorType.GreaterThanEquals:
return TokenType.GreaterThanEquals;
case OperatorType.ShiftLeft:
return TokenType.LessThanLessThan;
case OperatorType.ShiftRight:
return TokenType.GreaterThanGreaterThan;
case OperatorType.Modulus:
return TokenType.Mod;
case OperatorType.Or:
return TokenType.Or;
case OperatorType.OrElse:
return TokenType.OrElse;
case OperatorType.And:
return TokenType.And;
case OperatorType.AndAlso:
return TokenType.AndAlso;
case OperatorType.Xor:
return TokenType.Xor;
case OperatorType.Like:
return TokenType.Like;
case OperatorType.Is:
return TokenType.Is;
case OperatorType.IsNot:
return TokenType.IsNot;
case OperatorType.Not:
return TokenType.Not;
case OperatorType.To:
return TokenType.To;
default:
return TokenType.LexicalError;
}
}
private static TokenType GetCompoundAssignmentOperatorToken(OperatorType compoundOperator)
{
switch (compoundOperator)
{
case OperatorType.Plus:
return TokenType.PlusEquals;
case OperatorType.Concatenate:
return TokenType.AmpersandEquals;
case OperatorType.Multiply:
return TokenType.StarEquals;
case OperatorType.Minus:
return TokenType.MinusEquals;
case OperatorType.Divide:
return TokenType.ForwardSlashEquals;
case OperatorType.IntegralDivide:
return TokenType.BackwardSlashEquals;
case OperatorType.Power:
return TokenType.CaretEquals;
case OperatorType.ShiftLeft:
return TokenType.LessThanLessThanEquals;
case OperatorType.ShiftRight:
return TokenType.GreaterThanGreaterThanEquals;
default:
{
Debug.Assert(condition: false, "Unexpected!");
TokenType GetCompoundAssignmentOperatorToken = default(TokenType);
return GetCompoundAssignmentOperatorToken;
}
}
}
private static TokenType GetBlockTypeToken(BlockType blockType)
{
switch (blockType)
{
case BlockType.Class:
return TokenType.Class;
case BlockType.Enum:
return TokenType.Enum;
case BlockType.Function:
return TokenType.Function;
case BlockType.Get:
return TokenType.Get;
case BlockType.Event:
return TokenType.Event;
case BlockType.AddHandler:
return TokenType.AddHandler;
case BlockType.RemoveHandler:
return TokenType.RemoveHandler;
case BlockType.RaiseEvent:
return TokenType.RaiseEvent;
case BlockType.If:
return TokenType.If;
case BlockType.Interface:
return TokenType.Interface;
case BlockType.Module:
return TokenType.Module;
case BlockType.Namespace:
return TokenType.Namespace;
case BlockType.Property:
return TokenType.Property;
case BlockType.Select:
return TokenType.Select;
case BlockType.Set:
return TokenType.Set;
case BlockType.Structure:
return TokenType.Structure;
case BlockType.Sub:
return TokenType.Sub;
case BlockType.SyncLock:
return TokenType.SyncLock;
case BlockType.Using:
return TokenType.Using;
case BlockType.Try:
return TokenType.Try;
case BlockType.While:
return TokenType.While;
case BlockType.With:
return TokenType.With;
case BlockType.None:
return TokenType.LexicalError;
case BlockType.Do:
return TokenType.Do;
case BlockType.For:
return TokenType.For;
case BlockType.Operator:
return TokenType.Operator;
default:
{
Debug.Assert(condition: false, "Unexpected!");
TokenType GetBlockTypeToken = default(TokenType);
return GetBlockTypeToken;
}
}
}
private void SerializeSpan(Span Span)
{
Writer.WriteAttributeString("startLine", Conversions.ToString(Span.Start.Line));
Writer.WriteAttributeString("startCol", Conversions.ToString(Span.Start.Column));
Writer.WriteAttributeString("endLine", Conversions.ToString(Span.Finish.Line));
Writer.WriteAttributeString("endCol", Conversions.ToString(Span.Finish.Column));
}
private void SerializeLocation(Location Location)
{
Writer.WriteAttributeString("line", Conversions.ToString(Location.Line));
Writer.WriteAttributeString("col", Conversions.ToString(Location.Column));
}
protected void SerializeToken(TokenType TokenType, Location Location)
{
if (Location.IsValid)
{
Writer.WriteStartElement(TokenType.ToString());
SerializeLocation(Location);
Writer.WriteEndElement();
}
}
private void SerializeTypeCharacter(TypeCharacter TypeCharacter)
{
if (TypeCharacter == TypeCharacter.None)
{
return;
}
if (_0024STATIC_0024SerializeTypeCharacter_002420111182E4_0024TypeCharacterTable == null)
{
Dictionary<TypeCharacter, string> Table = new Dictionary<TypeCharacter, string>();
string[] TypeCharacters = new string[15]
{
"$", "%", "&", "S", "I", "L", "!", "#", "@", "F",
"R", "D", "US", "UI", "UL"
};
TypeCharacter TableTypeCharacter = TypeCharacter.StringSymbol;
int num = checked(TypeCharacters.Length - 1);
for (int Index = 0; Index <= num; Index = checked(Index + 1))
{
Table.Add(TableTypeCharacter, TypeCharacters[Index]);
TableTypeCharacter = (TypeCharacter)((int)TableTypeCharacter << 1);
}
_0024STATIC_0024SerializeTypeCharacter_002420111182E4_0024TypeCharacterTable = Table;
}
Writer.WriteAttributeString("typeChar", _0024STATIC_0024SerializeTypeCharacter_002420111182E4_0024TypeCharacterTable[TypeCharacter]);
}
private void SerializeColonDelimitedList<T>(ColonDelimitedTreeCollection<T> List) where T : Tree
{
ColonDelimitedTreeCollection<T> colonDelimitedTreeCollection = List;
IEnumerator<Location> ColonEnumerator;
bool MoreColons;
if (colonDelimitedTreeCollection.ColonLocations != null)
{
ColonEnumerator = colonDelimitedTreeCollection.ColonLocations.GetEnumerator();
MoreColons = ColonEnumerator.MoveNext();
}
else
{
ColonEnumerator = null;
MoreColons = false;
}
foreach (Tree Child in colonDelimitedTreeCollection.Children)
{
while (MoreColons && ColonEnumerator.Current <= Child.Span.Start)
{
SerializeToken(TokenType.Colon, ColonEnumerator.Current);
MoreColons = ColonEnumerator.MoveNext();
}
Serialize(Child);
}
while (MoreColons)
{
SerializeToken(TokenType.Colon, ColonEnumerator.Current);
MoreColons = ColonEnumerator.MoveNext();
}
colonDelimitedTreeCollection = null;
}
private void SerializeCommaDelimitedList<T>(CommaDelimitedTreeCollection<T> List) where T : Tree
{
CommaDelimitedTreeCollection<T> commaDelimitedTreeCollection = List;
IEnumerator<Location> CommaEnumerator;
bool MoreCommas;
if (commaDelimitedTreeCollection.CommaLocations != null)
{
CommaEnumerator = commaDelimitedTreeCollection.CommaLocations.GetEnumerator();
MoreCommas = CommaEnumerator.MoveNext();
}
else
{
CommaEnumerator = null;
MoreCommas = false;
}
foreach (Tree Child in commaDelimitedTreeCollection.Children)
{
if (Child != null)
{
while (MoreCommas && CommaEnumerator.Current <= Child.Span.Start)
{
SerializeToken(TokenType.Comma, CommaEnumerator.Current);
MoreCommas = CommaEnumerator.MoveNext();
}
Serialize(Child);
}
}
while (MoreCommas)
{
SerializeToken(TokenType.Comma, CommaEnumerator.Current);
MoreCommas = CommaEnumerator.MoveNext();
}
commaDelimitedTreeCollection = null;
}
private void SerializeList(Tree List)
{
switch (List.Type)
{
case TreeType.ArgumentCollection:
{
SerializeCommaDelimitedList((ArgumentCollection)List);
ArgumentCollection argumentCollection = (ArgumentCollection)List;
if (argumentCollection.RightParenthesisLocation.IsValid)
{
SerializeToken(TokenType.RightParenthesis, argumentCollection.RightParenthesisLocation);
}
argumentCollection = null;
return;
}
case TreeType.AttributeCollection:
{
SerializeCommaDelimitedList((AttributeCollection)List);
AttributeCollection attributeCollection = (AttributeCollection)List;
if (attributeCollection.RightBracketLocation.IsValid)
{
SerializeToken(TokenType.GreaterThan, attributeCollection.RightBracketLocation);
}
attributeCollection = null;
return;
}
case TreeType.CaseClauseCollection:
SerializeCommaDelimitedList((CaseClauseCollection)List);
return;
case TreeType.ExpressionCollection:
SerializeCommaDelimitedList((ExpressionCollection)List);
return;
case TreeType.ImportCollection:
SerializeCommaDelimitedList((ImportCollection)List);
return;
case TreeType.InitializerCollection:
{
SerializeCommaDelimitedList((InitializerCollection)List);
InitializerCollection initializerCollection = (InitializerCollection)List;
if (initializerCollection.RightCurlyBraceLocation.IsValid)
{
SerializeToken(TokenType.RightCurlyBrace, initializerCollection.RightCurlyBraceLocation);
}
initializerCollection = null;
return;
}
case TreeType.NameCollection:
SerializeCommaDelimitedList((NameCollection)List);
return;
case TreeType.VariableNameCollection:
SerializeCommaDelimitedList((VariableNameCollection)List);
return;
case TreeType.ParameterCollection:
{
SerializeCommaDelimitedList((ParameterCollection)List);
ParameterCollection parameterCollection = (ParameterCollection)List;
if (parameterCollection.RightParenthesisLocation.IsValid)
{
SerializeToken(TokenType.RightParenthesis, parameterCollection.RightParenthesisLocation);
}
parameterCollection = null;
return;
}
case TreeType.TypeNameCollection:
SerializeCommaDelimitedList((TypeNameCollection)List);
return;
case TreeType.VariableDeclaratorCollection:
SerializeCommaDelimitedList((VariableDeclaratorCollection)List);
return;
case TreeType.DeclarationCollection:
SerializeColonDelimitedList((DeclarationCollection)List);
return;
case TreeType.StatementCollection:
SerializeColonDelimitedList((StatementCollection)List);
return;
case TreeType.TypeParameterCollection:
{
TypeParameterCollection typeParameterCollection = (TypeParameterCollection)List;
if (typeParameterCollection.OfLocation.IsValid)
{
SerializeToken(TokenType.Of, typeParameterCollection.OfLocation);
}
SerializeCommaDelimitedList((TypeParameterCollection)List);
if (typeParameterCollection.RightParenthesisLocation.IsValid)
{
SerializeToken(TokenType.RightParenthesis, typeParameterCollection.RightParenthesisLocation);
}
typeParameterCollection = null;
return;
}
case TreeType.TypeConstraintCollection:
{
SerializeCommaDelimitedList((TypeConstraintCollection)List);
TypeConstraintCollection typeConstraintCollection = (TypeConstraintCollection)List;
if (typeConstraintCollection.RightBracketLocation.IsValid)
{
SerializeToken(TokenType.RightCurlyBrace, typeConstraintCollection.RightBracketLocation);
}
typeConstraintCollection = null;
return;
}
case TreeType.TypeArgumentCollection:
{
TypeArgumentCollection typeArgumentCollection = (TypeArgumentCollection)List;
if (typeArgumentCollection.OfLocation.IsValid)
{
SerializeToken(TokenType.Of, typeArgumentCollection.OfLocation);
}
SerializeCommaDelimitedList((TypeArgumentCollection)List);
if (typeArgumentCollection.RightParenthesisLocation.IsValid)
{
SerializeToken(TokenType.RightParenthesis, typeArgumentCollection.RightParenthesisLocation);
}
typeArgumentCollection = null;
return;
}
}
foreach (Tree Child in List.Children)
{
Serialize(Child);
}
}
private void SerializeName(Tree Name)
{
switch (Name.Type)
{
case TreeType.SimpleName:
{
SimpleName simpleName = (SimpleName)Name;
SerializeTypeCharacter(simpleName.TypeCharacter);
Writer.WriteAttributeString("escaped", Conversions.ToString(simpleName.Escaped));
Writer.WriteString(simpleName.Name);
simpleName = null;
break;
}
case TreeType.VariableName:
{
VariableName variableName = (VariableName)Name;
Serialize(variableName.Name);
Serialize(variableName.ArrayType);
variableName = null;
break;
}
case TreeType.QualifiedName:
{
QualifiedName qualifiedName = (QualifiedName)Name;
Serialize(qualifiedName.Qualifier);
SerializeToken(TokenType.Period, qualifiedName.DotLocation);
Serialize(qualifiedName.Name);
qualifiedName = null;
break;
}
}
}
private void SerializeType(Tree Type)
{
switch (Type.Type)
{
case TreeType.IntrinsicType:
Writer.WriteAttributeString("intrinsicType", ((IntrinsicTypeName)Type).IntrinsicType.ToString());
break;
case TreeType.NamedType:
{
NamedTypeName namedTypeName = (NamedTypeName)Type;
Serialize(namedTypeName.Name);
namedTypeName = null;
break;
}
case TreeType.ArrayType:
{
ArrayTypeName arrayTypeName = (ArrayTypeName)Type;
Writer.WriteAttributeString("rank", Conversions.ToString(arrayTypeName.Rank));
Serialize(arrayTypeName.ElementTypeName);
Serialize(arrayTypeName.Arguments);
arrayTypeName = null;
break;
}
case TreeType.ConstructedType:
{
ConstructedTypeName constructedTypeName = (ConstructedTypeName)Type;
Serialize(constructedTypeName.Name);
Serialize(constructedTypeName.TypeArguments);
constructedTypeName = null;
break;
}
}
}
private void SerializeInitializer(Tree Initializer)
{
switch (Initializer.Type)
{
case TreeType.AggregateInitializer:
{
AggregateInitializer aggregateInitializer = (AggregateInitializer)Initializer;
Serialize(aggregateInitializer.Elements);
aggregateInitializer = null;
break;
}
case TreeType.ExpressionInitializer:
{
ExpressionInitializer expressionInitializer = (ExpressionInitializer)Initializer;
Serialize(expressionInitializer.Expression);
expressionInitializer = null;
break;
}
}
}
private void SerializeExpression(Tree Expression)
{
Writer.WriteAttributeString("isConstant", Conversions.ToString(((Expression)Expression).IsConstant));
switch (Expression.Type)
{
case TreeType.StringLiteralExpression:
{
StringLiteralExpression stringLiteralExpression = (StringLiteralExpression)Expression;
Writer.WriteString(stringLiteralExpression.Literal);
stringLiteralExpression = null;
return;
}
case TreeType.CharacterLiteralExpression:
{
CharacterLiteralExpression characterLiteralExpression = (CharacterLiteralExpression)Expression;
Writer.WriteString(Conversions.ToString(characterLiteralExpression.Literal));
characterLiteralExpression = null;
return;
}
case TreeType.DateLiteralExpression:
{
DateLiteralExpression dateLiteralExpression = (DateLiteralExpression)Expression;
Writer.WriteString(Conversions.ToString(dateLiteralExpression.Literal));
dateLiteralExpression = null;
return;
}
case TreeType.IntegerLiteralExpression:
{
IntegerLiteralExpression integerLiteralExpression = (IntegerLiteralExpression)Expression;
SerializeTypeCharacter(integerLiteralExpression.TypeCharacter);
Writer.WriteAttributeString("base", integerLiteralExpression.IntegerBase.ToString());
Writer.WriteString(Conversions.ToString(integerLiteralExpression.Literal));
integerLiteralExpression = null;
return;
}
case TreeType.FloatingPointLiteralExpression:
{
FloatingPointLiteralExpression floatingPointLiteralExpression = (FloatingPointLiteralExpression)Expression;
SerializeTypeCharacter(floatingPointLiteralExpression.TypeCharacter);
Writer.WriteString(Conversions.ToString(floatingPointLiteralExpression.Literal));
floatingPointLiteralExpression = null;
return;
}
case TreeType.DecimalLiteralExpression:
{
DecimalLiteralExpression decimalLiteralExpression = (DecimalLiteralExpression)Expression;
SerializeTypeCharacter(decimalLiteralExpression.TypeCharacter);
Writer.WriteString(Conversions.ToString(decimalLiteralExpression.Literal));
decimalLiteralExpression = null;
return;
}
case TreeType.BooleanLiteralExpression:
{
BooleanLiteralExpression booleanLiteralExpression = (BooleanLiteralExpression)Expression;
Writer.WriteString(Conversions.ToString(booleanLiteralExpression.Literal));
booleanLiteralExpression = null;
return;
}
case TreeType.GetTypeExpression:
{
GetTypeExpression getTypeExpression = (GetTypeExpression)Expression;
SerializeToken(TokenType.LeftParenthesis, getTypeExpression.LeftParenthesisLocation);
Serialize(getTypeExpression.Target);
SerializeToken(TokenType.RightParenthesis, getTypeExpression.RightParenthesisLocation);
getTypeExpression = null;
return;
}
case TreeType.CTypeExpression:
case TreeType.DirectCastExpression:
{
CastTypeExpression castTypeExpression = (CastTypeExpression)Expression;
SerializeToken(TokenType.LeftParenthesis, castTypeExpression.LeftParenthesisLocation);
Serialize(castTypeExpression.Operand);
SerializeToken(TokenType.Comma, castTypeExpression.CommaLocation);
Serialize(castTypeExpression.Target);
SerializeToken(TokenType.RightParenthesis, castTypeExpression.RightParenthesisLocation);
castTypeExpression = null;
return;
}
case TreeType.TypeOfExpression:
{
TypeOfExpression typeOfExpression = (TypeOfExpression)Expression;
Serialize(typeOfExpression.Operand);
SerializeToken(TokenType.Is, typeOfExpression.IsLocation);
Serialize(typeOfExpression.Target);
typeOfExpression = null;
return;
}
case TreeType.IntrinsicCastExpression:
{
IntrinsicCastExpression intrinsicCastExpression = (IntrinsicCastExpression)Expression;
Writer.WriteAttributeString("intrinsicType", intrinsicCastExpression.IntrinsicType.ToString());
SerializeToken(TokenType.LeftParenthesis, intrinsicCastExpression.LeftParenthesisLocation);
Serialize(intrinsicCastExpression.Operand);
SerializeToken(TokenType.RightParenthesis, intrinsicCastExpression.RightParenthesisLocation);
intrinsicCastExpression = null;
return;
}
case TreeType.QualifiedExpression:
{
QualifiedExpression qualifiedExpression = (QualifiedExpression)Expression;
Serialize(qualifiedExpression.Qualifier);
SerializeToken(TokenType.Period, qualifiedExpression.DotLocation);
Serialize(qualifiedExpression.Name);
qualifiedExpression = null;
return;
}
case TreeType.DictionaryLookupExpression:
{
DictionaryLookupExpression dictionaryLookupExpression = (DictionaryLookupExpression)Expression;
Serialize(dictionaryLookupExpression.Qualifier);
SerializeToken(TokenType.Exclamation, dictionaryLookupExpression.BangLocation);
Serialize(dictionaryLookupExpression.Name);
dictionaryLookupExpression = null;
return;
}
case TreeType.InstanceExpression:
{
InstanceExpression instanceExpression = (InstanceExpression)Expression;
Writer.WriteAttributeString("type", instanceExpression.InstanceType.ToString());
instanceExpression = null;
return;
}
case TreeType.ParentheticalExpression:
{
ParentheticalExpression parentheticalExpression = (ParentheticalExpression)Expression;
Serialize(parentheticalExpression.Operand);
SerializeToken(TokenType.RightParenthesis, parentheticalExpression.RightParenthesisLocation);
parentheticalExpression = null;
return;
}
case TreeType.BinaryOperatorExpression:
{
BinaryOperatorExpression binaryOperatorExpression = (BinaryOperatorExpression)Expression;
Writer.WriteAttributeString("operator", binaryOperatorExpression.Operator.ToString());
Serialize(binaryOperatorExpression.LeftOperand);
SerializeToken(GetOperatorToken(binaryOperatorExpression.Operator), binaryOperatorExpression.OperatorLocation);
Serialize(binaryOperatorExpression.RightOperand);
binaryOperatorExpression = null;
return;
}
case TreeType.UnaryOperatorExpression:
{
UnaryOperatorExpression unaryOperatorExpression = (UnaryOperatorExpression)Expression;
SerializeToken(GetOperatorToken(unaryOperatorExpression.Operator), unaryOperatorExpression.Span.Start);
Serialize(unaryOperatorExpression.Operand);
unaryOperatorExpression = null;
return;
}
}
foreach (Tree Child in Expression.Children)
{
Serialize(Child);
}
}
private void SerializeStatementComments(Tree Statement)
{
Statement statement = (Statement)Statement;
if (statement.Comments != null)
{
foreach (Comment Comment in statement.Comments)
{
Serialize(Comment);
}
}
statement = null;
}
private void SerializeStatement(Tree Statement)
{
switch (Statement.Type)
{
case TreeType.GotoStatement:
case TreeType.LabelStatement:
{
LabelReferenceStatement labelReferenceStatement = (LabelReferenceStatement)Statement;
Writer.WriteAttributeString("isLineNumber", Conversions.ToString(labelReferenceStatement.IsLineNumber));
SerializeStatementComments(Statement);
Serialize(labelReferenceStatement.Name);
labelReferenceStatement = null;
return;
}
case TreeType.ContinueStatement:
{
ContinueStatement continueStatement = (ContinueStatement)Statement;
Writer.WriteAttributeString("continueType", continueStatement.ContinueType.ToString());
SerializeStatementComments(Statement);
SerializeToken(GetBlockTypeToken(continueStatement.ContinueType), continueStatement.ContinueArgumentLocation);
continueStatement = null;
return;
}
case TreeType.ExitStatement:
{
ExitStatement exitStatement = (ExitStatement)Statement;
Writer.WriteAttributeString("exitType", exitStatement.ExitType.ToString());
SerializeStatementComments(Statement);
SerializeToken(GetBlockTypeToken(exitStatement.ExitType), exitStatement.ExitArgumentLocation);
exitStatement = null;
return;
}
case TreeType.ReturnStatement:
case TreeType.ErrorStatement:
case TreeType.ThrowStatement:
{
ExpressionStatement expressionStatement = (ExpressionStatement)Statement;
SerializeStatementComments(Statement);
Serialize(expressionStatement.Expression);
expressionStatement = null;
return;
}
case TreeType.RaiseEventStatement:
{
RaiseEventStatement raiseEventStatement = (RaiseEventStatement)Statement;
SerializeStatementComments(Statement);
Serialize(raiseEventStatement.Name);
Serialize(raiseEventStatement.Arguments);
raiseEventStatement = null;
return;
}
case TreeType.AddHandlerStatement:
case TreeType.RemoveHandlerStatement:
{
HandlerStatement handlerStatement = (HandlerStatement)Statement;
SerializeStatementComments(Statement);
Serialize(handlerStatement.Name);
SerializeToken(TokenType.Comma, handlerStatement.CommaLocation);
Serialize(handlerStatement.DelegateExpression);
handlerStatement = null;
return;
}
case TreeType.OnErrorStatement:
{
OnErrorStatement onErrorStatement = (OnErrorStatement)Statement;
Writer.WriteAttributeString("onErrorType", onErrorStatement.OnErrorType.ToString());
SerializeStatementComments(Statement);
SerializeToken(TokenType.Error, onErrorStatement.ErrorLocation);
switch (onErrorStatement.OnErrorType)
{
case OnErrorType.Zero:
SerializeToken(TokenType.GoTo, onErrorStatement.ResumeOrGoToLocation);
Writer.WriteStartElement("Zero");
SerializeLocation(onErrorStatement.NextOrZeroOrMinusLocation);
Writer.WriteEndElement();
break;
case OnErrorType.MinusOne:
SerializeToken(TokenType.GoTo, onErrorStatement.ResumeOrGoToLocation);
SerializeToken(TokenType.Minus, onErrorStatement.NextOrZeroOrMinusLocation);
Writer.WriteStartElement("One");
SerializeLocation(onErrorStatement.OneLocation);
Writer.WriteEndElement();
break;
case OnErrorType.Label:
SerializeToken(TokenType.GoTo, onErrorStatement.ResumeOrGoToLocation);
Serialize(onErrorStatement.Name);
break;
case OnErrorType.Next:
SerializeToken(TokenType.Resume, onErrorStatement.ResumeOrGoToLocation);
SerializeToken(TokenType.Next, onErrorStatement.NextOrZeroOrMinusLocation);
break;
}
onErrorStatement = null;
return;
}
case TreeType.ResumeStatement:
{
ResumeStatement resumeStatement = (ResumeStatement)Statement;
Writer.WriteAttributeString("resumeType", resumeStatement.ResumeType.ToString());
SerializeStatementComments(Statement);
switch (resumeStatement.ResumeType)
{
case ResumeType.Next:
SerializeToken(TokenType.Next, resumeStatement.NextLocation);
break;
case ResumeType.Label:
Serialize(resumeStatement.Name);
break;
}
resumeStatement = null;
return;
}
case TreeType.ReDimStatement:
{
ReDimStatement reDimStatement = (ReDimStatement)Statement;
SerializeStatementComments(Statement);
SerializeToken(TokenType.Preserve, reDimStatement.PreserveLocation);
Serialize(reDimStatement.Variables);
reDimStatement = null;
return;
}
case TreeType.EraseStatement:
{
EraseStatement eraseStatement = (EraseStatement)Statement;
SerializeStatementComments(Statement);
Serialize(eraseStatement.Variables);
eraseStatement = null;
return;
}
case TreeType.CallStatement:
{
CallStatement callStatement = (CallStatement)Statement;
SerializeStatementComments(Statement);
SerializeToken(TokenType.Call, callStatement.CallLocation);
Serialize(callStatement.TargetExpression);
Serialize(callStatement.Arguments);
callStatement = null;
return;
}
case TreeType.AssignmentStatement:
{
AssignmentStatement assignmentStatement = (AssignmentStatement)Statement;
SerializeStatementComments(Statement);
Serialize(assignmentStatement.TargetExpression);
SerializeToken(TokenType.Equals, assignmentStatement.OperatorLocation);
Serialize(assignmentStatement.SourceExpression);
assignmentStatement = null;
return;
}
case TreeType.MidAssignmentStatement:
{
MidAssignmentStatement midAssignmentStatement = (MidAssignmentStatement)Statement;
Writer.WriteAttributeString("hasTypeCharacter", Conversions.ToString(midAssignmentStatement.HasTypeCharacter));
SerializeStatementComments(Statement);
SerializeToken(TokenType.LeftParenthesis, midAssignmentStatement.LeftParenthesisLocation);
Serialize(midAssignmentStatement.TargetExpression);
SerializeToken(TokenType.Comma, midAssignmentStatement.StartCommaLocation);
Serialize(midAssignmentStatement.StartExpression);
SerializeToken(TokenType.Comma, midAssignmentStatement.LengthCommaLocation);
Serialize(midAssignmentStatement.LengthExpression);
SerializeToken(TokenType.RightParenthesis, midAssignmentStatement.RightParenthesisLocation);
SerializeToken(TokenType.Equals, midAssignmentStatement.OperatorLocation);
Serialize(midAssignmentStatement.SourceExpression);
midAssignmentStatement = null;
return;
}
case TreeType.CompoundAssignmentStatement:
{
CompoundAssignmentStatement compoundAssignmentStatement = (CompoundAssignmentStatement)Statement;
SerializeStatementComments(Statement);
Serialize(compoundAssignmentStatement.TargetExpression);
SerializeToken(GetCompoundAssignmentOperatorToken(compoundAssignmentStatement.CompoundOperator), compoundAssignmentStatement.OperatorLocation);
Serialize(compoundAssignmentStatement.SourceExpression);
compoundAssignmentStatement = null;
return;
}
case TreeType.LocalDeclarationStatement:
{
LocalDeclarationStatement localDeclarationStatement = (LocalDeclarationStatement)Statement;
SerializeStatementComments(Statement);
Serialize(localDeclarationStatement.Modifiers);
Serialize(localDeclarationStatement.VariableDeclarators);
localDeclarationStatement = null;
return;
}
case TreeType.EndBlockStatement:
{
EndBlockStatement endBlockStatement = (EndBlockStatement)Statement;
Writer.WriteAttributeString("endType", endBlockStatement.EndType.ToString());
SerializeStatementComments(Statement);
SerializeToken(GetBlockTypeToken(endBlockStatement.EndType), endBlockStatement.EndArgumentLocation);
endBlockStatement = null;
return;
}
case TreeType.WhileBlockStatement:
case TreeType.SyncLockBlockStatement:
case TreeType.WithBlockStatement:
{
ExpressionBlockStatement expressionBlockStatement = (ExpressionBlockStatement)Statement;
SerializeStatementComments(Statement);
Serialize(expressionBlockStatement.Expression);
Serialize(expressionBlockStatement.Statements);
Serialize(expressionBlockStatement.EndStatement);
expressionBlockStatement = null;
return;
}
case TreeType.UsingBlockStatement:
{
UsingBlockStatement usingBlockStatement = (UsingBlockStatement)Statement;
SerializeStatementComments(Statement);
if (usingBlockStatement.Expression != null)
{
Serialize(usingBlockStatement.Expression);
}
else
{
Serialize(usingBlockStatement.VariableDeclarators);
}
Serialize(usingBlockStatement.Statements);
Serialize(usingBlockStatement.EndStatement);
usingBlockStatement = null;
return;
}
case TreeType.DoBlockStatement:
{
DoBlockStatement doBlockStatement = (DoBlockStatement)Statement;
if (doBlockStatement.Expression != null)
{
Writer.WriteAttributeString("isWhile", Conversion.Str(doBlockStatement.IsWhile));
SerializeStatementComments(Statement);
if (doBlockStatement.IsWhile)
{
SerializeToken(TokenType.While, doBlockStatement.WhileOrUntilLocation);
}
else
{
SerializeToken(TokenType.Until, doBlockStatement.WhileOrUntilLocation);
}
Serialize(doBlockStatement.Expression);
}
else
{
SerializeStatementComments(Statement);
}
Serialize(doBlockStatement.Statements);
Serialize(doBlockStatement.EndStatement);
doBlockStatement = null;
return;
}
case TreeType.LoopStatement:
{
LoopStatement loopStatement = (LoopStatement)Statement;
if (loopStatement.Expression != null)
{
Writer.WriteAttributeString("isWhile", Conversion.Str(loopStatement.IsWhile));
SerializeStatementComments(Statement);
if (loopStatement.IsWhile)
{
SerializeToken(TokenType.While, loopStatement.WhileOrUntilLocation);
}
else
{
SerializeToken(TokenType.Until, loopStatement.WhileOrUntilLocation);
}
Serialize(loopStatement.Expression);
}
else
{
SerializeStatementComments(Statement);
}
loopStatement = null;
return;
}
case TreeType.NextStatement:
{
NextStatement nextStatement = (NextStatement)Statement;
SerializeStatementComments(Statement);
Serialize(nextStatement.Variables);
nextStatement = null;
return;
}
case TreeType.ForBlockStatement:
{
ForBlockStatement forBlockStatement = (ForBlockStatement)Statement;
SerializeStatementComments(Statement);
Serialize(forBlockStatement.ControlExpression);
Serialize(forBlockStatement.ControlVariableDeclarator);
SerializeToken(TokenType.Equals, forBlockStatement.EqualsLocation);
Serialize(forBlockStatement.LowerBoundExpression);
SerializeToken(TokenType.To, forBlockStatement.ToLocation);
Serialize(forBlockStatement.UpperBoundExpression);
SerializeToken(TokenType.Step, forBlockStatement.StepLocation);
Serialize(forBlockStatement.StepExpression);
Serialize(forBlockStatement.Statements);
Serialize(forBlockStatement.NextStatement);
forBlockStatement = null;
return;
}
case TreeType.ForEachBlockStatement:
{
ForEachBlockStatement forEachBlockStatement = (ForEachBlockStatement)Statement;
SerializeStatementComments(Statement);
SerializeToken(TokenType.Each, forEachBlockStatement.EachLocation);
Serialize(forEachBlockStatement.ControlExpression);
Serialize(forEachBlockStatement.ControlVariableDeclarator);
SerializeToken(TokenType.In, forEachBlockStatement.InLocation);
Serialize(forEachBlockStatement.CollectionExpression);
Serialize(forEachBlockStatement.Statements);
Serialize(forEachBlockStatement.NextStatement);
forEachBlockStatement = null;
return;
}
case TreeType.CatchStatement:
{
CatchStatement catchStatement = (CatchStatement)Statement;
SerializeStatementComments(Statement);
Serialize(catchStatement.Name);
SerializeToken(TokenType.As, catchStatement.AsLocation);
Serialize(catchStatement.ExceptionType);
SerializeToken(TokenType.When, catchStatement.WhenLocation);
Serialize(catchStatement.FilterExpression);
catchStatement = null;
return;
}
case TreeType.CaseElseStatement:
{
CaseElseStatement caseElseStatement = (CaseElseStatement)Statement;
SerializeStatementComments(Statement);
SerializeToken(TokenType.Else, caseElseStatement.ElseLocation);
caseElseStatement = null;
return;
}
case TreeType.SelectBlockStatement:
{
SelectBlockStatement selectBlockStatement = (SelectBlockStatement)Statement;
SerializeStatementComments(Statement);
SerializeToken(TokenType.Case, selectBlockStatement.CaseLocation);
Serialize(selectBlockStatement.Expression);
Serialize(selectBlockStatement.Statements);
Serialize(selectBlockStatement.CaseBlockStatements);
Serialize(selectBlockStatement.CaseElseBlockStatement);
Serialize(selectBlockStatement.EndStatement);
selectBlockStatement = null;
return;
}
case TreeType.ElseIfStatement:
{
ElseIfStatement elseIfStatement = (ElseIfStatement)Statement;
SerializeStatementComments(Statement);
Serialize(elseIfStatement.Expression);
SerializeToken(TokenType.Then, elseIfStatement.ThenLocation);
elseIfStatement = null;
return;
}
case TreeType.IfBlockStatement:
{
IfBlockStatement ifBlockStatement = (IfBlockStatement)Statement;
SerializeStatementComments(Statement);
Serialize(ifBlockStatement.Expression);
SerializeToken(TokenType.Then, ifBlockStatement.ThenLocation);
Serialize(ifBlockStatement.Statements);
Serialize(ifBlockStatement.ElseIfBlockStatements);
Serialize(ifBlockStatement.ElseBlockStatement);
Serialize(ifBlockStatement.EndStatement);
ifBlockStatement = null;
return;
}
case TreeType.LineIfBlockStatement:
{
LineIfStatement lineIfStatement = (LineIfStatement)Statement;
SerializeStatementComments(Statement);
Serialize(lineIfStatement.Expression);
SerializeToken(TokenType.Then, lineIfStatement.ThenLocation);
Serialize(lineIfStatement.IfStatements);
SerializeToken(TokenType.Else, lineIfStatement.ElseLocation);
Serialize(lineIfStatement.ElseStatements);
lineIfStatement = null;
return;
}
}
SerializeStatementComments(Statement);
foreach (Tree Child in Statement.Children)
{
Serialize(Child);
}
}
private void SerializeCaseClause(Tree CaseClause)
{
switch (CaseClause.Type)
{
case TreeType.ComparisonCaseClause:
{
ComparisonCaseClause comparisonCaseClause = (ComparisonCaseClause)CaseClause;
SerializeToken(TokenType.Is, comparisonCaseClause.IsLocation);
SerializeToken(GetOperatorToken(comparisonCaseClause.ComparisonOperator), comparisonCaseClause.OperatorLocation);
Serialize(comparisonCaseClause.Operand);
comparisonCaseClause = null;
break;
}
case TreeType.RangeCaseClause:
{
RangeCaseClause rangeCaseClause = (RangeCaseClause)CaseClause;
Serialize(rangeCaseClause.RangeExpression);
rangeCaseClause = null;
break;
}
default:
Debug.Assert(condition: false, "Unexpected.");
break;
}
}
private void SerializeDeclarationComments(Tree Declaration)
{
Declaration declaration = (Declaration)Declaration;
if (declaration.Comments != null)
{
foreach (Comment Comment in declaration.Comments)
{
Serialize(Comment);
}
}
declaration = null;
}
private void SerializeDeclaration(Tree Declaration)
{
switch (Declaration.Type)
{
case TreeType.EndBlockDeclaration:
{
EndBlockDeclaration endBlockDeclaration = (EndBlockDeclaration)Declaration;
Writer.WriteAttributeString("endType", endBlockDeclaration.EndType.ToString());
SerializeDeclarationComments(Declaration);
SerializeToken(GetBlockTypeToken(endBlockDeclaration.EndType), endBlockDeclaration.EndArgumentLocation);
endBlockDeclaration = null;
return;
}
case TreeType.EventDeclaration:
{
EventDeclaration eventDeclaration = (EventDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(eventDeclaration.Attributes);
Serialize(eventDeclaration.Modifiers);
SerializeToken(TokenType.Event, eventDeclaration.KeywordLocation);
Serialize(eventDeclaration.Name);
Serialize(eventDeclaration.Parameters);
SerializeToken(TokenType.As, eventDeclaration.AsLocation);
Serialize(eventDeclaration.ResultTypeAttributes);
Serialize(eventDeclaration.ResultType);
Serialize(eventDeclaration.ImplementsList);
eventDeclaration = null;
return;
}
case TreeType.CustomEventDeclaration:
{
CustomEventDeclaration customEventDeclaration = (CustomEventDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(customEventDeclaration.Attributes);
Serialize(customEventDeclaration.Modifiers);
SerializeToken(TokenType.Custom, customEventDeclaration.CustomLocation);
SerializeToken(TokenType.Event, customEventDeclaration.KeywordLocation);
Serialize(customEventDeclaration.Name);
SerializeToken(TokenType.As, customEventDeclaration.AsLocation);
Serialize(customEventDeclaration.ResultType);
Serialize(customEventDeclaration.ImplementsList);
Serialize(customEventDeclaration.Accessors);
Serialize(customEventDeclaration.EndDeclaration);
customEventDeclaration = null;
return;
}
case TreeType.SubDeclaration:
case TreeType.FunctionDeclaration:
case TreeType.ConstructorDeclaration:
{
MethodDeclaration methodDeclaration = (MethodDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(methodDeclaration.Attributes);
Serialize(methodDeclaration.Modifiers);
switch (Declaration.Type)
{
case TreeType.SubDeclaration:
SerializeToken(TokenType.Sub, methodDeclaration.KeywordLocation);
break;
case TreeType.FunctionDeclaration:
SerializeToken(TokenType.Function, methodDeclaration.KeywordLocation);
break;
case TreeType.ConstructorDeclaration:
SerializeToken(TokenType.New, methodDeclaration.KeywordLocation);
break;
}
Serialize(methodDeclaration.Name);
Serialize(methodDeclaration.Parameters);
Serialize(methodDeclaration.TypeParameters);
SerializeToken(TokenType.As, methodDeclaration.AsLocation);
Serialize(methodDeclaration.ResultTypeAttributes);
Serialize(methodDeclaration.ResultType);
Serialize(methodDeclaration.ImplementsList);
Serialize(methodDeclaration.HandlesList);
Serialize(methodDeclaration.Statements);
Serialize(methodDeclaration.EndDeclaration);
methodDeclaration = null;
return;
}
case TreeType.OperatorDeclaration:
{
OperatorDeclaration operatorDeclaration = (OperatorDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(operatorDeclaration.Attributes);
Serialize(operatorDeclaration.Modifiers);
SerializeToken(TokenType.Operator, operatorDeclaration.KeywordLocation);
if (operatorDeclaration.OperatorToken != null)
{
SerializeToken(operatorDeclaration.OperatorToken.Type, operatorDeclaration.OperatorToken.Span.Start);
}
Serialize(operatorDeclaration.Parameters);
SerializeToken(TokenType.As, operatorDeclaration.AsLocation);
Serialize(operatorDeclaration.ResultTypeAttributes);
Serialize(operatorDeclaration.ResultType);
Serialize(operatorDeclaration.Statements);
Serialize(operatorDeclaration.EndDeclaration);
operatorDeclaration = null;
return;
}
case TreeType.ExternalSubDeclaration:
case TreeType.ExternalFunctionDeclaration:
{
ExternalDeclaration externalDeclaration = (ExternalDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(externalDeclaration.Attributes);
Serialize(externalDeclaration.Modifiers);
SerializeToken(TokenType.Declare, externalDeclaration.KeywordLocation);
switch (externalDeclaration.Charset)
{
case Charset.Auto:
SerializeToken(TokenType.Auto, externalDeclaration.CharsetLocation);
break;
case Charset.Ansi:
SerializeToken(TokenType.Ansi, externalDeclaration.CharsetLocation);
break;
case Charset.Unicode:
SerializeToken(TokenType.Unicode, externalDeclaration.CharsetLocation);
break;
}
switch (Declaration.Type)
{
case TreeType.ExternalSubDeclaration:
SerializeToken(TokenType.Sub, externalDeclaration.SubOrFunctionLocation);
break;
case TreeType.ExternalFunctionDeclaration:
SerializeToken(TokenType.Function, externalDeclaration.SubOrFunctionLocation);
break;
}
Serialize(externalDeclaration.Name);
SerializeToken(TokenType.Lib, externalDeclaration.LibLocation);
Serialize(externalDeclaration.LibLiteral);
SerializeToken(TokenType.Alias, externalDeclaration.AliasLocation);
Serialize(externalDeclaration.AliasLiteral);
Serialize(externalDeclaration.Parameters);
SerializeToken(TokenType.As, externalDeclaration.AsLocation);
Serialize(externalDeclaration.ResultTypeAttributes);
Serialize(externalDeclaration.ResultType);
externalDeclaration = null;
return;
}
case TreeType.PropertyDeclaration:
{
PropertyDeclaration propertyDeclaration = (PropertyDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(propertyDeclaration.Attributes);
Serialize(propertyDeclaration.Modifiers);
SerializeToken(TokenType.Event, propertyDeclaration.KeywordLocation);
Serialize(propertyDeclaration.Name);
Serialize(propertyDeclaration.Parameters);
SerializeToken(TokenType.As, propertyDeclaration.AsLocation);
Serialize(propertyDeclaration.ResultTypeAttributes);
Serialize(propertyDeclaration.ResultType);
Serialize(propertyDeclaration.ImplementsList);
Serialize(propertyDeclaration.Accessors);
Serialize(propertyDeclaration.EndDeclaration);
propertyDeclaration = null;
return;
}
case TreeType.GetAccessorDeclaration:
{
GetAccessorDeclaration getAccessorDeclaration = (GetAccessorDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(getAccessorDeclaration.Attributes);
Serialize(getAccessorDeclaration.Modifiers);
SerializeToken(TokenType.Get, getAccessorDeclaration.GetLocation);
Serialize(getAccessorDeclaration.Statements);
Serialize(getAccessorDeclaration.EndDeclaration);
getAccessorDeclaration = null;
return;
}
case TreeType.SetAccessorDeclaration:
{
SetAccessorDeclaration setAccessorDeclaration = (SetAccessorDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(setAccessorDeclaration.Attributes);
Serialize(setAccessorDeclaration.Modifiers);
SerializeToken(TokenType.Set, setAccessorDeclaration.SetLocation);
Serialize(setAccessorDeclaration.Parameters);
Serialize(setAccessorDeclaration.Statements);
Serialize(setAccessorDeclaration.EndDeclaration);
setAccessorDeclaration = null;
return;
}
case TreeType.EnumValueDeclaration:
{
EnumValueDeclaration enumValueDeclaration = (EnumValueDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(enumValueDeclaration.Attributes);
Serialize(enumValueDeclaration.Modifiers);
Serialize(enumValueDeclaration.Name);
SerializeToken(TokenType.Equals, enumValueDeclaration.EqualsLocation);
Serialize(enumValueDeclaration.Expression);
enumValueDeclaration = null;
return;
}
case TreeType.DelegateSubDeclaration:
{
DelegateSubDeclaration delegateSubDeclaration = (DelegateSubDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(delegateSubDeclaration.Attributes);
Serialize(delegateSubDeclaration.Modifiers);
SerializeToken(TokenType.Delegate, delegateSubDeclaration.KeywordLocation);
SerializeToken(TokenType.Sub, delegateSubDeclaration.SubOrFunctionLocation);
Serialize(delegateSubDeclaration.Name);
Serialize(delegateSubDeclaration.TypeParameters);
Serialize(delegateSubDeclaration.Parameters);
delegateSubDeclaration = null;
return;
}
case TreeType.DelegateFunctionDeclaration:
{
DelegateFunctionDeclaration delegateFunctionDeclaration = (DelegateFunctionDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(delegateFunctionDeclaration.Attributes);
Serialize(delegateFunctionDeclaration.Modifiers);
SerializeToken(TokenType.Delegate, delegateFunctionDeclaration.KeywordLocation);
SerializeToken(TokenType.Function, delegateFunctionDeclaration.SubOrFunctionLocation);
Serialize(delegateFunctionDeclaration.Name);
Serialize(delegateFunctionDeclaration.Parameters);
SerializeToken(TokenType.As, delegateFunctionDeclaration.AsLocation);
Serialize(delegateFunctionDeclaration.ResultTypeAttributes);
Serialize(delegateFunctionDeclaration.ResultType);
delegateFunctionDeclaration = null;
return;
}
case TreeType.ModuleDeclaration:
{
BlockDeclaration blockDeclaration = (BlockDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(blockDeclaration.Attributes);
Serialize(blockDeclaration.Modifiers);
SerializeToken(TokenType.Module, blockDeclaration.KeywordLocation);
Serialize(blockDeclaration.Name);
Serialize(blockDeclaration.Declarations);
Serialize(blockDeclaration.EndDeclaration);
blockDeclaration = null;
return;
}
case TreeType.ClassDeclaration:
case TreeType.StructureDeclaration:
case TreeType.InterfaceDeclaration:
{
GenericBlockDeclaration genericBlockDeclaration = (GenericBlockDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(genericBlockDeclaration.Attributes);
Serialize(genericBlockDeclaration.Modifiers);
switch (Declaration.Type)
{
case TreeType.ClassDeclaration:
SerializeToken(TokenType.Class, genericBlockDeclaration.KeywordLocation);
break;
case TreeType.StructureDeclaration:
SerializeToken(TokenType.Structure, genericBlockDeclaration.KeywordLocation);
break;
case TreeType.ModuleDeclaration:
SerializeToken(TokenType.Module, genericBlockDeclaration.KeywordLocation);
break;
case TreeType.InterfaceDeclaration:
SerializeToken(TokenType.Interface, genericBlockDeclaration.KeywordLocation);
break;
}
Serialize(genericBlockDeclaration.Name);
Serialize(genericBlockDeclaration.TypeParameters);
Serialize(genericBlockDeclaration.Declarations);
Serialize(genericBlockDeclaration.EndDeclaration);
genericBlockDeclaration = null;
return;
}
case TreeType.NamespaceDeclaration:
{
NamespaceDeclaration namespaceDeclaration = (NamespaceDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(namespaceDeclaration.Attributes);
Serialize(namespaceDeclaration.Modifiers);
SerializeToken(TokenType.Namespace, namespaceDeclaration.NamespaceLocation);
Serialize(namespaceDeclaration.Name);
Serialize(namespaceDeclaration.Declarations);
Serialize(namespaceDeclaration.EndDeclaration);
namespaceDeclaration = null;
return;
}
case TreeType.EnumDeclaration:
{
EnumDeclaration enumDeclaration = (EnumDeclaration)Declaration;
SerializeDeclarationComments(Declaration);
Serialize(enumDeclaration.Attributes);
Serialize(enumDeclaration.Modifiers);
SerializeToken(TokenType.Enum, enumDeclaration.KeywordLocation);
Serialize(enumDeclaration.Name);
SerializeToken(TokenType.As, enumDeclaration.AsLocation);
Serialize(enumDeclaration.ElementType);
Serialize(enumDeclaration.Declarations);
Serialize(enumDeclaration.EndDeclaration);
enumDeclaration = null;
return;
}
case TreeType.OptionDeclaration:
{
OptionDeclaration optionDeclaration = (OptionDeclaration)Declaration;
Writer.WriteAttributeString("type", optionDeclaration.OptionType.ToString());
SerializeDeclarationComments(Declaration);
switch (optionDeclaration.OptionType)
{
case OptionType.Explicit:
case OptionType.ExplicitOn:
case OptionType.ExplicitOff:
Writer.WriteStartElement("Explicit");
SerializeLocation(optionDeclaration.OptionTypeLocation);
Writer.WriteEndElement();
if (optionDeclaration.OptionType == OptionType.ExplicitOn)
{
SerializeToken(TokenType.On, optionDeclaration.OptionArgumentLocation);
}
else if (optionDeclaration.OptionType == OptionType.ExplicitOff)
{
Writer.WriteStartElement("Off");
SerializeLocation(optionDeclaration.OptionArgumentLocation);
Writer.WriteEndElement();
}
break;
case OptionType.Strict:
case OptionType.StrictOn:
case OptionType.StrictOff:
Writer.WriteStartElement("Strict");
SerializeLocation(optionDeclaration.OptionTypeLocation);
Writer.WriteEndElement();
if (optionDeclaration.OptionType == OptionType.StrictOn)
{
SerializeToken(TokenType.On, optionDeclaration.OptionArgumentLocation);
}
else if (optionDeclaration.OptionType == OptionType.StrictOff)
{
Writer.WriteStartElement("Off");
SerializeLocation(optionDeclaration.OptionArgumentLocation);
Writer.WriteEndElement();
}
break;
case OptionType.CompareBinary:
case OptionType.CompareText:
Writer.WriteStartElement("Compare");
SerializeLocation(optionDeclaration.OptionTypeLocation);
Writer.WriteEndElement();
if (optionDeclaration.OptionType == OptionType.CompareBinary)
{
Writer.WriteStartElement("Binary");
SerializeLocation(optionDeclaration.OptionArgumentLocation);
Writer.WriteEndElement();
}
else
{
Writer.WriteStartElement("Text");
SerializeLocation(optionDeclaration.OptionArgumentLocation);
Writer.WriteEndElement();
}
break;
}
optionDeclaration = null;
return;
}
}
SerializeDeclarationComments(Declaration);
foreach (Tree Child in Declaration.Children)
{
Serialize(Child);
}
}
private void SerializeImport(Tree Import)
{
switch (Import.Type)
{
case TreeType.NameImport:
{
NameImport nameImport = (NameImport)Import;
Serialize(nameImport.TypeName);
nameImport = null;
break;
}
case TreeType.AliasImport:
{
AliasImport aliasImport = (AliasImport)Import;
Serialize(aliasImport.AliasedTypeName);
SerializeToken(TokenType.Equals, aliasImport.EqualsLocation);
Serialize(aliasImport.Name);
aliasImport = null;
break;
}
}
}
public void Serialize(Tree Tree)
{
if (Tree == null)
{
return;
}
Writer.WriteStartElement(Tree.Type.ToString());
if (Tree.IsBad)
{
Writer.WriteAttributeString("isBad", Conversions.ToString(Value: true));
}
SerializeSpan(Tree.Span);
TreeType type = Tree.Type;
if (type >= TreeType.ArgumentCollection && type <= TreeType.DeclarationCollection)
{
SerializeList(Tree);
}
else if (type == TreeType.Comment)
{
Comment comment = (Comment)Tree;
Writer.WriteAttributeString("isRem", Conversions.ToString(comment.IsREM));
if (comment.VComment != null)
{
Writer.WriteString(comment.VComment);
}
comment = null;
}
else if (type >= TreeType.SimpleName && type <= TreeType.QualifiedName)
{
SerializeName(Tree);
}
else if (type >= TreeType.IntrinsicType && type <= TreeType.ArrayType)
{
SerializeType(Tree);
}
else if (type == TreeType.Argument)
{
Argument argument = (Argument)Tree;
Serialize(argument.Name);
SerializeToken(TokenType.ColonEquals, argument.ColonEqualsLocation);
Serialize(argument.Expression);
argument = null;
}
else if (type >= TreeType.SimpleNameExpression && type <= TreeType.GetTypeExpression)
{
SerializeExpression(Tree);
}
else if (type >= TreeType.EmptyStatement && type <= TreeType.EndBlockStatement)
{
SerializeStatement(Tree);
}
else if (type == TreeType.Modifier)
{
Modifier modifier = (Modifier)Tree;
Writer.WriteAttributeString("type", modifier.ModifierType.ToString());
modifier = null;
}
else if (type == TreeType.VariableDeclarator)
{
VariableDeclarator variableDeclarator = (VariableDeclarator)Tree;
Serialize(variableDeclarator.VariableNames);
SerializeToken(TokenType.As, variableDeclarator.AsLocation);
SerializeToken(TokenType.New, variableDeclarator.NewLocation);
Serialize(variableDeclarator.VariableType);
Serialize(variableDeclarator.Arguments);
SerializeToken(TokenType.Equals, variableDeclarator.EqualsLocation);
Serialize(variableDeclarator.Initializer);
variableDeclarator = null;
}
else if (type >= TreeType.ComparisonCaseClause && type <= TreeType.RangeCaseClause)
{
SerializeCaseClause(Tree);
}
else if (type == TreeType.Attribute)
{
Attribute attribute = (Attribute)Tree;
Writer.WriteAttributeString("type", attribute.AttributeType.ToString());
switch (attribute.AttributeType)
{
case AttributeTypes.Assembly:
SerializeToken(TokenType.Colon, attribute.ColonLocation);
SerializeToken(TokenType.Assembly, attribute.AttributeTypeLocation);
break;
case AttributeTypes.Module:
SerializeToken(TokenType.Module, attribute.AttributeTypeLocation);
SerializeToken(TokenType.Colon, attribute.ColonLocation);
break;
}
Serialize(attribute.Name);
Serialize(attribute.Arguments);
attribute = null;
}
else if (type >= TreeType.EmptyDeclaration && type <= TreeType.DelegateFunctionDeclaration)
{
SerializeDeclaration(Tree);
}
else if (type == TreeType.Parameter)
{
Parameter parameter = (Parameter)Tree;
Serialize(parameter.Attributes);
Serialize(parameter.Modifiers);
Serialize(parameter.VariableName);
SerializeToken(TokenType.As, parameter.AsLocation);
Serialize(parameter.ParameterType);
SerializeToken(TokenType.Equals, parameter.EqualsLocation);
Serialize(parameter.Initializer);
parameter = null;
}
else if (type == TreeType.TypeParameter)
{
TypeParameter typeParameter = (TypeParameter)Tree;
Serialize(typeParameter.TypeName);
SerializeToken(TokenType.As, typeParameter.AsLocation);
Serialize(typeParameter.TypeConstraints);
typeParameter = null;
}
else if (type < TreeType.NameImport || type > TreeType.AliasImport)
{
foreach (Tree Child in Tree.Children)
{
Serialize(Child);
}
}
else
{
SerializeImport(Tree);
}
Writer.WriteEndElement();
}
}