diff options
author | fche <fche> | 2006-02-23 22:35:40 +0000 |
---|---|---|
committer | fche <fche> | 2006-02-23 22:35:40 +0000 |
commit | 213bee8fc2b826ca8467fbbe35398450449bf082 (patch) | |
tree | 7e4a637195c704109e333906b377c7060970cf23 /parse.cxx | |
parent | 5ae893a12a652a31d2f96f4e81aab78c922b6ec8 (diff) | |
download | systemtap-steved-213bee8fc2b826ca8467fbbe35398450449bf082.tar.gz systemtap-steved-213bee8fc2b826ca8467fbbe35398450449bf082.tar.xz systemtap-steved-213bee8fc2b826ca8467fbbe35398450449bf082.zip |
2006-02-23 Frank Ch. Eigler <fche@elastic.org>
PR 1304
* parse.cxx (lexer): Take systemtap_session argument.
(lexer::scan): Support $1..$NNNN and @1...@NNNN expansion.
* stap.1.in: Document this.
* testsuite/semok/args.stp: New test.
* translate.cxx (var::init, emit_global): Emit code to allow
named module parameters to initialize global string/number scalars.
* stap.1.in: Don't document this yet.
PR 2334
* main.cxx (main): Clarify "-v" option repeatibility.
* stap.1.in: Ditto.
Diffstat (limited to 'parse.cxx')
-rw-r--r-- | parse.cxx | 35 |
1 files changed, 30 insertions, 5 deletions
@@ -1,5 +1,5 @@ // recursive descent parser for systemtap scripts -// Copyright (C) 2005 Red Hat Inc. +// Copyright (C) 2005-2006 Red Hat Inc. // // This file is part of systemtap, and is free software. You can // redistribute it and/or modify it under the terms of the GNU General @@ -28,14 +28,14 @@ using namespace std; parser::parser (systemtap_session& s, istream& i, bool p): session (s), input_name ("<input>"), free_input (0), - input (i, input_name), privileged (p), + input (i, input_name, s), privileged (p), last_t (0), next_t (0), num_errors (0) { } parser::parser (systemtap_session& s, const string& fn, bool p): session (s), input_name (fn), free_input (new ifstream (input_name.c_str(), ios::in)), - input (* free_input, input_name), privileged (p), + input (* free_input, input_name, s), privileged (p), last_t (0), next_t (0), num_errors (0) { } @@ -397,8 +397,8 @@ parser::peek_kw (std::string const & kw) -lexer::lexer (istream& i, const string& in): - input (i), input_name (in), cursor_line (1), cursor_column (1) +lexer::lexer (istream& i, const string& in, systemtap_session& s): + input (i), input_name (in), cursor_line (1), cursor_column (1), session(s) { } @@ -472,6 +472,31 @@ lexer::scan () else break; } + + // Expand command line arguments to literals. $1 .. $999 as + // numbers and @1 .. @999 as strings. + if (n->content[0] == '@' || n->content[0] == '$') + { + string idxstr = n->content.substr(1); + const char* startp = idxstr.c_str(); + char *endp; + errno = 0; + unsigned long idx = strtoul (startp, &endp, 10); + if (endp == startp) + ; // no numbers at all - leave alone as identifier + else + { + // Use @1/$1 as the base, not @0/$0. Thus the idx-1. + if (errno == ERANGE || errno == EINVAL || *endp != '\0' || + idx == 0 || idx-1 >= session.args.size ()) + throw parse_error ("command line argument index invalid or out of range"); + + string arg = session.args[idx-1]; + n->type = (n->content[0] == '@') ? tok_string : tok_number; + n->content = arg; + } + } + return n; } |