1 //===- DependencyInfoParser.h -----------------------------------*- C++ -*-===//
2 //
3 // This source file is part of the Swift.org open source project
4 //
5 // Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
6 // Licensed under Apache License v2.0 with Runtime Library Exception
7 //
8 // See http://swift.org/LICENSE.txt for license information
9 // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLBUILD_CORE_DEPENDENCYINFOPARSER_H
14 #define LLBUILD_CORE_DEPENDENCYINFOPARSER_H
15 
16 #include "llbuild/Basic/LLVM.h"
17 
18 #include "llvm/ADT/StringRef.h"
19 
20 #include <cstdint>
21 
22 namespace llbuild {
23 namespace core {
24 
25 /// Interface for parsing the "dependency info" format used by Darwin tools.
26 class DependencyInfoParser {
27 public:
28   /// Delegate interface for parser behavior.
29   struct ParseActions {
30     virtual ~ParseActions();
31 
32     /// Called if an error is encountered in parsing the input.
33     ///
34     /// \param message A C-string text message including information on the
35     /// error.
36     ///
37     /// \param position The approximate position of the error in the input
38     /// buffer.
39     virtual void error(const char* message, uint64_t position) = 0;
40 
41     /// Called when the version information is found.
42     ///
43     /// There can only ever be one version info record in the file.
44     virtual void actOnVersion(StringRef) = 0;
45 
46     /// Called when an input is found.
47     virtual void actOnInput(StringRef) = 0;
48 
49     /// Called when an output is found.
50     virtual void actOnOutput(StringRef) = 0;
51 
52     /// Called when a missing file entry is found.
53     ///
54     /// These entries indicate a file which was looked for by the tool, but not
55     /// found, and can be used to track anti-dependencies.
56     virtual void actOnMissing(StringRef) = 0;
57   };
58 
59   StringRef data;
60   ParseActions& actions;
61 
62 public:
DependencyInfoParser(StringRef data,ParseActions & actions)63   DependencyInfoParser(StringRef data, ParseActions& actions)
64     : data(data), actions(actions) {}
65 
66   void parse();
67 };
68 
69 }
70 }
71 
72 #endif
73