CUBRID Engine  latest
load_driver.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * load_driver.hpp - interface for loader lexer and parser
21  */
22 
23 #ifndef _LOAD_DRIVER_HPP_
24 #define _LOAD_DRIVER_HPP_
25 
26 #if !defined (SERVER_MODE) && !defined (SA_MODE)
27 #error Wrong module
28 #endif // not SERVER_MODE and not SA_MODE
29 
30 #include "load_common.hpp"
31 #include "load_grammar.hpp"
32 #include "load_scanner.hpp"
33 #include "load_semantic_helper.hpp"
34 
35 #include <istream>
36 
37 namespace cubload
38 {
39 
40  /*
41  * cubload::driver
42  *
43  * description
44  * A mediator class used by both lexer & grammar.
45  * The main purpose of the class is to offer interaction between flex scanner/bison parser classes and main code
46  * The class offers as well an entry point for parsing input files/string and to collects syntax errors if any.
47  * Be aware that copy c-tor and assignment operator are disable since a reference is passed to scanner and parser
48  *
49  * how to use
50  * cubload::driver driver;
51  * std::ifstream input (file_to_parse, std::fstream::in);
52  * // optionally input variable can be a string. e.g. std::string input = "";
53  *
54  * int parse_result = driver.parse (input);
55  * if (parse_result != 0)
56  * {
57  * // handle the error
58  * }
59  * else
60  * {
61  * // parsing was done successfully
62  * }
63  */
64  class driver
65  {
66  public:
67  driver ();
68 
69  // Copy constructor (disabled).
70  driver (const driver &copy) = delete;
71 
72  // Copy assignment operator (disabled)
73  driver &operator= (const driver &other) = delete;
74 
75  // Destructor
76  ~driver ();
77 
78  void initialize (class_installer *cls_installer, object_loader *obj_loader, error_handler *error_handler);
79  bool is_initialized ();
80 
81  void clear ();
82 
83  // Parse functions
84  int parse (std::istream &iss, int line_offset = 0);
85 
89  error_handler &get_error_handler ();
90  scanner &get_scanner ();
91  void update_start_line ();
92  int get_start_line ();
93 
94  private:
98  error_handler *m_error_handler;
101 
103  }; // class driver
104 
105 } // namespace cubload
106 
107 #endif /* _LOAD_DRIVER_HPP_ */
int parse(std::istream &iss, int line_offset=0)
Definition: load_driver.cpp:83
object_loader * m_object_loader
Definition: load_driver.hpp:97
error_handler * m_error_handler
Definition: load_driver.hpp:98
semantic_helper & get_semantic_helper()
scanner & get_scanner()
bool is_initialized()
Definition: load_driver.cpp:77
semantic_helper m_semantic_helper
Definition: load_driver.hpp:99
class_installer & get_class_installer()
Definition: load_driver.cpp:96
object_loader & get_object_loader()
void initialize(class_installer *cls_installer, object_loader *obj_loader, error_handler *error_handler)
Definition: load_driver.cpp:65
driver & operator=(const driver &other)=delete
scanner * m_scanner
Definition: load_driver.hpp:95
class_installer * m_class_installer
Definition: load_driver.hpp:96
error_handler & get_error_handler()
void update_start_line()