private Expr createMatchMethodAndCallFor( String symbol, Expr outerLookahead, NodeList<Expr> args) { if (!symbolToMatchNames.contains(symbol)) { symbolToMatchNames.add(symbol); GProduction production = productions.get(symbol); GExpansion symbolExpansion = production.expansion; return createMatchMethodAndCallFor( symbol, matchMethodName(symbol), symbolExpansion, outerLookahead, production.hintParams, args, MEMOIZE_MATCHES && (MEMOIZE_ALL_MATCHES || production.memoizeMatches)); } else return matchMethodCall(matchMethodName(symbol), outerLookahead, args); }
@Override protected ClassDecl contributeBody( ClassDecl decl, ImportManager importManager, TreeClassDescriptor[] arg) { importManager.addImports( listOf( importDecl(qualifiedName("org.jlato.internal.bu")).setOnDemand(true), importDecl(qualifiedName("org.jlato.internal.bu.coll")).setOnDemand(true), importDecl(qualifiedName("org.jlato.internal.bu.decl")).setOnDemand(true), importDecl(qualifiedName("org.jlato.internal.bu.expr")).setOnDemand(true), importDecl(qualifiedName("org.jlato.internal.bu.name")).setOnDemand(true), importDecl(qualifiedName("org.jlato.internal.bu.stmt")).setOnDemand(true), importDecl(qualifiedName("org.jlato.internal.bu.type")).setOnDemand(true), importDecl(qualifiedName("org.jlato.internal.parser.Token")), importDecl(qualifiedName("org.jlato.internal.parser.TokenType")), importDecl(qualifiedName("org.jlato.tree.Problem.Severity")), importDecl(qualifiedName("org.jlato.parser.ParseException")), importDecl(qualifiedName("org.jlato.tree.expr.AssignOp")), importDecl(qualifiedName("org.jlato.tree.expr.BinaryOp")), importDecl(qualifiedName("org.jlato.tree.expr.UnaryOp")), importDecl(qualifiedName("org.jlato.tree.decl.ModifierKeyword")), importDecl(qualifiedName("org.jlato.tree.type.Primitive")))); List<GProduction> allProductions = productions.getAll(); int memoizedProductionCount = MEMOIZE_ALL_MATCHES ? allProductions.size() : 0; if (!MEMOIZE_ALL_MATCHES) { for (GProduction production : allProductions) { if (production.memoizeMatches) memoizedProductionCount++; } } NodeList<MemberDecl> members = Trees.emptyList(); members = members.append( memberDecl( "protected int memoizedProductionCount() { return " + memoizedProductionCount + "; }") .build()); for (GProduction production : allProductions) { if (excluded(production)) continue; parseMethods = parseMethods.append(parseMethod(importManager, production)); } for (MethodDecl parseMethod : parseMethods) { members = members.append(parseMethod); String id = parseMethod.name().id(); int indexOfUnderscore = id.indexOf('_'); String symbol = id.substring("parse".length(), indexOfUnderscore == -1 ? id.length() : indexOfUnderscore); List<MethodDecl> methods = perSymbolMatchMethods.get(symbol); if (methods != null) { Collections.sort(methods, (m1, m2) -> m1.name().id().compareTo(m2.name().id())); members = members.appendAll(listOf(methods)); } } return decl.withMembers(members); }