HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_CodeGenContext.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_CodeGenContext.h ( VEX Library, C++ )
7  *
8  * COMMENTS: A container class for useful data to be passed down to the
9  * VOP_Node::getCode and getOuterCode functions.
10  */
11 
12 #ifndef __VOP_CodeGenContext__
13 #define __VOP_CodeGenContext__
14 
15 #include "VOP_API.h"
16 #include <stdlib.h>
17 #include <UT/UT_StringHolder.h>
18 #include <VEX/VEX_VexTypes.h>
19 #include "VOP_Types.h"
20 
24 
25 
27 {
28 public:
30  const char *context_name = NULL,
32  VOP_CodeVarMapperContext *var_mapper_ctx = NULL,
33  bool should_output_parm_defaults = true) :
34  myShaderContextType(context_type),
35  myShaderContextName(context_name),
36  myCodeGenFlags(cg_flags),
37  myVarMapperCtx(var_mapper_ctx),
38  myShouldOutputParmDefaults(should_output_parm_defaults),
39  myForceParmExport(false),
40  mySetParentShaderGlobals(false),
41  myShaderSpace(nullptr),
42  myExtraVarRequests(nullptr)
43  {}
44 
46  { return myShaderContextType; }
48  { return myShaderContextName; }
50  { return myCodeGenFlags; }
52  { return myVarMapperCtx; }
54  { return myShouldOutputParmDefaults; }
55 
57  { myForceParmExport = force; }
58  bool isForceParmExport() const
59  { return myForceParmExport; }
60 
61  void setSetParentShaderGlobals(bool set)
62  { mySetParentShaderGlobals = set; }
64  { return mySetParentShaderGlobals; }
65 
67  { myShaderSpace = space; }
69  { return myShaderSpace; }
70 
72  const VOP_ExtraVarRequests *requests)
73  { myExtraVarRequests = requests; }
75  { return myExtraVarRequests; }
76 
77  /// @{ Utility functions for manipulating shader context name that
78  /// involves shader node path along with the traditional context name.
79  static bool isOpPrefixContext( const char *opprefixpath );
80  static bool isRelativeOpPrefixContext(
81  const char *opprefixpath );
82  static UT_StringHolder buildOpPrefixContext( const char *node_path,
83  const char *context_name );
84  static void parseOpPrefixContext( const char *opprefixpath,
85  UT_StringHolder &node_path,
86  UT_StringHolder &context_name );
87  /// @}
88 
89  /// Returns true if the context accepts any of the given names.
90  bool matchesAnyShaderContextName(
91  const UT_StringArray &context_names) const;
92 
93 private:
94  // Shading context type.
95  VOP_ContextType myShaderContextType;
96 
97  // Snading contesxt name. Usually corresponds to context type above,
98  // but for some shaders (like "class") it will contain a method name, etc.
99  UT_StringHolder myShaderContextName;
100 
101  // Flags for code generation.
102  VEX_CodeGenFlags myCodeGenFlags;
103 
104  // Variable mapper (and variable renaming) cotnext.
105  VOP_CodeVarMapperContext *myVarMapperCtx;
106 
107  // Info about space in which the shader calls occur.
108  const VOP_ShaderSpaceInfo *myShaderSpace;
109 
110  // Requests for var that are optional and not computed by default.
111  const VOP_ExtraVarRequests *myExtraVarRequests;
112 
113  // If true, the parm declaration should include initialization to defaults.
114  bool myShouldOutputParmDefaults;
115 
116  // If true, the parm declaration should use export keyword.
117  bool myForceParmExport;
118 
119  // If true, the shader node should generate code to set caller's globals
120  // after it generates the shader call code.
121  bool mySetParentShaderGlobals;
122 };
123 
124 
125 #endif // __VOP_CodeGenContext__
const VOP_ExtraVarRequests * getExtraVarRequests() const
const VOP_ShaderSpaceInfo * getShaderSpace() const
void setExtraVarRequests(const VOP_ExtraVarRequests *requests)
void setSetParentShaderGlobals(bool set)
int VOP_ContextType
Definition: VOP_Types.h:177
bool shouldSetParentShaderGlobals() const
VOP_CodeVarMapperContext * varMapperCtx() const
void setShaderSpace(const VOP_ShaderSpaceInfo *space)
bool shouldOutputParmDefaults() const
#define VOP_API
Definition: VOP_API.h:10
VEX_CodeGenFlags codeGenFlags() const
#define VOP_CONTEXT_TYPE_INVALID
Definition: VOP_Types.h:178
VOP_ContextType shaderContextType() const
SIM_API const UT_StringHolder force
VEX_CodeGenFlags
VEX code generation flags when calling VEX_VexResolver::getVflCode.
Definition: VEX_VexTypes.h:138
bool isForceParmExport() const
const UT_StringHolder & shaderContextName() const
void setForceParmExport(bool force)
VOP_CodeGenContext(VOP_ContextType context_type=VOP_CONTEXT_TYPE_INVALID, const char *context_name=NULL, VEX_CodeGenFlags cg_flags=VEX_CG_DEFAULT, VOP_CodeVarMapperContext *var_mapper_ctx=NULL, bool should_output_parm_defaults=true)