## symbol.pkg
# Compiled by:
#
src/lib/c-kit/src/ast/ast.sublib# K&R2, A11.1, C names fall into four spaces. Same name may be used for
# different purposes in the same scope if the uses are in different name
# spaces. These spaces are:
#
# 0. Chunks, functions, typedef names, and enum constants,
# 1. Labels,
# 2. Tags of structures, unions, and enumerations,
# 3. Members of structures and unions individually.
package symbol: Symbol { # Symbol is from
src/lib/c-kit/src/ast/symbol.api Symbol_Kind
= CHUNK
| FUNCTION
| TYPEDEF
| ENUMCONST
| LABEL
| TAG
| MEMBER tid::Uid
;
Symbol
=
{ name: String,
hash: unt::Unt,
kind: Symbol_Kind,
namespace: Int
};
hash = hash_string::hash_string;
fun namespace CHUNK => 0;
namespace FUNCTION => 0;
namespace TYPEDEF => 0;
namespace ENUMCONST => 0;
namespace LABEL => 1;
namespace TAG => 2;
namespace (MEMBER tid) => 3 + tid; # David B MacQueen: beware negative tid
end;
fun symbol { name, kind }
=
{ name,
kind,
hash => hash name,
namespace => namespace kind
};
fun name ( { name, ... }:Symbol) = name;
fun kind ( { kind, ... }:Symbol) = kind;
fun equal (symbol1: Symbol, symbol2: Symbol)
=
symbol1.hash == symbol2.hash and
symbol1.namespace == symbol2.namespace and
symbol1.name == symbol2.name;
fun compare (symbol1: Symbol, symbol2: Symbol)
=
case (unt::compare (symbol1.hash, symbol2.hash))
EQUAL
=>
case (int::compare (symbol1.namespace, symbol2.namespace))
EQUAL => string::compare (symbol1.name, symbol2.name);
x => x;
esac;
x => x;
esac;
fun chunk name = symbol { name, kind => CHUNK };
fun fn name = symbol { name, kind => FUNCTION };
fun typedef name = symbol { name, kind => TYPEDEF };
fun enum_const name = symbol { name, kind => ENUMCONST };
fun label name = symbol { name, kind => LABEL };
fun tag name = symbol { name, kind => TAG };
fun member (tid, name) = symbol { name, kind => MEMBER tid };
}; # package symbol
## Copyright (c) 1998 by Lucent Technologies
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.