GNU PROLOG with UTF8 support
atom.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------*
2  * GNU Prolog *
3  * *
4  * Part : Prolog engine *
5  * File : atom.h *
6  * Descr.: atom table management - header file *
7  * Author: Daniel Diaz *
8  * *
9  * Copyright (C) 1999-2015 Daniel Diaz *
10  * *
11  * This file is part of GNU Prolog *
12  * *
13  * GNU Prolog is free software: you can redistribute it and/or *
14  * modify it under the terms of either: *
15  * *
16  * - the GNU Lesser General Public License as published by the Free *
17  * Software Foundation; either version 3 of the License, or (at your *
18  * option) any later version. *
19  * *
20  * or *
21  * *
22  * - the GNU General Public License as published by the Free *
23  * Software Foundation; either version 2 of the License, or (at your *
24  * option) any later version. *
25  * *
26  * or both in parallel, as here. *
27  * *
28  * GNU Prolog is distributed in the hope that it will be useful, *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
31  * General Public License for more details. *
32  * *
33  * You should have received copies of the GNU General Public License and *
34  * the GNU Lesser General Public License along with this program. If *
35  * not, see http://www.gnu.org/licenses/. *
36  *-------------------------------------------------------------------------*/
37 
38 #include "pl_wchar.h"
39 #if 1
40 #define OPTIM_1_CHAR_ATOM
41 #endif
42 
43 
44 
45 
46 /*---------------------------------*
47  * Constants *
48  *---------------------------------*/
49 
50  /* Character Classification */
51 
52 #define LA 1 /* layout character */
53 #define SC 2 /* solo character */
54 #define QT 4 /* quote */
55 #define DQ 8 /* double quote */
56 #define BQ 16 /* back quote */
57 #define GR 32 /* graphic char */
58 #define PC 64 /* punctuation character */
59 #define DI 128 /* digit */
60 #define UL 256 /* underline */
61 #define CL 512 /* capital letter */
62 #define SL 1024 /* small letter */
63 #define CM 2048 /* comment character (%) */
64 #define EX 4096 /* extended character */
65 
66 
67 
68 /* NB: (hash) atom table size should not be < ATOM_NIL (else module will change it) */
69 
70 #define ATOM_NIL 256
71 
72 
73 
74 
75  /* Atom Type */
76 
77 #define IDENTIFIER_ATOM 0
78 #define GRAPHIC_ATOM 1
79 #define SOLO_ATOM 2
80 #define OTHER_ATOM 3
81 
82 
83 
84 #if 0
85 #define Is_Valid_Code(c) ((PlULong) (c)-1 < 256-1) /* 1 <= c < 256 */
86 #else
87 #define Is_Valid_Code(c) 1
88 #endif
89 #define Is_Valid_Byte(c) ((PlULong) (c) < 256) /* 0 <= c < 256 */
90 #define Is_Valid_Atom(a) ((PlULong) (a) < pl_max_atom && \
91  pl_atom_tbl[(a)].name!=NULL)
92 
93 
94 
95 /*---------------------------------*
96  * Type Definitions *
97  *---------------------------------*/
98 
99 
100 typedef struct /* Atom properties */
101 { /* ------------------------------ */
102  unsigned length:16; /* its length (in bytess) */
103  unsigned count:16; /* its length (in characters) */
104  unsigned op_mask:4; /* operator defined for the atom */
105  unsigned type:2; /* IDENTIFIER GRAPHIC SOLO OTHER */
106  unsigned needs_quote:1; /* needs ' around it ? */
107  unsigned needs_scan:1; /* contains ' or control char ? */
108 }
109 AtomProp;
110 
111 
112 
113 
114 typedef struct /* Atom information */
115 { /* ------------------------------ */
116  char *name; /* key is <name> (the string) */
117  unsigned hash; /* the hash code of string (name) */
118  AtomProp prop; /* associated properties */
119  void *info; /* an user info (used by g_var) */
120 }
121 AtomInf;
122 
123 
124 
125 
126 /*---------------------------------*
127  * Global Variables *
128  *---------------------------------*/
129 
130 #ifdef ATOM_FILE
131 
134 int pl_nb_atom;
135 
136 int pl_atom_void;
138 
139 int pl_atom_false;
140 int pl_atom_true;
141 
143 
144 #ifndef OPTIM_1_CHAR_ATOM
145 int atom_char[256];
146 #endif
147 
148  /* int pl_char_type[256]; see definition in atom.c */
149 char pl_char_conv[256];
150 
151 
152  /* char pl_escape_symbol[]; see definition in atom.c */
153  /* char pl_escape_char []; see definition in atom.c */
154 
155 #else
156 
157 extern AtomInf *pl_atom_tbl;
158 extern PlULong pl_max_atom;
159 extern int pl_nb_atom;
160 
161 extern int pl_atom_void;
162 extern int pl_atom_curly_brackets;
163 
164 extern int pl_atom_false;
165 extern int pl_atom_true;
166 
167 extern int pl_atom_end_of_file;
168 
169 #ifndef OPTIM_1_CHAR_ATOM
170 extern int atom_char[];
171 #endif
172 
173 extern char pl_char_conv[];
174 extern int pl_char_type[];
175 
176 extern char pl_escape_symbol[];
177 extern char pl_escape_char[];
178 
179 #endif
180 
181 PlLong pl_def_max_atom; /* overwritten if needed (see top_comp.c) */
182 
183 
184 
185 /*---------------------------------*
186  * Function Prototypes *
187  *---------------------------------*/
188 
189 void Pl_Init_Atom(void);
190 
191 int Pl_Create_Allocate_Atom(char *name);
192 
193 int Pl_Create_Atom(char *name);
194 
196 
197 int Pl_Find_Atom(char *name);
198 
199 int Pl_Gen_New_Atom(char *prefix);
200 
201 int Pl_Find_Next_Atom(int last_atom);
202 
203 
204 
205 #ifdef OPTIM_1_CHAR_ATOM
206 
207 #define ATOM_CHAR(c) ((int) (unsigned char) (c))
208 
209 #else
210 
211 #define ATOM_CHAR(c) (atom_char[(int) (unsigned char) (c)])
212 
213 #endif
214 
215 extern int ATOM_CHAR32(CHAR32_T c);
static char name[32]
Definition: test_oc_defs.h:8
int Pl_Create_Atom(char *name)
Definition: atom.c:219
PlLong pl_def_max_atom
Definition: atom.h:181
#define CHAR32_T
Definition: pl_wchar.h:9
void Pl_Init_Atom(void)
Definition: atom.c:144
AtomProp prop
Definition: atom.h:118
static CHAR32_T c
Definition: scan_supp.c:65
int pl_atom_false
int pl_atom_end_of_file
void * info
Definition: atom.h:119
PlULong pl_max_atom
Definition: test_linedit.c:52
intptr_t PlLong
Definition: gprolog.h:88
char pl_escape_char[]
Definition: atom.c:114
int pl_char_type[]
Definition: atom.c:84
AtomInf * pl_atom_tbl
Definition: chkma.c:1044
char pl_char_conv[]
Definition: atom.h:100
Definition: atom.h:114
unsigned hash
Definition: atom.h:117
char * name
Definition: atom.h:116
int Pl_Find_Next_Atom(int last_atom)
Definition: atom.c:589
int pl_atom_curly_brackets
int Pl_Create_Allocate_Atom(char *name)
Definition: atom.c:201
int pl_nb_atom
int pl_atom_true
int Pl_Gen_New_Atom(char *prefix)
Definition: atom.c:472
int count
Definition: test_oc.c:6
long WamWord
Definition: LINUX_SIGSEGV.c:4
char pl_escape_symbol[]
Definition: atom.c:113
int pl_atom_void
int Pl_Find_Atom(char *name)
Definition: atom.c:357
#define FC
Definition: arch_dep.h:294
int ATOM_CHAR32(CHAR32_T c)
Definition: atom.c:615
WamWord FC Pl_Create_Atom_Tagged(char *name)
Definition: atom.c:343
uintptr_t PlULong
Definition: gprolog.h:90