aboutsummaryrefslogtreecommitdiff
path: root/build2/cc/parser.hxx
blob: d52ddc904a365f047212a903529e9475e6f3ee63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// file      : build2/cc/parser.hxx -*- C++ -*-
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#ifndef BUILD2_CC_PARSER_HXX
#define BUILD2_CC_PARSER_HXX

#include <build2/types.hxx>
#include <build2/utility.hxx>

#include <build2/diagnostics.hxx>

namespace build2
{
  namespace cc
  {
    // Extract (currently module) information from a preprocessed C/C++
    // source.
    //
    struct translation_unit
    {
      string         module_name;      // If not empty, then a module unit.
      bool           module_interface; // If true, then module interface unit.
      vector<string> module_imports;   // Imported modules.
    };

    struct token;
    class lexer;

    class parser
    {
    public:
      parser (): fail ("error", &name_), warn ("warning", &name_) {}

      translation_unit
      parse (istream&, const path& name);

    private:
      void
      parse_import (token&);

      void
      parse_module (token&, bool);

      string
      parse_module_name (token&);

    private:
      const path* name_;

      const fail_mark  fail;
      const basic_mark warn;

      lexer* l_;
      translation_unit* u_;
    };
  }
}

#endif // BUILD2_CC_PARSER_HXX