Skip to content

Commit 17c6445

Browse files
committed
Have SymbolTable track and retrieve the currently opened struct.
1 parent 4f205f0 commit 17c6445

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/liboslcomp/oslgram.y

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ struct_declaration
350350
}
351351
field_declarations '}' ';'
352352
{
353+
oslcompiler->symtab().end_struct ();
353354
$$ = 0;
354355
}
355356
;

src/liboslcomp/symtab.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,25 @@ SymbolTable::insert (Symbol *sym)
237237
int
238238
SymbolTable::new_struct (ustring name)
239239
{
240-
int structid = TypeSpec::new_struct (new StructSpec (name, scopeid()));
241-
insert (new Symbol (name, TypeSpec ("",structid), SymTypeType));
242-
return structid;
240+
m_structid = TypeSpec::new_struct (new StructSpec (name, scopeid()));
241+
insert (new Symbol (name, TypeSpec ("", m_structid), SymTypeType));
242+
return m_structid;
243+
}
244+
245+
246+
247+
void
248+
SymbolTable::end_struct ()
249+
{
250+
m_structid = 0;
243251
}
244252

245253

246254

247255
StructSpec *
248256
SymbolTable::current_struct ()
249257
{
250-
return TypeSpec::struct_list().back().get();
258+
return m_structid ? TypeSpec::struct_list().back().get() : nullptr;
251259
}
252260

253261

src/liboslcomp/symtab.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class SymbolTable {
208208
typedef SymbolPtrVec::const_iterator const_iterator;
209209

210210
SymbolTable (OSLCompilerImpl &comp)
211-
: m_comp(comp), m_scopeid(-1), m_nextscopeid(0)
211+
: m_comp(comp), m_scopeid(-1), m_nextscopeid(0), m_structid(0)
212212
{
213213
m_scopetables.reserve (20); // So unlikely to ever copy tables
214214
push (); // Create scope 0 -- global scope
@@ -246,6 +246,8 @@ class SymbolTable {
246246

247247
StructSpec *current_struct ();
248248

249+
void end_struct ();
250+
249251
/// Return the current scope ID
250252
///
251253
int scopeid () const {
@@ -283,6 +285,7 @@ class SymbolTable {
283285
ScopeTable m_allmangled; ///< All syms, mangled, in a hash table
284286
int m_scopeid; ///< Current scope ID
285287
int m_nextscopeid; ///< Next unique scope ID
288+
int m_structid; ///< Currently declaring a struct
286289
};
287290

288291

0 commit comments

Comments
 (0)