]> git.sur5r.net Git - cc65/blob - src/cc65/macrotab.h
New optimization
[cc65] / src / cc65 / macrotab.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                macrotab.h                                 */
4 /*                                                                           */
5 /*             Preprocessor macro table for the cc65 C compiler              */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000     Ullrich von Bassewitz                                        */
10 /*              Wacholderweg 14                                              */
11 /*              D-70597 Stuttgart                                            */
12 /* EMail:       uz@musoftware.de                                             */
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 /*****************************************************************************/
42 /*                                   data                                    */
43 /*****************************************************************************/
44
45
46
47 typedef struct Macro_ Macro;
48 struct Macro_ {
49     Macro*       Next;          /* Next macro with same hash value */
50     int          ArgCount;      /* Number of parameters, -1 = no parens */
51     unsigned     MaxArgs;       /* Size of formal argument list */
52     char**       FormalArgs;    /* Formal argument list */
53     char const** ActualArgs;    /* Actual argument list */
54     char*        Replacement;   /* Replacement text */
55     char         Name[1];       /* Name, dynamically allocated */
56 };
57
58
59
60 /*****************************************************************************/
61 /*                                   code                                    */
62 /*****************************************************************************/
63
64
65
66 Macro* NewMacro (const char* Name);
67 /* Allocate a macro structure with the given name. The structure is not
68  * inserted into the macro table.
69  */
70
71 void FreeMacro (Macro* M);
72 /* Delete a macro definition. The function will NOT remove the macro from the
73  * table, use UndefineMacro for that.
74  */
75
76 void AddNumericMacro (const char* Name, long Val);
77 /* Add a macro for a numeric constant */
78
79 void AddTextMacro (const char* Name, const char* Val);
80 /* Add a macro for a textual constant */
81
82 void InsertMacro (Macro* M);
83 /* Insert the given macro into the macro table. This call will also allocate
84  * the ActualArgs parameter array.
85  */
86
87 int UndefineMacro (const char* Name);
88 /* Search for the macro with the given name and remove it from the macro
89  * table if it exists. Return 1 if a macro was found and deleted, return
90  * 0 otherwise.
91  */
92
93 Macro* FindMacro (const char* Name);
94 /* Find a macro with the given name. Return the macro definition or NULL */
95
96 int IsMacro (const char* Name);
97 /* Return true if the given name is the name of a macro, return false otherwise */
98
99 int MaybeMacro (unsigned char C);
100 /* Return true if the given character may be the start of the name of an
101  * existing macro, return false if not.
102  */
103
104 const char* FindMacroArg (Macro* M, const char* Arg);
105 /* Search for a formal macro argument. If found, return the actual
106  * (replacement) argument. If the argument was not found, return NULL.
107  */
108
109 void AddMacroArg (Macro* M, const char* Arg);
110 /* Add a formal macro argument. */
111
112 int MacroCmp (const Macro* M1, const Macro* M2);
113 /* Compare two macros and return zero if both are identical. */
114
115 void PrintMacroStats (FILE* F);
116 /* Print macro statistics to the given text file. */
117
118
119
120 /* End of macrotab.h */
121 #endif
122
123
124
125