public void VisitAttribute(ICSharpCode.NRefactory.CSharp.Attribute attribute) { JsonObject visit = new JsonObject(); visit.Comment = "VisitAttribute"; visit.AddJsonValue("type", GenTypeInfo(attribute.Type)); if (attribute.Arguments.Count != 0 || !attribute.GetChildByRole(Roles.LPar).IsNull) { visit.AddJsonValue("arguments", GetCommaSeparatedList(attribute.Arguments)); } Push(visit); }
public void VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration) { JsonObject declaration = new JsonObject(); declaration.Comment = "VisitTypeParameterDeclaration"; declaration.AddJsonValue("attributes", GetAttributes(typeParameterDeclaration.Attributes)); switch (typeParameterDeclaration.Variance) { case VarianceModifier.Invariant: break; case VarianceModifier.Covariant: declaration.AddJsonValue("keyword", GetKeyword(TypeParameterDeclaration.OutVarianceKeywordRole)); break; case VarianceModifier.Contravariant: declaration.AddJsonValue("keyword", GetKeyword(TypeParameterDeclaration.InVarianceKeywordRole)); break; default: throw new NotSupportedException("Invalid value for VarianceModifier"); } declaration.AddJsonValue("identifier", GetIdentifier(typeParameterDeclaration.NameToken)); Push(declaration); }
public void VisitConstraint(Constraint constraint) { JsonObject visit = new JsonObject(); visit.Comment = "VisitConstraint"; AddKeyword(visit, Roles.WhereKeyword); visit.AddJsonValue("type-parameter", GenTypeInfo(constraint.TypeParameter)); visit.AddJsonValue("base-types", GetCommaSeparatedList(constraint.BaseTypes)); Push(visit); }
public void VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration) { JsonObject declaration = new JsonObject(); declaration.Comment = "VisitExternAliasDeclaration"; AddKeyword(declaration, "extern-keyword", Roles.ExternKeyword); AddKeyword(declaration, "alias-keyword", Roles.AliasKeyword); declaration.AddJsonValue("identifier", GetIdentifier(externAliasDeclaration.NameToken)); Push(declaration); //implement already, but not tested throw new FirstTimeUseException(); }
public void VisitCaseLabel(CaseLabel caseLabel) { JsonObject label = new JsonObject(); label.Comment = "VisitCaseLabel"; if (caseLabel.Expression.IsNull) { AddKeyword(label, CaseLabel.DefaultKeywordRole); } else { AddKeyword(label, CaseLabel.CaseKeywordRole); label.AddJsonValue("expression", GenExpression(caseLabel.Expression)); } Push(label); }
public void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration) { JsonObject declaration = new JsonObject(); declaration.Comment = "VisitNamespaceDeclaration"; AddKeyword(declaration, Roles.NamespaceKeyword); declaration.AddJsonValue("namespace-name", GenerateNamespaceString(namespaceDeclaration.NamespaceName)); JsonArray memberList = new JsonArray(); foreach (var member in namespaceDeclaration.Members) { member.AcceptVisitor(this); var temp = Pop(); if (temp != null) { memberList.AddJsonValue(temp); } } if (memberList.Count == 0) { memberList = null; } declaration.AddJsonValue("members", memberList); Push(declaration); }
public void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration) { JsonObject declaration = new JsonObject(); declaration.Comment = "VisitUsingAliasDeclaration"; AddKeyword(declaration, UsingAliasDeclaration.UsingKeywordRole); declaration.AddJsonValue("identifier", GetIdentifier(usingAliasDeclaration.GetChildByRole(UsingAliasDeclaration.AliasRole))); declaration.AddJsonValue("assign-token", GetKeyword(Roles.Assign)); declaration.AddJsonValue("import", GenTypeInfo(usingAliasDeclaration.Import)); Push(declaration); //implement already, but not tested throw new FirstTimeUseException(); }
public void VisitSyntaxTree(SyntaxTree syntaxTree) { JsonArray arr = new JsonArray(); arr.Comment = "VisitSyntaxTree"; int counter = 0; CreateGlobalSymbolTable(); foreach (AstNode node in syntaxTree.Children) { node.AcceptVisitor(this); arr.AddJsonValue(Pop()); counter++; } //----------- //type reference table JsonObject symbolInformations = new JsonObject(); JsonArray typerefs = new JsonArray(); symbolInformations.AddJsonValue("typerefs", typerefs); foreach (string k in this.typeReferences.Keys) { //type reference typerefs.AddJsonValue(new JsonElement(k)); } arr.AddJsonValue(symbolInformations); //----------- if (counter == 1) { LastValue = arr.ValueList[0]; } else { LastValue = arr; } }
public void VisitMemberType(MemberType memberType) { JsonObject memtype = new JsonObject(); memtype.Comment = "VisitMemberType"; memtype.AddJsonValue("type-info", GenTypeInfo(memberType.Target)); memtype.AddJsonValue("member-name", GetIdentifier(memberType.MemberNameToken)); Push(memtype); }
public void VisitParameterDeclaration(ParameterDeclaration parameterDeclaration) { JsonObject parameter = new JsonObject(); parameter.Comment = "VisitParameterDeclaration"; if (parameterDeclaration.Attributes.Count > 0) { parameter.AddJsonValue("attributes", GetAttributes(parameterDeclaration.Attributes)); } JsonValue keyword; switch (parameterDeclaration.ParameterModifier) { case ParameterModifier.Out: keyword = GetKeyword(ParameterDeclaration.OutModifierRole); break; case ParameterModifier.Params: keyword = GetKeyword(ParameterDeclaration.ParamsModifierRole); break; case ParameterModifier.Ref: keyword = GetKeyword(ParameterDeclaration.RefModifierRole); break; case ParameterModifier.This: keyword = GetKeyword(ParameterDeclaration.ThisModifierRole); break; default: keyword = null; break; } if (keyword != null) { parameter.AddJsonValue("modifier", keyword); } parameter.AddJsonValue("type-info", GenTypeInfo(parameterDeclaration.Type)); parameter.AddJsonValue("name", parameterDeclaration.Name); if (!parameterDeclaration.DefaultExpression.IsNull) { parameter.AddJsonValue("default-expression", GenExpression(parameterDeclaration.DefaultExpression)); } Push(parameter); }
public void VisitVariableInitializer(VariableInitializer variableInitializer) { JsonObject variable = new JsonObject(); variable.Comment = "VisitVariableInitializer"; variable.AddJsonValue("variable-name", GetIdentifier(variableInitializer.NameToken)); if (!variableInitializer.Initializer.IsNull) { variable.AddJsonValue("initializer", GenExpression(variableInitializer.Initializer)); } else { variable.AddJsonNull("initializer"); } Push(variable); }
public void VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer) { JsonObject initializer = new JsonObject(); initializer.Comment = "VisitFixedVariableInitializer"; initializer.AddJsonValue("identifier", GetIdentifier(fixedVariableInitializer.NameToken)); if (!fixedVariableInitializer.CountExpression.IsNull) { initializer.AddJsonValue("count-expression", GenExpression(fixedVariableInitializer.CountExpression)); } Push(initializer); throw new FirstTimeUseException(); }
public void VisitConstructorInitializer(ConstructorInitializer constructorInitializer) { JsonObject initializer = new JsonObject(); initializer.Comment = "VisitConstructorInitializer"; if (constructorInitializer.ConstructorInitializerType == ConstructorInitializerType.This) { initializer.AddJsonValue("keyword", GetKeyword(ConstructorInitializer.ThisKeywordRole)); } else { initializer.AddJsonValue("keyword", GetKeyword(ConstructorInitializer.BaseKeywordRole)); } initializer.AddJsonValue("arguments", GetCommaSeparatedList(constructorInitializer.Arguments)); Push(initializer); }
public void VisitCatchClause(CatchClause catchClause) { JsonObject visitCatch = new JsonObject(); visitCatch.Comment = "VisitCatchClause"; AddKeyword(visitCatch, "catch-keyword", CatchClause.CatchKeywordRole); if (!catchClause.Type.IsNull) { visitCatch.AddJsonValue("type-info", GenTypeInfo(catchClause.Type)); if (!string.IsNullOrEmpty(catchClause.VariableName)) { visitCatch.AddJsonValue("identifier", GetIdentifier(catchClause.VariableNameToken)); } } visitCatch.AddJsonValue("catch-body", GenStatement(catchClause.Body)); Push(visitCatch); }
public void VisitAttributeSection(AttributeSection attributeSection) { JsonObject visit = new JsonObject(); visit.Comment = "VisitAttributeSection"; if (!string.IsNullOrEmpty(attributeSection.AttributeTarget)) { visit.AddJsonValue("target", new JsonElement(attributeSection.AttributeTarget)); } visit.AddJsonValue("attributes", GetCommaSeparatedList(attributeSection.Attributes)); Push(visit); }
public void VisitComposedType(ComposedType composedType) { JsonObject jsonComposedType = new JsonObject(); jsonComposedType.Comment = "VisitComposedType"; composedType.BaseType.AcceptVisitor(this); jsonComposedType.AddJsonValue("basetype", Pop()); if (composedType.HasNullableSpecifier) { jsonComposedType.AddJsonValue("nullable-specifier", ComposedType.NullableRole.Token); } jsonComposedType.AddJsonValue("pointerrank", composedType.PointerRank); JsonArray arraySpecifier = new JsonArray(); foreach (var node in composedType.ArraySpecifiers) { node.AcceptVisitor(this); arraySpecifier.AddJsonValue(Pop()); } Push(jsonComposedType); }
public void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration) { JsonObject declaration = new JsonObject(); declaration.Comment = "VisitDelegateDeclaration"; AddAttributes(declaration, delegateDeclaration); AddModifiers(declaration, delegateDeclaration); AddReturnType(declaration, delegateDeclaration); AddKeyword(declaration, Roles.DelegateKeyword); declaration.AddJsonValue("identifier", GetIdentifier(delegateDeclaration.NameToken)); declaration.AddJsonValue("type-parameters", GetTypeParameters(delegateDeclaration.TypeParameters)); declaration.AddJsonValue("parameters", GetCommaSeparatedList(delegateDeclaration.Parameters)); JsonArray contraintList = new JsonArray(); foreach (Constraint constraint in delegateDeclaration.Constraints) { constraint.AcceptVisitor(this); var temp = Pop(); if (temp != null) { contraintList.AddJsonValue(temp); } } if (contraintList.Count == 0) { contraintList = null; } declaration.AddJsonValue("constraint", contraintList); Push(declaration); }
public void VisitArraySpecifier(ArraySpecifier arraySpecifier) { JsonObject arrSpec = new JsonObject(); arrSpec.Comment = "VisitArraySpecifier"; arrSpec.AddJsonValue("array-specifier", arraySpecifier.GetChildrenByRole(Roles.Comma).Count); if (arraySpecifier.GetChildrenByRole(Roles.Comma).Count == 0) { arrSpec = null; } Push(arrSpec); }
public void VisitTypeDeclaration(TypeDeclaration typeDeclaration) { JsonObject declaration = new JsonObject(); declaration.Comment = "VisitTypeDeclaration"; AddAttributes(declaration, typeDeclaration); AddModifiers(declaration, typeDeclaration); switch (typeDeclaration.ClassType) { case ClassType.Enum: declaration.AddJsonValue("keyword", GetKeyword(Roles.EnumKeyword)); break; case ClassType.Interface: declaration.AddJsonValue("keyword", GetKeyword(Roles.InterfaceKeyword)); break; case ClassType.Struct: declaration.AddJsonValue("keyword", GetKeyword(Roles.StructKeyword)); break; default: declaration.AddJsonValue("keyword", GetKeyword(Roles.ClassKeyword)); break; } JsonElement identifier = GetIdentifier(typeDeclaration.NameToken); bool thisTypeIsLamda = false; declaration.AddJsonValue("identifier", identifier); declaration.AddJsonValue("parameters", GetTypeParameters(typeDeclaration.TypeParameters)); if (typeDeclaration.BaseTypes.Any()) { declaration.AddJsonValue("base-types", GetCommaSeparatedList(typeDeclaration.BaseTypes)); } JsonArray constraintArr = new JsonArray(); foreach (Constraint constraint in typeDeclaration.Constraints) { constraint.AcceptVisitor(this); constraintArr.AddJsonValue(Pop()); } declaration.AddJsonValue("constraint", constraintArr); JsonArray memberArr = new JsonArray(); foreach (var member in typeDeclaration.Members) { member.AcceptVisitor(this); memberArr.AddJsonValue(Pop()); } declaration.AddJsonValue("members", memberArr); if (thisTypeIsLamda) { declaration = null; } Push(declaration); }
public void VisitComment(Comment comment) { JsonObject visit = new JsonObject(); visit.Comment = "VisitComment"; switch (comment.CommentType) { case CommentType.Documentation: visit.AddJsonValue("comment-type", new JsonElement("documentation")); break; case CommentType.InactiveCode: visit.AddJsonValue("comment-type", new JsonElement("inactive-code")); break; case CommentType.MultiLine: visit.AddJsonValue("comment-type", new JsonElement("multiline")); break; case CommentType.MultiLineDocumentation: visit.AddJsonValue("comment-type", new JsonElement("multiline-documentation")); break; case CommentType.SingleLine: visit.AddJsonValue("comment-type", new JsonElement("single-line")); break; default: throw new NotSupportedException("Invalid value for CommentType"); } visit.AddJsonValue("comment-content", new JsonElement(comment.Content)); Push(visit); throw new FirstTimeUseException(); }
public void VisitUsingDeclaration(UsingDeclaration usingDeclaration) { JsonObject declaration = new JsonObject(); declaration.Comment = "VisitUsingDeclaration"; AddKeyword(declaration, UsingDeclaration.UsingKeywordRole); declaration.AddJsonValue("import", GenerateNamespaceString(usingDeclaration.Import)); Push(declaration); }
public void VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective) { JsonObject visit = new JsonObject(); visit.Comment = "VisitPreProcessorDirective"; var type = preProcessorDirective.Type; string typeStr = "#" + type.ToString().ToLowerInvariant(); visit.AddJsonValue("preprocessordirective-type", new JsonElement(typeStr)); if (!string.IsNullOrEmpty(preProcessorDirective.Argument)) { visit.AddJsonValue("argument", new JsonElement(preProcessorDirective.Argument)); } else { visit.AddJsonNull("argument"); } Push(visit); throw new FirstTimeUseException(); }
JsonObject ReadJsonObject() { JsonObject obj = new JsonObject(); if (CurrentChar != '{') { throw new Exception("The first char it's not object brace"); } string key; JsonValueType rightJsonValueType; while (CurrentChar != '}') { eat(); key = GetString(); ClearSpace(); if (CurrentChar != ':') { throw new Exception("Something wrong"); } eat(); rightJsonValueType = GetJsonType(); obj.AddJsonValue(key, ReadByType(rightJsonValueType)); if (CurrentChar == ',') { eat(); } else { ClearSpace(); } } eat();//eat '}' return obj; }
public void VisitSwitchSection(SwitchSection switchSection) { JsonObject section = new JsonObject(); section.Comment = "VisitSwitchSection"; JsonArray label = new JsonArray(); foreach (var lb in switchSection.CaseLabels) { lb.AcceptVisitor(this); label.AddJsonValue(Pop()); } if (label.Count == 0) { label = null; } section.AddJsonValue("label", label); JsonArray statement = new JsonArray(); foreach (var stmt in switchSection.Statements) { stmt.AcceptVisitor(this); statement.AddJsonValue(Pop()); } if (statement.Count == 0) { statement = null; } section.AddJsonValue("statements", statement); Push(section); }