void ProcessCompilationUnit(CompilationUnitSyntax syntax, CancellationToken cancellationToken) {

            if (!_processAsIncludedFile) {
                foreach(var includeDirectiveSyntax in syntax.DescendantNodes().OfType<IncludeDirectiveSyntax>()) {
                    cancellationToken.ThrowIfCancellationRequested();
                    ProcessIncludeDirective(includeDirectiveSyntax, cancellationToken);
                }
                foreach (var taskDeclarationSyntax in syntax.DescendantNodes().OfType<TaskDeclarationSyntax>()) {
                    cancellationToken.ThrowIfCancellationRequested();
                    ProcessTaskDeclaration(taskDeclarationSyntax);
                }
            }
            foreach (var taskDefinitionSyntax in syntax.DescendantNodes().OfType<TaskDefinitionSyntax>()) {
                cancellationToken.ThrowIfCancellationRequested();
                ProcessTaskDefinition(taskDefinitionSyntax);
            }
        }
        internal CompilationUnit(CompilationUnitSyntax syntax,
                               IReadOnlyList<string> codeUsings,
                               IReadOnlySymbolCollection<ITaskDeclarationSymbol> taskDeclarations,
                               IReadOnlySymbolCollection<ITaskDefinitionSymbol> taskDefinitions,
                               IReadOnlySymbolCollection<IIncludeSymbol> includes,
                               IEnumerable<ISymbol> symbols,
                               IReadOnlyList<Diagnostic> diagnostics) {

            if(syntax == null) {
                throw new ArgumentNullException(nameof(syntax));
            }

            Syntax           = syntax;
            CodeUsings       = codeUsings       ?? new List<string>();
            TaskDeclarations = taskDeclarations ?? new SymbolCollection<ITaskDeclarationSymbol>();
            TaskDefinitions  = taskDefinitions  ?? new SymbolCollection<ITaskDefinitionSymbol>();
            Diagnostics      = diagnostics      ?? new List<Diagnostic>();
            Includes         = includes         ?? new SymbolCollection<IIncludeSymbol>();
            Symbols          = new SymbolList(symbols ?? Enumerable.Empty<IIncludeSymbol>());            
        }
        public static CompilationUnit FromCompilationUnit(CompilationUnitSyntax syntax, CancellationToken cancellationToken) {

            if (syntax == null) {
                throw new ArgumentNullException(nameof(syntax));
            }

            var builder = new CompilationUnitBuilder();

            builder.Process(syntax, cancellationToken);

            var model=new CompilationUnit(
                syntax, 
                builder._codeUsings, 
                builder._taskDeclarations, 
                builder._taskDefinitions,
                builder._includes,
                builder._symbols,
                builder._diagnostics.ToUnique());

            return model;
        }
        void ProcessNavLanguage(CompilationUnitSyntax syntax, CancellationToken cancellationToken) {

            cancellationToken.ThrowIfCancellationRequested();

            //====================
            // 1. TaskDeclarations 
            //====================
            var taskDeclarationResult = TaskDeclarationSymbolBuilder.FromCompilationUnit(syntax, cancellationToken);

            _diagnostics.AddRange(taskDeclarationResult.Diagnostics);
            _taskDeclarations.AddRange(taskDeclarationResult.TaskDeklarations);
            _includes.AddRange(taskDeclarationResult.Includes);

            cancellationToken.ThrowIfCancellationRequested();

            //====================
            // 2. TaskDefinitions
            //====================
            foreach (var taskDefinitionSyntax in syntax.DescendantNodes().OfType<TaskDefinitionSyntax>()) {
                ProcessTaskDefinitionSyntax(taskDefinitionSyntax, cancellationToken);
            }

            //====================
            // 3. Collect Symbols
            //====================
            // Nur Symbole von Taskdeklarationen der eigenen Datei, und auch nur solche, die aus "taskrefs task" entstanden sind
            _symbols.AddRange(_taskDeclarations.Where(td => !td.IsIncluded && 
                                                            td.Origin==TaskDeclarationOrigin.TaskDeclaration)
                                               .SelectMany(td => td.SymbolsAndSelf()));

            // Alle Symbole und deren "Kinder" der Taskdefinitionen
            _symbols.AddRange(_taskDefinitions.SelectMany(td => td.SymbolsAndSelf()));

            // Alle Includes (= taskref "filepath") hinzufügen
            _symbols.AddRange(_includes);            
        }
        static TaskDeclarationResult FromCompilationUnit(CompilationUnitSyntax syntax, bool processAsIncludedFile, CancellationToken cancellationToken) {
            var builder = new TaskDeclarationSymbolBuilder(processAsIncludedFile);
            builder.ProcessCompilationUnit(syntax, cancellationToken);

            return new TaskDeclarationResult(builder._diagnostics, builder._taskDeklarations, builder._includes);
        }
 public static TaskDeclarationResult FromCompilationUnit(CompilationUnitSyntax syntax, CancellationToken cancellationToken) {
     return FromCompilationUnit(syntax, false, cancellationToken);
 }
 void Process(CompilationUnitSyntax syntax, CancellationToken cancellationToken) {
     ProcessNavLanguage(syntax, cancellationToken);
     ProcessCodeLanguage(syntax, cancellationToken);
     ProcessFinalSemanticErrors(syntax, cancellationToken);
 }
        void ProcessFinalSemanticErrors(CompilationUnitSyntax syntax, CancellationToken cancellationToken) {

            // =====================
            // Unused Includes
            var unusedIncludes = _includes.Where(i => !i.TaskDeklarations.SelectMany(td => td.References).Any());
            foreach (var includeSymbol in unusedIncludes) {

                cancellationToken.ThrowIfCancellationRequested();

                _diagnostics.Add(new Diagnostic(
                    includeSymbol.Syntax.GetLocation(), 
                    DiagnosticDescriptors.DeadCode.Nav1003IncludeNotRequired));
            }
            
            // =====================
            // Unused Task Declarations
            var unusedTaskDeclarations = _taskDeclarations.Where(td => !td.IsIncluded && td.Origin == TaskDeclarationOrigin.TaskDeclaration && !td.References.Any());
            foreach (var taskDeclarationSymbol in unusedTaskDeclarations) {

                cancellationToken.ThrowIfCancellationRequested();

                var location = taskDeclarationSymbol.Location;

                // wenn möglich markieren wir "taskref Identifier"
                var taskDeclarationSyntax = syntax.FindNode(taskDeclarationSymbol.Location.Start) as TaskDeclarationSyntax;
                if (taskDeclarationSyntax != null) {
                    var start  = taskDeclarationSyntax.TaskrefKeyword.Start;
                    var end    = taskDeclarationSyntax.Identifier.End;
                    var extent = TextExtent.FromBounds(start, end);
                    location   = syntax.SyntaxTree.GetLocation(extent);
                }
                            
                _diagnostics.Add(new Diagnostic(
                    location, 
                    DiagnosticDescriptors.DeadCode.Nav1005TaskDeclaration0NotRequired,
                    taskDeclarationSymbol.Name));
            }
        }
        void ProcessCodeLanguage(CompilationUnitSyntax syntax, CancellationToken cancellationToken) {
            foreach (var codeUsingDeclarationSyntax in syntax.DescendantNodes().OfType<CodeUsingDeclarationSyntax>()) {

                cancellationToken.ThrowIfCancellationRequested();

                ProcessCodeUsingDeclaration(codeUsingDeclarationSyntax);
            }
        }
 public static CompilationUnit FromCompilationUnitSyntax(CompilationUnitSyntax syntax, CancellationToken cancellationToken = default(CancellationToken)) {
     return CompilationUnitBuilder.FromCompilationUnit(syntax, cancellationToken);
 }