printDocReturn("ATtrue if |arg| corresponds to the signature of a " + alt.getId() + ", or ATfalse otherwise");
printDocReturn("ATtrue if #arg corresponds to the signature of a " + alt.getId() + ", or ATfalse otherwise");
	private void genIsAlt(Type type, Alternative alt)			throws GenerationException {		String type_name = buildTypeName(type);		String decl = "inline ATbool " + buildIsAltName(type, alt) + "("				+ type_name + " arg)";		String pattern;		StringBuffer match_code = new StringBuffer();		boolean contains_placeholder = alt.containsPlaceholder();		int alt_count = type.getAlternativeCount();		boolean inverted = false;		pattern = prefix + "pattern"				+ StringConversions.makeIdentifier(type.getId())				+ StringConversions.makeCapitalizedIdentifier(alt.getId());		match_code.append("ATmatchTerm((ATerm)arg, " + pattern);		Iterator fields = type.altFieldIterator(alt.getId());		while (fields.hasNext()) {			fields.next();			match_code.append(", NULL");		}		match_code.append(")");		hprintln(decl + ";");		printDocHead("Assert whether a " + type_name + " is a " + alt.getId(), alt_count == 1 ? "Always returns ATtrue" : "" + ". May not be used to assert correctness of the " + type_name);		printDocArg("arg", "input " + type_name);		printDocReturn("ATtrue if |arg| corresponds to the signature of a " + alt.getId() + ", or ATfalse otherwise");		printDocTail();		printFoldOpen(decl);		println(decl + " {");		if (false && inverted) {			println("  return !(" + match_code + ");");		} else if (false && alt_count != 1 && !contains_placeholder) {			println("  return " + match_code + ";");		} else {			AlternativeList alts_left = type.getAlternatives();			alts_left.remove(alt);			alt_count = alts_left.size();			int pat_type = alt.getPatternType();			alts_left.keepByType(pat_type);			if (alts_left.size() != alt_count) {				println("  if (ATgetType((ATerm)arg) != "						+ getATermTypeName(pat_type) + ") {");				println("    return ATfalse;");				println("  }");			}			if (pat_type == ATerm.APPL) {				if (alt instanceof ATermAppl) {					AFun afun = ((ATermAppl) alt.buildMatchPattern()).getAFun();					alt_count = alts_left.size();					alts_left.keepByAFun(afun);					if (alts_left.size() < alt_count) {						println("  if (ATgetAFun((ATermAppl)arg) != ATgetAFun("								+ pattern + ")) {");						println("    return ATfalse;");						println("  }");					}				}			} else if (pat_type == ATerm.LIST) {				ATermList matchPattern = (ATermList) alt.buildMatchPattern();				if (matchPattern.isEmpty()) {					alts_left.clear();					println("  if (!ATisEmpty((ATermList)arg)) {");					println("    return ATfalse;");					println("  }");				} else if (!matchPattern.equals(matchPattern.getFactory()						.parse("[<list>]"))) {					alts_left.removeEmptyList();					println("  if (ATisEmpty((ATermList)arg)) {");					println("    return ATfalse;");					println("  }");				}			}			if (alts_left.size() == 0) {				println("#ifndef DISABLE_DYNAMIC_CHECKING");				println("  assert(arg != NULL);");				println("  assert(" + match_code + ");");				println("#endif");				println("  return ATtrue;");			} else {				println("  {");				println("    static ATerm last_arg = NULL;");				println("    static int last_gc = -1;");				println("    static ATbool last_result;");				println();				println("    assert(arg != NULL);");				println();				println("    if (last_gc != ATgetGCCount() || "						+ "(ATerm)arg != last_arg) {");				println("      last_arg = (ATerm)arg;");				println("      last_result = " + match_code + ";");				println("      last_gc = ATgetGCCount();");				println("    }");				println();				println("    return last_result;");				println("  }");			}		}		println("}");		println();		printFoldClose();	}