6#ifndef MATERIALX_SYNTAX_H
7#define MATERIALX_SYNTAX_H
19MATERIALX_NAMESPACE_BEGIN
49 DOUBLE_SQUARE_BRACKETS
58 [[deprecated]]
void registerTypeSyntax(
const TypeDesc* type,
TypeSyntaxPtr syntax) { registerTypeSyntax(*type, syntax); }
79 [[deprecated]]
const TypeSyntax& getTypeSyntax(
const TypeDesc* type)
const {
return getTypeSyntax(*type); }
86 [[deprecated]]
const string& getTypeName(
const TypeDesc* type)
const {
return getTypeName(*type); }
90 [[deprecated]]
string getOutputTypeName(
const TypeDesc* type)
const {
return getOutputTypeName(*type); }
95 [[deprecated]]
const string& getTypeAlias(
const TypeDesc* type)
const {
return getTypeAlias(*type); }
100 [[deprecated]]
const string& getTypeDefinition(
const TypeDesc* type)
const {
return getTypeDefinition(*type); }
104 [[deprecated]]
const string& getDefaultValue(
const TypeDesc* type,
bool uniform =
false)
const {
return getDefaultValue(*type, uniform); }
108 [[deprecated]]
string getValue(
const TypeDesc* type,
const Value& value,
bool uniform =
false)
const {
return getValue(*type, value, uniform); }
133 virtual const string&
getNewline()
const {
return NEWLINE; };
158 [[deprecated]]
string getArrayTypeSuffix(
const TypeDesc* type,
const Value& value)
const {
return getArrayTypeSuffix(*type, value); }
162 [[deprecated]]
string getArrayVariableSuffix(
const TypeDesc* type,
const Value& value)
const {
return getArrayVariableSuffix(*type, value); }
181 [[deprecated]]
string getVariableName(
const string& name,
const TypeDesc* type,
IdentifierMap& identifiers)
const {
return getVariableName(name, *type, identifiers); }
191 std::pair<TypeDesc, ValuePtr>& result)
const;
195 static const string SEMICOLON;
196 static const string COMMA;
202 vector<TypeSyntaxPtr> _typeSyntaxes;
203 std::unordered_map<TypeDesc, size_t, TypeDesc::Hasher> _typeSyntaxIndexByType;
208 static const string INDENTATION;
209 static const string STRING_QUOTE;
210 static const string INCLUDE_STATEMENT;
211 static const string SINGLE_LINE_COMMENT;
212 static const string BEGIN_MULTI_LINE_COMMENT;
213 static const string END_MULTI_LINE_COMMENT;
215 static const std::unordered_map<char, size_t> CHANNELS_MAPPING;
226 const string&
getName()
const {
return _name; }
235 const string&
getDefaultValue(
bool uniform)
const {
return uniform ? _uniformDefaultValue : _defaultValue; }
251 TypeSyntax(
const string& name,
const string& defaultValue,
const string& uniformDefaultValue,
252 const string& typeAlias,
const string& typeDefinition,
const StringVec& members);
255 string _defaultValue;
256 string _uniformDefaultValue;
258 string _typeDefinition;
268 ScalarTypeSyntax(
const string& name,
const string& defaultValue,
const string& uniformDefaultValue,
269 const string& typeAlias = EMPTY_STRING,
const string& typeDefinition = EMPTY_STRING);
278 StringTypeSyntax(
const string& name,
const string& defaultValue,
const string& uniformDefaultValue,
279 const string& typeAlias = EMPTY_STRING,
const string& typeDefinition = EMPTY_STRING);
288 AggregateTypeSyntax(
const string& name,
const string& defaultValue,
const string& uniformDefaultValue,
289 const string& typeAlias = EMPTY_STRING,
const string& typeDefinition = EMPTY_STRING,
290 const StringVec& members = EMPTY_MEMBERS);
295MATERIALX_NAMESPACE_END
Definition element subclasses.
Library-wide includes and types.
std::set< string > StringSet
A set of strings.
Definition: Library.h:59
vector< string > StringVec
A vector of strings.
Definition: Library.h:55
std::unordered_map< string, string > StringMap
An unordered map with strings as both keys and values.
Definition: Library.h:57
Macros for declaring imported and exported symbols.
shared_ptr< TypeSyntax > TypeSyntaxPtr
Shared pointer to a TypeSyntax.
Definition: Syntax.h:31
shared_ptr< const Syntax > ConstSyntaxPtr
Shared pointer to a constant Syntax.
Definition: Syntax.h:29
shared_ptr< Syntax > SyntaxPtr
Shared pointer to a Syntax.
Definition: Syntax.h:27
std::unordered_map< string, size_t > IdentifierMap
Map holding identifier names and a counter for creating unique names from them.
Definition: Syntax.h:35
Type descriptor for a MaterialX data type.
Specialization of TypeSyntax for aggregate types.
Definition: Syntax.h:286
string getValue(const Value &value, bool uniform) const override
Returns a value formatted according to this type syntax.
Specialization of TypeSyntax for scalar types.
Definition: Syntax.h:266
string getValue(const Value &value, bool uniform) const override
Returns a value formatted according to this type syntax.
An input or output port on a ShaderNode.
Definition: ShaderNode.h:123
Specialization of TypeSyntax for string types.
Definition: Syntax.h:276
string getValue(const Value &value, bool uniform) const override
Returns a value formatted according to this type syntax.
Base class for syntax objects used by shader generators to emit code with correct syntax for each lan...
Definition: Syntax.h:41
virtual string getArrayVariableSuffix(TypeDesc type, const Value &value) const
Return the array suffix to use for declaring an array variable.
virtual string getArrayTypeSuffix(TypeDesc, const Value &) const
Return the array suffix to use for declaring an array type.
Definition: Syntax.h:157
virtual string getValue(const ShaderPort *port, bool uniform=false) const
Returns the value string for a given shader port object.
virtual const string & getBeginMultiLineComment() const
Return the characters used to begin a multi line comments block.
Definition: Syntax.h:148
virtual const string & getIndentation() const
Return the characters used for a single indentation level.
Definition: Syntax.h:136
virtual const string & getSourceFileExtension() const =0
Return the file extension used for source code files in this language.
const string & getDefaultValue(TypeDesc type, bool uniform=false) const
Returns the default value string for the given type.
const vector< TypeSyntaxPtr > & getTypeSyntaxes() const
Returns an array of all registered type syntax objects.
Definition: Syntax.h:82
virtual void makeValidName(string &name) const
Modify the given name string to remove any invalid characters or tokens.
const StringMap & getInvalidTokens() const
Returns a mapping from disallowed tokens to replacement strings for this language syntax.
Definition: Syntax.h:74
virtual const string & getStringQuote() const
Return the characters used to begin/end a string definition.
Definition: Syntax.h:139
virtual const string & getNewline() const
Return the characters used for a newline.
Definition: Syntax.h:133
const string & getTypeAlias(TypeDesc type) const
Returns a type alias for the given data type.
virtual bool typeSupported(const TypeDesc *type) const
Query if given type is suppored in the syntax.
const string & getTypeDefinition(TypeDesc type) const
Returns a custom type definition if needed for the given data type.
void registerReservedWords(const StringSet &names)
Register names that are reserved words not to be used by a code generator when naming variables and f...
Syntax()
Protected constructor.
virtual string getVariableName(const string &name, TypeDesc type, IdentifierMap &identifiers) const
Create a unique identifier for the given variable name and type.
virtual const string & getOutputQualifier() const
Returns a type qualifier to be used when declaring types for output variables.
Definition: Syntax.h:121
void registerTypeSyntax(TypeDesc type, TypeSyntaxPtr syntax)
Register syntax handling for a data type.
virtual const string & getConstantQualifier() const =0
Get the qualifier used when declaring constant variables.
virtual const string & getIncludeStatement() const
Return the string pattern used for a file include statement.
Definition: Syntax.h:142
virtual string getOutputTypeName(TypeDesc type) const
Returns the type name in an output context.
Punctuation
Punctuation types.
Definition: Syntax.h:45
void registerInvalidTokens(const StringMap &tokens)
Register a set string replacements for disallowed tokens for a code generator when naming variables a...
virtual const string & getEndMultiLineComment() const
Return the characters used to end a multi line comments block.
Definition: Syntax.h:151
virtual const string & getSingleLineComment() const
Return the characters used for single line comment.
Definition: Syntax.h:145
const string & getTypeName(TypeDesc type) const
Returns the name syntax of the given type.
const TypeSyntax & getTypeSyntax(TypeDesc type) const
Returns the type syntax object for a named type.
static const string NEWLINE
Constants with commonly used strings.
Definition: Syntax.h:194
virtual const string & getUniformQualifier() const
Get the qualifier used when declaring uniform variables.
Definition: Syntax.h:130
virtual const string & getInputQualifier() const
Returns a type qualifier to be used when declaring types for input variables.
Definition: Syntax.h:116
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 getValue(TypeDesc type, const Value &value, bool uniform=false) const
Returns the value string for a given type and value object.
virtual bool remapEnumeration(const string &value, TypeDesc type, const string &enumNames, std::pair< TypeDesc, ValuePtr > &result) const
Given an input specification attempt to remap this to an enumeration which is accepted by the shader ...
const StringSet & getReservedWords() const
Returns a set of names that are reserved words for this language syntax.
Definition: Syntax.h:71
A type descriptor for MaterialX data types.
Definition: TypeDesc.h:35
Base class for syntax handling of types.
Definition: Syntax.h:221
const string & getDefaultValue(bool uniform) const
Returns the default value for this type.
Definition: Syntax.h:235
virtual string getValue(const Value &value, bool uniform) const =0
Returns a value formatted according to this type syntax.
const string & getName() const
Returns the type name.
Definition: Syntax.h:226
virtual string getValue(const ShaderPort *port, bool uniform) const
Returns a value formatted according to this type syntax.
const string & getTypeAlias() const
Returns a type alias if needed to define the type in the target language.
Definition: Syntax.h:229
TypeSyntax(const string &name, const string &defaultValue, const string &uniformDefaultValue, const string &typeAlias, const string &typeDefinition, const StringVec &members)
Protected constructor.
const StringVec & getMembers() const
Returns the syntax for accessing type members if the type can be swizzled.
Definition: Syntax.h:239
const string & getTypeDefinition() const
Returns a type definition if needed to define the type in the target language.
Definition: Syntax.h:232
A generic, discriminated value, whose type may be queried dynamically.
Definition: Value.h:45