1/*****************************************************************************/
2/* */
3/* macrotab.h */
4/* */
5/* Preprocessor macro table for the cc65 C compiler */
6/* */
7/* */
8/* */
9/* (C) 2000-2005, Ullrich von Bassewitz */
10/* Roemerstrasse 52 */
11/* D-70794 Filderstadt */
12/* EMail: uz@cc65.org */
13/* */
14/* */
15/* This software is provided 'as-is', without any expressed or implied */
16/* warranty. In no event will the authors be held liable for any damages */
17/* arising from the use of this software. */
18/* */
19/* Permission is granted to anyone to use this software for any purpose, */
20/* including commercial applications, and to alter it and redistribute it */
21/* freely, subject to the following restrictions: */
22/* */
23/* 1. The origin of this software must not be misrepresented; you must not */
24/* claim that you wrote the original software. If you use this software */
25/* in a product, an acknowledgment in the product documentation would be */
26/* appreciated but is not required. */
27/* 2. Altered source versions must be plainly marked as such, and must not */
28/* be misrepresented as being the original software. */
29/* 3. This notice may not be removed or altered from any source */
30/* distribution. */
31/* */
32/*****************************************************************************/
33
34
35
36#ifndef MACROTAB_H
37#define MACROTAB_H
38
39
40
41/* common */
42#include "coll.h"
43#include "inline.h"
44#include "strbuf.h"
45
46
47
48/*****************************************************************************/
49/* data */
50/*****************************************************************************/
51
52
53
54/* Structure describing a macro */
55typedef struct Macro Macro;
56struct Macro {
57 Macro* Next; /* Next macro with same hash value */
58 int Expanding; /* Are we currently expanding this macro? */
59 int ArgCount; /* Number of parameters, -1 = no parens */
60 unsigned MaxArgs; /* Size of formal argument list */
61 Collection FormalArgs; /* Formal argument list (char*) */
62 StrBuf Replacement; /* Replacement text */
63 unsigned char Variadic; /* C99 variadic macro */
64 char Name[1]; /* Name, dynamically allocated */
65};
66
67
68
69/*****************************************************************************/
70/* Code */
71/*****************************************************************************/
72
73
74
75Macro* NewMacro (const char* Name);
76/* Allocate a macro structure with the given name. The structure is not
77** inserted into the macro table.
78*/
79
80void FreeMacro (Macro* M);
81/* Delete a macro definition. The function will NOT remove the macro from the
82** table, use UndefineMacro for that.
83*/
84
85void DefineNumericMacro (const char* Name, long Val);
86/* Define a macro for a numeric constant */
87
88void DefineTextMacro (const char* Name, const char* Val);
89/* Define a macro for a textual constant */
90
91void InsertMacro (Macro* M);
92/* Insert the given macro into the macro table. */
93
94int UndefineMacro (const char* Name);
95/* Search for the macro with the given name and remove it from the macro
96** table if it exists. Return 1 if a macro was found and deleted, return
97** 0 otherwise.
98*/
99
100Macro* FindMacro (const char* Name);
101/* Find a macro with the given name. Return the macro definition or NULL */
102
103#if defined(HAVE_INLINE)
104INLINE int IsMacro (const char* Name)
105/* Return true if the given name is the name of a macro, return false otherwise */
106{
107 return FindMacro (Name) != 0;
108}
109#else
110# define IsMacro(Name) (FindMacro (Name) != 0)
111#endif
112
113int FindMacroArg (Macro* M, const char* Arg);
114/* Search for a formal macro argument. If found, return the index of the
115** argument. If the argument was not found, return -1.
116*/
117
118void AddMacroArg (Macro* M, const char* Arg);
119/* Add a formal macro argument. */
120
121int MacroCmp (const Macro* M1, const Macro* M2);
122/* Compare two macros and return zero if both are identical. */
123
124void PrintMacroStats (FILE* F);
125/* Print macro statistics to the given text file. */
126
127
128
129/* End of macrotab.h */
130
131#endif
132