HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_CodeVarMapper.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  */
7 
8 #ifndef __VOP_CodeVarMapper_h__
9 #define __VOP_CodeVarMapper_h__
10 
11 #include "VOP_API.h"
12 #include "VOP_Language.h"
13 
14 #include <UT/UT_Array.h>
15 #include <UT/UT_ArrayMap.h>
16 #include <UT/UT_Map.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_StringArray.h>
19 #include <UT/UT_StringMap.h>
20 #include <UT/UT_UniquePtr.h>
21 #include <SYS/SYS_Hash.h>
22 
23 class VOP_Fetch;
24 class VOP_Node;
25 class VOP_CodeGenContext;
26 
27 template<typename T> class UT_SymbolMap;
31 
32 /// Simple class used to divide variable mappings into different contexts.
33 /// With the introduction of the Fetch VOP, a node can produce code
34 /// and variables multiple times. So we need contexts to separate
35 /// mappings from the same node from trampling over each other.
37 {
38 public:
39  /// Constructor.
41  VOP_Fetch *fetch_vop=NULL);
42 
43  /// Destructor.
45 
46  /// Return the child context which is associated to the given key.
47  /// If no such child context exists, then create one.
49 
50  /// Return the child context which is associated to the given key.
51  /// Return NULL if no such context exists.
52  VOP_CodeVarMapperContext *findChildContext(VOP_Fetch *fetch_vop) const;
53 
54  /// Return a pointer to the parent context.
55  VOP_CodeVarMapperContext *getParent() const { return myParent; }
56 
57  /// Return a pointer to the Fetch VOP which was responsible
58  /// for the creation of this context.
59  VOP_Fetch *getFetchVOP() const { return myFetchVOP; }
60 
61 private:
62  // A mapping of keys to child contexts.
64 
65  // A pointer to the parent context.
66  VOP_CodeVarMapperContext *myParent;
67 
68  // A pointer to the Fetch VOP which was responsible for the creation
69  // of this context.
70  VOP_Fetch *myFetchVOP;
71 };
72 
73 /// An entry corresponding to a vop node in a given mapper context.
74 /// It contains information about output variable names and types for that vop.
76 {
77 public:
80 
81  void addOutputVariable(const char *codevar,
82  const char *var,
83  int index,
84  const VOP_TypeInfo &typeinfo,
85  bool outonly);
86  const char *getOutputVariableCodeName(int index) const;
87  const char *getOutputVariableName(int index) const;
88  const VOP_TypeInfo &getOutputVariableTypeInfo(int index) const;
89  bool getDeclareOutputVariable(int index) const;
90  int getNumEntries() const;
91  VOP_Node *getVop() const;
92 
93 private:
94  void clear();
95 
96  UT_StringArray myOutputVariableCodeNames;
97  UT_StringArray myOutputVariableNames;
99  myOutputVariableTypeInfos;
100  UT_Array<bool> myDeclareOutputVariables;
101  VOP_Node *myVop;
102 
103  friend class VOP_CodeVarMapper;
104 };
105 
106 /// Container class that keeps track of all var mapper entries, that is
107 /// infos about output varialbe names for each vop node in a given mapper
108 /// context.
110 {
111 public:
112  using KeyType = std::pair<VOP_Node *, VOP_CodeVarMapperContext *>;
114  {
115  //using KeyType = Keystd::pair<VOP_Node *, VOP_CodeVarMapperContext *>;
117  {
118  SYS_HashType h = 0;
119  SYShashCombine(h, s.first);
120  SYShashCombine(h, s.second);
121  return h;
122  }
123  };
124 
127 
128  VOP_CodeVarMapperEntry *findOrAddEntry(VOP_Node *node,
129  VOP_CodeVarMapperContext *context);
130  VOP_CodeVarMapperEntry *findEntry(VOP_Node *node,
131  VOP_CodeVarMapperContext *context)
132  const;
133  const VOP_CodeVarMapperEntry *getEntry(int idx) const;
134  int getNumEntries() const;
135 
136  /// Some nodes use temporary variables with custom types, and types are
137  /// inspected and automatically defined (if necessary) when declaring
138  /// variables for the outputs. If no output is of that custom type,
139  /// the type won't be defined. So, VOPs can use extra types list
140  /// to indicate which custom types need definition in the generated code.
141  void addExtraType(const VOP_TypeInfo &type_info);
142  const VOP_TypeInfo &getExtraType(int idx) const;
143  int getNumExtraTypes() const;
144 
145 private:
146  // Use an ArrayMap since there are fewer allocations
147  using MapType = UT::ArrayMap<KeyType,
149  false,
150  128,
152  KeyHasher>;
153 
154  MapType myMap;
156  UT_Array<VOP_TypeInfo> myExtraTypesToDefine;
157 };
158 
159 /// An aggregation of all the information about variable names and other
160 /// info needed during variable replacement process.
162 {
163 public:
165  UT_StringSet &varTable,
166  VOP_NodeVarMapsTable &localVarTables,
167  VOP_VariableMap &localVarTable,
168  VOP_CodeVarMapper &varMapper,
169  VOP_CodeVarMapperEntry *varMapperEntry,
170  const VOP_CodeGenContext &codegen_context,
171  VOP_CodeVarMapperContext *varmap_context,
172  VOP_Node *function_subnet = NULL,
173  UT_SortedStringMap<UT_String> *is_connected_map = NULL)
174  : myVop(vop), myVarTable(varTable),
175  myLocalVarTables(localVarTables),
176  myLocalVarTable(localVarTable), myVarMapper(varMapper),
177  myVarMapperEntry(varMapperEntry), myDoingOuterCode(true),
178  myCodegenContext(codegen_context),
179  myCodeVarMapperContext(varmap_context),
180  myFunctionSubnet(function_subnet),
181  myIsConnectedMap(is_connected_map)
182  { }
184  { }
185 
198 };
199 
200 #endif
VOP_CodeVarMapperContext * myCodeVarMapperContext
Unsorted map container.
Definition: UT_Map.h:107
VOP_CodeVarMapperContext * findOrCreateChildContext(VOP_Fetch *fetch_vop)
VOP_Fetch * getFetchVOP() const
UT_SymbolMap< UT_StringHolder > VOP_VariableMap
const VOP_CodeGenContext & myCodegenContext
VOP_CodeVarLookupData(VOP_Node *vop, UT_StringSet &varTable, VOP_NodeVarMapsTable &localVarTables, VOP_VariableMap &localVarTable, VOP_CodeVarMapper &varMapper, VOP_CodeVarMapperEntry *varMapperEntry, const VOP_CodeGenContext &codegen_context, VOP_CodeVarMapperContext *varmap_context, VOP_Node *function_subnet=NULL, UT_SortedStringMap< UT_String > *is_connected_map=NULL)
GLdouble s
Definition: glad.h:3009
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
UT_Map< const VOP_Node *, VOP_VariableMap * > VOP_NodeVarMapsTable
UT_StringHolder myVariableString
#define VOP_API
Definition: VOP_API.h:10
std::pair< VOP_Node *, VOP_CodeVarMapperContext * > KeyType
VOP_NodeVarMapsTable & myLocalVarTables
VOP_CodeVarMapperContext * getParent() const
Return a pointer to the parent context.
VOP_CodeVarMapperContext * findChildContext(VOP_Fetch *fetch_vop) const
VOP_VariableMap & myLocalVarTable
SYS_HashType operator()(KeyType const &s) const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
VOP_CodeVarMapper & myVarMapper
GLuint index
Definition: glcorearb.h:786
VOP_CodeVarMapperEntry * myVarMapperEntry
UT_SortedStringMap< UT_String > * myIsConnectedMap
~VOP_CodeVarMapperContext()
Destructor.
VOP_CodeVarMapperContext(VOP_CodeVarMapperContext *parent=NULL, VOP_Fetch *fetch_vop=NULL)
Constructor.
UT_SymbolMap< VOP_VariableMap * > VOP_OpVarMapsTable