]> git.sur5r.net Git - cc65/blob - src/ca65/symbol.c
Replace error/warning numbers by strings.
[cc65] / src / ca65 / symbol.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 symbol.c                                  */
4 /*                                                                           */
5 /*                   Parse a symbol name and search for it                   */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2003 Ullrich von Bassewitz                                       */
10 /*               Römerstraße 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 #include <string.h>
37
38 /* ca65 */
39 #include "error.h"
40 #include "nexttok.h"
41 #include "scanner.h"
42 #include "symbol.h"
43 #include "symtab.h"
44
45
46
47 /*****************************************************************************/
48 /*                                   Data                                    */
49 /*****************************************************************************/
50
51
52
53 /*****************************************************************************/
54 /*                                   Code                                    */
55 /*****************************************************************************/
56
57
58
59 SymEntry* ParseScopedSymName (int AllocNew)
60 /* Parse a (possibly scoped) symbol name, search for it in the symbol table
61  * and return the symbol table entry.
62  */
63 {
64     /* Get the starting table */
65     SymTable* Scope;
66     if (Tok == TOK_NAMESPACE) {
67         Scope = RootScope;
68         NextTok ();
69     } else {
70         Scope = CurrentScope;
71     }
72
73     /* Resolve scopes */
74     while (1) {
75
76         /* An identifier must follow. Remember and skip it. */
77         char Name[sizeof (SVal)];
78         if (Tok != TOK_IDENT) {
79             Error ("Identifier expected");
80             return 0;
81         }
82         strcpy (Name, SVal);
83         NextTok ();
84
85         /* If the next token is a namespace token, handle the name as the
86          * name of a scope, otherwise it's the name of a symbol in that
87          * scope.
88          */
89
90         if (Tok == TOK_NAMESPACE) {
91
92             /* Search for the child scope */
93             Scope = SymFindScope (Scope, Name, AllocNew);
94
95             /* Skip the namespace token */
96             NextTok ();
97
98             /* If we didn't find the scope, bail out */
99             if (Scope == 0) {
100                 return 0;
101             }
102
103         } else {
104
105             /* Search for the symbol and return it */
106             return SymFind (Scope, Name, AllocNew);
107
108         }
109     }
110 }
111
112
113