diff options
author | Josh Stone <jistone@redhat.com> | 2009-08-03 15:16:09 -0700 |
---|---|---|
committer | Josh Stone <jistone@redhat.com> | 2009-08-03 15:16:09 -0700 |
commit | 0164a29cfb80344dced2e1683df05f6b62fe6cb3 (patch) | |
tree | f1135402bc2f45e03718733eb8490cd1f9df52f6 /parse.cxx | |
parent | 28ad563d57d03e0d21936e394061e3380607d83b (diff) | |
parent | 6fda2dff51c667a8c73545dd397b844108715310 (diff) | |
download | systemtap-steved-0164a29cfb80344dced2e1683df05f6b62fe6cb3.tar.gz systemtap-steved-0164a29cfb80344dced2e1683df05f6b62fe6cb3.tar.xz systemtap-steved-0164a29cfb80344dced2e1683df05f6b62fe6cb3.zip |
Merge branch 'array_index'
Diffstat (limited to 'parse.cxx')
-rw-r--r-- | parse.cxx | 74 |
1 files changed, 32 insertions, 42 deletions
@@ -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 : */ |