zcov: / lib/Frontend/ASTMerge.cpp


Files: 1 Branches Taken: 50.0% 17 / 34
Generated: 2010-02-10 01:31 Branches Executed: 70.6% 24 / 34
Line Coverage: 79.1% 34 / 43


Programs: 1 Runs 2897


       1                 : //===-- ASTMerge.cpp - AST Merging Frontent Action --------------*- C++ -*-===//
       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                 : #include "clang/Frontend/ASTUnit.h"
      10                 : #include "clang/Frontend/CompilerInstance.h"
      11                 : #include "clang/Frontend/FrontendActions.h"
      12                 : #include "clang/AST/ASTContext.h"
      13                 : #include "clang/AST/ASTDiagnostic.h"
      14                 : #include "clang/AST/ASTImporter.h"
      15                 : 
      16                 : using namespace clang;
      17                 : 
      18                 : ASTConsumer *ASTMergeAction::CreateASTConsumer(CompilerInstance &CI,
      19                1:                                                llvm::StringRef InFile) {
      20                1:   return AdaptedAction->CreateASTConsumer(CI, InFile);
      21                 : }
      22                 : 
      23                 : bool ASTMergeAction::BeginSourceFileAction(CompilerInstance &CI,
      24                1:                                            llvm::StringRef Filename) {
      25                 :   // FIXME: This is a hack. We need a better way to communicate the
      26                 :   // AST file, compiler instance, and file name than member variables
      27                 :   // of FrontendAction.
      28                1:   AdaptedAction->setCurrentFile(getCurrentFile(), takeCurrentASTUnit());
      29                1:   AdaptedAction->setCompilerInstance(&CI);
      30                1:   return AdaptedAction->BeginSourceFileAction(CI, Filename);
      31                 : }
      32                 : 
      33                1: void ASTMergeAction::ExecuteAction() {
      34                1:   CompilerInstance &CI = getCompilerInstance();
      35                 :   CI.getDiagnostics().SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
      36                1:                                        &CI.getASTContext());
                        2: branch 3 taken
                        0: branch 4 not taken
                        2: branch 5 taken
                        1: branch 6 taken
      37                5:   for (unsigned I = 0, N = ASTFiles.size(); I != N; ++I) {
      38                2:     Diagnostic ASTDiags(CI.getDiagnostics().getClient());
      39                 :     
      40                 :     ASTUnit *Unit = ASTUnit::LoadFromPCHFile(ASTFiles[I], ASTDiags,
      41                2:                                              false, true);
                        0: branch 0 not taken
                        2: branch 1 taken
      42                2:     if (!Unit)
      43                0:       continue;
      44                 : 
      45                 :     ASTDiags.SetArgToStringFn(&FormatASTNodeDiagnosticArgument,
      46                2:                               &Unit->getASTContext());
      47                 :     ASTImporter Importer(CI.getASTContext(), 
      48                 :                          CI.getFileManager(),
      49                 :                          CI.getDiagnostics(),
      50                 :                          Unit->getASTContext(), 
      51                 :                          Unit->getFileManager(),
      52                2:                          ASTDiags);
      53                 : 
      54                2:     TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl();
                        8: branch 3 taken
                        2: branch 4 taken
      55               12:     for (DeclContext::decl_iterator D = TU->decls_begin(), 
      56                2:                                  DEnd = TU->decls_end();
      57                 :          D != DEnd; ++D) {
      58                 :       // FIXME: We only merge variables whose names start with x. Why
      59                 :       // would anyone want anything else?
                        6: branch 2 taken
                        2: branch 3 taken
      60                8:       if (VarDecl *VD = dyn_cast<VarDecl>(*D))
                        6: branch 1 taken
                        0: branch 2 not taken
                        6: branch 5 taken
                        0: branch 6 not taken
                        6: branch 7 taken
                        0: branch 8 not taken
      61                6:         if (VD->getIdentifier() && 
      62                 :             *VD->getIdentifier()->getNameStart() == 'x') {
      63                6:           Decl *Merged = Importer.Import(VD);
      64                 :           (void)Merged;
      65                 :         }
      66                 :     }
      67                 : 
                        2: branch 0 taken
                        0: branch 1 not taken
      68                2:     delete Unit;
      69                 :   }
      70                 : 
      71                 : 
      72                1:   return AdaptedAction->ExecuteAction();
      73                 : }
      74                 : 
      75                1: void ASTMergeAction::EndSourceFileAction() {
      76                1:   return AdaptedAction->EndSourceFileAction();
      77                 : }
      78                 : 
      79                 : ASTMergeAction::ASTMergeAction(FrontendAction *AdaptedAction,
      80                1:                                std::string *ASTFiles, unsigned NumASTFiles)
      81                1:   : AdaptedAction(AdaptedAction), ASTFiles(ASTFiles, ASTFiles + NumASTFiles) {
                        0: branch 0 not taken
                        1: branch 1 taken
                        0: branch 3 not taken
                        0: branch 4 not taken
      82                1:   assert(AdaptedAction && "ASTMergeAction needs an action to adapt");
      83                1: }
      84                 : 
      85                1: ASTMergeAction::~ASTMergeAction() { 
                        1: branch 0 taken
                        0: branch 1 not taken
                        1: branch 3 taken
                        1: branch 4 taken
                        0: branch 6 not taken
                        0: branch 7 not taken
      86                1:   delete AdaptedAction;
                        1: branch 2 taken
                        0: branch 3 not taken
                        0: branch 7 not taken
                        0: branch 8 not taken
                        0: branch 12 not taken
                        0: branch 13 not taken
      87                1: }
      88                 : 
      89                1: bool ASTMergeAction::usesPreprocessorOnly() const {
      90                1:   return AdaptedAction->usesPreprocessorOnly();
      91                 : }
      92                 : 
      93                0: bool ASTMergeAction::usesCompleteTranslationUnit() {
      94                0:   return AdaptedAction->usesCompleteTranslationUnit();
      95                 : }
      96                 : 
      97                0: bool ASTMergeAction::hasPCHSupport() const {
      98                0:   return AdaptedAction->hasPCHSupport();
      99                 : }
     100                 : 
     101                0: bool ASTMergeAction::hasASTSupport() const {
     102                0:   return AdaptedAction->hasASTSupport();
     103                 : }
     104                 : 
     105                0: bool ASTMergeAction::hasCodeCompletionSupport() const {
     106                0:   return AdaptedAction->hasCodeCompletionSupport();
     107                 : }

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