Skip to content

Commit

Permalink
Headerizer happiness work
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/trunk@43996 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
bacek committed Feb 16, 2010
1 parent ddb72fb commit 64d14f3
Showing 1 changed file with 42 additions and 30 deletions.
72 changes: 42 additions & 30 deletions src/pirmacro.c
Expand Up @@ -11,6 +11,17 @@

/* HEADERIZER HFILE: none */

/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */

static void check_size(ARGIN(macro_def * const macro), unsigned length)
__attribute__nonnull__(1);

#define ASSERT_ARGS_check_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(macro))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */

/*
=head1 FUNCTIONS
Expand All @@ -24,10 +35,6 @@ Actual expansion of the macros is completely handled in the lexer (pir.l).
*/

static void check_size(macro_def * const macro, unsigned length);




/*
Expand All @@ -41,6 +48,7 @@ Create a new macro definition node and store it in the macro_table C<table>
*/
PARROT_MALLOC
PARROT_IGNORABLE_RESULT
PARROT_CAN_RETURN_NULL
macro_def *
new_macro(macro_table * const table, char const * const name, int lineno, int takes_args,
unsigned initsize)
Expand All @@ -65,8 +73,7 @@ new_macro(macro_table * const table, char const * const name, int lineno, int ta

/*
=item C<macro_param *
new_macro_param(char const * const value)>
=item C<macro_param * new_macro_param(char const * const value)>
Constructor for a C<macro_param> struct object. Initializes
the C<name> attribute of the C<macro_param> object to C<value>.
Expand All @@ -79,7 +86,8 @@ PARROT_MALLOC
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
macro_param *
new_macro_param(char const * const value) {
new_macro_param(char const * const value)
{
macro_param *param = (macro_param *)mem_sys_allocate(sizeof (macro_param));
param->name = value;
param->next = NULL;
Expand All @@ -88,16 +96,16 @@ new_macro_param(char const * const value) {

/*
=item C<void
add_macro_param(macro_def * const macro, char * const name)>
=item C<void add_macro_param(macro_def * const macro, char const * const name)>
Add a macro parameter by name of C<name> to the macro definition C<macro>.
=cut
*/
void
add_macro_param(macro_def * const macro, char const * const name) {
add_macro_param(macro_def * const macro, char const * const name)
{
macro_param *param = new_macro_param(name);
param->next = macro->parameters;
macro->parameters = param;
Expand Down Expand Up @@ -130,8 +138,7 @@ new_macro_const(macro_table * const table, char const * const name, char const *

/*
=item C<void
check_size(macro_def * const macro, unsigned length)>
=item C<static void check_size(macro_def * const macro, unsigned length)>
Check C<macro>'s buffer size whether C<length> bytes can be added;
if not, then the buffer is doubled in size.
Expand All @@ -140,7 +147,8 @@ if not, then the buffer is doubled in size.
*/
static void
check_size(macro_def * const macro, unsigned length) {
check_size(ARGIN(macro_def * const macro), unsigned length)
{
unsigned used = macro->cursor - macro->body;
if (used + length >= macro->buffersize) {
unsigned newsize = macro->buffersize << 1;
Expand All @@ -159,16 +167,16 @@ check_size(macro_def * const macro, unsigned length) {

/*
=item C<void
store_macro_char(macro_def * const macro, char c)>
=item C<void store_macro_char(macro_def * const macro, char c)>
Store the character C<c> in C<macro>'s body buffer.
=cut
*/
void
store_macro_char(macro_def * const macro, char c) {
store_macro_char(ARGIN(macro_def * const macro), char c)
{
/* if buffer is full, resize it. */
check_size(macro, 1);
*(macro->cursor)++ = c;
Expand All @@ -190,7 +198,8 @@ beforehand how much space we need in the buffer due to the var. arg. list.
*/
void
store_macro_string(macro_def * const macro, char const * const str, ...) {
store_macro_string(macro_def * const macro, char const * const str, ...)
{
va_list arg_ptr;

#define MAX_NUM_CHARS_IN_STRING 256
Expand All @@ -206,8 +215,8 @@ store_macro_string(macro_def * const macro, char const * const str, ...) {

/*
=item C<macro_def *
find_macro(constant_table * const table, char * const name)>
=item C<macro_def * find_macro(macro_table * const table, char const * const
name)>
Find the specified macro. If the specified macro does not exist,
NULL is returned.
Expand All @@ -218,7 +227,8 @@ NULL is returned.
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
macro_def *
find_macro(macro_table * const table, char const * const name) {
find_macro(macro_table * const table, char const * const name)
{
macro_def *iter = table->definitions;

PARROT_ASSERT(name != NULL);
Expand All @@ -243,8 +253,7 @@ find_macro(macro_table * const table, char const * const name) {

/*
=item C<macro_table *
new_macro_table(macro_table * const current)>
=item C<macro_table * new_macro_table(macro_table * const current)>
Create a new macro_table structure; set C<current> as its previous.
The newly created table is returned.
Expand All @@ -256,7 +265,8 @@ PARROT_MALLOC
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
macro_table *
new_macro_table(macro_table * const current) {
new_macro_table(ARGIN(macro_table * const current))
{
macro_table *table = (macro_table *)mem_sys_allocate_zeroed(sizeof (macro_table));
table->definitions = NULL;
table->prev = NULL;
Expand All @@ -278,22 +288,24 @@ Free resources allocated for the macro_table C<table>.
*/
void
delete_macro_table(macro_table * table) {
delete_macro_table(macro_table * table)
{
mem_sys_free(table);
}

/*
=item C<void
declare_macro_local(macro_def * const macro, char * const name)>
=item C<void declare_macro_local(macro_def * const macro, char const * const
name)>
Declare C<name> as a C<.macro_local> for the macro definition C<macro>.
=cut
*/
void
declare_macro_local(macro_def * const macro, char const * const name) {
declare_macro_local(macro_def * const macro, char const * const name)
{
macro_param * param = new_macro_param(name);
param->next = macro->macrolocals;
macro->macrolocals = param;
Expand All @@ -302,8 +314,7 @@ declare_macro_local(macro_def * const macro, char const * const name) {

/*
=item C<int
is_macro_local(macro_def * const macro, char * const name)>
=item C<int is_macro_local(macro_def * const macro, char const * const name)>
Check whether C<name> was declared as a C<.macro_local> in the macro
definition C<macro>.
Expand All @@ -313,7 +324,8 @@ definition C<macro>.
*/
PARROT_WARN_UNUSED_RESULT
int
is_macro_local(macro_def * const macro, char const * const name) {
is_macro_local(macro_def * const macro, char const * const name)
{
macro_param *iter = macro->macrolocals;

while (iter) {
Expand Down

0 comments on commit 64d14f3

Please sign in to comment.