Example #1
0
        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);
        } 
Example #2
0
        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);
        }
Example #3
0
 JsonValue GetModifiers(IEnumerable<CSharpModifierToken> modifierTokens)
 {
     List<CSharpModifierToken> modifierList = new List<CSharpModifierToken>();
     foreach (CSharpModifierToken modifier in modifierTokens)
     {
         modifierList.Add(modifier);
     }
     int count = modifierList.Count;
     int lastIndex = count - 1;
     if (count > 1)
     {
         JsonArray modifierArr = new JsonArray();
         modifierArr.Comment = "GetModifiers";
         for (int i = 0; i < count; i++)
         {
             modifierList[i].AcceptVisitor(this);
             modifierArr.AddJsonValue(Pop());
         }
         return modifierArr;
     }
     else if (count == 1)
     {
         modifierList[0].AcceptVisitor(this);
         return Pop();
     }
     else//count = 0;
     {
         JsonElement nullElement = new JsonElement();
         nullElement.SetValue(null);
         return nullElement;
     }
 }
Example #4
0
 public void VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression)
 {
     JsonObject expression = CreateJsonExpression(arrayCreateExpression);
     AddKeyword(expression, ArrayCreateExpression.NewKeywordRole);
     expression.AddJsonValue("array-type", GenTypeInfo(arrayCreateExpression.Type));
     if (arrayCreateExpression.Arguments.Count > 0)
     {
         expression.AddJsonValue("arguments", GetCommaSeparatedList(arrayCreateExpression.Arguments));
     }
     JsonArray specifierArr = new JsonArray();
     foreach (var specifier in arrayCreateExpression.AdditionalArraySpecifiers)
     {
         specifier.AcceptVisitor(this);
         var pop = Pop();
         if (pop != null)
         {
             specifierArr.AddJsonValue(pop);
         }
     }
     if (specifierArr.Count == 0)
     {
         specifierArr = null;
     }
     expression.AddJsonValue("specifier", specifierArr);
     expression.AddJsonValue("initializer", GenExpression(arrayCreateExpression.Initializer));
     Push(expression);
 }
Example #5
0
 JsonValue GetInitializerElements(AstNodeCollection<Expression> elements)
 {
     JsonArray initArr = new JsonArray();
     foreach (AstNode node in elements)
     {
         node.AcceptVisitor(this);
         initArr.AddJsonValue(Pop());
     }
     if (initArr.Count == 0)
     {
         initArr = null;
     }
     return initArr;
 }
Example #6
0
        public void VisitJsonArray(JsonArray jsonArr)
        {
            if (jsonArr == null || jsonArr.Count == 0)
            {
                VisitNull();
                return;
            }

            OpenBrace(BraceStyle.Array);
            bool isFirst = true;
            if (Debug)
            {
                //comment member of
                if (jsonArr.Comment != null)
                {
                    writer.Write('{');
                    isFirst = (WriteComment(jsonArr.Comment) != true);
                    writer.Write('}');
                }
            }

            foreach (JsonValue value in jsonArr.ValueList)
            {
                if (isFirst)
                {
                    WriteLine();
                    isFirst = false;
                }
                else
                {
                    Write(',');
                    WriteLine();
                }
                if (value == null)
                {
                    VisitNull();
                }
                else
                {
                    value.AcceptVisitor(this);
                }
            }
            CloseBrace(BraceStyle.Array);
        }
Example #7
0
        public void VisitSwitchStatement(SwitchStatement switchStatement)
        {
            JsonObject statement = CreateJsonStatement(switchStatement);

            AddKeyword(statement, SwitchStatement.SwitchKeywordRole);
            statement.AddJsonValue("expression", GenExpression(switchStatement.Expression));
            JsonArray sections = new JsonArray();
            foreach (var sec in switchStatement.SwitchSections)
            {
                sec.AcceptVisitor(this);
                var temp = Pop();
                if (temp != null)
                    sections.AddJsonValue(temp);
            }
            if (sections.Count == 0)
            {
                sections = null;
            }
            statement.AddJsonValue("switch-sections", sections);

            Push(statement);
        }
Example #8
0
        public void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration)
        {
            ClearLocalSymbolReferenecs();
            JsonObject declaration = CreateJsonEntityDeclaration(propertyDeclaration);
            declaration.AddJsonValue("private-implementation-type", GetPrivateImplementationType(propertyDeclaration.PrivateImplementationType));
            declaration.AddJsonValue("identifier", GetIdentifier(propertyDeclaration.NameToken));

            JsonArray children = new JsonArray();
            foreach (AstNode node in propertyDeclaration.Children)
            {
                if (node.Role == IndexerDeclaration.GetterRole || node.Role == IndexerDeclaration.SetterRole)
                {
                    node.AcceptVisitor(this);
                    var temp = Pop();
                    if (temp != null)
                    {
                        children.AddJsonValue(temp);
                    }
                }
            }
            if (children.Count == 0)
            {
                children = null;
            }
            declaration.AddJsonValue("children", children);
            declaration.AddJsonValue("local_symbols", GetLocalSymbolReferences());
            Push(declaration);
        }
Example #9
0
        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;
            }
        }
Example #10
0
 JsonValue GetCommaSeparatedList(IEnumerable<AstNode> list)
 {
     int count = list.Count();
     if (count > 0)
     {
         JsonArray nodeArr = new JsonArray();
         nodeArr.Comment = "GetCommaSeparatedList";
         foreach (AstNode node in list)
         {
             node.AcceptVisitor(this);
             if (count == 1)
             {
                 return Pop();
             }
             else
             {
                 nodeArr.AddJsonValue(Pop());
             }
         }
         return nodeArr;
     }
     else//count == 0
     {
         return null;
     }
 }
Example #11
0
        public void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration)
        {
            ClearLocalSymbolReferenecs();
            JsonObject declaration = CreateJsonEntityDeclaration(indexerDeclaration);
            declaration.AddJsonValue("private-implementation-type", GetPrivateImplementationType(indexerDeclaration.PrivateImplementationType));

            AddKeyword(declaration, IndexerDeclaration.ThisKeywordRole);
            declaration.AddJsonValue("parameters", GetCommaSeparatedList(indexerDeclaration.Parameters));
            JsonArray children = new JsonArray();
            foreach (AstNode node in indexerDeclaration.Children)
            {
                if (node.Role == IndexerDeclaration.GetterRole || node.Role == IndexerDeclaration.SetterRole)
                {
                    node.AcceptVisitor(this);
                    var temp = Pop();
                    if (temp != null)
                    {
                        children.AddJsonValue(temp);
                    }
                }
            }
            if (children.Count == 0)
            {
                children = null;
            }
            declaration.AddJsonValue("children", children);

            declaration.AddJsonValue("local_symbols", GetLocalSymbolReferences());
            Push(declaration);

        }
Example #12
0
        public void VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration)
        {
            JsonObject declaration = CreateJsonEntityDeclaration(customEventDeclaration);

            AddKeyword(declaration, EventDeclaration.EventKeywordRole);
            declaration.AddJsonValue("private-implementation-type", GetPrivateImplementationType(customEventDeclaration.PrivateImplementationType));
            declaration.AddJsonValue("identifier", GetIdentifier(customEventDeclaration.NameToken));
            JsonArray children = new JsonArray();
            foreach (AstNode node in customEventDeclaration.Children)
            {
                if (node.Role == CustomEventDeclaration.AddAccessorRole || node.Role == CustomEventDeclaration.RemoveAccessorRole)
                {
                    node.AcceptVisitor(this);
                    var temp = Pop();
                    if (temp != null)
                    {
                        children.AddJsonValue(temp);
                    }
                }
            }
            if (children.Count == 0)
            {
                children = null;
            }
            declaration.AddJsonValue("children", children);

            Push(declaration);
        }
Example #13
0
 JsonValue GetTypeInfoList(List<string> typeInfoList)
 {
     JsonArray typeArr = new JsonArray();
     typeArr.Comment = "GetTypeInfoList";
     foreach (string value in typeInfoList)
     {
         typeArr.AddJsonValue(new JsonElement(value));
     }
     if (typeArr.Count == 0)
     {
         typeArr = null;
     }
     return typeArr;
 }
Example #14
0
        public void VisitTryCatchStatement(TryCatchStatement tryCatchStatement)
        {
            JsonObject statement = CreateJsonStatement(tryCatchStatement);
            AddKeyword(statement, "try-keyword", TryCatchStatement.TryKeywordRole);

            statement.AddJsonValue("try-block", GenStatement(tryCatchStatement.TryBlock));
            JsonArray catchClauseList = new JsonArray();
            foreach (var catchClause in tryCatchStatement.CatchClauses)
            {
                catchClause.AcceptVisitor(this);
                catchClauseList.AddJsonValue(Pop());
            }
            statement.AddJsonValue("catch-clause", catchClauseList);
            if (!tryCatchStatement.FinallyBlock.IsNull)
            {
                AddKeyword(statement, "final-keyword", TryCatchStatement.FinallyKeywordRole);
                statement.AddJsonValue("final-block", GenStatement(tryCatchStatement.FinallyBlock));
            }
            Push(statement);
        }
Example #15
0
        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); 
        }
Example #16
0
 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);
 }
Example #17
0
 public void VisitBlockStatement(BlockStatement blockStatement)
 {
     JsonObject statement = CreateJsonStatement(blockStatement);
     int count = blockStatement.Statements.Count;
     if (count == 0)
     {
         Push(null);
         return;
     }
     JsonArray stmtList = new JsonArray();
     foreach (var node in blockStatement.Statements)
     {
         node.AcceptVisitor(this);
         stmtList.AddJsonValue(Pop());
     }
     statement.AddJsonValue("statement-list", stmtList);
     Push(statement);
 }
Example #18
0
 JsonValue GetAttributes(IEnumerable<AttributeSection> attributes)
 {
     JsonArray attrArray = new JsonArray();
     foreach (AttributeSection attr in attributes)
     {
         attr.AcceptVisitor(this);
         attrArray.AddJsonValue(Pop());
     }
     if (attrArray.Count == 0)
     {
         attrArray = null;
     }
     return attrArray;
 }
Example #19
0
 JsonArray ReadJsonArray()
 {
     JsonArray arr = new JsonArray();
     if (CurrentChar != '[')
     {
         throw new Exception("The first cha it's not array brace");
     }
     eat();
     while (CurrentChar != ']')
     {
         arr.AddJsonValue(ReadByType(GetJsonType()));
         if (CurrentChar == ',')
         {
             eat();
         }
         else
         {
             ClearSpace();
         }
     }
     eat();//eat ']'
     return arr;
 }
Example #20
0
        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);
        }