Significantly reduce the tendrils of DeclSpecs/Declarator/Declaration code

The stuff in decl.h/decl.cpp is messy, largely due to its close mapping
to C-style variable declarations.  This checkin has updated code throughout
all of the declaration statement, variable, and function code that operates
on symbols and types directly.  Thus, Decl* related stuff is now localized
to decl.h/decl.cpp and the parser.

Issue #13.
This commit is contained in:
Matt Pharr
2011-10-18 15:33:18 -07:00
parent 9b8ea3d500
commit f45ab0744e
13 changed files with 562 additions and 498 deletions

30
decl.h
View File

@@ -56,6 +56,11 @@
#include "ispc.h"
struct VariableDeclaration;
class Declaration;
class Declarator;
enum StorageClass {
SC_NONE,
SC_EXTERN,
@@ -137,6 +142,9 @@ public:
DeclSpecs */
const Type *GetType(DeclSpecs *ds) const;
void GetFunctionInfo(DeclSpecs *ds, Symbol **sym,
std::vector<Symbol *> *args);
void Print() const;
const SourcePos pos;
@@ -157,27 +165,13 @@ public:
*/
class Declaration {
public:
Declaration(DeclSpecs *ds, std::vector<Declarator *> *dlist = NULL) {
declSpecs = ds;
if (dlist != NULL)
declarators = *dlist;
for (unsigned int i = 0; i < declarators.size(); ++i)
if (declarators[i] != NULL)
declarators[i]->InitFromDeclSpecs(declSpecs);
}
Declaration(DeclSpecs *ds, Declarator *d) {
declSpecs = ds;
if (d) {
d->InitFromDeclSpecs(ds);
declarators.push_back(d);
}
}
Declaration(DeclSpecs *ds, std::vector<Declarator *> *dlist = NULL);
Declaration(DeclSpecs *ds, Declarator *d);
/** Adds the symbols for the variables in the declaration to the symbol
table. */
void AddSymbols(SymbolTable *st) const;
void Print() const;
std::vector<VariableDeclaration> GetVariableDeclarations() const;
DeclSpecs *declSpecs;
std::vector<Declarator *> declarators;
};