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_StringHolder.h>
16 #include "VOP_Types.h"
17 
18 class UT_String;
19 class UT_StringArray;
20 class UT_StringSet;
22 class VOP_TypeInfo;
23 class VOP_VarInfo;
24 
25 
26 /// Reprsents a language for which VOPs can generate source code.
28 public:
29  /// Constructor and destructor.
30  VOP_Language();
31  virtual ~VOP_Language();
32 
33  /// Convenience function to get the default language (VEX).
34  static VOP_Language *getVex();
35 
36  /// Returns the name of the language.
37  virtual const char *getName() const = 0;
38 
39  /// Returns the enumerated type of this language.
40  virtual VOP_LanguageType getLanguageType() const = 0;
41  bool isVex() const;
42 
43  /// Gets source code file extension used for code written in this language.
44  virtual const char *getFileExtension() const = 0;
45 
46  /// Gets the list of words reserved for special language meaning.
47  /// These words cannot be used as variable or function names, etc.
48  virtual const UT_StringSet &getReservedWords() const = 0;
49 
50  /// Returns the keyword used for shader export (output) parameters.
51  virtual const char *getExportKeyword() const = 0;
52 
53  /// Returns the separator character between shader arguments in
54  /// the shader function definition.
55  virtual const char *getShaderParmSeparator() const;
56 
57  /// Returns the name of formated print function, or NULL if none.
58  virtual const char *getSprintf() const = 0;
59 
60  /// Returns the name of the isbound() function, or NULL if none.
61  virtual const char *getIsBoundFunction() const = 0;
62 
63  /// Gets the source code snippet that represents a default constant value
64  /// for the variable of a given type.
65  virtual void getEmptyConstantCode(UT_String &code,
66  const VOP_TypeInfo &type_info) const = 0;
67 
68  /// Get the source code for a default value of a struct given in type_info.
69  virtual void getCustomTypeEmptyConstantCode(UT_String &code,
70  const VOP_TypeInfo &type_info) const;
71 
72  /// Gets the source code snippet that represents a constant for a variable
73  /// of the given type, whose value is given in the 'value' argument.
74  virtual void getConstantCode(UT_String &code,
75  const VOP_TypeInfo &type_info, bool unquoted,
76  const UT_StringArray &value) const = 0;
78  const VOP_TypeInfo &type_info, bool unquoted,
79  const UT_StringArray &value) const
80  {
81  UT_String tmp;
82  getConstantCode(tmp, type_info, unquoted, value);
83  code.adoptFromString(tmp);
84  }
85 
86  /// @{ Gets type source code keyword for declaring variables of that type.
87  virtual void getTypeCode(UT_String &code,
88  const VOP_TypeInfo &type_info) const = 0;
89  virtual void getVaryingTypeCode(UT_String &code,
90  const VOP_TypeInfo &type_info) const;
91  /// @}
92 
93  /// Get the shader contexts available in that language.
94  virtual void getSupportedShaderTypes(VOP_ShaderTypeList &list) const;
95 
96  /// Get the source code keyword for the given shader type.
97  virtual void getShaderTypeCode(UT_String &code,
98  VOP_ContextType context) const;
99 
100  /// Get the source code that declares a variable of the given struct type.
101  virtual void getCustomTypeCode(UT_String &code,
102  const VOP_TypeInfo &type_info) const;
103 
104  /// Get the source code that defines the given type (eg, struct definition).
105  virtual void getTypeDefinitionCode(UT_String &type_definition,
106  const VOP_TypeInfo &type_info) const;
107 
108  /// Get the variable member access operator for structs/classes.
109  virtual void getMemberVarAccessOpCode(UT_String &access_op) const;
110 
111  /// Returns true if structs and class definitions should include
112  /// the default values for their members.
113  virtual bool shouldSpecifyMemberDefaults() const;
114 
115  /// Returns the terminator that follows the struct definition (usually
116  /// a semicolon or NULL, if terminator is not required.
117  virtual void getStructDefinitionTerminator(UT_String &term) const;
118 
119  /// @{ Gets array declaration brackets string for a given type.
120  /// If the type is indeed a string, returns "[]", otherwise returns
121  /// an empty string "".
122  virtual void getArrayBracketsCode( UT_String &code,
123  const VOP_TypeInfo &type_info) const;
124  /// @}
125 
126  /// Returns true if function parameters are const references by default
127  /// and outgoing parameters need an explicit "export" keyword.
128  /// Otherwise, returns false (eg for VEX whose function paramerers
129  /// are non-const references by default).
130  virtual bool needsFunctionParmExportKeyword() const;
131 
132  /// Returns true if it's possible to use shader calls to call a shader
133  /// function for this context.
134  virtual bool canUseShaderCalls(VOP_ContextType context) const = 0;
135 
136  /// Writes out a function call to the buffer.
137  virtual void getFunctionCall( UT_String &str,
138  const UT_String &func_name,
139  const UT_StringArray &args) const = 0;
140 
141  /// Writes out a co-shader call to the buffer.
142  virtual void getShaderCall( UT_String &buffer,
143  const UT_String &shader_name,
144  const UT_StringArray &arg_names,
145  const UT_StringArray &arg_vals) const = 0;
146 
147  /// Obtains the list of global variables available in the given context.
148  virtual void getGlobalVariables( UT_Array<VOP_VarInfo> &global_vars,
149  VOP_ContextType context) const;
150 
151  /// Returns a manager that maps VOP types to PRM node parameters.
153  { return *myParmManager; }
154 
155  /// Returns the name that encodes the given language and context.
156  /// This name is then targetted by various VOP nodes with a vopnet mask,
157  /// to see if these VOPs can show up in that vopnet or not.
158  virtual const char *getVopnetMaskTarget(VOP_ContextType context_type) const;
159 
160  /// Returns a color name for the connectors of the given type.
161  virtual const char *getTypeUIColor(VOP_Type type) const;
162 
163  /// @{ Returns true, if the language supports uniform varying variables.
164  virtual bool supportsUniformVarying() const;
165  virtual bool isTypeUniformVarying(VOP_Type type) const;
166  /// @}
167 
168  /// @{ Take an arbitrary type and return the type supported by the language.
169  virtual VOP_Type conditionType(VOP_Type type) const = 0;
171  { return conditionType(type) == type; }
172  /// @}
173 
174  /// Returns ture if the second type can be assigned directly to first.
175  virtual bool canDirectlyAssign( const VOP_TypeInfo &dst_type,
176  const VOP_TypeInfo &src_type ) const;
177 
178 protected:
179  /// Returns an element at a given array index, quoting it if requested.
180  void getStringValue(UT_String &value,
181  const UT_StringArray &values, int index,
182  bool unquoted ) const;
183 private:
184  /// Mapper between VOP types and the PRM node parameters.
185  VOP_NodeParmManager * myParmManager;
186 };
187 
188 #endif
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:27
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:170
void getConstantCode(UT_StringHolder &code, const VOP_TypeInfo &type_info, bool unquoted, const UT_StringArray &value) const
Definition: VOP_Language.h:77
GLuint buffer
Definition: glcorearb.h:659
int VOP_ContextType
Definition: VOP_Types.h:149
const VOP_NodeParmManager & getParmManager() const
Returns a manager that maps VOP types to PRM node parameters.
Definition: VOP_Language.h:152
#define VOP_API
Definition: VOP_API.h:10
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1601
GLsizei const GLfloat * value
Definition: glcorearb.h:823
GLuint index
Definition: glcorearb.h:785
VOP_Type
Definition: VOP_Types.h:24
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
VOP_LanguageType
Definition: VOP_Types.h:158