<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">// -*- mode: java; c-basic-offset: 4 -*-
//
// Copyright 2001-2002 by the Regents of the University of California.
// All rights reserved.
//
//      HARMONIA: C language module name resolution
//
// RCS Info: $Revision: 1.1 $ on $Date: 2003/05/12 01:49:32 $
//           $Source: /home/cs/harmonia/cvsroot/www/harmonia/projects/langs/c/c-resolve.def,v $
//


// Not usable yet, alas:
// -*- mode: harmonia-astdef2; c-basic-offset: 4 -*-
import "Node.def";
import "ParentNode.def";
import "ListNode.def";

import "AmbigNode.def";
import "GLRStateMixin.def";

include "common/stl.h"
include "common/PooledString.h"
include "lk/isemant/Scope.h"
include "lk/isemant/NestedScope.h"
include "lk/isemant/OverlayScope.h"
include "lk/isemant/SemantErrors.h"
include "lk/node/UltraRoot.h"

include "c.h"

phylum trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
    
    public virtual method void semant() {}
}

// trans_unit -&gt; SeqR0E0:ext_decls 
operator TranslationUnit extends ParentNode, trans_unit, GLRStateMixin {
    public slot TypecheckContext *type_context;

    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	for (ext_decls_iterator i = get_ext_decls(); i; ++i) {
	    if (!i.get_ext_decl()-&gt;resolve_idents(ctx, idents))
		return false;
	}
	return true;
    }

    public virtual method void semant() {
	clear_semant_errors_subtree(cast_to_Node());
 	for (ext_decls_iterator i = get_ext_decls(); i; ++i) {
	    bool keep_going = root()-&gt;get_bool_prop(ALWAYS_DO_SEMANTICS);
	    //fprintf(stderr, "keep_going is %d\n", keep_going);
	    bool is_preproc
                = i.get_ext_decl()-&gt;is_preproc_directive(keep_going);
 	    if (is_preproc)
 		return;
	}
	{
	    ResolveContext ctx;
	    RootIdentTable filescope_idents;
	    if (!resolve_idents(&amp;ctx, &amp;filescope_idents))
		error("Unexpected mismatch at top level!\n");
	} {
	    type_context = new TypecheckContext();
	    check_types(type_context);
	}
    }
}

operator no_trans_unit extends Node, trans_unit, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
    public virtual method void semant() {}
}

operator trans_unit_sym extends AmbigNode, trans_unit, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in translation unit!\n");
	return false;
    }
    public virtual method void semant() {
	error("Unexpected ambiguity in translation unit!\n");
    }
}

phylum ext_decl depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
    public virtual method bool is_preproc_directive(bool keep_going) {
	return false;
    }
}

// ext_decl -&gt; SeqR1E0:specs declr:declr SeqR1E2:decls comp_stmt:body 
operator FunctionDefinition extends ParentNode, ext_decl, GLRStateMixin
depends on decl, declr, Declaration {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	decl::ResolveType base_type;
	Localizer&lt;DeclContext&gt; save(&amp;ctx-&gt;decl_cx);
	Localizer&lt;LabelTable *&gt; save2(&amp;ctx-&gt;labels); // not really needed
	ctx-&gt;decl_cx = FUNC_DEF;
	for (specs_iterator i = get_specs(); i; ++i) {
	    if (!i.get_spec()-&gt;resolve_idents(ctx, idents))
		return false;
	    i.get_spec()-&gt;get_resolve_type(ctx, &amp;base_type);
	}
	if (!Declaration::check_resolve_type(ctx, &amp;base_type, this))
	    return false;
	if (!get_declr()-&gt;resolve_idents(ctx, idents, &amp;base_type))
	    return false;
	ctx-&gt;decl_cx = FUNC_DEF;
	declr::FunctionDeclType type = get_declr()-&gt;declares_func();
	if (type == declr::NOT_A_FUNCTION) {
	    ambig_semant_error(ctx, this, "function declaration "
			       "does not declare a function");
	    if (ctx-&gt;inside_ambig)
		return false;
	}
	NestedIdentTable func_idents;
	func_idents.add_parent(idents);
	if (type == declr::ANSI_FUNCTION) {
	    if (get_decls())
		set_semant_error(this, "ANSI functions cannot take extra "
				 "declarations");
	    get_declr()-&gt;declare_ansi_idents(ctx, &amp;func_idents);
	} else if (type == declr::K_AND_R_FUNCTION) {
	    ctx-&gt;decl_cx = KnR_PARAM;
	    for (decls_iterator i = get_decls(); i; ++i) {
		if (!i.get_decl()-&gt;resolve_idents(ctx, &amp;func_idents))
		    return false;
	    }
	    get_declr()-&gt;check_KnR_idents(ctx, &amp;func_idents);
	}
	ctx-&gt;decl_cx = NO_DECL;
	ctx-&gt;labels = new LabelTable();
	int ret = get_body()-&gt;resolve_idents(ctx, &amp;func_idents, false);
	for (LabelTable::iterator i 
		 = ctx-&gt;labels-&gt;get_bindings(); i; ++i) {
	    LabelInfo *info = i.get_entity();
	    if (info-&gt;defs.size() == 0) {
		for (vector&lt;GotoStatement *, gc_allocator&gt;::iterator i
			 = info-&gt;uses.begin(); i != info-&gt;uses.end(); ++i) {
		    set_semant_error(*i, "Undefined label %s",
				     info-&gt;name.chars());
		}
	    } else if (info-&gt;defs.size() &gt; 1) {
		for (vector&lt;LabeledStatement *, gc_allocator&gt;::iterator i 
			 = info-&gt;defs.begin(); i != info-&gt;defs.end(); ++i) {
		    set_semant_error(*i, "Duplicate definition of label %s",
				     info-&gt;name.chars());
		}
	    } else {
		for (vector&lt;GotoStatement *, gc_allocator&gt;::iterator i
			 = info-&gt;uses.begin(); i != info-&gt;uses.end(); ++i) {
		    (*i)-&gt;target.set_value(vg(), info-&gt;defs[0]);
		    (*i)-&gt;compute_synth_attrs(true);
		}
	    }
	}
	ctx-&gt;labels = 0;
	return ret;
    }
}

// ext_decl -&gt; decl:decl 
operator OtherExtDeclaration extends ParentNode, ext_decl, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	Localizer&lt;DeclContext&gt; save(&amp;ctx-&gt;decl_cx);
	ctx-&gt;decl_cx = FILE_SCOPE;
	bool res = get_decl()-&gt;resolve_idents(ctx, idents);
// 	cerr &lt;&lt; "Ident table is now:" &lt;&lt; endl;
// 	idents-&gt;dump(cerr);
	return res;
    }
}

operator PreprocessorJunk {
    public virtual method bool is_preproc_directive(bool keep_going) {
	if (!keep_going) {
	    set_semant_error(this, "Can't run semantics with preprocessor "
	                     "directives");
	    return true;
	}
	return false;
    }
}

operator no_ext_decl extends Node, ext_decl, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

operator ext_decl_sym extends AmbigNode, ext_decl, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return resolve_idents_func&lt;ext_decl, ext_decl_sym&gt;(ctx, idents, this);
    }
}

phylum decl_spec depends on decl {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	error("Unexpected call to decl_spec::get_resolve_type\n");
    }
}

// decl_spec -&gt; stor_class_spec:spec 
operator StorageDeclSpec extends ParentNode, decl_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	get_spec()-&gt;get_resolve_type(ctx, type);
    }
}

// decl_spec -&gt; type_spec:spec 
operator TypeSpecDeclSpec extends ParentNode, decl_spec, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_spec()-&gt;resolve_idents(ctx, idents);
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	get_spec()-&gt;get_resolve_type(ctx, type);
    }
}

// decl_spec -&gt; type_qual:qual 
operator TypeQualDeclSpec extends ParentNode, decl_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	get_qual()-&gt;get_resolve_type(ctx, type);
    }
}

// decl_spec -&gt; INLINE:qual 
operator FunctionQualDeclSpec extends ParentNode, decl_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	/* nothing to do */
    }
}

operator decl_spec_sym extends AmbigNode, decl_spec, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in declaration specifier!\n");
	return true;
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	error("Unexpected ambiguity in declaration specifier!\n");
    }
}

phylum declr depends on decl {
    public enum FunctionDeclType {
	NOT_A_FUNCTION,
	K_AND_R_FUNCTION,
	ANSI_FUNCTION
    };

    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      decl::ResolveType *base_type) {
	return true;
    }
    public virtual method declr::FunctionDeclType declares_func() {
	error("Not reached\n");
	return NOT_A_FUNCTION;
    }
    public virtual method IDSYM* find_name() { 
	return 0;
    }
    public virtual method void declare_ansi_idents(ResolveContext *ctx,
						   IdentTable *func_idents) {
	error("Unexpected call to declr::declare_ansi_idents\n");
    }
    public virtual method void declare_ident(ResolveContext *ctx,
					     IdentTable *func_idents) {
	error("Unexpected call to declr::declare_ident\n");
    }
    public virtual method void check_KnR_idents(ResolveContext *ctx,
						IdentTable *func_idents) {
	error("Unexpected call to declr::check_KnR-idents\n");
    }
}

// declr -&gt; OptR47E0:ptr direct_declr:direct 
operator Declarator extends ParentNode, declr, GLRStateMixin {
    public versioned slot Vptr identifier = NULL;
    versioned Semantics attribute identifier
	= TypedVal((Node*)identifier.value(vg(), gvid));

    public versioned slot Vptr linkage_link = NULL;
    versioned Semantics attribute linkage_link
	= TypedVal((Node*)linkage_link.value(vg(), gvid));

    public slot int decl_context;

    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      decl::ResolveType *base_type) {
	// decl TypeInfo my_type = *base_type;
	// if (has_ptr())
	//     get_ptr()-&gt;specify(my_type)
	if (!get_direct()-&gt;resolve_idents(ctx, idents))
	    return false;
	IDSYM *name_node = find_name();
	identifier.set_value(vg(), name_node-&gt;cast_to_Node());
	compute_synth_attrs(true);
	PooledString id_name = name_node-&gt;pooled_string();
	IdentInfo::IdentType id_type;
	if (base_type-&gt;storage == decl::TYPEDEF_STORAGE) {
	    id_type = IdentInfo::TYPEDEF_ID;
	    name_node-&gt;set_subspecies(ctx, IDSYM::TYPEDEF_DECL_NAME);
	} else {
	    id_type = IdentInfo::OBJECT_ID;
	    name_node-&gt;set_subspecies(ctx, IDSYM::DECLARATION_NAME);
	}
	IdentInfo *info = new IdentInfo(id_name, id_type, this);
	decl_context = ctx-&gt;decl_cx;
	switch (ctx-&gt;decl_cx) {
	case FOR_INIT:
	case BLOCK:
	    if (base_type-&gt;storage != decl::EXTERN_STORAGE) {
		if (idents-&gt;has_ident_binding(id_name)) {
		    set_semant_error(this, "Identifier `%s' redefined",
				     id_name.chars());
		    return true;
		}
		break;
	    }
	    /* fall through */
	case FILE_SCOPE:
	case FUNC_DEF:
	    {
		IdentInfo *prev_info = idents-&gt;resolve_ident(id_name);
		info-&gt;link = prev_info;
		if (prev_info) {
		    linkage_link.set_value(vg(), prev_info-&gt;definition);
		    compute_synth_attrs(true);
		}
		info-&gt;defined = (ctx-&gt;decl_init || ctx-&gt;decl_cx == FUNC_DEF);
		if (prev_info &amp;&amp; prev_info-&gt;type != IdentInfo::OBJECT_ID)
		    set_semant_error(this, "Identifier `%s' redeclared as a "
				     "different kind of identifier",
				     id_name.chars());
		if (prev_info &amp;&amp; prev_info-&gt;defined &amp;&amp; info-&gt;defined)
		    set_semant_error(this, "Duplicate definition of `%s'",
				     id_name.chars());
		if (base_type-&gt;storage == decl::STATIC_STORAGE) {
		    if (prev_info &amp;&amp;
			prev_info-&gt;linkage != IdentInfo::INTERNAL_LINKAGE) {
			set_semant_error(this, "Identifier `%s' was declared "
					 "non-static and then static",
					 id_name.chars());
		    }
		    info-&gt;linkage = IdentInfo::INTERNAL_LINKAGE;
		} else if (base_type-&gt;storage == decl::EXTERN_STORAGE ||
			   (ctx-&gt;decl_cx == FUNC_DEF &amp;&amp;
			    base_type-&gt;storage == decl::NO_STORAGE)) {
		    if (prev_info &amp;&amp;
			prev_info-&gt;linkage != IdentInfo::NO_LINKAGE) {
			info-&gt;linkage = prev_info-&gt;linkage;
		    } else {
			info-&gt;linkage = IdentInfo::EXTERNAL_LINKAGE;
		    }
		} else if (base_type-&gt;storage == decl::NO_STORAGE) {
		    if (!prev_info) {
			info-&gt;linkage = IdentInfo::EXTERNAL_LINKAGE;
		    } else if (prev_info-&gt;linkage
			       == IdentInfo::INTERNAL_LINKAGE) {
			set_semant_error(this, "Identifier `%s' was declared "
					 "static and then non-static",
					 id_name.chars());
		    } else {
			info-&gt;linkage = prev_info-&gt;linkage;
		    }
		} else if (base_type-&gt;storage == decl::TYPEDEF_STORAGE) {
		    if (idents-&gt;has_ident_binding(id_name)) {
			set_semant_error(this, "Identifier `%s' redefined",
					 id_name.chars());
			return true;
		    }		    
		} else {
		    error("Unexpected storage class in declaration\n");
		}
		break;
	    }

	case KnR_PARAM:
	    name_node-&gt;set_subspecies(ctx, IDSYM::KNR_PARAM_DECL_NAME);
	    goto parameter;
	case DEF_PARAM:
	case DECL_PARAM:
	    name_node-&gt;set_subspecies(ctx, IDSYM::PARAM_DECL_NAME);
	parameter:
	    if (idents-&gt;has_ident_binding(id_name)) {
		set_semant_error(this, "Duplicate parameter `%s'",
				 id_name.chars());
		return true;
	    }
	    break;

	case STRUCT_UNION_CX:
	    assert(ctx-&gt;aggr_members);
	    name_node-&gt;set_subspecies(ctx, IDSYM::AGGR_MEMBER_DECL_NAME);
	    if (ctx-&gt;aggr_members-&gt;has_binding(id_name)) {
		set_semant_error(this, "Duplicate member `%s'",
				 id_name.chars());
	    } else {
		info-&gt;type = IdentInfo::STRUCT_UNION_MEMBER;
		ctx-&gt;aggr_members-&gt;add(id_name, info);
	    }
	    return true;

	case NO_DECL:
	default:
	    error("Strange decl context\n");
	    break;
	}
	idents-&gt;add_ident(id_name, info);
	return true;
    }
    public virtual method void declare_ident(ResolveContext *ctx,
					     IdentTable
					     *func_idents) {
	PooledString id_name = find_name()-&gt;pooled_string();
	IdentInfo *info = new IdentInfo(id_name, IdentInfo::OBJECT_ID, this);
	func_idents-&gt;add_ident(id_name, info);
    }
    public virtual method declr::FunctionDeclType declares_func() {
	return get_direct()-&gt;declares_func();
    }
    public virtual method IDSYM* find_name() {
	return get_direct()-&gt;find_name();
    }
    public virtual method void declare_ansi_idents(ResolveContext *ctx,
						   IdentTable *func_idents) {
	get_direct()-&gt;declare_ansi_idents(ctx, func_idents);
    }
    public virtual method void check_KnR_idents(ResolveContext *ctx,
						IdentTable *func_idents) {
	get_direct()-&gt;check_KnR_idents(ctx, func_idents);
    }
}

operator declr_sym extends AmbigNode, declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      decl::ResolveType *base_type) {
	error("Unexpected ambiguity in declarator!\n");
	return false;
    }
    public virtual method IDSYM* find_name() { 
	error("Unexpected ambiguity in declarator!\n");
	return 0;
    }
    public virtual method declr::FunctionDeclType declares_func() {
	error("Unexpected ambiguity in declarator!\n");
	return NOT_A_FUNCTION;
    }
    public virtual method void declare_ansi_idents(ResolveContext *ctx,
						   IdentTable *func_idents) {
	error("Unexpected ambiguity in declarator!\n");
    }
    public virtual method void declare_ident(ResolveContext *ctx,
					     IdentTable
					     *func_idents) {
	error("Unexpected ambiguity in declarator!\n");
    }
    public virtual method void check_KnR_idents(ResolveContext *ctx,
						IdentTable *func_idents) {
	error("Unexpected call to declr::check_KnR-idents\n");
    }
}

phylum direct_declr depends on trans_unit, declr {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {

	error("Unexpected call too direct_declr::resolve_idents\n");
	return true;
    }
    public virtual method IDSYM* find_name() { 
	return 0;
    }
    public virtual method declr::FunctionDeclType declares_func() {
	return declr::NOT_A_FUNCTION;
    }
    public virtual method void declare_ansi_idents(ResolveContext *ctx,
						   IdentTable *func_idents) {
	error("Unexpected call to direct_declr::declare_ansi_idents\n");
    }
    public virtual method void check_KnR_idents(ResolveContext *ctx,
						IdentTable *func_idents) {
	error("Unexpected call to direct_declr::check_KnR_idents\n");
    }
    public virtual method bool could_be_typedef(ResolveContext *ctx,
						IdentTable *idents) {
	return false;
    }
}

// direct_declr -&gt; IDSYM:name 
operator DeclarNameDirDeclr extends ParentNode, direct_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {

	return true;	    
    }
    public virtual method IDSYM* find_name() { 
	return get_name();
    }
    public virtual method bool could_be_typedef(ResolveContext *ctx,
						IdentTable *idents) {
	IdentInfo *info = idents-&gt;resolve_ident(get_name()-&gt;pooled_string());
	if (info &amp;&amp; info-&gt;type == IdentInfo::TYPEDEF_ID)
	    return true;
	return false;
    }
}

// direct_declr -&gt; '(' ptr:(ptr:pointer)? direct:direct_declr ')'
operator ParenNameDirDeclr extends ParentNode, direct_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if ((ctx-&gt;decl_cx == DEF_PARAM || ctx-&gt;decl_cx == DECL_PARAM) &amp;&amp;
	    get_direct()-&gt;could_be_typedef(ctx, idents) &amp;&amp; ctx-&gt;inside_ambig) {
	    ambig_semant_error(ctx,  this, "single parenthesized typename in "
			       "parameter must be abstract function "
			       "declaration");
	    return false;
	}
	return get_direct()-&gt;resolve_idents(ctx, idents);
    }
    public virtual method IDSYM* find_name() { 
	return get_direct()-&gt;find_name();
    }
    public virtual method declr::FunctionDeclType declares_func() {
	return get_direct()-&gt;declares_func();
    }
}

// direct_declr -&gt; direct_declr:declr '[' SeqR52E2:quals OptR52E3 ']' 
operator BasicArrayDirDeclr extends ParentNode, direct_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_declr()-&gt;resolve_idents(ctx, idents))
	    return false;
	if (has_expr())
	    return get_expr_expr()-&gt;resolve_idents(ctx, idents);
	else
	    return true;
    }
    public virtual method IDSYM* find_name() { 
	return get_declr()-&gt;find_name();
    }
}

// direct_declr -&gt; direct_declr:declr '[' SeqR52E2:quals1 STATIC SeqR52E2:quals2 assign_expr:expr ']' 
operator StaticArrayDirDeclr extends ParentNode, direct_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_declr()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
    public virtual method IDSYM* find_name() { 
	return get_declr()-&gt;find_name();
    }
}

// direct_declr -&gt; direct_declr:declr '[' SeqR52E2:quals '*' ']' 
operator VariableArrayDirDeclr 
extends ParentNode, direct_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {

	return get_declr()-&gt;resolve_idents(ctx, idents);
    }
    public virtual method IDSYM* find_name() { 
	return get_declr()-&gt;find_name();
    }
}

// direct_declr -&gt; direct_declr:declr '(' param_type_list:params ')' 
operator TypeFuncListDirDeclr extends ParentNode, direct_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_declr()-&gt;resolve_idents(ctx, idents))
	    return false;
	Localizer&lt;DeclContext&gt; save(&amp;ctx-&gt;decl_cx);
	if (ctx-&gt;decl_cx == FUNC_DEF)
	    ctx-&gt;decl_cx = DEF_PARAM;
	else
	    ctx-&gt;decl_cx = DECL_PARAM;
	NestedIdentTable param_table;
	param_table.add_parent(idents);
	return get_params()-&gt;resolve_idents(ctx, &amp;param_table);
    }
    public virtual method IDSYM* find_name() { 
	return get_declr()-&gt;find_name();
    }
    public virtual method declr::FunctionDeclType declares_func() {
	return declr::ANSI_FUNCTION;
    }
    public virtual method void declare_ansi_idents(ResolveContext *ctx,
						   IdentTable *func_idents) {
	get_params()-&gt;declare_ansi_idents(ctx, func_idents);
    }
}

// direct_declr -&gt; direct_declr:declr '(' SeqR56E2:idents ')' 
operator IDFuncListDirDeclr extends ParentNode, direct_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_declr()-&gt;resolve_idents(ctx, idents))
	    return false;
	NestedIdentTable param_ids;
	param_ids.add_parent(idents);
	for (idents_iterator i = get_idents(); i; ++i) {	    
	    IDSYM *token = i.get_ident();
	    PooledString id_name = token-&gt;pooled_string();
	    IdentInfo *info = new IdentInfo(id_name, IdentInfo::OBJECT_ID, 
					    this);
	    IdentInfo *old_info = idents-&gt;resolve_ident(id_name);
	    if (old_info &amp;&amp; old_info-&gt;type == IdentInfo::TYPEDEF_ID) {
		ambig_semant_error(ctx, this, "typedef name can't be "
				   "redeclared as an old-style function "
				   "parameter");
		if (ctx-&gt;inside_ambig)
		    return false;
	    }
	    if (param_ids.has_ident_binding(id_name)) {
		// It would be nice to put this on "token" rather than "this",
		// but tokens are shared between alternatives, so the error
		// message would leak out to the other alternative.
		// We could fix this by postponing setting error messages,
		// but that would be a pain.
		set_semant_error(this, "Parameter `%s' redefined",
				 id_name.chars());
	    } else {
		param_ids.add_ident(id_name, info);
	    }
	}
	return true;
    }
    public virtual method void check_KnR_idents(ResolveContext *ctx,
						IdentTable *func_idents) {
	int num_params = 0;
	for (idents_iterator i = get_idents(); i; ++i) {
	    IDSYM *token = i.get_ident();
	    PooledString id_name = token-&gt;pooled_string();
	    token-&gt;set_subspecies(ctx, IDSYM::KNR_PARAM_LIST_NAME);
	    if (!func_idents-&gt;has_ident_binding(id_name)) {
		set_semant_error(token, "Parameter %s was not declared",
				 id_name.chars());		
	    }
	    num_params++;
	}
	if (num_params &lt; func_idents-&gt;idents_size()) {
	    int extra = func_idents-&gt;idents_size() - num_params;
	    set_semant_error(this, "%d variable%s declared but "
			     "not present in prototype", extra,
			     (extra != 1 ? "s" : ""));
	}
    }
    public virtual method IDSYM* find_name() { 
	return get_declr()-&gt;find_name();
    }
    public virtual method declr::FunctionDeclType declares_func() {
	return declr::K_AND_R_FUNCTION;
    }
}

operator direct_declr_sym extends AmbigNode, direct_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return resolve_idents_func&lt;direct_declr, direct_declr_sym&gt;
	    (ctx, idents, this);
    }
    public virtual method IDSYM* find_name() {
	return direct_declr::phylum_cast(primary_alternative())-&gt;find_name();
    }
    public virtual method declr::FunctionDeclType declares_func() {
	return direct_declr::phylum_cast(primary_alternative())
	    -&gt;declares_func();
    }
    public virtual method void check_KnR_idents(ResolveContext *ctx,
						IdentTable *func_idents) {
	return direct_declr::phylum_cast(primary_alternative())
	    -&gt;check_KnR_idents(ctx, func_idents);
    }
}

phylum decl depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }

    public enum StorageClass {
	NO_STORAGE,
	TYPEDEF_STORAGE,
	STATIC_STORAGE,
	EXTERN_STORAGE,
	AUTO_STORAGE,
	REGISTER_STORAGE
    };

    public struct ResolveType : public Collectable {
	bool declares_typedef : 1;
	bool uses_typename : 1;
	bool uses_nontypename : 1;
	bool multiple_typename : 1;
	StorageClass storage;

	ResolveType() : declares_typedef(false), uses_typename(false),
	    uses_nontypename(false), multiple_typename(false),
	    storage(NO_STORAGE) {}
    };
}

// decl -&gt; SeqR1E0:specs SeqR8E1:declrs ';' 
operator Declaration extends ParentNode, decl, GLRStateMixin {
    public slot StorageClass storage_class;

    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	ResolveType base_type;
	for (specs_iterator i = get_specs(); i; ++i) {
	    if (!i.get_spec()-&gt;resolve_idents(ctx, idents))
		return false;
	    i.get_spec()-&gt;get_resolve_type(ctx, &amp;base_type);
	}	
	if (!check_resolve_type(ctx, &amp;base_type, this))
	    return false;
	storage_class = base_type.storage;
	for (declrs_iterator i = get_declrs(); i; ++i) {
	    if (!i.get_declr()-&gt;resolve_idents(ctx, idents, &amp;base_type))
		return false;
	}
	return true;
    }

    public static method bool check_resolve_type(ResolveContext *ctx,
						 ResolveType *type,
						 Node *node) {
	if (type-&gt;multiple_typename) {
	    ambig_semant_error(ctx, node, "too many typedef "
			       "names in declaration");
	    if (ctx-&gt;inside_ambig)
		return false;
	} else if (type-&gt;uses_typename &amp;&amp; type-&gt;uses_nontypename) {
	    ambig_semant_error(ctx, node,
			       "specifiers include both a typedef name and "
			       "another type specifier");
	    if (ctx-&gt;inside_ambig)
		return false;
	} else if (!type-&gt;uses_typename &amp;&amp; !type-&gt;uses_nontypename) {
	    ambig_semant_error(ctx, node, "C99 forbids a declaration with "
			       "no type");
	    if (ctx-&gt;inside_ambig)
		return false;
	}
	return true;
    }
}

operator no_decl extends Node, decl, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

operator decl_sym extends AmbigNode, decl, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return resolve_idents_func&lt;decl, decl_sym&gt;(ctx, idents, this);
    }
}

phylum init_declr depends on decl {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      decl::ResolveType *base_type) {
	return true;
    }
}

// init_declr -&gt; declr:declr OptR39E1:init 
operator InitDeclr extends ParentNode, init_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      decl::ResolveType *base_type) {
	Localizer&lt;bool&gt; save(&amp;ctx-&gt;decl_init);
	ctx-&gt;decl_init = has_init();
	if (!get_declr()-&gt;resolve_idents(ctx, idents, base_type))
	    return false;
	if (has_init()) {
	    return get_init_init()-&gt;resolve_idents(ctx, idents);
	}
	return true;
    }
}

operator init_declr_sym extends AmbigNode, init_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      decl::ResolveType *base_type) {
	error("Unexpected ambiguity in declrator!\n");
	return true;
    }
}


phylum comp_stmt depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      bool new_scope = true) {
	return true;
    }
}

// comp_stmt -&gt; '{' SeqR88E1:items '}' 
operator BlockStatement extends ParentNode, comp_stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      bool new_scope = true) {
	NestedIdentTable local_idents;
	IdentTable *table;
	if (new_scope) {
	    local_idents.add_parent(idents);
	    table = &amp;local_idents;
	} else {
	    table = idents;
	}
	for (items_iterator i = get_items(); i; ++i) {
	    if (!i.get_item_()-&gt;resolve_idents(ctx, table))
		return false;
	}
	return true;	    
    }
}

operator comp_stmt_sym extends AmbigNode, comp_stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      bool new_scope) {
	error("Unexpected ambiguity in block!\n");
	return true;
    }
}

phylum stor_class_spec depends on decl {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	error("Unexpected call to stor_class_spec::get_resolve_type\n");
    }
}

// stor_class_spec -&gt; AUTO 
operator AutoStrClassSpec extends ParentNode, stor_class_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	if (type-&gt;storage != decl::NO_STORAGE)
	    set_semant_error(this, "Duplicate storage class specifier");
	if (ctx-&gt;decl_cx != BLOCK &amp;&amp;
	    ctx-&gt;decl_cx != FOR_INIT)
	    set_semant_error(this, "'auto' is not allowed in this context");
	type-&gt;storage = decl::AUTO_STORAGE;
    }
}

// stor_class_spec -&gt; REGISTER 
operator RegisterStrClassSpec
extends ParentNode, stor_class_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	if (type-&gt;storage != decl::NO_STORAGE)
	    set_semant_error(this, "Duplicate storage class specifier");
	if (ctx-&gt;decl_cx == FILE_SCOPE ||
	    ctx-&gt;decl_cx == FUNC_DEF)
	    set_semant_error(this, "File-scope identifiers may not "
			     "be declared 'register'");
	type-&gt;storage = decl::REGISTER_STORAGE;
    }
}

// stor_class_spec -&gt; STATIC 
operator StaticStrClassSpec
extends ParentNode, stor_class_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	if (type-&gt;storage != decl::NO_STORAGE)
	    set_semant_error(this, "Duplicate storage class specifier");
	if (ctx-&gt;decl_cx != FILE_SCOPE &amp;&amp;
	    ctx-&gt;decl_cx != BLOCK &amp;&amp;
	    ctx-&gt;decl_cx != FUNC_DEF)
	    set_semant_error(this, "'static' is not allowed in this context");
	type-&gt;storage = decl::STATIC_STORAGE;
    }
}

// stor_class_spec -&gt; EXTERN 
operator ExternStrClassSpec
extends ParentNode, stor_class_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	if (type-&gt;storage != decl::NO_STORAGE)
	    set_semant_error(this, "Duplicate storage class specifier");
	if (ctx-&gt;decl_cx == KnR_PARAM ||
	    ctx-&gt;decl_cx == DEF_PARAM ||
	    ctx-&gt;decl_cx == DECL_PARAM)
	    set_semant_error(this, "Parameters can't be 'extern'");
	type-&gt;storage = decl::EXTERN_STORAGE;
    }
}

// stor_class_spec -&gt; TYPEDEF
operator TypedefStrClassSpec
extends ParentNode, stor_class_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	if (type-&gt;storage != decl::NO_STORAGE)
	    set_semant_error(this, "Duplicate storage class specifier");
	if (ctx-&gt;decl_cx != BLOCK &amp;&amp;
	    ctx-&gt;decl_cx != FILE_SCOPE)
	    set_semant_error(this, "You can't make a typedef out of that");
	type-&gt;storage = decl::TYPEDEF_STORAGE;
    }
}

operator no_stor_class_spec extends Node, stor_class_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	/* nothing */
    }
}

operator stor_class_spec_sym
extends AmbigNode, stor_class_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	error("Unexpected ambiguity in storage class specifier\n");
    }
}

phylum type_spec depends on decl {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	error("Unexpected call to type_spec::get_resolve_type\n");
    }
}

// type_spec -&gt; VOID 
operator VoidTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; CHAR 
operator CharTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; SHORT 
operator ShortTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; INT 
operator IntTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; LONG 
operator LongTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; FLOAT 
operator FloatTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; DOUBLE 
operator DoubleTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; SIGNED 
operator SignedTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; UNSIGNED 
operator UnsignedTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; _BOOL 
operator BooleanTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; _COMPLEX 
operator ComplexTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; _IMAGINARY 
operator ImaginaryTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; STRUCT OptR29E1:name '{' SeqR29E3:decls '}' 
operator StructDefinitionSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (has_name()) {
	    get_name_name()-&gt;set_subspecies(ctx, IDSYM::STRUCT_TAG_NAME);
	    PooledString tag = get_name_name()-&gt;pooled_string();
	    IdentInfo *info;
	    if (idents-&gt;has_tag_binding(tag)) {
		info = idents-&gt;resolve_tag(tag);
		assert(info);
		if (info-&gt;type != IdentInfo::STRUCT_TAG)
		    set_semant_error(this,"`%s' is a %s tag, not a struct tag",
				     tag.chars(),
				     info-&gt;type == IdentInfo::UNION_TAG ?
				     "union" : "enum");
		/* There's a subtle bug here with the interaction of this
		   check with ambiguity. If there's a forward declaration of
		   the struct before the current ambiguous region, as well
		   as this definition inside, we might have already seen this
		   definition before, and made a note that it's already been
		   defined. However, because we only localize changes to the
		   pointers in the symbol table, changes to members of the
		   info struct 'leak out'. The second condition here is a
		   quick check to avoid giving an error in that case. If
		   ambiguities covered larger portions of the syntax tree,
		   we'd need a better fix of actually saving and possibly
		   restoring all these fields. */
		else if (info-&gt;defined &amp;&amp; info-&gt;definition != this)
		    set_semant_error(this, "Duplicate definition of"
				     " struct `%s'",
				     tag.chars());
		else if (info-&gt;definition &amp;&amp; !info-&gt;defined) {
		    StructReferenceSpec *ref
		        = (StructReferenceSpec *)info-&gt;definition;
		    ref-&gt;completion.set_value(vg(), this);
		    ref-&gt;compute_synth_attrs(true);
		}
	    } else {
		info = new IdentInfo(tag, IdentInfo::STRUCT_TAG,
						this);
		idents-&gt;add_tag(tag, info);
	    }
	    info-&gt;definition = this;
	    info-&gt;defined = true;
	}
	Localizer&lt;DeclContext&gt; save(&amp;ctx-&gt;decl_cx);
	ctx-&gt;decl_cx = STRUCT_UNION_CX;
	Localizer&lt;SingleIdentTable *&gt; save2(&amp;ctx-&gt;aggr_members);
	ctx-&gt;aggr_members = new SingleIdentTable();
	for (decls_iterator i = get_decls(); i; ++i) {
	    if (!i.get_decl()-&gt;resolve_idents(ctx, idents))
		return false;
	}
	return true;
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; UNION OptR29E1:name '{' SeqR29E3:decls '}' 
operator UnionDefinitionSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (has_name()) {
	    get_name_name()-&gt;set_subspecies(ctx, IDSYM::UNION_TAG_NAME);
	    PooledString tag = get_name_name()-&gt;pooled_string();
	    IdentInfo *info;
	    if (idents-&gt;has_tag_binding(tag)) {
		info = idents-&gt;resolve_tag(tag);
		assert(info);
		if (info-&gt;type != IdentInfo::UNION_TAG)
		    set_semant_error(this, "`%s' is a %s tag, not a union tag",
				     tag.chars(),
				     info-&gt;type == IdentInfo::STRUCT_TAG ?
				     "struct" : "enum");
		else if (info-&gt;defined &amp;&amp; info-&gt;definition != this)
		    set_semant_error(this,"Duplicate definition of union `%s'",
				     tag.chars());
		else if (info-&gt;definition &amp;&amp; !info-&gt;defined) {
		    StructReferenceSpec *ref
		        = (StructReferenceSpec *)info-&gt;definition;
		    ref-&gt;completion.set_value(vg(), this);
		    ref-&gt;compute_synth_attrs(true);
		}
	    } else {
		info = new IdentInfo(tag, IdentInfo::UNION_TAG, this);
		idents-&gt;add_tag(tag, info);
	    }
	    info-&gt;definition = this;
	    info-&gt;defined = true;
	}
	Localizer&lt;DeclContext&gt; save(&amp;ctx-&gt;decl_cx);
	ctx-&gt;decl_cx = STRUCT_UNION_CX;
	Localizer&lt;SingleIdentTable *&gt; save2(&amp;ctx-&gt;aggr_members);
	ctx-&gt;aggr_members = new SingleIdentTable();
	for (decls_iterator i = get_decls(); i; ++i) {
	    if (!i.get_decl()-&gt;resolve_idents(ctx, idents))
		return false;
	}
	return true;
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; STRUCT IDSYM:name 
operator StructReferenceSpec extends ParentNode, type_spec, GLRStateMixin {
    public versioned slot Vptr definition = NULL;
    versioned Semantics attribute definition
	= TypedVal((Node*)definition.value(vg(), gvid));

    public versioned slot Vptr completion = NULL;
    versioned Semantics attribute completion
	= TypedVal((Node*)completion.value(vg(), gvid));

    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	PooledString tag = get_name()-&gt;pooled_string();
	get_name()-&gt;set_subspecies(ctx, IDSYM::STRUCT_TAG_NAME);
	IdentInfo *info = idents-&gt;resolve_tag(tag);
	if (info) {
	    if (info-&gt;type != IdentInfo::STRUCT_TAG)
		set_semant_error(this, "`%s' is a %s tag, not a struct tag",
				 tag.chars(),
				 info-&gt;type == IdentInfo::UNION_TAG ?
				 "union" : "enum");
	    definition.set_value(vg(), info-&gt;definition);
	    compute_synth_attrs(true);
	} else {
	    IdentInfo *info = new IdentInfo(tag, IdentInfo::STRUCT_TAG, this);
	    idents-&gt;add_tag(tag, info);
	}
	return true;
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; UNION IDSYM:name 
operator UnionReferenceSpec extends ParentNode, type_spec, GLRStateMixin {
    public versioned slot Vptr definition = NULL;
    versioned Semantics attribute definition
	= TypedVal((Node*)definition.value(vg(), gvid));

    public versioned slot Vptr completion = NULL;
    versioned Semantics attribute completion
	= TypedVal((Node*)completion.value(vg(), gvid));

    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	get_name()-&gt;set_subspecies(ctx, IDSYM::UNION_TAG_NAME);
	PooledString tag = get_name()-&gt;pooled_string();
	IdentInfo *info = idents-&gt;resolve_tag(tag);
	if (info) {
	    if (info-&gt;type != IdentInfo::UNION_TAG)
		set_semant_error(this, "`%s' is a %s tag, not a union tag",
				 tag.chars(),
				 info-&gt;type == IdentInfo::STRUCT_TAG ?
				 "struct" : "enum");
	    definition.set_value(vg(), info-&gt;definition);
	    compute_synth_attrs(true);
	} else {
	    IdentInfo *info = new IdentInfo(tag, IdentInfo::UNION_TAG, this);
	    idents-&gt;add_tag(tag, info);
	}
	return true;
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; ENUM OptR29E1:name '{' SeqR33E3:enums OptR33E4 '}' 
operator DefinedEnumSpec extends ParentNode, type_spec, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {	
	if (has_name()) {
	    get_name_name()-&gt;set_subspecies(ctx, IDSYM::ENUM_TAG_NAME);
	    PooledString tag = get_name_name()-&gt;pooled_string();
	    if (idents-&gt;has_tag_binding(tag)) {
		set_semant_error(this, "Aggregate tag `%s' redefined",
				 tag.chars());
	    } else {
		IdentInfo *info = new IdentInfo(tag, IdentInfo::ENUM_TAG,
						this);
		idents-&gt;add_tag(tag, info);
	    }
	}
	for (enums_iterator i = get_enums(); i; ++i) {
	    if (!i.get_enum_()-&gt;resolve_idents(ctx, idents))
		return false;
	} 
	return true;
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; ENUM IDSYM:name 
operator ReferencedEnumSpec extends ParentNode, type_spec, GLRStateMixin {
    public versioned slot Vptr definition = NULL;
    versioned Semantics attribute definition
	= TypedVal((Node*)definition.value(vg(), gvid));

    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	get_name()-&gt;set_subspecies(ctx, IDSYM::ENUM_TAG_NAME);
	PooledString tag = get_name()-&gt;pooled_string();
	IdentInfo *info = idents-&gt;resolve_tag(tag);
	if (!info) {
	    /* GCC allows you to forward declare enums, but the C99
               standard doesn't */
	    set_semant_error(this, "Undefined enum `%s'", tag.chars());
	} else if (info-&gt;type != IdentInfo::ENUM_TAG) {
	    set_semant_error(this, "`%s' is a %s tag, not an enum tag",
			     tag.chars(), info-&gt;type == IdentInfo::STRUCT_TAG ?
			                  "struct" : "union");
	} else {
	    definition.set_value(vg(), info-&gt;definition);
	    compute_synth_attrs(true);
	}
	return true;
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	type-&gt;uses_nontypename = true;
    }
}

// type_spec -&gt; IDSYM:type_name 
operator TypedefTypeSpec extends ParentNode, type_spec, GLRStateMixin {
    public versioned slot Vptr definition = NULL;
    versioned Semantics attribute definition
	= TypedVal((Node*)definition.value(vg(), gvid));

    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	PooledString id = get_type_name()-&gt;pooled_string();
	get_type_name()-&gt;set_subspecies(ctx, IDSYM::TYPEDEF_NAME);
// 	cerr &lt;&lt; "Before TTS, idents are:" &lt;&lt; endl;
// 	idents-&gt;dump(cerr);
	if (!idents-&gt;resolve_ident(id)) {
	    assert(!idents-&gt;has_ident_binding(id));
	    ambig_semant_error(ctx, this, "undefined typedef name"
			       " %s", id.chars());
	    return !ctx-&gt;inside_ambig;
	}
// 	cerr &lt;&lt; "In the middle of TTS, idents are:" &lt;&lt; endl;
// 	idents-&gt;dump(cerr);
	IdentInfo *info = idents-&gt;resolve_ident(id);
	assert(info);
	if (info-&gt;type != IdentInfo::TYPEDEF_ID) {
	    ambig_semant_error(ctx, this, "identifier is not "
			       "a typedef name: %s", id.chars());
	    return !ctx-&gt;inside_ambig;
	} else {
// 	    cerr &lt;&lt; "After TTS, idents are:" &lt;&lt; endl;
// 	    idents-&gt;dump(cerr);
	    definition.set_value(vg(), info-&gt;definition);
	    compute_synth_attrs(true);
	    return true;
	}
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	if (type-&gt;uses_typename)
	    type-&gt;multiple_typename = true;
	else
	    type-&gt;uses_typename = true;
    }
}

operator type_spec_sym extends AmbigNode, type_spec, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	error("Unexpected ambiguity in type_spec::get_resolve_type\n");	
    }
}

phylum type_qual depends on decl {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	/* nothing */
    }
}

operator type_qual_sym extends AmbigNode, type_qual, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
 	error("Unexpected ambiguity in type qualifier!\n");
    }
}

phylum type_name depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// type_name -&gt; SeqR14E0:spec_quals OptR14E1:declr 
operator TypeName extends ParentNode, type_name, GLRStateMixin
depends on Declaration {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	decl::ResolveType base_type;
	for (spec_quals_iterator i = get_spec_quals(); i; ++i) {
	    if (!i.get_spec_qual()-&gt;resolve_idents(ctx, idents))
		return false;
	    i.get_spec_qual()-&gt;get_resolve_type(ctx, &amp;base_type);
	}
	if (!Declaration::check_resolve_type(ctx, &amp;base_type, this))
	    return false;
	if (has_declr())
	    return get_declr_declr()-&gt;resolve_idents(ctx, idents);
	else
	    return true;
    }
}

operator type_name_sym extends AmbigNode, type_name, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in type name!\n");
	return true;
    }
}

phylum type_spec_qual depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	error("Unexpected call to type_spec_qual::get_resolve_type\n");
    }
}

// type_spec_qual -&gt; type_spec:spec 
operator TypeSpecifier extends ParentNode, type_spec_qual, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_spec()-&gt;resolve_idents(ctx, idents);
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	get_spec()-&gt;get_resolve_type(ctx, type);
    }
}

// type_spec_qual -&gt; type_qual:qual 
operator TypeQualifier extends ParentNode, type_spec_qual, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	/* nothing to do */
    }
}

operator no_type_spec_qual extends Node, type_spec_qual, GLRStateMixin {
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
    }
}

operator type_spec_qual_sym extends AmbigNode, type_spec_qual, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in type specifier/qualifier\n");
	return true;
    }
    public virtual method void get_resolve_type(ResolveContext *ctx,
						decl::ResolveType *type) {
	error("Unexpected ambiguity in type specifier/qualifier\n");
    }
}

phylum abst_declr {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// abst_declr -&gt; OptR47E0:ptr direct_abst_declr:direct 
operator DirectAbstDecl extends ParentNode, abst_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_direct()-&gt;resolve_idents(ctx, idents);
    }
}

operator abst_declr_sym extends AmbigNode, abst_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in abst_declr\n");
	return true;
    }
}

phylum struct_decl depends on decl {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected call to struct_decl::resolve_idents()\n");
	return true;
    }
}

// struct_decl -&gt; SeqR14E0:spec_quals SeqR62E1:declrs ';' 
operator StructDecl extends ParentNode, struct_decl, GLRStateMixin
depends on Declaration {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	decl::ResolveType base_type;
	for (spec_quals_iterator i = get_spec_quals(); i; ++i) {
	    if (!i.get_spec_qual()-&gt;resolve_idents(ctx, idents))
		return false;
	    i.get_spec_qual()-&gt;get_resolve_type(ctx, &amp;base_type);
	}
	if (!Declaration::check_resolve_type(ctx, &amp;base_type, this))
	    return false;
	for (declrs_iterator i = get_declrs(); i; ++i) {
	    if (!i.get_declr()-&gt;resolve_idents(ctx, idents, &amp;base_type))
		return false;
	}
	return true;
    }
}

// struct_decl -&gt; PREPROC
operator PreprocMember extends ParentNode, struct_decl
depends on Declaration {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	set_semant_error(this, "Can't run semantics with preprocessor "
			 "directives");
	return true;
    }
}    

operator no_struct_decl extends Node, struct_decl, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

operator struct_decl_sym extends AmbigNode, struct_decl, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return resolve_idents_func&lt;struct_decl, struct_decl_sym&gt;(ctx, idents,
								 this);
    }
}

phylum enum_ {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected call to enum_::resolve_idents\n");
	return true;
    }
}

// enum_ -&gt; IDSYM:name OptR46E1:init 
operator EnumerationItem extends ParentNode, enum_, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (has_init() &amp;&amp; !get_init_val()-&gt;resolve_idents(ctx, idents))
	    return false;
	IDSYM *ident = get_name();
	PooledString id_name = ident-&gt;pooled_string();
	ident-&gt;set_subspecies(ctx, IDSYM::ENUM_CONST_DECL_NAME);
	if (idents-&gt;has_ident_binding(id_name)) {
	    set_semant_error(this, "Identifier `%s' redefined as enumeration"
			     " constant", id_name.chars());
	} else {
	    IdentInfo *info = new IdentInfo(id_name, IdentInfo::ENUM_CONST,
					    this);
	    idents-&gt;add_ident(id_name, info);
	}
	return true;
    }
}

operator no_enum_ extends Node, enum_, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

operator enum__sym extends AmbigNode, enum_, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in enumeration member declaration\n");
	return false;
    }
}

phylum init_ depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// init_ -&gt; assign_expr 
operator ExprInit extends ParentNode, init_, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// init_ -&gt; '{' SeqR45E1:inits OptR33E4 '}' 
operator BlockInit extends ParentNode, init_, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	for (inits_iterator i = get_inits(); i; ++i)
	    if (!i.get_init()-&gt;resolve_idents(ctx, idents))
		return false;
	return true;
    }
}

operator init__sym extends AmbigNode, init_, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in initializer!\n");
	return false;
    }
}

phylum designator {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;       
    }
}

// designator -&gt; '[' expr:idx ']' 
operator ArrayElemDesignator extends ParentNode, designator, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_idx()-&gt;resolve_idents(ctx, idents);
    }
}

// designator -&gt; '.' IDSYM:field 
operator FieldDesignator extends ParentNode, designator, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	get_field()-&gt;set_subspecies(ctx, IDSYM::AGGR_MEMBER_NAME);
	return true;
    }
}

operator designator_sym extends AmbigNode, designator, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in designator\n");
	return true;       
    }
}

phylum expr depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;       
    }
}

// expr -&gt; expr:pred '?' expr:texpr ':' expr:fexpr 
operator TernaryOp extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx, 
					      IdentTable *idents) {
	if (!get_pred()-&gt;resolve_idents(ctx, idents))
	    return false;
	if (has_texpr() &amp;&amp; !get_texpr_expr()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_fexpr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left LOR expr:right 
operator LogicalOr extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left LAND expr:right 
operator LogicalAnd extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left '|' expr:right 
operator BitwiseOr extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left '^' expr:right 
operator BitwiseXor extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left '&amp;' expr:right 
operator BitwiseAnd extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left EQ expr:right 
operator Equals extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left NE expr:right 
operator NotEquals extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left '&lt;' expr:right 
operator LessThan extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left '&gt;' expr:right 
operator GreaterThan extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left LE expr:right 
operator LessThanEquals extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left GE expr:right 
operator GreaterThanEquals extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left LSHIFT expr:right 
operator LeftShift extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left RSHIFT expr:right 
operator RightShift extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left '+' expr:right 
operator Add extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left '-' expr:right 
operator Subtract extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left '*' expr:right 
operator Multiply extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left '/' expr:right 
operator Divide extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:left '%' expr:right 
operator Modulo extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; '(' type_name:name ')' expr:expr 
operator TypeCast extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_name()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; '&amp;' expr:expr 
operator AddressOf extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; '+' expr:expr 
operator Positive extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; '-' expr:expr 
operator Negate extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; '~' expr:expr 
operator BitwiseNegate extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx, 
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; '!' expr:expr 
operator LogicalNot extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr:func '(' SeqR128E2:exprs ')' 
operator FunctionCall extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_func()-&gt;resolve_idents(ctx, idents))
	    return false;
	for (exprs_iterator i = get_exprs(); i; ++i)
	    if (!i.get_expr()-&gt;resolve_idents(ctx, idents))
		return false;
	return true;
    }
}

// expr -&gt; INC expr:expr 
operator PreIncrement extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; DEC expr:expr 
operator PreDecrement extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr INC 
operator PostIncrement extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; expr DEC 
operator PostDecrement extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; SIZEOF expr 
operator VarSizeof extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; SIZEOF '(' type_name ')' 
operator TypeSizeof extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	get_type()-&gt;resolve_idents(ctx, idents);
	return true;
    }
}

// expr -&gt; '(' exprs:expr ')' 
operator ParenthExpr extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; int_const:val 
operator IntegerConstant extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// expr -&gt; char_const:val 
operator CharacterConstant extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// expr -&gt; float_const:val 
operator FloatingConstant extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// expr -&gt; str_const:val 
operator StringConstant extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// expr -&gt; '(' type_name ')' '{' SeqR45E1:inits OptR33E4 '}' 
operator CompoundLiteral extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_type()-&gt;resolve_idents(ctx, idents))
	    return false;
	for (inits_iterator i = get_inits(); i; ++i)
	    if (!i.get_init()-&gt;resolve_idents(ctx, idents))
		return false;
	return true;
    }
}

// expr -&gt; IDSYM:name 
operator VariableExpr extends ParentNode, expr, GLRStateMixin depends on decl {
    public versioned slot Vptr declarator = NULL;
    versioned Semantics attribute declarator
	= TypedVal((Node*)declarator.value(vg(), gvid));

    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	PooledString ident = get_name()-&gt;pooled_string();
	IdentInfo *info;
	if ((info = idents-&gt;resolve_ident(ident))) {
	    switch (info-&gt;type) {
	    case IdentInfo::TYPEDEF_ID:
		get_name()-&gt;set_subspecies(ctx, IDSYM::TYPEDEF_NAME);
		ambig_semant_error(ctx, this, "tried to use "
				   "typedef name %s in expression",
				   ident.chars());
		return !ctx-&gt;inside_ambig;
	    case IdentInfo::ENUM_CONST:
		get_name()-&gt;set_subspecies(ctx, IDSYM::ENUM_CONST_NAME);
		break;
	    case IdentInfo::OBJECT_ID:
		get_name()-&gt;set_subspecies(ctx, IDSYM::PLAIN_NAME);
		declarator.set_value(vg(), info-&gt;definition);
		compute_synth_attrs(true);
		break;
	    default:
		error("Unexpected type for identifier");
	    }
	} else {
	    set_semant_error(this, "Undefined identifier `%s'",
			     ident.chars());
	}
	return true;
    }
}

// expr -&gt; expr '.' IDSYM:field 
operator StructAccess extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	get_expr()-&gt;resolve_idents(ctx, idents);
	get_field()-&gt;set_subspecies(ctx, IDSYM::AGGR_MEMBER_NAME);
	// resolve field?
	return true;
    }
}

// expr -&gt; expr PTR IDSYM:field 
operator PointerAccess extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	get_expr()-&gt;resolve_idents(ctx, idents);
	get_field()-&gt;set_subspecies(ctx, IDSYM::AGGR_MEMBER_NAME);
	// resolve field?
	return true;
    }
}

// expr -&gt; expr '[' exprs:index ']' 
operator ArrayAccess extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_expr()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_index()-&gt;resolve_idents(ctx, idents);
    }
}

// expr -&gt; '*' expr:expr 
operator PointerDereference extends ParentNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

operator expr_sym extends AmbigNode, expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return resolve_idents_func&lt;expr, expr_sym&gt;(ctx, idents, this);
    }
}

phylum designation {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }    
}

// designation -&gt; SeqR42E0:desigs '=' 
operator Designation extends ParentNode, designation, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	for (desigs_iterator i = get_desigs();i ; ++i)
	    if (!i.get_desig()-&gt;resolve_idents(ctx, idents))
		return false;
	return true;
    }    
}

operator designation_sym extends AmbigNode, designation, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in initializer designator\n");
	return true;
    }    
}

phylum inner_init {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }    
}

// inner_init -&gt; OptR43E0:desig init_:init 
operator InnerInitializer extends ParentNode, inner_init, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (has_desig() &amp;&amp; !get_desig_desig()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_init()-&gt;resolve_idents(ctx, idents);
    }    
}

operator inner_init_sym extends AmbigNode, inner_init, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in inner initializer\n");
	return true;
    }    
}

phylum arg_expr depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// arg_expr -&gt; assign_expr:expr
operator ExpressionArgument extends arg_expr {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

// arg_expr -&gt; type_name:type
operator FakeTypeArgument extends arg_expr {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	ambig_semant_error(ctx, this, "only macros can take type arguments");
	return !ctx-&gt;inside_ambig;
    }
}

operator arg_expr_sym extends AmbigNode, arg_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return resolve_idents_func&lt;arg_expr, arg_expr_sym&gt;(ctx, idents, this);
    }
}


phylum assign_expr depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// assign_expr -&gt; expr:left '=' assign_expr:right 
operator NormalAssign extends ParentNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// assign_expr -&gt; expr:left MULASSIGN assign_expr:right 
operator MultiplyAssign extends ParentNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// assign_expr -&gt; expr:left DIVASSIGN assign_expr:right 
operator DivideAssign extends ParentNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// assign_expr -&gt; expr:left MODASSIGN assign_expr:right 
operator ModAssign extends ParentNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// assign_expr -&gt; expr:left ADDASSIGN assign_expr:right 
operator AddAssign extends ParentNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// assign_expr -&gt; expr:left SUBASSIGN assign_expr:right 
operator SubtractAssign extends ParentNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// assign_expr -&gt; expr:left SHLASSIGN assign_expr:right 
operator ShiftLeftAssign extends ParentNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// assign_expr -&gt; expr:left SHRASSIGN assign_expr:right 
operator ShiftRightAssign extends ParentNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// assign_expr -&gt; expr:left ANDASSIGN assign_expr:right 
operator AndAssign extends ParentNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// assign_expr -&gt; expr:left XORASSIGN assign_expr:right 
operator XorAssign extends ParentNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// assign_expr -&gt; expr:left ORASSIGN assign_expr:right 
operator OrAssign extends ParentNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// assign_expr -&gt; expr:expr 
operator SimpleExpression extends ParentNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

operator assign_expr_sym extends AmbigNode, assign_expr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in expression!\n");
	return false;
    }
}

phylum direct_abst_declr {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// direct_abst_declr -&gt; '(' abst_declr:declr ')' 
operator ParenAbstDecl extends ParentNode, direct_abst_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_declr()-&gt;resolve_idents(ctx, idents);
    }
}

// direct_abst_declr -&gt; OptR58E0:declr '[' OptR58E2:expr ']' 
operator ArrayAbstDecl extends ParentNode, direct_abst_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (has_declr() &amp;&amp; !get_declr_declr()-&gt;resolve_idents(ctx, idents))
	    return false;
	if (has_expr() &amp;&amp; !get_expr_expr()-&gt;resolve_idents(ctx, idents))
	    return false;
	return true;
    }
}

// direct_abst_declr -&gt; OptR58E0:declr '[' '*' ']' 
operator VariableAbstDecl 
extends ParentNode, direct_abst_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (has_declr() &amp;&amp; !get_declr_declr()-&gt;resolve_idents(ctx, idents))
	    return false;
	return true;
    }
}

// direct_abst_declr -&gt; direct_abst_declr:declr '(' OptR60E2:params ')' 
operator NestedFuncAbstDecl 
extends ParentNode, direct_abst_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_declr()-&gt;resolve_idents(ctx, idents))
	    return false;
	Localizer&lt;DeclContext&gt; save(&amp;ctx-&gt;decl_cx);
	ctx-&gt;decl_cx = DECL_PARAM;
	NestedIdentTable param_table;
	param_table.add_parent(idents);
	if (has_params())
	    return get_params_params()-&gt;resolve_idents(ctx, &amp;param_table);
	else
	    return true;
    }
}

// direct_abst_declr -&gt; '(' OptR60E2:params ')' 
operator FuncAbstDecl extends ParentNode, direct_abst_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	Localizer&lt;DeclContext&gt; save(&amp;ctx-&gt;decl_cx);
	ctx-&gt;decl_cx = DECL_PARAM;
	NestedIdentTable param_table;
	param_table.add_parent(idents);
	if (has_params())
	    return get_params_params()-&gt;resolve_idents(ctx, &amp;param_table);
	else
	    return true;
    }
}

operator direct_abst_declr_sym 
extends AmbigNode, direct_abst_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in direct_abst_declr\n");
	return true;
    }
}

phylum param_type_list depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
    public virtual method void declare_ansi_idents(ResolveContext *ctx,
						   IdentTable *func_idents) {
	error("Unexpected call to param_type_list::declare_ansi_idents\n");
    }
}

// param_type_list -&gt; SeqR68E0:decls OptR68E1:dotdotdot 
operator ParameterTypeList extends ParentNode, param_type_list, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	for (decls_iterator i = get_decls(); i; ++i) {
	    if (!i.get_decl()-&gt;resolve_idents(ctx, idents))
		return false;
	}
	return true;
    }
    public virtual method void declare_ansi_idents(ResolveContext *ctx,
						   IdentTable *func_idents) {
	bool first_param = true;
	for (decls_iterator i = get_decls(); i; ++i) {
	    i.get_decl()-&gt;declare_ansi_idents(ctx, func_idents);
	    first_param = false;
	}
    }
}

operator param_type_list_sym 
extends AmbigNode, param_type_list, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in parameter list!\n");
	return false;
    }
    public virtual method void declare_ansi_idents(ResolveContext *ctx,
						   IdentTable *func_idents) {
	error("Unexpected ambiguity in parameter list!\n");
    }
}

phylum struct_declr depends on decl {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      decl::ResolveType *base_type) {
	error("Unexpected call to struct_declr::resolve_idents\n");
	return true;
    }
}

// struct_declr -&gt; declr:declr 
operator StructDeclr extends ParentNode, struct_declr, GLRStateMixin depends on decl {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      decl::ResolveType *base_type) {
	return get_declr()-&gt;resolve_idents(ctx, idents, base_type);
    }
}

// struct_declr -&gt; OptR64E0:declr ':' expr:expr 
operator BitfieldDeclr extends ParentNode, struct_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      decl::ResolveType *base_type) {
	if (has_declr()) {	    
	    if (!get_declr_declr()-&gt;resolve_idents(ctx, idents, base_type))
		return false;
	}
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

operator no_struct_declr extends Node, struct_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      decl::ResolveType *base_type) {
	return true;
    }
}

operator struct_declr_sym extends AmbigNode, struct_declr, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents,
					      decl::ResolveType *base_type) {
	error("Unexpected ambiguity in structure member declarator\n");
	return true;
    }
}

phylum param_decl depends on trans_unit, decl {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
    public virtual method void declare_ansi_idents(ResolveContext *ctx, 
						   IdentTable *func_idents) {
	error("Unexpected call to param_type_list::declare_ansi_idents\n");
    }

}

// param_decl -&gt; SeqR1E0:specs declr:declr 
operator NamedParamDecl extends ParentNode, param_decl, GLRStateMixin
depends on Declaration {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	decl::ResolveType base_type;
	for (specs_iterator i = get_specs(); i; ++i) {
	    if (!i.get_spec()-&gt;resolve_idents(ctx, idents))
		return false;
	    i.get_spec()-&gt;get_resolve_type(ctx, &amp;base_type);
	}
	if (!Declaration::check_resolve_type(ctx, &amp;base_type, this))
	    return false;
	return get_declr()-&gt;resolve_idents(ctx, idents, &amp;base_type);
    }
    public virtual method void declare_ansi_idents(ResolveContext *ctx,
						   IdentTable *func_idents) {
	get_declr()-&gt;declare_ident(ctx, func_idents);
    }
}

// param_decl -&gt; SeqR1E0:specs OptR14E1:declr 
operator UnnamedParamDecl extends ParentNode, param_decl, GLRStateMixin
depends on Declaration {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	decl::ResolveType base_type;
	for (specs_iterator i = get_specs(); i; ++i) {
	    if (!i.get_spec()-&gt;resolve_idents(ctx, idents))
		return false;
	    i.get_spec()-&gt;get_resolve_type(ctx, &amp;base_type);
	    // XXX This still allows foo(void, void) {}
	}
	if (!Declaration::check_resolve_type(ctx, &amp;base_type, this))
	    return false;
	if (has_declr()) {
	   return get_declr_declr()-&gt;resolve_idents(ctx, idents);
	}
	return true;
    }
    public virtual method void declare_ansi_idents(ResolveContext *ctx, 
						   IdentTable *func_idents) {
    }
}

operator param_decl_sym extends AmbigNode, param_decl, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return resolve_idents_func&lt;param_decl, param_decl_sym&gt;(ctx, idents,
							       this);
    }
    public virtual method void declare_ansi_idents(ResolveContext *ctx,
						   IdentTable *func_idents) {
	param_decl::phylum_cast(primary_alternative())
	    -&gt;declare_ansi_idents(ctx, func_idents);
    }
}

phylum for_init depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// for_init -&gt; OptR69E0:expr ';' 
operator ExpressionInit extends ParentNode, for_init, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (has_expr())
	    return get_expr_expr()-&gt;resolve_idents(ctx, idents);
	return true;
    }
}

// for_init -&gt; decl:decl 
operator DeclarationInit extends ParentNode, for_init, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	Localizer&lt;DeclContext&gt; save(&amp;ctx-&gt;decl_cx);
	ctx-&gt;decl_cx = FOR_INIT;
	return get_decl()-&gt;resolve_idents(ctx, idents);
    }
}

operator for_init_sym extends AmbigNode, for_init, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return resolve_idents_func&lt;for_init, for_init_sym&gt;(ctx, idents, this);
    }

}

phylum exprs depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// exprs -&gt; exprs:left ',' assign_expr:right 
operator CommaList extends ParentNode, exprs, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_left()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_right()-&gt;resolve_idents(ctx, idents);
    }
}

// exprs -&gt; assign_expr:expr 
operator SingleExpr extends ParentNode, exprs, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_expr()-&gt;resolve_idents(ctx, idents);
    }
}

operator exprs_sym extends AmbigNode, exprs, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in expressions!\n");
	return false;
    }
}

phylum stmt depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// stmt -&gt; IDSYM:label ':' stmt:stmt 
operator LabeledStatement extends ParentNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	PooledString label = get_label()-&gt;pooled_string();	
	get_label()-&gt;set_subspecies(ctx, IDSYM::LABEL_DECL_NAME);
	LabelInfo *info;
	if (!ctx-&gt;labels-&gt;has_binding(label)) {
	    info = new LabelInfo(label);
	    ctx-&gt;labels-&gt;add(label, info);
	} else {
	    info = ctx-&gt;labels-&gt;resolve(label);
	}
	info-&gt;defs.push_back(this);
	return get_stmt()-&gt;resolve_idents(ctx, idents);
    }
}

// stmt -&gt; CASE expr:expr ':' stmt:stmt 
operator CaseLabelStatement extends ParentNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_expr()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_stmt()-&gt;resolve_idents(ctx, idents);
    }
}

// stmt -&gt; DEFAULT ':' stmt:stmt 
operator DefaultLabelStatement extends ParentNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_stmt()-&gt;resolve_idents(ctx, idents);
    }
}

// stmt -&gt; OptR69E0:expr ';' 
operator ExprStatement extends ParentNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (has_expr())
	    return get_expr_expr()-&gt;resolve_idents(ctx, idents);
	return true;
    }
}

// stmt -&gt; comp_stmt:stmt 
operator CompoundStatement extends ParentNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_stmt()-&gt;resolve_idents(ctx, idents);
    }
}

// stmt -&gt; IF '(' exprs:pred ')' stmt:t_stmt 
operator IfNoElseStatement extends ParentNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_pred()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_t_stmt()-&gt;resolve_idents(ctx, idents);
    }
}

// stmt -&gt; IF '(' exprs:pred ')' stmt:t_stmt ELSE stmt:f_stmt 
operator IfElseStatement extends ParentNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_pred()-&gt;resolve_idents(ctx, idents))
	    return false;
	if (!get_t_stmt()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_f_stmt()-&gt;resolve_idents(ctx, idents);
    }
}

// stmt -&gt; SWITCH '(' exprs:val ')' stmt:stmt 
operator SwitchStatement extends ParentNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_val()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_stmt()-&gt;resolve_idents(ctx, idents);
    }
}

// stmt -&gt; WHILE '(' exprs:val ')' stmt:stmt 
operator WhileStatement extends ParentNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_val()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_stmt()-&gt;resolve_idents(ctx, idents);
    }
}

// stmt -&gt; DO stmt:stmt WHILE '(' exprs:val ')' ';' 
operator DoWhileStatement extends ParentNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_stmt()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_val()-&gt;resolve_idents(ctx, idents);
    }
}

// stmt -&gt; FOR '(' for_init:init OptR69E0:pred ';' OptR69E0:inc ')' stmt:stmt 
operator ForStatement extends ParentNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (!get_init()-&gt;resolve_idents(ctx, idents))
	    return false;
	if (has_pred() &amp;&amp; !get_pred_expr()-&gt;resolve_idents(ctx, idents))
	    return false;
	if (has_inc() &amp;&amp; !get_inc_expr()-&gt;resolve_idents(ctx, idents))
	    return false;
	return get_stmt()-&gt;resolve_idents(ctx, idents);
    }
}

// stmt -&gt; GOTO IDSYM:label ';' 
operator GotoStatement extends ParentNode, stmt, GLRStateMixin {
    public versioned slot Vptr target = NULL;
    versioned Semantics attribute target
	= TypedVal((Node*)target.value(vg(), gvid));

    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	PooledString label = get_label()-&gt;pooled_string();	
	get_label()-&gt;set_subspecies(ctx, IDSYM::LABEL_NAME);
	LabelInfo *info;
	if (!ctx-&gt;labels-&gt;has_binding(label)) {
	    info = new LabelInfo(label);
	    ctx-&gt;labels-&gt;add(label, info);
	} else {
	    info = ctx-&gt;labels-&gt;resolve(label);
	}
	info-&gt;uses.push_back(this);
	return true;
    }
}

// stmt -&gt; RETURN OptR69E0:ret ';' 
operator ReturnStatement extends ParentNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	if (has_ret())
	    return get_ret_expr()-&gt;resolve_idents(ctx, idents);
	return true;
    }
}

operator stmt_sym extends AmbigNode, stmt, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	error("Unexpected ambiguity in statement!\n");
	return true;
    }
}

phylum block_item depends on trans_unit {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return true;
    }
}

// block_item -&gt; decl:decl 
operator DeclarationItem extends ParentNode, block_item, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	Localizer&lt;DeclContext&gt; save(&amp;ctx-&gt;decl_cx);
	ctx-&gt;decl_cx = BLOCK;
	return get_decl()-&gt;resolve_idents(ctx, idents);
    }
}

// block_item -&gt; stmt:stmt 
operator StatementItem extends ParentNode, block_item, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return get_stmt()-&gt;resolve_idents(ctx, idents);
    }
}

operator block_item_sym extends AmbigNode, block_item, GLRStateMixin {
    public virtual method bool resolve_idents(ResolveContext *ctx,
					      IdentTable *idents) {
	return resolve_idents_func&lt;block_item, block_item_sym&gt;(ctx, idents,
							       this);
    }
}

operator IDSYM  {
    public enum NameType {
	PLAIN_NAME = 0,
	DECLARATION_NAME,
	TYPEDEF_NAME,
	TYPEDEF_DECL_NAME,
	LABEL_NAME,
	LABEL_DECL_NAME,
	STRUCT_TAG_NAME,
	UNION_TAG_NAME,
	ENUM_TAG_NAME,    
	AGGR_MEMBER_NAME,
	AGGR_MEMBER_DECL_NAME,
	ENUM_CONST_NAME,
	ENUM_CONST_DECL_NAME,
	PARAM_DECL_NAME,
	KNR_PARAM_LIST_NAME,
	KNR_PARAM_DECL_NAME
    };

    // Note -- this enum has to be kept in sync with the definition
    // of harmonia-c-idsym-face-array in harmonia-c.el
    public static slot const char *subspecies_names[] = {
	"Plain",
	"Declaration",
	"Typedef",
	"TypedefDecl",
	"Label",
	"LabelDecl",
	"StructTag",
	"UnionTag",
	"EnumTag",
	"AggregateMember",
	"AggregateMemberDecl",
	"EnumerationConstant",
	"EnumerationConstantDecl",
	"ParameterDecl",
	"K&amp;RParameterList",
	"K&amp;RParameterDecl"};

    public versioned slot Vint subspecies = 0;
    versioned Semantics attribute subspecies
	= TypedVal(subspecies.value(vg(), gvid));
    versioned Semantics attribute subspecies_name
	= TypedVal(subspecies_names[subspecies.value(vg(), gvid)]); 

    public virtual method void set_subspecies(ResolveContext *ctx, int type) {
	if (ctx-&gt;inside_ambig) {
	    ctx-&gt;deferred_classifications
		-&gt;push_back(pair&lt;IDSYM*,int&gt;(this, type));
	} else {
	    subspecies.set_value(vg(), type);
	    compute_synth_attrs(true);
	}
    }
}
</pre></body></html>