LIBINT 2.9.0
Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
libint2::CodeContext Class Referenceabstract

CodeContext provides context for generating code. More...

#include <context.h>

Inheritance diagram for libint2::CodeContext:
Inheritance graph
[legend]

Public Member Functions

const std::shared_ptr< CompilationParameters > & cparams () const
 Returns the CompilationParameters used to create this context.
 
void turn_comments (bool on)
 turn comments on and off (the default is on)
 
bool comments_on () const
 returns true if to print comments
 
virtual void reset ()
 this function resets the context to be used for the next source file
 
virtual std::string code_prefix () const =0
 produces prefix to function declarations or definitions
 
virtual std::string code_postfix () const =0
 produces postfix to function declarations or definitions
 
virtual std::string copyright () const =0
 copyright() returns the copyright statement
 
virtual std::string std_header () const =0
 std_header() returns declarations necessary for every source file
 
virtual std::string std_function_header () const =0
 std_function_header() returns declarations and definitions necessary for every function
 
virtual std::string label_to_name (const std::string &label) const =0
 label_to_name(label) converts label to a name valid within the context of the language
 
virtual std::string declare (const std::string &type, const std::string &name) const =0
 declare returns a statement which declares variable named 'name' of type 'type'
 
virtual std::string declare_v (const std::string &type, const std::string &name, const std::string &nelem) const =0
 declare_v returns a statement which declares a vector 'name' of 'nelem' elements of type 'type'
 
virtual std::string decldef (const std::string &type, const std::string &name, const std::string &value)=0
 decldef returns a statement which declares variable named 'name' of type 'type' and defines its value to be 'value'
 
virtual std::string assign (const std::string &name, const std::string &value)=0
 assign returns a statement which assigns variable 'value' to variable 'name'
 
virtual std::string accumulate (const std::string &name, const std::string &value)=0
 accumulate returns a statement which assigns variable 'value' to variable 'name'
 
virtual std::string assign_binary_expr (const std::string &name, const std::string &left, const std::string &oper, const std::string &right)=0
 assign_binary_expr returns a statement which assigns binary expression 'left oper right' to variable 'name'
 
virtual std::string assign_ternary_expr (const std::string &name, const std::string &arg1, const std::string &oper1, const std::string &arg2, const std::string &oper2, const std::string &arg3)=0
 assign_ternary_expr returns a statement which assigns ternary expression 'arg1 oper1 arg2 oper2 arg3' to variable 'name'
 
virtual std::string accumulate_binary_expr (const std::string &name, const std::string &left, const std::string &oper, const std::string &right)=0
 accumulate_binary_expr returns a statement which accumulates binary expression 'left oper right' to variable 'name'
 
virtual std::string accumulate_ternary_expr (const std::string &name, const std::string &arg1, const std::string &oper1, const std::string &arg2, const std::string &oper2, const std::string &arg3)=0
 accumulate_ternary_expr returns a statement which accumulates ternary expression 'arg1 oper1 arg2 oper2 arg3' to variable 'name'
 
virtual std::string stack_address (const DGVertex::Address &a) const =0
 converts an address on the stack to its string representation
 
virtual std::string macro_define (const std::string &name) const =0
 #define a macro
 
virtual std::string macro_define (const std::string &name, const std::string &value) const =0
 #define a macro
 
virtual std::string macro_if (const std::string &name) const =0
 #if macro
 
virtual std::string macro_ifdef (const std::string &name) const =0
 #ifdef macro
 
virtual std::string macro_endif () const =0
 #endif
 
virtual std::string comment (const std::string &statement) const =0
 comment(statement) returns commented statement
 
virtual std::string open_block () const =0
 open a code block
 
virtual std::string close_block () const =0
 close a code block
 
virtual std::string end_of_stat () const =0
 end a statement
 
virtual std::string value_to_pointer (const std::string &val) const =0
 converts a value to a pointer
 
virtual std::shared_ptr< ForLoopfor_loop (std::string &varname, const std::shared_ptr< Entity > &less_than, const std::shared_ptr< Entity > &start_at=std::shared_ptr< Entity >(new CTimeEntity< int >(0))) const =0
 returns a ForLoop object.
 
template<typename T >
std::string unique_name () const
 unique_name<T> returns a unique name for a variable of type T
 
template<typename T >
std::string type_name () const
 type_name<T> returns name for type T
 
virtual std::string inteval_type_name (const std::string &task) const =0
 returns the name of the evaluator type for task 'task'
 
virtual std::string inteval_spec_type_name (const std::string &task) const =0
 returns the name of the specialized evaluator type for task 'task'
 
virtual std::string inteval_gen_type_name () const =0
 returns the name of the generic evaluator type (works for any task)
 
virtual std::string const_modifier () const =0
 returns the modifier for constant variables
 
virtual std::string mutable_modifier () const =0
 returns the modifier for mutable variables
 
template<>
std::string type_name () const
 
template<>
std::string type_name () const
 
template<>
std::string type_name () const
 
template<>
std::string type_name () const
 
template<>
std::string type_name () const
 
template<>
std::string type_name () const
 
template<>
std::string type_name () const
 
template<>
std::string type_name () const
 

Protected Member Functions

 CodeContext (const std::shared_ptr< CompilationParameters > &cparams)
 Lone constructor takes CompilationParams.
 
virtual std::string unique_fp_name () const =0
 generates a unique name for a floating-point variable
 
virtual std::string unique_int_name () const =0
 generates a unique name for an integer
 
unsigned int next_fp_index () const
 next fp index
 
unsigned int next_int_index () const
 next int index
 
virtual std::string void_type () const =0
 returns name of void type
 
virtual std::string int_type () const =0
 returns name of integer type
 
virtual std::string size_type () const =0
 returns name of array size type (e.g. size_t)
 
virtual std::string fp_type () const =0
 returns name of floating-point type
 
virtual std::string ptr_fp_type () const =0
 returns name of pointer to floating-point type
 

Static Protected Member Functions

static std::string replace_chars (const std::string &S, const std::string &From, const std::string &To)
 replaces every appearance of From with To in S
 

Detailed Description

CodeContext provides context for generating code.

Member Function Documentation

◆ accumulate()

virtual std::string libint2::CodeContext::accumulate ( const std::string & name,
const std::string & value )
pure virtual

accumulate returns a statement which assigns variable 'value' to variable 'name'

Implemented in libint2::CppCodeContext.

◆ accumulate_binary_expr()

virtual std::string libint2::CodeContext::accumulate_binary_expr ( const std::string & name,
const std::string & left,
const std::string & oper,
const std::string & right )
pure virtual

accumulate_binary_expr returns a statement which accumulates binary expression 'left oper right' to variable 'name'

Implemented in libint2::CppCodeContext.

◆ accumulate_ternary_expr()

virtual std::string libint2::CodeContext::accumulate_ternary_expr ( const std::string & name,
const std::string & arg1,
const std::string & oper1,
const std::string & arg2,
const std::string & oper2,
const std::string & arg3 )
pure virtual

accumulate_ternary_expr returns a statement which accumulates ternary expression 'arg1 oper1 arg2 oper2 arg3' to variable 'name'

Implemented in libint2::CppCodeContext.

◆ assign()

virtual std::string libint2::CodeContext::assign ( const std::string & name,
const std::string & value )
pure virtual

assign returns a statement which assigns variable 'value' to variable 'name'

Implemented in libint2::CppCodeContext.

◆ assign_binary_expr()

virtual std::string libint2::CodeContext::assign_binary_expr ( const std::string & name,
const std::string & left,
const std::string & oper,
const std::string & right )
pure virtual

assign_binary_expr returns a statement which assigns binary expression 'left oper right' to variable 'name'

Implemented in libint2::CppCodeContext.

◆ assign_ternary_expr()

virtual std::string libint2::CodeContext::assign_ternary_expr ( const std::string & name,
const std::string & arg1,
const std::string & oper1,
const std::string & arg2,
const std::string & oper2,
const std::string & arg3 )
pure virtual

assign_ternary_expr returns a statement which assigns ternary expression 'arg1 oper1 arg2 oper2 arg3' to variable 'name'

Implemented in libint2::CppCodeContext.

◆ close_block()

virtual std::string libint2::CodeContext::close_block ( ) const
pure virtual

close a code block

Implemented in libint2::CppCodeContext.

◆ code_postfix()

virtual std::string libint2::CodeContext::code_postfix ( ) const
pure virtual

produces postfix to function declarations or definitions

Implemented in libint2::CppCodeContext.

◆ code_prefix()

virtual std::string libint2::CodeContext::code_prefix ( ) const
pure virtual

produces prefix to function declarations or definitions

Implemented in libint2::CppCodeContext.

◆ comment()

virtual std::string libint2::CodeContext::comment ( const std::string & statement) const
pure virtual

comment(statement) returns commented statement

Implemented in libint2::CppCodeContext.

◆ copyright()

virtual std::string libint2::CodeContext::copyright ( ) const
pure virtual

copyright() returns the copyright statement

Implemented in libint2::CppCodeContext.

◆ declare()

virtual std::string libint2::CodeContext::declare ( const std::string & type,
const std::string & name ) const
pure virtual

declare returns a statement which declares variable named 'name' of type 'type'

Implemented in libint2::CppCodeContext.

◆ declare_v()

virtual std::string libint2::CodeContext::declare_v ( const std::string & type,
const std::string & name,
const std::string & nelem ) const
pure virtual

declare_v returns a statement which declares a vector 'name' of 'nelem' elements of type 'type'

Implemented in libint2::CppCodeContext.

◆ decldef()

virtual std::string libint2::CodeContext::decldef ( const std::string & type,
const std::string & name,
const std::string & value )
pure virtual

decldef returns a statement which declares variable named 'name' of type 'type' and defines its value to be 'value'

Implemented in libint2::CppCodeContext.

◆ end_of_stat()

virtual std::string libint2::CodeContext::end_of_stat ( ) const
pure virtual

end a statement

Implemented in libint2::CppCodeContext.

◆ for_loop()

virtual std::shared_ptr< ForLoop > libint2::CodeContext::for_loop ( std::string & varname,
const std::shared_ptr< Entity > & less_than,
const std::shared_ptr< Entity > & start_at = std::shared_ptr< Entity >(new CTimeEntity< int >(0)) ) const
pure virtual

returns a ForLoop object.

Implemented in libint2::CppCodeContext.

◆ inteval_gen_type_name()

virtual std::string libint2::CodeContext::inteval_gen_type_name ( ) const
pure virtual

returns the name of the generic evaluator type (works for any task)

Implemented in libint2::CppCodeContext.

◆ inteval_spec_type_name()

virtual std::string libint2::CodeContext::inteval_spec_type_name ( const std::string & task) const
pure virtual

returns the name of the specialized evaluator type for task 'task'

Implemented in libint2::CppCodeContext.

◆ inteval_type_name()

virtual std::string libint2::CodeContext::inteval_type_name ( const std::string & task) const
pure virtual

returns the name of the evaluator type for task 'task'

Implemented in libint2::CppCodeContext.

◆ label_to_name()

virtual std::string libint2::CodeContext::label_to_name ( const std::string & label) const
pure virtual

label_to_name(label) converts label to a name valid within the context of the language

Implemented in libint2::CppCodeContext.

◆ macro_define() [1/2]

virtual std::string libint2::CodeContext::macro_define ( const std::string & name) const
pure virtual

#define a macro

Implemented in libint2::CppCodeContext.

◆ macro_define() [2/2]

virtual std::string libint2::CodeContext::macro_define ( const std::string & name,
const std::string & value ) const
pure virtual

#define a macro

Implemented in libint2::CppCodeContext.

◆ macro_endif()

virtual std::string libint2::CodeContext::macro_endif ( ) const
pure virtual

#endif

Implemented in libint2::CppCodeContext.

◆ macro_if()

virtual std::string libint2::CodeContext::macro_if ( const std::string & name) const
pure virtual

#if macro

Implemented in libint2::CppCodeContext.

◆ macro_ifdef()

virtual std::string libint2::CodeContext::macro_ifdef ( const std::string & name) const
pure virtual

#ifdef macro

Implemented in libint2::CppCodeContext.

◆ open_block()

virtual std::string libint2::CodeContext::open_block ( ) const
pure virtual

open a code block

Implemented in libint2::CppCodeContext.

◆ stack_address()

virtual std::string libint2::CodeContext::stack_address ( const DGVertex::Address & a) const
pure virtual

converts an address on the stack to its string representation

Implemented in libint2::CppCodeContext.

◆ std_function_header()

virtual std::string libint2::CodeContext::std_function_header ( ) const
pure virtual

std_function_header() returns declarations and definitions necessary for every function

Implemented in libint2::CppCodeContext.

◆ std_header()

virtual std::string libint2::CodeContext::std_header ( ) const
pure virtual

std_header() returns declarations necessary for every source file

Implemented in libint2::CppCodeContext.

◆ value_to_pointer()

virtual std::string libint2::CodeContext::value_to_pointer ( const std::string & val) const
pure virtual

converts a value to a pointer

Implemented in libint2::CppCodeContext.


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