return services_[name];
}
+ void add_constant(std::string name, t_const* constant) {
+ constants_[name] = constant;
+ }
+
+ t_const* get_constant(std::string name) {
+ return constants_[name];
+ }
+
void print() {
std::map<std::string, t_type*>::iterator iter;
for (iter = types_.begin(); iter != types_.end(); ++iter) {
// Map of names to types
std::map<std::string, t_type*> types_;
+ // Map of names to constants
+ std::map<std::string, t_const*> constants_;
+
// Map of names to services
std::map<std::string, t_service*> services_;
if ($1 != NULL) {
$$->set_doc($1);
}
+ if (g_parse_mode == PROGRAM) {
+ g_scope->add_constant($2, new t_const(g_type_i32, $2, new t_const_value($4)));
+ if (g_parent_scope != NULL) {
+ g_parent_scope->add_constant(g_parent_prefix + $2, new t_const(g_type_i32, $2, new t_const_value($4)));
+ }
+ }
}
|
DocTextOptional tok_identifier CommaOrSemicolonOptional
if (g_parse_mode == PROGRAM) {
$$ = new t_const($2, $3, $5);
validate_const_type($$);
+
+ g_scope->add_constant($3, $$);
+ if (g_parent_scope != NULL) {
+ g_parent_scope->add_constant(g_parent_prefix + $3, $$);
+ }
+
} else {
$$ = NULL;
}
| tok_literal
{
pdebug("ConstValue => tok_literal");
- $$ = new t_const_value();
- $$->set_string($1);
+ $$ = new t_const_value($1);
}
| tok_identifier
{
pdebug("ConstValue => tok_identifier");
- $$ = new t_const_value();
- $$->set_string($1);
+ t_const* constant = g_scope->get_constant($1);
+ if (constant != NULL) {
+ $$ = constant->get_value();
+ } else {
+ if (g_parse_mode == PROGRAM) {
+ pwarning(1, "Constant strings should be quoted: %s\n", $1);
+ }
+ $$ = new t_const_value($1);
+ }
}
| ConstList
{
pdebug("Xception -> tok_xception tok_identifier { FieldList }");
$4->set_name($2);
$4->set_xception(true);
-/*
- if ($4 != NULL) {
- $5->set_doc($4);
- }
-*/
$$ = $4;
y_field_val = -1;
}