From ef474d24145b85f933d06a1648b0d9cbf6695fe5 Mon Sep 17 00:00:00 2001 From: jistone Date: Fri, 22 Dec 2006 02:34:05 +0000 Subject: 2006-12-21 Josh Stone PR 3671 * parse.cxx (parser::parse_global): Allow a maxsize on global arrays. * staptree.h (struct vardecl): Add the maxsize field. * staptree.cxx (vardecl::vardecl): Init. maxsize. (vardecl::set_arity): Don't allow arity 0 when there's a maxsize. (vardecl::compatible_arity): Ditto. (vardecl::print): Include maxsize in output. (target_symbol::print): Ditto. * translate.cxx (struct mapvar, mapvar::mapvar): Add maxsize. (mapvar::init): Init maps with the given maxsize if specified, else keep using MAXMAPENTRIES. (mapvar::set): Make the error message give the maxsize. (mapvar::add): Ditto, and check for overflow on pmap add. (c_unparser::getmap): Pass the maxsize from the vardecl to mapvar. --- parse.cxx | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'parse.cxx') diff --git a/parse.cxx b/parse.cxx index 26792010..881c75bc 100644 --- a/parse.cxx +++ b/parse.cxx @@ -1043,14 +1043,29 @@ parser::parse_global (vector & globals, vector& probes) globals.push_back (d); t = peek (); + + if (t && t->type == tok_operator && t->content == "[") // array size + { + int64_t size; + next (); + expect_number(size); + if (size <= 0 || size > 1000000) // arbitrary max + throw parse_error("array size out of range"); + d->maxsize = (int)size; + expect_known(tok_operator, "]"); + t = peek (); + } + if (t && t->type == tok_operator && t->content == "=") // initialization - { - next (); - d->init = parse_literal (); - d->set_arity(0); - d->type = d->init->type; - t = peek (); - } + { + if (!d->compatible_arity(0)) + throw parse_error("only scalar globals can be initialized"); + d->set_arity(0); + next (); + d->init = parse_literal (); + d->type = d->init->type; + t = peek (); + } if (t && t->type == tok_operator && t->content == ",") // next global { -- cgit