From: Ian Romanick Date: Mon, 15 Mar 2010 21:28:17 +0000 (-0700) Subject: Add new constructors for ast_type_specifier X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ed85a5dd4b36f4a583fc321b6d8d49a050d48678;p=mesa.git Add new constructors for ast_type_specifier Add a constructor that uses an ast_struct_specifier and one that uses a type name. This saves a (trivial) bit of code, but it also ensures some of the class invariants (i.e., type_name != NULL) are met. --- diff --git a/ast.h b/ast.h index 32cd5b6b4f5..1bc38d355cb 100644 --- a/ast.h +++ b/ast.h @@ -357,6 +357,22 @@ class ast_type_specifier : public ast_node { public: ast_type_specifier(int specifier); + /** Construct a type specifier from a type name */ + ast_type_specifier(const char *name) + : type_specifier(ast_type_name), type_name(name), structure(NULL), + is_array(false), array_size(NULL), precision(ast_precision_high) + { + /* empty */ + } + + /** Construct a type specifier from a structure definition */ + ast_type_specifier(ast_struct_specifier *s) + : type_specifier(ast_struct), type_name(s->name), structure(s), + is_array(false), array_size(NULL), precision(ast_precision_high) + { + /* empty */ + } + virtual void print(void) const; enum ast_types type_specifier; diff --git a/glsl_parser.ypp b/glsl_parser.ypp index 3645e96f721..2bc5cb06e6c 100644 --- a/glsl_parser.ypp +++ b/glsl_parser.ypp @@ -861,13 +861,11 @@ type_specifier_nonarray: } | struct_specifier { - $$ = new ast_type_specifier(ast_struct); - $$->structure = $1; + $$ = new ast_type_specifier($1); } | TYPE_NAME { - $$ = new ast_type_specifier(ast_type_name); - $$->type_name = $1; + $$ = new ast_type_specifier($1); } ;