aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/archetype/semantic.h
blob: 2166e81220b44b83920d3f88ef87c332beea7441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef ARCHETYPE_SEMANTIC
#define ARCHETYPE_SEMANTIC

/* Used by the SYNTAX unit, it provides the high-level semantic checking
 * as well as .ACX file output.
 */

#include "glk/archetype/array.h"
#include "glk/archetype/expression.h"
#include "glk/archetype/linked_list.h"

namespace Glk {
namespace Archetype {

/**
 * Works closely with the ID_Table to create and verify the various semantic
 * interpretations of identifiers, which are classified as either:
 *   TYPE_ID:      names a type definition template in the type list.
 *   OBJECT_ID:    names an object instantiation in the object list.
 *   ATTRIBUTE_ID: an attribute identifier.
 *   ENUMERATE_ID: an identifier like "open" or "closed" which is simply
 *                   assigned so that it can be tested.
 *   UNDEFINED_ID: Not defined anywhere.  If /K is asserted for CREATE, then
 *                 this is the value returned by default; otherwise,
 *                 ENUMERATE_ID is.
 *
 * @param f					the progfile that is being read.  Since this function is part
 *							of the first "pass", it needs access to the file being read.
 * @param id_number			the index in the ID table
 * @param interpretation	one of the constants above
 * @param ptr_to_data (IN)  if not nil, points to the data that the identifier represents
 *							(when first encountered)
 * @returns					depends on interpretation:
 *           TYPE_ID:      the index in Type_List
 *           OBJECT_ID:    the index in Object_List
 *           ATTRIBUTE_ID: the order the identifier was declared in, i.e.
 *                           for the first attribute encountered, 1, for the
 *                           second, 2, etc.
 *           ENUMERATE_ID: the unchanged id_number, for a simple unique number.
 *           UNDEFINED_ID: same as ENUMERATE_ID
 *
 *         In any case, classify_as returns 0 if there was an error.
 *         Such an error will have been printed by this routine, so there
 *         will be no need for the caller to print out its own.
 */
extern int classify_as(progfile &f, int id_number, ClassifyType interpretation, void *ptr_to_data);

/**
 * Given an ID_Table index, finds what it represents and returns an appropriate enumerated
 * type and index.
 * 
 * If /K is asserted, default return is UNDEFINED_ID; else it is ENUMERATE_ID.
 * @param id_number		integer index to ID_Table
 * @param meaning		Output classification of ID
 * @param number		Output integer appropriate to classification
 */
extern void get_meaning(int id_number, ClassifyType &meaning, int &number);

/**
 * Used for adding the number of an undefined identifier to a list to be produced
 * at the end of translation.
 */
extern void add_undefined(int the_ID);

/**
 * Displays the list of undefined identifiers collected with add_undefined
 */
extern bool display_undefined();

/**
 * Assumes that expression tree contains no OP_LPAREN nodes.
 * Ensures the following:
 * 1.    All OP_DOT operators have identifiers as their right-hand
 *       arguments, which are classified as ATTRIBUTE_ID's.
 * 2.    All assignment operators have OP_DOT operators or identifiers
 *       as their left-hand arguments, and any such identifiers are
 *       classified as ATTRIBUTE_ID's.
 * This is necessary because the only way to use the OP_DOT operator is
 * to discover the value of some attribute, and attributes are the only
 * things which may be assigned to.
 *
 * @param f				Program file (for logging errors)
 * @param the_expr		Expression to be verified
 */
extern bool verify_expr(progfile &f, ExprTree the_expr);

} // End of namespace Archetype
} // End of namespace Glk

#endif