Graphite  Version 3
An experimental 3D geometry processing program
codegen.h
Go to the documentation of this file.
1 /*
2  * GXML/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000 Bruno Levy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * If you modify this software, you should include a notice giving the
20  * name of the person performing the modification, the date of modification,
21  * and the reason for such modification.
22  *
23  * Contact: Bruno Levy
24  *
25  * levy@loria.fr
26  *
27  * ISA Project
28  * LORIA, INRIA Lorraine,
29  * Campus Scientifique, BP 239
30  * 54506 VANDOEUVRE LES NANCY CEDEX
31  * FRANCE
32  *
33  * Note that the GNU General Public License does not permit incorporating
34  * the Software into proprietary programs.
35  */
36 
37 
38 #ifndef H_GOM_CODEGEN_CODEGEN_H
39 #define H_GOM_CODEGEN_CODEGEN_H
40 
41 #include <OGF/gom/common/common.h>
42 
43 #include <iostream>
44 #include <string>
45 #include <map>
46 #include <set>
47 
53 namespace OGF {
54 
55  class MetaType;
56  class MetaClass;
57  class MetaBuiltinType;
58  class MetaEnum;
59  class MetaMethod;
60  class MetaSignal;
61  class MetaConstructor;
62  class MetaInformation;
63  class CustomAttributes;
64  class MetaArg;
65  class Any;
66 
76  class GOM_API GomCodeGenerator {
77  public:
78 
83 
84 
96  void generate(
97  std::ostream& out, std::vector<MetaClass*> classes,
98  const std::string& package_name
99  );
100 
101  protected:
102 
111  void generate(MetaClass* type);
112 
121 
129  void generate_enum(MetaEnum* menum);
130 
140  void generate_class(MetaClass* mclass);
141 
148 
158 
166 
173  void generate_factory(MetaConstructor* constructor);
174 
186  const CustomAttributes* info, const std::string& variable_name,
187  bool is_pointer=true
188  );
189 
195  std::string stringify(const std::string& s);
196 
212  std::string stringify_default_value(const MetaArg* marg);
213 
219  std::string colons_to_underscores(const std::string& s);
220 
227  std::string method_adapter_name(MetaMethod* method);
228 
235  std::string factory_name(MetaConstructor* constructor);
236 
237  protected:
238 
244  std::ostream& out() {
245  return *out_;
246  }
247 
257  bool pass_by_value(const std::string& type_name);
258 
259  private:
260  std::ostream* out_;
261  std::set<std::string> pass_by_value_;
262  std::set<MetaClass*> to_generate_;
263  std::vector<MetaClass*> sorted_;
264  std::string package_name_;
265  };
266 
267 }
268 
269 #endif
Stores a set of custom attributes, i.e. name-value pairs attached to the objects.
Definition: meta_type.h:63
Generates C++ code to create the GOM meta information.
Definition: codegen.h:76
std::string factory_name(MetaConstructor *constructor)
Generates a C++ name for a factory from a MetaMethod.
void generate_attributes(const CustomAttributes *info, const std::string &variable_name, bool is_pointer=true)
Generates C++ code that creates the CustomAttributes associated with a language construct.
GomCodeGenerator()
GomCodeGenerator constructor.
std::string stringify_default_value(const MetaArg *marg)
Generates the code that computes an object that represents a default value.
void generate_method_adapter(MetaMethod *method)
Generates a method adapter.
std::string colons_to_underscores(const std::string &s)
Replaces all colons (":") with underscores ("_") in a string.
void generate_enum(MetaEnum *menum)
Generates C++ code that creates the meta information associated with an enum.
void generate_class(MetaClass *mclass)
Generates C++ code that creates the meta information associated with a class.
std::string method_adapter_name(MetaMethod *method)
Generates a C++ name for a method adapter from a MetaMethod.
void generate(std::ostream &out, std::vector< MetaClass * > classes, const std::string &package_name)
Generates C++ code to create the Meta information and adapters.
void generate_signal_adapter(MetaSignal *signal)
Generates a signal adapter.
std::string stringify(const std::string &s)
Adds double quotes to a string.
void generate(MetaClass *type)
Generates C++ code that creates the meta information associated with a class.
std::ostream & out()
Gets a reference to the output stream, where the generated C++ code is sent.
Definition: codegen.h:244
void generate_factory(MetaConstructor *constructor)
Generates a factory from a MetaConstructor.
bool pass_by_value(const std::string &type_name)
Tests whether objects of a given type should be passed by value or by reference.
void generate_method_adapter_arglist(MetaMethod *method)
Generates a method adapter.
void generate_builtin(MetaBuiltinType *mbuiltin)
Generates C++ code that creates the meta information associated with a builtin type.
The representation of the arguments in the Meta repository.
Definition: meta_arg.h:60
MetaType for builting types.
Definition: meta_builtin.h:55
The representation of a class in the Meta repository.
Definition: meta_class.h:64
The representation of a constructor in the Meta repository.
MetaType for enums.
Definition: meta_enum.h:56
The representation of a method in the Meta repository.
Definition: meta_method.h:72
The representation of a signal in the Meta repository.
Definition: meta_signal.h:54
Global Graphite namespace.
Definition: common.h:76
Definitions common to all include files in the gom library.