HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Syntax Class Referenceabstract

#include <Syntax.h>

+ Inheritance diagram for Syntax:

Public Types

enum  Punctuation { PARENTHESES, CURLY_BRACKETS, SQUARE_BRACKETS, DOUBLE_SQUARE_BRACKETS }
 Punctuation types. More...
 

Public Member Functions

virtual ~Syntax ()
 
void registerTypeSyntax (TypeDesc type, TypeSyntaxPtr syntax)
 
void registerTypeSyntax (const TypeDesc *type, TypeSyntaxPtr syntax)
 
void registerReservedWords (const StringSet &names)
 
void registerInvalidTokens (const StringMap &tokens)
 
const StringSetgetReservedWords () const
 Returns a set of names that are reserved words for this language syntax. More...
 
const StringMapgetInvalidTokens () const
 Returns a mapping from disallowed tokens to replacement strings for this language syntax. More...
 
const TypeSyntaxgetTypeSyntax (TypeDesc type) const
 
const TypeSyntaxgetTypeSyntax (const TypeDesc *type) const
 
const vector< TypeSyntaxPtr > & getTypeSyntaxes () const
 Returns an array of all registered type syntax objects. More...
 
TypeDesc getType (const string &name) const
 Return a type description for the given type name. More...
 
const stringgetTypeName (TypeDesc type) const
 Returns the name syntax of the given type. More...
 
const stringgetTypeName (const TypeDesc *type) const
 
virtual string getOutputTypeName (TypeDesc type) const
 Returns the type name in an output context. More...
 
string getOutputTypeName (const TypeDesc *type) const
 
const stringgetTypeAlias (TypeDesc type) const
 
const stringgetTypeAlias (const TypeDesc *type) const
 
const stringgetTypeDefinition (TypeDesc type) const
 
const stringgetTypeDefinition (const TypeDesc *type) const
 
const stringgetDefaultValue (TypeDesc type, bool uniform=false) const
 Returns the default value string for the given type. More...
 
const stringgetDefaultValue (const TypeDesc *type, bool uniform=false) const
 
virtual string getValue (TypeDesc type, const Value &value, bool uniform=false) const
 Returns the value string for a given type and value object. More...
 
string getValue (const TypeDesc *type, const Value &value, bool uniform=false) const
 
virtual string getValue (const ShaderPort *port, bool uniform=false) const
 Returns the value string for a given shader port object. More...
 
virtual const stringgetInputQualifier () const
 
virtual const stringgetOutputQualifier () const
 
virtual const stringgetConstantQualifier () const =0
 
virtual const stringgetUniformQualifier () const
 
virtual const stringgetNewline () const
 Return the characters used for a newline. More...
 
virtual const stringgetIndentation () const
 Return the characters used for a single indentation level. More...
 
virtual const stringgetStringQuote () const
 Return the characters used to begin/end a string definition. More...
 
virtual const stringgetIncludeStatement () const
 Return the string pattern used for a file include statement. More...
 
virtual const stringgetSingleLineComment () const
 Return the characters used for single line comment. More...
 
virtual const stringgetBeginMultiLineComment () const
 Return the characters used to begin a multi line comments block. More...
 
virtual const stringgetEndMultiLineComment () const
 Return the characters used to end a multi line comments block. More...
 
virtual const stringgetSourceFileExtension () const =0
 Return the file extension used for source code files in this language. More...
 
virtual string getArrayTypeSuffix (TypeDesc, const Value &) const
 Return the array suffix to use for declaring an array type. More...
 
string getArrayTypeSuffix (const TypeDesc *type, const Value &value) const
 
virtual string getArrayVariableSuffix (TypeDesc type, const Value &value) const
 Return the array suffix to use for declaring an array variable. More...
 
string getArrayVariableSuffix (const TypeDesc *type, const Value &value) const
 
virtual bool typeSupported (const TypeDesc *type) const
 
virtual void makeValidName (string &name) const
 Modify the given name string to remove any invalid characters or tokens. More...
 
virtual void makeIdentifier (string &name, IdentifierMap &identifiers) const
 
virtual string getVariableName (const string &name, TypeDesc type, IdentifierMap &identifiers) const
 
string getVariableName (const string &name, const TypeDesc *type, IdentifierMap &identifiers) const
 
virtual bool remapEnumeration (const string &value, TypeDesc type, const string &enumNames, std::pair< TypeDesc, ValuePtr > &result) const
 
virtual StructTypeSyntaxPtr createStructSyntax (const string &structTypeName, const string &defaultValue, const string &uniformDefaultValue, const string &typeAlias, const string &typeDefinition) const
 

Static Public Attributes

static const string NEWLINE
 Constants with commonly used strings. More...
 
static const string SEMICOLON
 
static const string COMMA
 

Protected Member Functions

 Syntax (TypeSystemPtr typeSystem)
 Protected constructor. More...
 

Protected Attributes

TypeSystemPtr _typeSystem
 
vector< TypeSyntaxPtr_typeSyntaxes
 
std::unordered_map< TypeDesc,
size_t, TypeDesc::Hasher
_typeSyntaxIndexByType
 
StringSet _reservedWords
 
StringMap _invalidTokens
 

Static Protected Attributes

static const string INDENTATION
 
static const string STRING_QUOTE
 
static const string INCLUDE_STATEMENT
 
static const string SINGLE_LINE_COMMENT
 
static const string BEGIN_MULTI_LINE_COMMENT
 
static const string END_MULTI_LINE_COMMENT
 
static const
std::unordered_map< char,
size_t > 
CHANNELS_MAPPING
 

Detailed Description

Base class for syntax objects used by shader generators to emit code with correct syntax for each language.

Definition at line 43 of file Syntax.h.

Member Enumeration Documentation

Punctuation types.

Enumerator
PARENTHESES 
CURLY_BRACKETS 
SQUARE_BRACKETS 
DOUBLE_SQUARE_BRACKETS 

Definition at line 47 of file Syntax.h.

Constructor & Destructor Documentation

virtual Syntax::~Syntax ( )
inlinevirtual

Definition at line 56 of file Syntax.h.

Syntax::Syntax ( TypeSystemPtr  typeSystem)
protected

Protected constructor.

Member Function Documentation

virtual StructTypeSyntaxPtr Syntax::createStructSyntax ( const string structTypeName,
const string defaultValue,
const string uniformDefaultValue,
const string typeAlias,
const string typeDefinition 
) const
virtual

Reimplemented in GlslSyntax.

virtual string Syntax::getArrayTypeSuffix ( TypeDesc  ,
const Value  
) const
inlinevirtual

Return the array suffix to use for declaring an array type.

Reimplemented in MdlSyntax.

Definition at line 163 of file Syntax.h.

string Syntax::getArrayTypeSuffix ( const TypeDesc type,
const Value value 
) const
inline

Definition at line 164 of file Syntax.h.

virtual string Syntax::getArrayVariableSuffix ( TypeDesc  type,
const Value value 
) const
virtual

Return the array suffix to use for declaring an array variable.

Reimplemented in MdlSyntax.

string Syntax::getArrayVariableSuffix ( const TypeDesc type,
const Value value 
) const
inline

Definition at line 168 of file Syntax.h.

virtual const string& Syntax::getBeginMultiLineComment ( ) const
inlinevirtual

Return the characters used to begin a multi line comments block.

Definition at line 154 of file Syntax.h.

virtual const string& Syntax::getConstantQualifier ( ) const
pure virtual

Get the qualifier used when declaring constant variables. Derived classes must define this method.

Implemented in MdlSyntax, GlslSyntax, MslSyntax, and OslSyntax.

const string& Syntax::getDefaultValue ( TypeDesc  type,
bool  uniform = false 
) const

Returns the default value string for the given type.

const string& Syntax::getDefaultValue ( const TypeDesc type,
bool  uniform = false 
) const
inline

Definition at line 110 of file Syntax.h.

virtual const string& Syntax::getEndMultiLineComment ( ) const
inlinevirtual

Return the characters used to end a multi line comments block.

Definition at line 157 of file Syntax.h.

virtual const string& Syntax::getIncludeStatement ( ) const
inlinevirtual

Return the string pattern used for a file include statement.

Definition at line 148 of file Syntax.h.

virtual const string& Syntax::getIndentation ( ) const
inlinevirtual

Return the characters used for a single indentation level.

Definition at line 142 of file Syntax.h.

virtual const string& Syntax::getInputQualifier ( ) const
inlinevirtual

Returns a type qualifier to be used when declaring types for input variables. Default implementation returns empty string and derived syntax classes should override this method.

Reimplemented in GlslSyntax, MslSyntax, and VkSyntax.

Definition at line 122 of file Syntax.h.

const StringMap& Syntax::getInvalidTokens ( ) const
inline

Returns a mapping from disallowed tokens to replacement strings for this language syntax.

Definition at line 77 of file Syntax.h.

virtual const string& Syntax::getNewline ( ) const
inlinevirtual

Return the characters used for a newline.

Definition at line 139 of file Syntax.h.

virtual const string& Syntax::getOutputQualifier ( ) const
inlinevirtual

Returns a type qualifier to be used when declaring types for output variables. Default implementation returns empty string and derived syntax classes should override this method.

Reimplemented in GlslSyntax, MslSyntax, and OslSyntax.

Definition at line 127 of file Syntax.h.

virtual string Syntax::getOutputTypeName ( TypeDesc  type) const
virtual

Returns the type name in an output context.

Reimplemented in MslSyntax.

string Syntax::getOutputTypeName ( const TypeDesc type) const
inline

Definition at line 96 of file Syntax.h.

const StringSet& Syntax::getReservedWords ( ) const
inline

Returns a set of names that are reserved words for this language syntax.

Definition at line 74 of file Syntax.h.

virtual const string& Syntax::getSingleLineComment ( ) const
inlinevirtual

Return the characters used for single line comment.

Definition at line 151 of file Syntax.h.

virtual const string& Syntax::getSourceFileExtension ( ) const
pure virtual

Return the file extension used for source code files in this language.

Implemented in MdlSyntax, GlslSyntax, MslSyntax, and OslSyntax.

virtual const string& Syntax::getStringQuote ( ) const
inlinevirtual

Return the characters used to begin/end a string definition.

Definition at line 145 of file Syntax.h.

TypeDesc Syntax::getType ( const string name) const
inline

Return a type description for the given type name.

Definition at line 88 of file Syntax.h.

const string& Syntax::getTypeAlias ( TypeDesc  type) const

Returns a type alias for the given data type. If not used returns an empty string.

const string& Syntax::getTypeAlias ( const TypeDesc type) const
inline

Definition at line 101 of file Syntax.h.

const string& Syntax::getTypeDefinition ( TypeDesc  type) const

Returns a custom type definition if needed for the given data type. If not used returns an empty string.

const string& Syntax::getTypeDefinition ( const TypeDesc type) const
inline

Definition at line 106 of file Syntax.h.

const string& Syntax::getTypeName ( TypeDesc  type) const

Returns the name syntax of the given type.

const string& Syntax::getTypeName ( const TypeDesc type) const
inline

Definition at line 92 of file Syntax.h.

const TypeSyntax& Syntax::getTypeSyntax ( TypeDesc  type) const

Returns the type syntax object for a named type. Throws an exception if a type syntax is not defined for the given type.

const TypeSyntax& Syntax::getTypeSyntax ( const TypeDesc type) const
inline

Definition at line 82 of file Syntax.h.

const vector<TypeSyntaxPtr>& Syntax::getTypeSyntaxes ( ) const
inline

Returns an array of all registered type syntax objects.

Definition at line 85 of file Syntax.h.

virtual const string& Syntax::getUniformQualifier ( ) const
inlinevirtual

Get the qualifier used when declaring uniform variables. Default implementation returns empty string and derived syntax classes should override this method.

Reimplemented in MdlSyntax, GlslSyntax, and MslSyntax.

Definition at line 136 of file Syntax.h.

virtual string Syntax::getValue ( TypeDesc  type,
const Value value,
bool  uniform = false 
) const
virtual

Returns the value string for a given type and value object.

string Syntax::getValue ( const TypeDesc type,
const Value value,
bool  uniform = false 
) const
inline

Definition at line 114 of file Syntax.h.

virtual string Syntax::getValue ( const ShaderPort port,
bool  uniform = false 
) const
virtual

Returns the value string for a given shader port object.

virtual string Syntax::getVariableName ( const string name,
TypeDesc  type,
IdentifierMap identifiers 
) const
virtual

Create a unique identifier for the given variable name and type. The method is used for naming variables (inputs and outputs) in generated code. Derived classes can override this method to have a custom naming strategy. Default implementation adds a number suffix, or increases an existing number suffix, on the name string if there is a name collision.

string Syntax::getVariableName ( const string name,
const TypeDesc type,
IdentifierMap identifiers 
) const
inline

Definition at line 187 of file Syntax.h.

virtual void Syntax::makeIdentifier ( string name,
IdentifierMap identifiers 
) const
virtual

Make sure the given name is a unique identifier, updating it if needed to make it unique.

virtual void Syntax::makeValidName ( string name) const
virtual

Modify the given name string to remove any invalid characters or tokens.

Reimplemented in MdlSyntax.

void Syntax::registerInvalidTokens ( const StringMap tokens)

Register a set string replacements for disallowed tokens for a code generator when naming variables and functions. Multiple calls will add to the internal set of tokens.

void Syntax::registerReservedWords ( const StringSet names)

Register names that are reserved words not to be used by a code generator when naming variables and functions. Keywords, types, built-in functions etc. should be added to this set. Multiple calls will add to the internal set of names.

void Syntax::registerTypeSyntax ( TypeDesc  type,
TypeSyntaxPtr  syntax 
)

Register syntax handling for a data type. Required to be set for all supported data types.

void Syntax::registerTypeSyntax ( const TypeDesc type,
TypeSyntaxPtr  syntax 
)
inline

Definition at line 61 of file Syntax.h.

virtual bool Syntax::remapEnumeration ( const string value,
TypeDesc  type,
const string enumNames,
std::pair< TypeDesc, ValuePtr > &  result 
) const
virtual

Given an input specification attempt to remap this to an enumeration which is accepted by the shader generator. The enumeration may be converted to a different type than the input.

Parameters
valueThe value string to remap.
typeThe type of the value to remap,
enumNamesType enumeration names
resultEnumeration type and value (returned).
Returns
Return true if the remapping was successful.

Reimplemented in MdlSyntax, MslSyntax, and GlslSyntax.

virtual bool Syntax::typeSupported ( const TypeDesc type) const
virtual

Query if given type is supported in the syntax. By default all types are assumed to be supported.

Reimplemented in MslSyntax, and GlslSyntax.

Member Data Documentation

StringMap Syntax::_invalidTokens
protected

Definition at line 218 of file Syntax.h.

StringSet Syntax::_reservedWords
protected

Definition at line 217 of file Syntax.h.

vector<TypeSyntaxPtr> Syntax::_typeSyntaxes
protected

Definition at line 214 of file Syntax.h.

std::unordered_map<TypeDesc, size_t, TypeDesc::Hasher> Syntax::_typeSyntaxIndexByType
protected

Definition at line 215 of file Syntax.h.

TypeSystemPtr Syntax::_typeSystem
protected

Definition at line 213 of file Syntax.h.

const string Syntax::BEGIN_MULTI_LINE_COMMENT
staticprotected

Definition at line 224 of file Syntax.h.

const std::unordered_map<char, size_t> Syntax::CHANNELS_MAPPING
staticprotected

Definition at line 227 of file Syntax.h.

const string Syntax::COMMA
static

Definition at line 207 of file Syntax.h.

const string Syntax::END_MULTI_LINE_COMMENT
staticprotected

Definition at line 225 of file Syntax.h.

const string Syntax::INCLUDE_STATEMENT
staticprotected

Definition at line 222 of file Syntax.h.

const string Syntax::INDENTATION
staticprotected

Definition at line 220 of file Syntax.h.

const string Syntax::NEWLINE
static

Constants with commonly used strings.

Definition at line 205 of file Syntax.h.

const string Syntax::SEMICOLON
static

Definition at line 206 of file Syntax.h.

const string Syntax::SINGLE_LINE_COMMENT
staticprotected

Definition at line 223 of file Syntax.h.

const string Syntax::STRING_QUOTE
staticprotected

Definition at line 221 of file Syntax.h.


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