Skip to content

Instantly share code, notes, and snippets.

@jpf91
Created September 19, 2012 14:07
Show Gist options
  • Select an option

  • Save jpf91/3749879 to your computer and use it in GitHub Desktop.

Select an option

Save jpf91/3749879 to your computer and use it in GitHub Desktop.
struct StructBuilder
{
Scope *scope;
Loc loc;
StructDeclaration *decl;
TypeStruct *type;
StructBuilder(Module *mod, const char* name)
{
scope = mod->scope;
loc = Loc(mod, 1);
decl = new StructDeclaration(loc, new Identifier(name, 0));
type = new TypeStruct(decl);
decl->type = type;
decl->members = new Dsymbols();
}
void addField(const char* name, Type* fieldType)
{
Identifier* fieldId = new Identifier(name, 0);
VarDeclaration *fieldDecl = new VarDeclaration(loc, fieldType, fieldId, NULL);
decl->members->push(fieldDecl);
}
void finish()
{
decl->semantic(scope);
decl->finalizeSize(scope);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment