Exemplo n.º 1
0
        static List <CGFDocument> ProcessDocuments(CGFParserReporter reporter, List <Microsoft.CodeAnalysis.Document> documents, Microsoft.CodeAnalysis.Project project)
        {
            using (reporter.CreateContextScope(CGFParserReporterContext.Type.Project, project.FilePath))
            {
                List <CGFDocument> documentsToProcess = new List <CGFDocument>();
                foreach (Microsoft.CodeAnalysis.Document document in documents)
                {
                    using (reporter.CreateContextScope(CGFParserReporterContext.Type.File, document.FilePath))
                    {
                        List <CGFTypeSymbol> typesToProcess = new List <CGFTypeSymbol>();

                        Microsoft.CodeAnalysis.SemanticModel semanticModel = document.GetSemanticModelAsync().Result;

                        Microsoft.CodeAnalysis.SyntaxTree syntaxTree = document.GetSyntaxTreeAsync().Result;
                        IEnumerable <Microsoft.CodeAnalysis.SyntaxNode> syntaxNodes = syntaxTree.GetRoot().DescendantNodes().Where(n => (n as ClassDeclarationSyntax) != null || (n as EnumDeclarationSyntax) != null);
                        foreach (Microsoft.CodeAnalysis.SyntaxNode node in syntaxNodes)
                        {
                            ClassDeclarationSyntax classSyntax = node as ClassDeclarationSyntax;
                            if (classSyntax != null)
                            {
                                Microsoft.CodeAnalysis.INamedTypeSymbol typeSymbol = semanticModel.GetDeclaredSymbol(classSyntax);
                                using (reporter.CreateContextScope(CGFParserReporterContext.Type.Type, typeSymbol.Name))
                                {
                                    CGFTypeSymbol cgfTypeSymbol = CGFTypeSymbol.Parse(reporter, typeSymbol);
                                    typesToProcess.Add(cgfTypeSymbol);
                                }
                            }
                            else
                            {
                                EnumDeclarationSyntax enumSyntax = node as EnumDeclarationSyntax;
                                Microsoft.CodeAnalysis.INamedTypeSymbol typeSymbol = semanticModel.GetDeclaredSymbol(enumSyntax);

                                using (reporter.CreateContextScope(CGFParserReporterContext.Type.Type, typeSymbol.Name))
                                {
                                    CGFTypeSymbol cgfTypeSymbol = CGFTypeSymbol.Parse(reporter, typeSymbol);
                                    typesToProcess.Add(cgfTypeSymbol);
                                }
                            }
                        }

                        if (typesToProcess.Count > 0)
                        {
                            CGFDocument cgfDocument = CGFDocument.Parse(reporter, document, typesToProcess);
                            documentsToProcess.Add(cgfDocument);
                        }
                    }
                }

                return(documentsToProcess);
            }
        }
Exemplo n.º 2
0
        private static Symbol SymbolFromRoslynSymbol(int offset, Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.ISymbol symbol)
        {
            var result = new Symbol();

            if (symbol is Microsoft.CodeAnalysis.IMethodSymbol methodSymbol)
            {
                result.IsVariadic = methodSymbol.Parameters.LastOrDefault()?.IsParams ?? false;
                result.Kind       = CursorKind.CXXMethod;

                result.Arguments = new List <ParameterSymbol>();

                foreach (var parameter in methodSymbol.Parameters)
                {
                    var argument = new ParameterSymbol();
                    argument.Name = parameter.Name;

                    var info = CheckForStaticExtension.GetReturnType(parameter);

                    if (info.HasValue)
                    {
                        argument.TypeDescription = info.Value.name;
                        argument.IsBuiltInType   = info.Value.inbuilt;
                    }

                    result.Arguments.Add(argument);
                }
            }

            result.Name = symbol.Name;

            var returnTypeInfo = CheckForStaticExtension.GetReturnType(symbol);

            if (returnTypeInfo.HasValue)
            {
                result.ResultType    = returnTypeInfo.Value.name;
                result.IsBuiltInType = returnTypeInfo.Value.inbuilt;
            }

            result.TypeDescription = symbol.Kind == Microsoft.CodeAnalysis.SymbolKind.NamedType ? symbol.ToDisplayString() : symbol.ToMinimalDisplayString(semanticModel, offset);
            var xmlDocumentation = symbol.GetDocumentationCommentXml();

            var docComment = DocumentationComment.From(xmlDocumentation, Environment.NewLine);

            result.BriefComment = docComment.SummaryText;

            return(result);
        }
Exemplo n.º 3
0
 public CastStatementInterpreter(StatementInterpreterHandler statementInterpreterHandler, CastExpressionSyntax castExpressionSyntax, Microsoft.CodeAnalysis.SemanticModel semanticModel)
 {
     this.statementInterpreterHandler = statementInterpreterHandler;
     this.castExpressionSyntax        = castExpressionSyntax;
     this.semanticModel = semanticModel;
 }
 public ArrayCreationStatementInterpreter(StatementInterpreterHandler statementInterpreterHandler, ArrayCreationExpressionSyntax arrayCreationExpressionSyntax, Microsoft.CodeAnalysis.SemanticModel semanticModel)
 {
     this.statementInterpreterHandler   = statementInterpreterHandler;
     this.arrayCreationExpressionSyntax = arrayCreationExpressionSyntax;
     this.semanticModel = semanticModel;
 }