[svn:parrot] r44001 - trunk/compilers/pirc/src
bacek at svn.parrot.org
bacek at svn.parrot.org
Tue Feb 16 10:37:55 UTC 2010
Author: bacek
Date: Tue Feb 16 10:37:54 2010
New Revision: 44001
URL: https://trac.parrot.org/parrot/changeset/44001
Log:
Really use headerizer
Modified:
trunk/compilers/pirc/src/pircompiler.c
trunk/compilers/pirc/src/pircompiler.h
Modified: trunk/compilers/pirc/src/pircompiler.c
==============================================================================
--- trunk/compilers/pirc/src/pircompiler.c Tue Feb 16 09:43:29 2010 (r44000)
+++ trunk/compilers/pirc/src/pircompiler.c Tue Feb 16 10:37:54 2010 (r44001)
@@ -15,17 +15,44 @@
#include "pirregalloc.h"
#include "pirerr.h"
-/* HEADERIZER HFILE: none */
+/* HEADERIZER HFILE: compilers/pirc/src/pircompiler.h */
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+PARROT_WARN_UNUSED_RESULT
+PARROT_CAN_RETURN_NULL
+static char const * find_string(
+ ARGIN(lexer_state * const lexer),
+ ARGIN(char const * const str))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
PARROT_MALLOC
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
static allocated_mem_ptrs * new_mem_ptrs_block(void);
+static void register_ptr(ARGIN(lexer_state *lexer), ARGIN(void *ptr))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+static void store_string(
+ ARGIN(lexer_state * const lexer),
+ ARGIN(char const * const str))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+#define ASSERT_ARGS_find_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer) \
+ , PARROT_ASSERT_ARG(str))
#define ASSERT_ARGS_new_mem_ptrs_block __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_register_ptr __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer) \
+ , PARROT_ASSERT_ARG(ptr))
+#define ASSERT_ARGS_store_string __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer) \
+ , PARROT_ASSERT_ARG(str))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
@@ -54,15 +81,15 @@
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
static allocated_mem_ptrs *
-new_mem_ptrs_block(void) {
+new_mem_ptrs_block(void)
+{
ASSERT_ARGS(new_mem_ptrs_block)
return mem_allocate_zeroed_typed(allocated_mem_ptrs);
}
/*
-=item C<static void
-register_ptr(lexer_state *lexer, void *ptr)>
+=item C<static void register_ptr(lexer_state *lexer, void *ptr)>
Store the pointer C<ptr> in a datastructure; whenever C<release_resources()>
is invoked, C<ptr> will be freed through C<mem_sys_free()>.
@@ -71,7 +98,9 @@
*/
static void
-register_ptr(NOTNULL(lexer_state *lexer), ARGIN(void *ptr)) {
+register_ptr(ARGIN(lexer_state *lexer), ARGIN(void *ptr))
+{
+ ASSERT_ARGS(register_ptr)
allocated_mem_ptrs *ptrs = lexer->mem_allocations;
PARROT_ASSERT(ptrs);
@@ -89,8 +118,8 @@
/*
-=item C<void *
-pir_mem_allocate_zeroed(lexer_state * const lexer, size_t numbytes)>
+=item C<void * pir_mem_allocate_zeroed(lexer_state * const lexer, size_t
+numbytes)>
Memory allocation function for all PIR internal functions. Memory is allocated
through Parrot's allocation functions, but the pointer to the allocated memory
@@ -106,7 +135,8 @@
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
void *
-pir_mem_allocate_zeroed(NOTNULL(lexer_state * const lexer), size_t numbytes) {
+pir_mem_allocate_zeroed(ARGIN(lexer_state * const lexer), size_t numbytes)
+{
void *ptr = mem_sys_allocate_zeroed(numbytes);
totalmem += numbytes;
@@ -117,8 +147,7 @@
/*
-=item C<void *
-pir_mem_allocate(NOTNULL(lexer_state * const lexer), size_t numbytes)>
+=item C<void * pir_mem_allocate(lexer_state * const lexer, size_t numbytes)>
See C<pir_mem_allocate_zeroed()>. Memory is C<not> guaranteed to be zeroed.
(It might, it might not, depending on what your system finds appropriate.
@@ -131,7 +160,8 @@
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
void *
-pir_mem_allocate(NOTNULL(lexer_state * const lexer), size_t numbytes) {
+pir_mem_allocate(ARGIN(lexer_state * const lexer), size_t numbytes)
+{
void *ptr = mem_sys_allocate(numbytes);
totalmem += numbytes;
@@ -152,7 +182,7 @@
*/
void
-init_hashtable(NOTNULL(lexer_state * const lexer), NOTNULL(hashtable * const table),
+init_hashtable(ARGIN(lexer_state * const lexer), ARGIN(hashtable * const table),
unsigned size)
{
table->contents = (bucket **)pir_mem_allocate_zeroed(lexer, size * sizeof (bucket *));
@@ -162,8 +192,8 @@
/*
-=item C<lexer_state *
-new_lexer(char * const filename, int flags)>
+=item C<lexer_state * new_lexer(PARROT_INTERP, char * const filename, int
+flags)>
Constructor for a lexer structure. Initializes all fields, creates
a Parrot interpreter structure.
@@ -175,7 +205,8 @@
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
lexer_state *
-new_lexer(PARROT_INTERP, NULLOK(char * const filename), int flags) {
+new_lexer(PARROT_INTERP, NULLOK(char * const filename), int flags)
+{
lexer_state *lexer = mem_allocate_zeroed_typed(lexer_state);
lexer->filename = filename;
lexer->interp = interp;
@@ -231,14 +262,15 @@
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
bucket *
-new_bucket(NOTNULL(lexer_state * const lexer)) {
+new_bucket(ARGIN(lexer_state * const lexer))
+{
return pir_mem_allocate_zeroed_typed(lexer, bucket);
}
/*
-=item C<static void
-store_string(lexer_state * const lexer, char const * const str)>
+=item C<static void store_string(lexer_state * const lexer, char const * const
+str)>
Store the string C<str> in a hashtable; whenever this string is needed, a pointer
to the same physical string is returned, preventing allocating different buffers
@@ -249,7 +281,9 @@
*/
static void
-store_string(NOTNULL(lexer_state * const lexer), NOTNULL(char const * const str)) {
+store_string(ARGIN(lexer_state * const lexer), ARGIN(char const * const str))
+{
+ ASSERT_ARGS(store_string)
hashtable *table = &lexer->strings;
unsigned long hash = get_hashcode(str, table->size);
bucket *b = new_bucket(lexer);
@@ -259,8 +293,8 @@
/*
-=item C<static char const *
-find_string(lexer_state * const lexer, char const * const str)>
+=item C<static char const * find_string(lexer_state * const lexer, char const *
+const str)>
Find the string C<str> in the lexer's string hashtable. If the string was found,
then a pointer to that buffer is returned. So, whenever for instance the string
@@ -273,7 +307,9 @@
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static char const *
-find_string(NOTNULL(lexer_state * const lexer), NOTNULL(char const * const str)) {
+find_string(ARGIN(lexer_state * const lexer), ARGIN(char const * const str))
+{
+ ASSERT_ARGS(find_string)
hashtable *table = &lexer->strings;
unsigned long hash = get_hashcode(str, table->size);
bucket *b = get_bucket(table, hash);
@@ -291,8 +327,8 @@
/*
-=item C<char *
-dupstrn(lexer_state * const lexer, char const * const source, size_t slen)>
+=item C<char const * dupstrn(lexer_state * const lexer, char * const source,
+size_t slen)>
See dupstr, except that this version takes the number of characters to be
copied. Easy for copying a string except the quotes, for instance.
@@ -306,7 +342,8 @@
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
char const *
-dupstrn(NOTNULL(lexer_state * const lexer), NOTNULL(char * const source), size_t slen) {
+dupstrn(ARGIN(lexer_state * const lexer), ARGIN(char * const source), size_t slen)
+{
char const * result = find_string(lexer, source);
/* make sure the string is terminated in time */
source[slen] = '\0';
@@ -339,7 +376,8 @@
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
char const *
-dupstr(NOTNULL(lexer_state * const lexer), NOTNULL(char * const source)) {
+dupstr(ARGIN(lexer_state * const lexer), ARGIN(char * const source))
+{
return dupstrn(lexer, source, strlen(source));
}
@@ -355,7 +393,8 @@
*/
void
-release_resources(NOTNULL(lexer_state *lexer)) {
+release_resources(ARGIN(lexer_state *lexer))
+{
allocated_mem_ptrs *iter;
if (TEST_FLAG(lexer->flags, LEXER_FLAG_VERBOSE))
@@ -398,7 +437,8 @@
*/
void
-pirwarning(lexer_state * const lexer, int lineno, char const * const message, ...) {
+pirwarning(lexer_state * const lexer, int lineno, char const * const message, ...)
+{
va_list arg_ptr;
fprintf(stderr, "warning (line %d): ", lineno);
va_start(arg_ptr, message);
Modified: trunk/compilers/pirc/src/pircompiler.h
==============================================================================
--- trunk/compilers/pirc/src/pircompiler.h Tue Feb 16 09:43:29 2010 (r44000)
+++ trunk/compilers/pirc/src/pircompiler.h Tue Feb 16 10:37:54 2010 (r44001)
@@ -158,20 +158,6 @@
/* accessor for current macro; always first on the list. */
#define CURRENT_MACRO(X) (X)->macros->definitions
-
-/* constructor for a lexer_state object */
-lexer_state *new_lexer(PARROT_INTERP, char * const filename, int flags);
-
-void release_resources(lexer_state *lexer);
-
-char const *dupstr(lexer_state * const lexer, char * const str);
-
-char const *dupstrn(lexer_state * const lexer, char * const str, size_t numchars);
-
-bucket *new_bucket(lexer_state * const lexer);
-
-void init_hashtable(lexer_state * const lexer, hashtable * const table, unsigned size);
-
/* same trick as in parrot's memory system, for "automagic" casting */
#define pir_mem_allocate_zeroed_typed(lxr, type) (type *)pir_mem_allocate_zeroed(lxr, sizeof (type))
@@ -179,11 +165,93 @@
* allocated will be freed after the compilation. If you only need some memory temporarily
* and freeing can be done soon after (manually), then use parrot's mem_sys_allocate().
*/
-void *pir_mem_allocate_zeroed(lexer_state * const lexer, size_t numbytes);
-void *pir_mem_allocate(lexer_state * const lexer, size_t numbytes);
+/* HEADERIZER BEGIN: compilers/pirc/src/pircompiler.c */
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+char const * dupstr(
+ ARGIN(lexer_state * const lexer),
+ ARGIN(char * const source))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+char const * dupstrn(
+ ARGIN(lexer_state * const lexer),
+ ARGIN(char * const source),
+ size_t slen)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+void init_hashtable(
+ ARGIN(lexer_state * const lexer),
+ ARGIN(hashtable * const table),
+ unsigned size)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+bucket * new_bucket(ARGIN(lexer_state * const lexer))
+ __attribute__nonnull__(1);
+
+PARROT_MALLOC
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+lexer_state * new_lexer(PARROT_INTERP,
+ NULLOK(char * const filename),
+ int flags)
+ __attribute__nonnull__(1);
+
+PARROT_MALLOC
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+void * pir_mem_allocate(ARGIN(lexer_state * const lexer), size_t numbytes)
+ __attribute__nonnull__(1);
+
+PARROT_MALLOC
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+void * pir_mem_allocate_zeroed(
+ ARGIN(lexer_state * const lexer),
+ size_t numbytes)
+ __attribute__nonnull__(1);
+
+void pirwarning(
+ lexer_state * const lexer,
+ int lineno,
+ char const * const message,
+ ...);
+
+void release_resources(ARGIN(lexer_state *lexer))
+ __attribute__nonnull__(1);
+
+#define ASSERT_ARGS_dupstr __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer) \
+ , PARROT_ASSERT_ARG(source))
+#define ASSERT_ARGS_dupstrn __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer) \
+ , PARROT_ASSERT_ARG(source))
+#define ASSERT_ARGS_init_hashtable __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer) \
+ , PARROT_ASSERT_ARG(table))
+#define ASSERT_ARGS_new_bucket __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_new_lexer __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp))
+#define ASSERT_ARGS_pir_mem_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_pir_mem_allocate_zeroed __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+#define ASSERT_ARGS_pirwarning __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_release_resources __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(lexer))
+/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+/* HEADERIZER END: compilers/pirc/src/pircompiler.c */
-void pirwarning(lexer_state * const lexer, int lineno, char const * const message, ...);
#endif /* PARROT_PIR_PIRCOMPILER_H_GUARD */
More information about the parrot-commits
mailing list