MaterialX 1.39.2
Loading...
Searching...
No Matches
MdlSyntax Class Reference

Syntax class for MDL (Material Definition Language) More...

#include <MdlSyntax.h>

Inheritance diagram for MdlSyntax:
Syntax

Public Member Functions

const string & getConstantQualifier () const override
 Get the qualifier used when declaring constant variables.
 
const string & getUniformQualifier () const override
 Get the qualifier used when declaring uniform variables.
 
const string & getSourceFileExtension () const override
 Return the file extension used for source code files in this language.
 
string getArrayTypeSuffix (TypeDesc type, const Value &value) const override
 Override to return array type suffix.
 
string getArrayVariableSuffix (TypeDesc, const Value &) const override
 Override to indicate array variables have no array suffix.
 
TypeDesc getEnumeratedType (const string &value) const
 Get an type description for an enumeration based on member value.
 
bool remapEnumeration (const string &value, TypeDesc type, const string &enumNames, std::pair< TypeDesc, ValuePtr > &result) const override
 Given an input specification attempt to remap this to an enumeration which is accepted by the shader generator.
 
void makeValidName (string &name) const override
 Modify the given name string to remove any invalid characters or tokens.
 
string modifyPortName (const string &word) const
 To avoid collisions with reserved names in MDL, input and output names are prefixed.
 
string replaceSourceCodeMarkers (const string &nodeName, const string &soureCode, std::function< string(const string &)> lambda) const
 Replaces all markers in a source code string indicated by {{...}}.
 
const string & getMdlVersionSuffixMarker () const
 Get the MDL language versing marker: {{MDL_VERSION_SUFFIX}}.
 
- Public Member Functions inherited from Syntax
void registerTypeSyntax (TypeDesc type, TypeSyntaxPtr syntax)
 Register syntax handling for a data type.
 
void registerTypeSyntax (const TypeDesc *type, TypeSyntaxPtr syntax)
 
void registerReservedWords (const StringSet &names)
 Register names that are reserved words not to be used by a code generator when naming variables and functions.
 
void registerInvalidTokens (const StringMap &tokens)
 Register a set string replacements for disallowed tokens for a code generator when naming variables and functions.
 
virtual void registerStructTypeDescSyntax ()
 
const StringSetgetReservedWords () const
 Returns a set of names that are reserved words for this language syntax.
 
const StringMapgetInvalidTokens () const
 Returns a mapping from disallowed tokens to replacement strings for this language syntax.
 
const TypeSyntaxgetTypeSyntax (TypeDesc type) const
 Returns the type syntax object for a named type.
 
const TypeSyntaxgetTypeSyntax (const TypeDesc *type) const
 
const vector< TypeSyntaxPtr > & getTypeSyntaxes () const
 Returns an array of all registered type syntax objects.
 
const string & getTypeName (TypeDesc type) const
 Returns the name syntax of the given type.
 
const string & getTypeName (const TypeDesc *type) const
 
virtual string getOutputTypeName (TypeDesc type) const
 Returns the type name in an output context.
 
string getOutputTypeName (const TypeDesc *type) const
 
const string & getTypeAlias (TypeDesc type) const
 Returns a type alias for the given data type.
 
const string & getTypeAlias (const TypeDesc *type) const
 
const string & getTypeDefinition (TypeDesc type) const
 Returns a custom type definition if needed for the given data type.
 
const string & getTypeDefinition (const TypeDesc *type) const
 
const string & getDefaultValue (TypeDesc type, bool uniform=false) const
 Returns the default value string for the given type.
 
const string & getDefaultValue (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.
 
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.
 
virtual const string & getInputQualifier () const
 Returns a type qualifier to be used when declaring types for input variables.
 
virtual const string & getOutputQualifier () const
 Returns a type qualifier to be used when declaring types for output variables.
 
virtual const string & getNewline () const
 Return the characters used for a newline.
 
virtual const string & getIndentation () const
 Return the characters used for a single indentation level.
 
virtual const string & getStringQuote () const
 Return the characters used to begin/end a string definition.
 
virtual const string & getIncludeStatement () const
 Return the string pattern used for a file include statement.
 
virtual const string & getSingleLineComment () const
 Return the characters used for single line comment.
 
virtual const string & getBeginMultiLineComment () const
 Return the characters used to begin a multi line comments block.
 
virtual const string & getEndMultiLineComment () const
 Return the characters used to end a multi line comments block.
 
string getArrayTypeSuffix (const TypeDesc *type, const Value &value) const
 
string getArrayVariableSuffix (const TypeDesc *type, const Value &value) const
 
virtual bool typeSupported (const TypeDesc *type) const
 Query if given type is supported in the syntax.
 
virtual void makeIdentifier (string &name, IdentifierMap &identifiers) const
 Make sure the given name is a unique identifier, updating it if needed to make it unique.
 
virtual string getVariableName (const string &name, TypeDesc type, IdentifierMap &identifiers) const
 Create a unique identifier for the given variable name and type.
 
string getVariableName (const string &name, const TypeDesc *type, IdentifierMap &identifiers) const
 

Static Public Member Functions

static SyntaxPtr create ()
 

Static Public Attributes

static const string CONST_QUALIFIER
 
static const string UNIFORM_QUALIFIER
 
static const string SOURCE_FILE_EXTENSION
 
static const StringVec VECTOR2_MEMBERS
 
static const StringVec VECTOR3_MEMBERS
 
static const StringVec VECTOR4_MEMBERS
 
static const StringVec COLOR3_MEMBERS
 
static const StringVec COLOR4_MEMBERS
 
static const StringVec ADDRESSMODE_MEMBERS
 
static const StringVec COORDINATESPACE_MEMBERS
 
static const StringVec FILTERLOOKUPMODE_MEMBERS
 
static const StringVec FILTERTYPE_MEMBERS
 
static const StringVec DISTRIBUTIONTYPE_MEMBERS
 
static const StringVec SCATTER_MODE_MEMBERS
 
static const string PORT_NAME_PREFIX
 
- Static Public Attributes inherited from Syntax
static const string NEWLINE
 Constants with commonly used strings.
 
static const string SEMICOLON
 
static const string COMMA
 

Additional Inherited Members

- Public Types inherited from Syntax
enum  Punctuation { PARENTHESES , CURLY_BRACKETS , SQUARE_BRACKETS , DOUBLE_SQUARE_BRACKETS }
 Punctuation types.
 
- Protected Member Functions inherited from Syntax
 Syntax ()
 Protected constructor.
 
virtual StructTypeSyntaxPtr createStructSyntax (const string &structTypeName, const string &defaultValue, const string &uniformDefaultValue, const string &typeAlias, const string &typeDefinition) const
 
- Protected Attributes inherited from Syntax
vector< TypeSyntaxPtr_typeSyntaxes
 
std::unordered_map< TypeDesc, size_t, TypeDesc::Hasher_typeSyntaxIndexByType
 
StringSet _reservedWords
 
StringMap _invalidTokens
 
- Static Protected Attributes inherited from Syntax
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

Syntax class for MDL (Material Definition Language)

Member Function Documentation

◆ getArrayTypeSuffix()

string getArrayTypeSuffix ( TypeDesc type,
const Value & value ) const
overridevirtual

Override to return array type suffix.

Reimplemented from Syntax.

◆ getArrayVariableSuffix()

string getArrayVariableSuffix ( TypeDesc ,
const Value &  ) const
inlineoverridevirtual

Override to indicate array variables have no array suffix.

Reimplemented from Syntax.

◆ getConstantQualifier()

const string & getConstantQualifier ( ) const
inlineoverridevirtual

Get the qualifier used when declaring constant variables.

Derived classes must define this method.

Implements Syntax.

◆ getSourceFileExtension()

const string & getSourceFileExtension ( ) const
inlineoverridevirtual

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

Implements Syntax.

◆ getUniformQualifier()

const string & getUniformQualifier ( ) const
inlineoverridevirtual

Get the qualifier used when declaring uniform variables.

Default implementation returns empty string and derived syntax classes should override this method.

Reimplemented from Syntax.

◆ makeValidName()

void makeValidName ( string & name) const
overridevirtual

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

Reimplemented from Syntax.

◆ remapEnumeration()

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

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.

Reimplemented from Syntax.

◆ replaceSourceCodeMarkers()

string replaceSourceCodeMarkers ( const string & nodeName,
const string & soureCode,
std::function< string(const string &)> lambda ) const

Replaces all markers in a source code string indicated by {{...}}.

The replacement is defined by a callback function.


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