From a1f459f8446370704695919b3131653300866ee9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 25 May 2017 10:41:20 +0200 Subject: Implement parsing of C++ module declarations --- build2/cc/parser.hxx | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 build2/cc/parser.hxx (limited to 'build2/cc/parser.hxx') diff --git a/build2/cc/parser.hxx b/build2/cc/parser.hxx new file mode 100644 index 0000000..d52ddc9 --- /dev/null +++ b/build2/cc/parser.hxx @@ -0,0 +1,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 +#include + +#include + +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 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 -- cgit v1.1