OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
src/contrail-common/sandesh/compiler/main.cc File Reference
#include <cassert>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include <string>
#include <algorithm>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <limits.h>
#include "globals.h"
#include "main.h"
#include "parse/t_program.h"
#include "parse/t_scope.h"
#include "generate/t_generator.h"
#include "version.h"
Include dependency graph for src/contrail-common/sandesh/compiler/main.cc:

Go to the source code of this file.

Functions

char * saferealpath (const char *path, char *resolved_path)
 
void yyerror (const char *fmt,...)
 
void pdebug (const char *fmt,...)
 
void pverbose (const char *fmt,...)
 
void pwarning (int level, const char *fmt,...)
 
void failure (const char *fmt,...)
 
string program_name (string filename)
 
string directory_name (string filename)
 
string include_file (string filename)
 
void clear_doctext ()
 
void reset_program_doctext_info ()
 
void declare_valid_program_doctext ()
 
char * clean_up_doctext (char *doctext)
 
void dump_docstrings (t_program *program)
 
void generate_all_fingerprints (t_program *program)
 
void version ()
 
void usage ()
 
void validate_const_rec (std::string name, t_type *type, t_const_value *value)
 
void validate_const_type (t_const *c)
 
void validate_field_value (t_field *field, t_const_value *cv)
 
bool validate_throws (t_struct *throws)
 
void parse (t_program *program, t_program *parent_program)
 
void generate (t_program *program, const vector< string > &generator_strings)
 

Variables

t_programg_program
 
t_typeg_type_void
 
t_typeg_type_string
 
t_typeg_type_binary
 
t_typeg_type_slist
 
t_typeg_type_bool
 
t_typeg_type_byte
 
t_typeg_type_i16
 
t_typeg_type_i32
 
t_typeg_type_i64
 
t_typeg_type_double
 
t_scopeg_scope
 
t_scopeg_parent_scope
 
string g_parent_prefix
 
PARSE_MODE g_parse_mode
 
string g_curdir
 
string g_curpath
 
vector< string > g_incl_searchpath
 
bool g_cpp_use_include_prefix = false
 
int g_debug = 0
 
int g_strict = 127
 
int g_warn = 1
 
int g_verbose = 0
 
char * g_time_str
 
char * g_doctext
 
int g_doctext_lineno
 
char * g_program_doctext_candidate
 
int g_program_doctext_lineno = 0
 
PROGDOCTEXT_STATUS g_program_doctext_status = INVALID
 
int g_allow_neg_field_keys
 
int g_allow_64bit_consts = 0
 
bool gen_cpp = false
 
bool gen_dense = false
 
bool gen_java = false
 
bool gen_javabean = false
 
bool gen_rb = false
 
bool gen_py = false
 
bool gen_py_newstyle = false
 
bool gen_xsd = false
 
bool gen_php = false
 
bool gen_phpi = false
 
bool gen_phps = true
 
bool gen_phpa = false
 
bool gen_phpo = false
 
bool gen_rest = false
 
bool gen_perl = false
 
bool gen_erl = false
 
bool gen_ocaml = false
 
bool gen_hs = false
 
bool gen_cocoa = false
 
bool gen_csharp = false
 
bool gen_delphi = false
 
bool gen_st = false
 
bool gen_recurse = false
 
static bool dump_docs = false
 

Function Documentation

char* clean_up_doctext ( char *  doctext)

Cleans up text commonly found in doxygen-like comments

Warning: if you mix tabs and spaces in a non-uniform way, you will get what you deserve.

Definition at line 437 of file src/contrail-common/sandesh/compiler/main.cc.

void clear_doctext ( )

Clears any previously stored doctext string. Also prints a warning if we are discarding information.

Definition at line 397 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

void declare_valid_program_doctext ( )

We are sure the program doctext candidate is really the program doctext.

Definition at line 421 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

string directory_name ( string  filename)

Gets the directory path of a filename

Definition at line 337 of file src/contrail-common/sandesh/compiler/main.cc.

void dump_docstrings ( t_program program)

Dumps docstrings to stdout Only works for top-level definitions and the whole program doc (i.e., not enum constants, struct fields, or functions.

Definition at line 573 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

void failure ( const char *  fmt,
  ... 
)

Prints a failure message and exits

Parameters
fmtC format string followed by additional arguments

Definition at line 309 of file src/contrail-common/sandesh/compiler/main.cc.

void generate ( t_program program,
const vector< string > &  generator_strings 
)

Generate code

Definition at line 1014 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

void generate_all_fingerprints ( t_program program)

Call generate_fingerprint for every structure and enum.

Definition at line 660 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

string include_file ( string  filename)

Finds the appropriate file path for the given filename

Definition at line 349 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

void parse ( t_program program,
t_program parent_program 
)

Parses a program

Definition at line 949 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

void pdebug ( const char *  fmt,
  ... 
)

Prints a debug message from the parser.

Parameters
fmtC format string followed by additional arguments

Definition at line 260 of file src/contrail-common/sandesh/compiler/main.cc.

string program_name ( string  filename)

Converts a string filename into a thrift program name

Definition at line 322 of file src/contrail-common/sandesh/compiler/main.cc.

void pverbose ( const char *  fmt,
  ... 
)

Prints a verbose output mode message

Parameters
fmtC format string followed by additional arguments

Definition at line 277 of file src/contrail-common/sandesh/compiler/main.cc.

void pwarning ( int  level,
const char *  fmt,
  ... 
)

Prints a warning message

Parameters
fmtC format string followed by additional arguments

Definition at line 292 of file src/contrail-common/sandesh/compiler/main.cc.

void reset_program_doctext_info ( )

Reset program doctext information after processing a file

Definition at line 408 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

char* saferealpath ( const char *  path,
char *  resolved_path 
)

MinGW doesn't have realpath, so use fallback implementation in that case, otherwise this just calls through to realpath

Definition at line 227 of file src/contrail-common/sandesh/compiler/main.cc.

void usage ( )

Diplays the usage message and then exits with an error code.

Definition at line 719 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

void validate_const_rec ( std::string  name,
t_type type,
t_const_value value 
)

You know, when I started working on Thrift I really thought it wasn't going to become a programming language because it was just a generator and it wouldn't need runtime type information and all that jazz. But then we decided to add constants, and all of a sudden that means runtime type validation and inference, except the "runtime" is the code generator runtime.

Definition at line 767 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

void validate_const_type ( t_const c)

Check the type of the parsed const information against its declared type

Definition at line 921 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

void validate_field_value ( t_field field,
t_const_value cv 
)

Check the type of a default value assigned to a field.

Definition at line 928 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

bool validate_throws ( t_struct throws)

Check that all the elements of a throws block are actually exceptions.

Definition at line 935 of file src/contrail-common/sandesh/compiler/main.cc.

Here is the call graph for this function:

void version ( )

Prints the version number

Definition at line 708 of file src/contrail-common/sandesh/compiler/main.cc.

void yyerror ( const char *  fmt,
  ... 
)

Report an error to the user. This is called yyerror for historical reasons (lex and yacc expect the error reporting routine to be called this). Call this function to report any errors to the user. yyerror takes printf style arguments.

Parameters
fmtC format string followed by additional arguments

Definition at line 240 of file src/contrail-common/sandesh/compiler/main.cc.

Variable Documentation

bool dump_docs = false
static

Set to true to debug docstring parsing

Definition at line 566 of file src/contrail-common/sandesh/compiler/main.cc.

int g_allow_64bit_consts = 0

Whether or not 64-bit constants will generate a warning.

Definition at line 194 of file src/contrail-common/sandesh/compiler/main.cc.

int g_allow_neg_field_keys

Whether or not negative field keys are accepted.

Definition at line 189 of file src/contrail-common/sandesh/compiler/main.cc.

bool g_cpp_use_include_prefix = false

Should C++ include statements use path prefixes for other thrift-generated header files

Definition at line 142 of file src/contrail-common/sandesh/compiler/main.cc.

string g_curdir

Current directory of file being parsed

Definition at line 126 of file src/contrail-common/sandesh/compiler/main.cc.

string g_curpath

Current file being parsed

Definition at line 131 of file src/contrail-common/sandesh/compiler/main.cc.

int g_debug = 0

Global debug state

Definition at line 147 of file src/contrail-common/sandesh/compiler/main.cc.

char* g_doctext

The last parsed doctext comment.

Definition at line 172 of file src/contrail-common/sandesh/compiler/main.cc.

int g_doctext_lineno

The location of the last parsed doctext comment.

Definition at line 177 of file src/contrail-common/sandesh/compiler/main.cc.

vector<string> g_incl_searchpath

Search path for inclusions

Definition at line 136 of file src/contrail-common/sandesh/compiler/main.cc.

string g_parent_prefix

Prefix for putting types in parent scope

Definition at line 116 of file src/contrail-common/sandesh/compiler/main.cc.

t_scope* g_parent_scope

Parent scope to also parse types

Definition at line 111 of file src/contrail-common/sandesh/compiler/main.cc.

PARSE_MODE g_parse_mode

Parsing pass

Definition at line 121 of file src/contrail-common/sandesh/compiler/main.cc.

t_program* g_program

Global program tree

Definition at line 62 of file src/contrail-common/sandesh/compiler/main.cc.

char* g_program_doctext_candidate

The First doctext comment

Definition at line 182 of file src/contrail-common/sandesh/compiler/main.cc.

int g_program_doctext_lineno = 0
PROGDOCTEXT_STATUS g_program_doctext_status = INVALID
t_scope* g_scope

Global scope

Definition at line 106 of file src/contrail-common/sandesh/compiler/main.cc.

int g_strict = 127

Strictness level

Definition at line 152 of file src/contrail-common/sandesh/compiler/main.cc.

char* g_time_str

Global time string

Definition at line 167 of file src/contrail-common/sandesh/compiler/main.cc.

t_type* g_type_binary

Definition at line 70 of file src/contrail-common/sandesh/compiler/main.cc.

t_type* g_type_bool

Definition at line 72 of file src/contrail-common/sandesh/compiler/main.cc.

t_type* g_type_byte

Definition at line 73 of file src/contrail-common/sandesh/compiler/main.cc.

t_type* g_type_double

Definition at line 77 of file src/contrail-common/sandesh/compiler/main.cc.

t_type* g_type_i16

Definition at line 74 of file src/contrail-common/sandesh/compiler/main.cc.

t_type* g_type_i32

Definition at line 75 of file src/contrail-common/sandesh/compiler/main.cc.

t_type* g_type_i64

Definition at line 76 of file src/contrail-common/sandesh/compiler/main.cc.

t_type* g_type_slist

Definition at line 71 of file src/contrail-common/sandesh/compiler/main.cc.

t_type* g_type_string

Definition at line 69 of file src/contrail-common/sandesh/compiler/main.cc.

t_type* g_type_void

Global types

Definition at line 68 of file src/contrail-common/sandesh/compiler/main.cc.

int g_verbose = 0

Verbose output

Definition at line 162 of file src/contrail-common/sandesh/compiler/main.cc.

int g_warn = 1

Warning level

Definition at line 157 of file src/contrail-common/sandesh/compiler/main.cc.

bool gen_cocoa = false
bool gen_cpp = false

Flags to control code generation

Definition at line 199 of file src/contrail-common/sandesh/compiler/main.cc.

bool gen_csharp = false
bool gen_delphi = false
bool gen_dense = false
bool gen_erl = false
bool gen_hs = false
bool gen_java = false
bool gen_javabean = false
bool gen_ocaml = false
bool gen_perl = false
bool gen_php = false
bool gen_phpa = false
bool gen_phpi = false
bool gen_phpo = false
bool gen_phps = true
bool gen_py = false
bool gen_py_newstyle = false
bool gen_rb = false
bool gen_recurse = false
bool gen_rest = false
bool gen_st = false
bool gen_xsd = false