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