HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_Language.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: VOP_Language.h ( VOP Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __VOP_Language__
12 #define __VOP_Language__
13 
14 #include "VOP_API.h"
15 #include <UT/UT_SharedPtr.h>
16 #include <UT/UT_StringHolder.h>
17 #include "VOP_LanguageInfo.h"
18 #include "VOP_Types.h"
19 
20 class UT_String;
21 class UT_StringArray;
22 class UT_StringSet;
24 class VOP_TypeInfo;
25 class VOP_VarInfo;
26 
27 
28 /// Reprsents a language for which VOPs can generate source code.
30 public:
31  /// Constructor and destructor.
32  VOP_Language();
33  virtual ~VOP_Language();
34 
35  /// Convenience function to get the default language (VEX).
36  static const VOP_Language *getVex();
37 
38  /// Returns the name of the language.
39  virtual UT_StringHolder getName() const = 0;
40 
41  /// Returns true if the language matches the given mask.
42  /// The mask is usually the "render mask" used in VOPs:
43  /// ie, any VOP whose mask matches this keyword belongs to this language
44  virtual bool matchesMask( const UT_StringRef &mask ) const=0;
45 
46 
47  /// Returns the enumerated type of this language.
48  virtual VOP_LanguageInfo getLanguageInfo() const = 0;
50  { return getLanguageInfo().getType(); }
51  bool isVex() const;
52 
53  /// Gets source code file extension used for code written in this language.
54  virtual const char *getFileExtension() const = 0;
55 
56  /// Gets the list of words reserved for special language meaning.
57  /// These words cannot be used as variable or function names, etc.
58  virtual const UT_StringSet &getReservedWords() const = 0;
59 
60  /// Returns the keyword used for shader export (output) parameters.
61  virtual const char *getExportKeyword() const = 0;
62 
63  /// Returns the separator character between shader arguments in
64  /// the shader function definition.
65  virtual const char *getShaderParmSeparator() const;
66 
67  /// Returns the name of formated print function, or NULL if none.
68  virtual const char *getSprintf() const = 0;
69 
70  /// Returns the name of the isbound() function, or NULL if none.
71  virtual const char *getIsBoundFunction() const = 0;
72 
73  /// Gets the source code snippet that represents a default constant value
74  /// for the variable of a given type.
75  virtual void getEmptyConstantCode(UT_String &code,
76  const VOP_TypeInfo &type_info) const = 0;
77 
78  /// Get the source code for a default value of a struct given in type_info.
79  virtual void getCustomTypeEmptyConstantCode(UT_String &code,
80  const VOP_TypeInfo &type_info) const;
81 
82  /// Gets the source code snippet that represents a constant for a variable
83  /// of the given type, whose value is given in the 'value' argument.
84  virtual void getConstantCode(UT_String &code,
85  const VOP_TypeInfo &type_info, bool unquoted,
86  const UT_StringArray &value) const = 0;
88  const VOP_TypeInfo &type_info, bool unquoted,
89  const UT_StringArray &value) const
90  {
91  UT_String tmp;
92  getConstantCode(tmp, type_info, unquoted, value);
93  code.adoptFromString(tmp);
94  }
95 
96  /// @{ Gets type source code keyword for declaring variables of that type.
97  virtual void getTypeCode(UT_String &code,
98  const VOP_TypeInfo &type_info) const = 0;
99  virtual void getVaryingTypeCode(UT_String &code,
100  const VOP_TypeInfo &type_info) const;
101  /// @}
102 
103  /// Get the shader contexts available in that language.
104  virtual void getSupportedShaderTypes(VOP_ShaderTypeList &list) const;
105 
106  /// Get the source code keyword for the given shader type.
107  virtual void getShaderTypeCode(UT_String &code,
108  VOP_ContextType context) const;
109 
110  /// Get the source code that declares a variable of the given struct type.
111  virtual void getCustomTypeCode(UT_String &code,
112  const VOP_TypeInfo &type_info) const;
113 
114  /// Get the source code that defines the given type (eg, struct definition).
115  virtual void getTypeDefinitionCode(UT_String &type_definition,
116  const VOP_TypeInfo &type_info) const;
117 
118  /// Get the variable member access operator for structs/classes.
119  virtual void getMemberVarAccessOpCode(UT_String &access_op) const;
120 
121  /// Returns true if structs and class definitions should include
122  /// the default values for their members.
123  virtual bool shouldSpecifyMemberDefaults() const;
124 
125  /// Returns the terminator that follows the struct definition (usually
126  /// a semicolon or NULL, if terminator is not required.
127  virtual void getStructDefinitionTerminator(UT_String &term) const;
128 
129  /// @{ Gets array declaration brackets string for a given type.
130  /// If the type is indeed a string, returns "[]", otherwise returns
131  /// an empty string "".
132  virtual void getArrayBracketsCode( UT_String &code,
133  const VOP_TypeInfo &type_info) const;
134  /// @}
135 
136  /// Returns true if function parameters are const references by default
137  /// and outgoing parameters need an explicit "export" keyword.
138  /// Otherwise, returns false (eg for VEX whose function paramerers
139  /// are non-const references by default).
140  virtual bool needsFunctionParmExportKeyword() const;
141 
142  /// Returns true if it's possible to use shader calls to call a shader
143  /// function for this context.
144  virtual bool canUseShaderCalls(VOP_ContextType context) const = 0;
145 
146  /// Writes out a function call to the buffer.
147  virtual void getFunctionCall( UT_String &str,
148  const UT_String &func_name,
149  const UT_StringArray &args) const = 0;
150 
151  /// Writes out a co-shader call to the buffer.
152  virtual void getShaderCall( UT_String &buffer,
153  const UT_String &shader_name,
154  const UT_StringArray &arg_names,
155  const UT_StringArray &arg_vals) const = 0;
156 
157  /// Obtains the list of global variables available in the given context.
158  virtual void getGlobalVariables( UT_Array<VOP_VarInfo> &global_vars,
159  VOP_ContextType context) const;
160 
161  /// Returns a manager that maps VOP types to PRM node parameters.
163  { return *myParmManager; }
164 
165  /// Returns the name that encodes the given language and context.
166  /// This name is then targetted by various VOP nodes with a vopnet mask,
167  /// to see if these VOPs can show up in that vopnet or not.
168  virtual const char *getVopnetMaskTarget(VOP_ContextType context_type) const;
169 
170  /// Returns a color name for the connectors of the given type.
171  virtual const char *getTypeUIColor(VOP_Type type) const;
172 
173  /// @{ Returns true, if the language supports uniform varying variables.
174  virtual bool supportsUniformVarying() const;
175  virtual bool isTypeUniformVarying(VOP_Type type) const;
176  /// @}
177 
178  /// @{ Take an arbitrary type and return the type supported by the language.
179  virtual VOP_Type conditionType(VOP_Type type) const = 0;
181  { return conditionType(type) == type; }
182  /// @}
183 
184  /// Returns ture if the second type can be assigned directly to first.
185  virtual bool canDirectlyAssign( const VOP_TypeInfo &dst_type,
186  const VOP_TypeInfo &src_type ) const;
187 
188  /// Return true if the language has casting functions that automatically
189  /// converts the value between some types.
190  virtual bool hasTypeAutoconvert() const;
191 
192 protected:
193  /// Returns an element at a given array index, quoting it if requested.
194  void getStringValue(UT_String &value,
195  const UT_StringArray &values, int index,
196  bool unquoted ) const;
197 private:
198  /// Mapper between VOP types and the PRM node parameters.
199  VOP_NodeParmManager * myParmManager;
200 };
201 
202 // ============================================================================
203 // The VOP_Language class defines a language, including custom languages,
204 // and to manage such objects troughout our code, we need a handle.
206 
207 #endif
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:29
void adoptFromString(UT_String &str)
int isTypeSupported(VOP_Type type) const
Take an arbitrary type and return the type supported by the language.
Definition: VOP_Language.h:180
virtual VOP_LanguageType getLanguageType() const
Definition: VOP_Language.h:49
void getConstantCode(UT_StringHolder &code, const VOP_TypeInfo &type_info, bool unquoted, const UT_StringArray &value) const
Definition: VOP_Language.h:87
int VOP_ContextType
Definition: VOP_Types.h:177
Definition: core.h:760
const VOP_NodeParmManager & getParmManager() const
Returns a manager that maps VOP types to PRM node parameters.
Definition: VOP_Language.h:162
#define VOP_API
Definition: VOP_API.h:10
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
GLint GLuint mask
Definition: glcorearb.h:124
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
UT_SharedPtr< const VOP_Language > VOP_LanguageHandle
Definition: VOP_Language.h:205
GLuint index
Definition: glcorearb.h:786
VOP_Type
Enumeration of the built-in (basic) VOP data types.
Definition: VOP_Types.h:25
**If you just want to fire and args
Definition: thread.h:609
Definition: core.h:1131
type
Definition: core.h:1059
VOP_LanguageType
Definition: VOP_Types.h:186