OpenSDN source code
t_generator Class Referenceabstract

#include <t_generator.h>

Inheritance diagram for t_generator:
Collaboration diagram for t_generator:

Public Member Functions

 t_generator (t_program *program)
 
virtual ~t_generator ()
 
virtual void generate_program ()
 
const t_program * get_program () const
 
void generate_docstring_comment (std::ofstream &out, const std::string &comment_start, const std::string &line_prefix, const std::string &contents, const std::string &comment_end)
 
virtual std::string escape_string (const std::string &in) const
 
std::string get_escaped_string (t_const_value *constval)
 

Static Public Member Functions

static bool is_valid_namespace (const std::string &sub_namespace)
 
static t_type * get_true_type (t_type *type)
 

Protected Member Functions

virtual void init_generator ()
 
virtual void close_generator ()
 
virtual void generate_consts (std::vector< t_const * > consts)
 
virtual void generate_typedef (t_typedef *ttypedef)=0
 
virtual void generate_enum (t_enum *tenum)=0
 
virtual void generate_const (t_const *tconst)
 
virtual void generate_struct (t_struct *tstruct)=0
 
virtual void generate_service (t_service *tservice)=0
 
virtual void generate_xception (t_struct *txception)
 
virtual std::string get_program_name (t_program *tprogram)
 
virtual std::string get_service_name (t_service *tservice)
 
virtual std::string get_out_dir () const
 
std::string tmp (std::string name)
 
void indent_up ()
 
void indent_down ()
 
std::string indent ()
 
std::ostream & indent (std::ostream &os)
 
std::string capitalize (std::string in)
 
std::string decapitalize (std::string in)
 
std::string lowercase (std::string in)
 
std::string uppercase (std::string in)
 
std::string underscore (std::string in)
 
std::string camelcase (std::string in)
 

Protected Attributes

t_program * program_
 
std::string program_name_
 
std::string service_name_
 
std::string out_dir_base_
 
std::map< char, std::string > escape_
 

Private Attributes

int indent_
 
int tmp_
 

Detailed Description

Base class for a thrift code generator. This class defines the basic routines for code generation and contains the top level method that dispatches code generation across various components.

Definition at line 40 of file t_generator.h.

Constructor & Destructor Documentation

◆ t_generator()

t_generator::t_generator ( t_program *  program)
inline

Definition at line 42 of file t_generator.h.

Here is the call graph for this function:

◆ ~t_generator()

virtual t_generator::~t_generator ( )
inlinevirtual

Definition at line 54 of file t_generator.h.

Member Function Documentation

◆ camelcase()

std::string t_generator::camelcase ( std::string  in)
inlineprotected

Transforms a string with words separated by underscores to a camel case equivalent e.g. a_multi_word -> aMultiWord some_name -> someName name -> name

Definition at line 247 of file t_generator.h.

Here is the call graph for this function:

◆ capitalize()

std::string t_generator::capitalize ( std::string  in)
inlineprotected

Capitalization helpers

Definition at line 203 of file t_generator.h.

◆ close_generator()

virtual void t_generator::close_generator ( )
inlineprotectedvirtual

Reimplemented in t_xsd_generator, t_py_generator, t_cpp_generator, and t_c_generator.

Definition at line 101 of file t_generator.h.

◆ decapitalize()

std::string t_generator::decapitalize ( std::string  in)
inlineprotected

Definition at line 207 of file t_generator.h.

◆ escape_string()

string t_generator::escape_string ( const std::string &  in) const
virtual

Escape string to use one in generated sources.

Definition at line 90 of file t_generator.cc.

◆ generate_const()

virtual void t_generator::generate_const ( t_const *  tconst)
inlineprotectedvirtual

Reimplemented in t_py_generator, t_html_generator, and t_doc_generator.

Definition at line 111 of file t_generator.h.

◆ generate_consts()

void t_generator::generate_consts ( std::vector< t_const * >  consts)
protectedvirtual

Reimplemented in t_cpp_generator.

Definition at line 103 of file t_generator.cc.

◆ generate_docstring_comment()

void t_generator::generate_docstring_comment ( std::ofstream &  out,
const std::string &  comment_start,
const std::string &  line_prefix,
const std::string &  contents,
const std::string &  comment_end 
)

Definition at line 110 of file t_generator.cc.

◆ generate_enum()

virtual void t_generator::generate_enum ( t_enum *  tenum)
protectedpure virtual

◆ generate_program()

void t_generator::generate_program ( )
virtual

Framework generator method that iterates over all the parts of a program and performs general actions. This is implemented by the base class and should not normally be overwritten in the subclasses.

Top level program generation function. Calls the generator subclass methods for preparing file streams etc. then iterates over all the parts of the program to perform the correct actions.

Parameters
programThe thrift program to compile into C++ source

Reimplemented in t_html_generator, and t_doc_generator.

Definition at line 33 of file t_generator.cc.

◆ generate_service()

virtual void t_generator::generate_service ( t_service *  tservice)
protectedpure virtual

◆ generate_struct()

virtual void t_generator::generate_struct ( t_struct *  tstruct)
protectedpure virtual

◆ generate_typedef()

virtual void t_generator::generate_typedef ( t_typedef *  ttypedef)
protectedpure virtual

Pure virtual methods implemented by the generator subclasses.

Implemented in t_xsd_generator, t_py_generator, t_html_generator, t_doc_generator, t_cpp_generator, and t_c_generator.

◆ generate_xception()

virtual void t_generator::generate_xception ( t_struct *  txception)
inlineprotectedvirtual

Reimplemented in t_py_generator, t_cpp_generator, and t_c_generator.

Definition at line 116 of file t_generator.h.

Here is the call graph for this function:

◆ get_escaped_string()

std::string t_generator::get_escaped_string ( t_const_value *  constval)
inline

Definition at line 89 of file t_generator.h.

Here is the call graph for this function:

◆ get_out_dir()

virtual std::string t_generator::get_out_dir ( ) const
inlineprotectedvirtual

Get the current output directory

Definition at line 151 of file t_generator.h.

Here is the call graph for this function:

◆ get_program()

const t_program* t_generator::get_program ( ) const
inline

Definition at line 63 of file t_generator.h.

◆ get_program_name()

virtual std::string t_generator::get_program_name ( t_program *  tprogram)
inlineprotectedvirtual

Method to get the program name, may be overridden

Definition at line 128 of file t_generator.h.

Here is the call graph for this function:

◆ get_service_name()

virtual std::string t_generator::get_service_name ( t_service *  tservice)
inlineprotectedvirtual

Method to get the service name, may be overridden

Definition at line 135 of file t_generator.h.

Here is the call graph for this function:

◆ get_true_type()

static t_type* t_generator::get_true_type ( t_type *  type)
inlinestatic

Get the true type behind a series of typedefs.

Definition at line 271 of file t_generator.h.

◆ indent() [1/2]

std::string t_generator::indent ( )
inlineprotected

Indentation print function

Definition at line 184 of file t_generator.h.

◆ indent() [2/2]

std::ostream& t_generator::indent ( std::ostream &  os)
inlineprotected

Indentation utility wrapper

Definition at line 196 of file t_generator.h.

Here is the call graph for this function:

◆ indent_down()

void t_generator::indent_down ( )
inlineprotected

Definition at line 177 of file t_generator.h.

◆ indent_up()

void t_generator::indent_up ( )
inlineprotected

Indentation level modifiers

Definition at line 173 of file t_generator.h.

◆ init_generator()

virtual void t_generator::init_generator ( )
inlineprotectedvirtual

Optional methods that may be imlemented by subclasses to take necessary steps at the beginning or end of code generation.

Reimplemented in t_xsd_generator, t_py_generator, t_cpp_generator, and t_c_generator.

Definition at line 100 of file t_generator.h.

◆ is_valid_namespace()

static bool t_generator::is_valid_namespace ( const std::string &  sub_namespace)
inlinestatic

check whether sub-namespace declaraction is used by generator. e.g. allow namespace py.twisted bar to specify namespace to use when -gen py:twisted is specified. Will be called with subnamespace, i.e. is_valid_namespace("twisted") will be called for the above example.

Definition at line 79 of file t_generator.h.

◆ lowercase()

std::string t_generator::lowercase ( std::string  in)
inlineprotected

Definition at line 211 of file t_generator.h.

◆ tmp()

std::string t_generator::tmp ( std::string  name)
inlineprotected

Creates a unique temporary variable name, which is just "name" with a number appended to it (i.e. name35)

Definition at line 163 of file t_generator.h.

◆ underscore()

std::string t_generator::underscore ( std::string  in)
inlineprotected

Transforms a camel case string to an equivalent one separated by underscores e.g. aMultiWord -> a_multi_word someName -> some_name CamelCase -> camel_case name -> name Name -> name

Definition at line 231 of file t_generator.h.

◆ uppercase()

std::string t_generator::uppercase ( std::string  in)
inlineprotected

Definition at line 217 of file t_generator.h.

Member Data Documentation

◆ escape_

std::map<char, std::string> t_generator::escape_
protected

Map of characters to escape in string literals.

Definition at line 309 of file t_generator.h.

◆ indent_

int t_generator::indent_
private

Current code indentation level

Definition at line 315 of file t_generator.h.

◆ out_dir_base_

std::string t_generator::out_dir_base_
protected

Output type-specifc directory name ("gen-*")

Definition at line 304 of file t_generator.h.

◆ program_

t_program* t_generator::program_
protected

The program being generated

Definition at line 279 of file t_generator.h.

◆ program_name_

std::string t_generator::program_name_
protected

Quick accessor for formatted program name that is currently being generated.

Definition at line 285 of file t_generator.h.

◆ service_name_

std::string t_generator::service_name_
protected

Quick accessor for formatted service name that is currently being generated.

Definition at line 291 of file t_generator.h.

◆ tmp_

int t_generator::tmp_
private

Temporary variable counter, for making unique variable names

Definition at line 320 of file t_generator.h.


The documentation for this class was generated from the following files: