summaryrefslogtreecommitdiffstats
path: root/parse.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'parse.cxx')
-rw-r--r--parse.cxx74
1 files changed, 32 insertions, 42 deletions
diff --git a/parse.cxx b/parse.cxx
index 35c78abe..41a13ca5 100644
--- a/parse.cxx
+++ b/parse.cxx
@@ -2346,27 +2346,8 @@ parser::parse_symbol ()
expect_unknown(tok_string, cop->module);
}
expect_op(")");
- while (true)
- {
- string c;
- if (peek_op ("->"))
- {
- next();
- expect_ident_or_keyword (c);
- cop->components.push_back
- (make_pair (target_symbol::comp_struct_member, c));
- }
- else if (peek_op ("["))
- {
- next();
- expect_unknown (tok_number, c);
- expect_op ("]");
- cop->components.push_back
- (make_pair (target_symbol::comp_literal_array_index, c));
- }
- else
- break;
- }
+ parse_target_symbol_components(cop);
+
// if there aren't any dereferences, then the cast is pointless
if (cop->components.empty())
{
@@ -2494,27 +2475,7 @@ parser::parse_symbol ()
target_symbol *tsym = new target_symbol;
tsym->tok = t;
tsym->base_name = name;
- while (true)
- {
- string c;
- if (peek_op ("->"))
- {
- next();
- expect_ident_or_keyword (c);
- tsym->components.push_back
- (make_pair (target_symbol::comp_struct_member, c));
- }
- else if (peek_op ("["))
- {
- next();
- expect_unknown (tok_number, c);
- expect_op ("]");
- tsym->components.push_back
- (make_pair (target_symbol::comp_literal_array_index, c));
- }
- else
- break;
- }
+ parse_target_symbol_components(tsym);
return tsym;
}
@@ -2604,4 +2565,33 @@ parser::parse_symbol ()
return sym;
}
+
+void
+parser::parse_target_symbol_components (target_symbol* e)
+{
+ while (true)
+ {
+ if (peek_op ("->"))
+ {
+ const token* t = next();
+ string member;
+ expect_ident_or_keyword (member);
+ e->components.push_back (target_symbol::component(t, member));
+ }
+ else if (peek_op ("["))
+ {
+ const token* t = next();
+ expression* index = parse_expression();
+ literal_number* ln = dynamic_cast<literal_number*>(index);
+ if (ln)
+ e->components.push_back (target_symbol::component(t, ln->value));
+ else
+ e->components.push_back (target_symbol::component(t, index));
+ expect_op ("]");
+ }
+ else
+ break;
+ }
+}
+
/* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */