replicode
preprocessor.h
Go to the documentation of this file.
1 // preprocessor.h
2 //
3 // Author: Thor List, Eric Nivel
4 //
5 // BSD license:
6 // Copyright (c) 2010, Thor List, Eric Nivel
7 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are met:
10 //
11 // - Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // - Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 // - Neither the name of Thor List or Eric Nivel nor the
17 // names of their contributors may be used to endorse or promote products
18 // derived from this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
24 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef preprocessor_h
32 #define preprocessor_h
33 
34 #include "replistruct.h"
35 #include "segments.h"
36 #include <istream>
37 #include <sstream>
38 #include <fstream>
39 #include <list>
40 
41 using namespace r_code;
42 
43 namespace r_comp {
45 {
46 public:
48 
49  Preprocessor();
50  ~Preprocessor();
51  RepliStruct *process(const char *file, // if an ifstream, stream must be open.
52  std::string &error, // set when function fails, e.g. returns false.
53  Metadata *metadata = NULL); // process will fill class_image, or use the exiting one if NULL.
54 
55 private:
56  enum ClassType
57  {
58  T_CLASS = 0,
59  T_SYS_CLASS = 1,
60  T_SET = 2
61  };
62 
63  void instantiateClass(RepliStruct *tpl_class, std::vector<RepliStruct *> &tpl_args, std::string &instantiated_class_name);
64  bool isSet(std::string className);
65  bool isTemplateClass(RepliStruct* replistruct);
66  void getMember(std::vector<StructureMember> &members, RepliStruct *m, std::list<RepliStruct *> &tpl_args, bool instantiate);
67  void getMembers(RepliStruct *s, std::vector<StructureMember> &members, std::list<RepliStruct *> &tpl_args, bool instantiate);
68  ReturnType getReturnType(RepliStruct *s);
69  void initialize(Metadata *metadata); // init definition_segment
70 
72  uint16_t m_classOpcode; // shared with sys_classes
73  std::unordered_map<std::string, RepliStruct *> m_templateClasses;
74 };
75 }
76 
77 
78 #endif
ReturnType
Definition: structure_member.h:48
#define dll_export
Definition: dll.h:44
Metadata * m_metadata
Definition: preprocessor.h:71
Definition: atom.cpp:36
Definition: segments.h:59
uint16_t m_classOpcode
Definition: preprocessor.h:72
Definition: preprocessor.h:44
ClassType
Definition: preprocessor.h:56
std::unordered_map< std::string, RepliStruct * > m_templateClasses
Definition: preprocessor.h:73
RepliStruct * root
Definition: preprocessor.h:47
Definition: image.h:41
Definition: replistruct.h:14
dll_export r_comp::Preprocessor Preprocessor
Definition: init.cpp:67