AFun afun = ((ATermAppl) alt.buildMatchPattern()).getAFun(); alt_count = alts_left.size(); alts_left.keepByAFun(afun); if (alts_left.size() < alt_count) { source.println( "  if (ATgetAFun((ATermAppl)arg) != ATgetAFun(" + pattern + ")) {"); source.println("    return ATfalse;"); source.println("  }"); }
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) { source.println( "  if (ATgetAFun((ATermAppl)arg) != ATgetAFun(" + pattern + ")) {"); source.println("    return ATfalse;"); source.println("  }"); } }
	private void genIsAlt(Type type, Alternative alt) {		String type_id = buildId(type.getId());		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;		//{{{ When OPTIMIZE_WITHOUT_ANNOS: check for patterns without holes		if (OPTIMIZE_WITHOUT_ANNOS && alt_count == 2 && contains_placeholder) {			Iterator iter = type.alternativeIterator();			while (iter.hasNext()) {				Alternative cur = (Alternative) iter.next();				if (cur != alt && !cur.containsPlaceholder()) {					inverted = true;					alt = cur;					contains_placeholder = false;				}			}		}		//}}}		//{{{ Create match_code		pattern = prefix + "pattern" + type_id + capitalize(buildId(alt.getId()));		if (!OPTIMIZE_WITHOUT_ANNOS || contains_placeholder) {			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(")");		}		else {			match_code.append("ATisEqual((ATerm)arg, " + pattern + ")");		}		//}}}		header.println(decl + ";");		printFoldOpen(source, decl);		source.println(decl);		source.println("{");		if (OPTIMIZE_WITHOUT_ANNOS && inverted) {			source.println("  return !(" + match_code + ");");		}		else if (			OPTIMIZE_WITHOUT_ANNOS && alt_count != 1 && !contains_placeholder) {			source.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) {				//{{{ Check term types				source.println(					"  if (ATgetType((ATerm)arg) != "						+ getATermTypeName(pat_type)						+ ") {");				source.println("    return ATfalse;");				source.println("  }");				//}}}			}			if (pat_type == ATerm.APPL) {				//{{{ Check function symbols				AFun afun = ((ATermAppl) alt.buildMatchPattern()).getAFun();				alt_count = alts_left.size();				alts_left.keepByAFun(afun);				if (alts_left.size() < alt_count) {					source.println(						"  if (ATgetAFun((ATermAppl)arg) != ATgetAFun(" + pattern + ")) {");					source.println("    return ATfalse;");					source.println("  }");				}				//}}}			}			else if (pat_type == ATerm.LIST) {				//{{{ Check list length				ATermList matchPattern = (ATermList) alt.buildMatchPattern();				if (matchPattern.isEmpty()) {					alts_left.clear();					source.println("  if (!ATisEmpty((ATermList)arg)) {");					source.println("    return ATfalse;");					source.println("  }");				}				else if (!matchPattern.equals(factory.parse("[<list>]"))) {					alts_left.removeEmptyList();					source.println("  if (ATisEmpty((ATermList)arg)) {");					source.println("    return ATfalse;");					source.println("  }");				}				//}}}			}			if (alts_left.size() == 0) {				source.println("#ifndef DISABLE_DYNAMIC_CHECKING");				source.println("  assert(arg != NULL);");				source.println("  assert(" + match_code + ");");				source.println("#endif");				source.println("  return ATtrue;");			}			else {				source.println("  {");				source.println("    static ATerm last_arg = NULL;");				source.println("    static int last_gc = -1;");				source.println("    static ATbool last_result;");				source.println();				source.println("    assert(arg != NULL);");				source.println();				source.println(					"    if (last_gc != ATgetGCCount() || "						+ "(ATerm)arg != last_arg) {");				source.println("      last_arg = (ATerm)arg;");				source.println("      last_result = " + match_code + ";");				source.println("      last_gc = ATgetGCCount();");				source.println("    }");				source.println();				source.println("    return last_result;");				source.println("  }");			}		}		source.println("}");		printFoldClose(source);	}