X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Flexer%2Fmacro.h;h=ba0f1fe735df4f36a8f989b6d6b94443ec6e0c02;hb=fcb970c24584cf72f46676ff1cb2e08013951392;hp=2264ad628bced23a4887b4206a80b24ac01f8820;hpb=237ba2110e3ceef00deffa01bd87189a269ca387;p=pspp diff --git a/src/language/lexer/macro.h b/src/language/lexer/macro.h index 2264ad628b..ba0f1fe735 100644 --- a/src/language/lexer/macro.h +++ b/src/language/lexer/macro.h @@ -20,20 +20,17 @@ #include #include +#include "libpspp/hmap.h" +#include "libpspp/str.h" #include "language/lexer/token.h" -struct macro_tokens - { - struct token *tokens; - size_t n; - }; - -void macro_tokens_uninit (struct macro_tokens *); +struct macro_expander; struct macro_param { - char *name; /* NULL for a positional parameter. */ - struct macro_tokens def; /* Default expansion. */ + bool positional; /* Is this a positional parameter? */ + char *name; /* "!1" or "!name". */ + struct tokens def; /* Default expansion. */ bool expand_arg; /* Macro-expand the argument? */ enum @@ -54,15 +51,44 @@ struct macro_param struct macro { + struct hmap_node hmap_node; /* Indexed by 'name'. */ char *name; struct macro_param *params; size_t n_params; - char **body; - size_t n_body; + struct substring body; + struct tokens body_tokens; }; void macro_destroy (struct macro *); +struct macro_set + { + struct hmap macros; + }; + +struct macro_set *macro_set_create (void); +void macro_set_destroy (struct macro_set *); +const struct macro *macro_set_find (const struct macro_set *, + const char *); +void macro_set_add (struct macro_set *, struct macro *); + +static inline bool +macro_set_is_empty (const struct macro_set *set) +{ + return hmap_is_empty (&set->macros); +} + +/* Macro expansion. */ + +int macro_expander_create (const struct macro_set *, + const struct token *, + struct macro_expander **); +void macro_expander_destroy (struct macro_expander *); + +int macro_expander_add (struct macro_expander *, const struct token *); + +void macro_expander_get_expansion (struct macro_expander *, struct tokens *); + #endif /* macro.h */