zcov: / lib/Sema/ParseAST.cpp


Files: 1 Branches Taken: 95.5% 21 / 22
Generated: 2010-02-10 01:31 Branches Executed: 100.0% 22 / 22
Line Coverage: 100.0% 41 / 41


Programs: 2 Runs 3018


       1                 : //===--- ParseAST.cpp - Provide the clang::ParseAST method ----------------===//
       2                 : //
       3                 : //                     The LLVM Compiler Infrastructure
       4                 : //
       5                 : // This file is distributed under the University of Illinois Open Source
       6                 : // License. See LICENSE.TXT for details.
       7                 : //
       8                 : //===----------------------------------------------------------------------===//
       9                 : //
      10                 : // This file implements the clang::ParseAST method.
      11                 : //
      12                 : //===----------------------------------------------------------------------===//
      13                 : 
      14                 : #include "clang/Sema/ParseAST.h"
      15                 : #include "Sema.h"
      16                 : #include "clang/Sema/CodeCompleteConsumer.h"
      17                 : #include "clang/Sema/SemaConsumer.h"
      18                 : #include "clang/Sema/ExternalSemaSource.h"
      19                 : #include "clang/AST/ASTConsumer.h"
      20                 : #include "clang/AST/ExternalASTSource.h"
      21                 : #include "clang/AST/Stmt.h"
      22                 : #include "clang/Parse/Parser.h"
      23                 : #include <cstdio>
      24                 : 
      25                 : using namespace clang;
      26                 : 
      27                 : //===----------------------------------------------------------------------===//
      28                 : // Public interface to the file
      29                 : //===----------------------------------------------------------------------===//
      30                 : 
      31                 : /// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
      32                 : /// the file is parsed.  This inserts the parsed decls into the translation unit
      33                 : /// held by Ctx.
      34                 : ///
      35                 : void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
      36                 :                      ASTContext &Ctx, bool PrintStats,
      37                 :                      bool CompleteTranslationUnit,
      38             2236:                      CodeCompleteConsumer *CompletionConsumer) {
      39                 :   // Collect global stats on Decls/Stmts (until we have a module streamer).
                        2: branch 0 taken
                     2234: branch 1 taken
      40             2236:   if (PrintStats) {
      41                2:     Decl::CollectingStats(true);
      42                2:     Stmt::CollectingStats(true);
      43                 :   }
      44                 : 
      45             2236:   Sema S(PP, Ctx, *Consumer, CompleteTranslationUnit, CompletionConsumer);
      46             2236:   Parser P(PP, S);
      47             2236:   PP.EnterMainSourceFile();
      48                 : 
      49                 :   // Initialize the parser.
      50             2236:   P.Initialize();
      51                 : 
      52             2236:   Consumer->Initialize(Ctx);
      53                 : 
                       44: branch 1 taken
                     2192: branch 2 taken
      54             2236:   if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer))
      55               44:     SC->InitializeSema(S);
      56                 : 
                       35: branch 1 taken
                     2201: branch 2 taken
      57             2236:   if (ExternalASTSource *External = Ctx.getExternalSource()) {
                       35: branch 0 taken
                        0: branch 1 not taken
      58               35:     if (ExternalSemaSource *ExternalSema =
      59               35:           dyn_cast<ExternalSemaSource>(External))
      60               35:       ExternalSema->InitializeSema(S);
      61                 : 
      62               35:     External->StartTranslationUnit(Consumer);
      63                 :   }
      64                 : 
      65             2236:   Parser::DeclGroupPtrTy ADecl;
      66                 : 
                    28134: branch 1 taken
                     2236: branch 2 taken
      67            32606:   while (!P.ParseTopLevelDecl(ADecl)) {  // Not end of file.
      68                 :     // If we got a null return and something *was* parsed, ignore it.  This
      69                 :     // is due to a top-level semicolon, an action override, or a parse error
      70                 :     // skipping something.
                    26237: branch 1 taken
                     1897: branch 2 taken
      71            28134:     if (ADecl)
      72            26237:       Consumer->HandleTopLevelDecl(ADecl.getAsVal<DeclGroupRef>());
      73                 :   };
      74                 :   // Check for any pending objective-c implementation decl.
                       15: branch 2 taken
                     2236: branch 3 taken
      75             4487:   while ((ADecl = P.RetrievePendingObjCImpDecl()))
      76               15:     Consumer->HandleTopLevelDecl(ADecl.getAsVal<DeclGroupRef>());
      77                 : 
      78                 :   // Process any TopLevelDecls generated by #pragma weak.
                       15: branch 0 taken
                     2236: branch 1 taken
      79             2251:   for (llvm::SmallVector<Decl*,2>::iterator
      80             2236:         I = S.WeakTopLevelDecls().begin(),
      81             2236:         E = S.WeakTopLevelDecls().end(); I != E; ++I)
      82               15:     Consumer->HandleTopLevelDecl(DeclGroupRef(*I));
      83                 : 
      84             2236:   Consumer->HandleTranslationUnit(Ctx);
      85                 : 
                       35: branch 0 taken
                     2201: branch 1 taken
      86             2236:   if (ExternalSemaSource *ESS =
      87             2236:         dyn_cast_or_null<ExternalSemaSource>(Ctx.getExternalSource()))
      88               35:     ESS->ForgetSema();
      89                 : 
                       44: branch 1 taken
                     2192: branch 2 taken
      90             2236:   if (SemaConsumer *SC = dyn_cast<SemaConsumer>(Consumer))
      91               44:     SC->ForgetSema();
      92                 : 
                        2: branch 0 taken
                     2234: branch 1 taken
      93             2236:   if (PrintStats) {
      94                2:     fprintf(stderr, "\nSTATISTICS:\n");
      95                2:     P.getActions().PrintStats();
      96                2:     Ctx.PrintStats();
      97                2:     Decl::PrintStats();
      98                2:     Stmt::PrintStats();
      99                2:     Consumer->PrintStats();
     100             2236:   }
     101             2236: }

Generated: 2010-02-10 01:31 by zcov