<commit_before>package polyglot.visit;

import java.util.*;

import polyglot.ast.*;
import polyglot.frontend.*;
import polyglot.frontend.Job;
import polyglot.frontend.MissingDependencyException;
import polyglot.frontend.goals.Goal;
import polyglot.main.Report;
import polyglot.types.*;
import polyglot.util.*;

/**
 * A visitor which traverses the AST and remove ambiguities found in fields,
 * method signatures and the code itself.
 */
public class AmbiguityRemover extends DisambiguationDriver
{
    boolean visitSigs;
    boolean visitBodies;
    
    public AmbiguityRemover(Job job, TypeSystem ts, NodeFactory nf) {
        this(job, ts, nf, true, true);
    }
    
    public AmbiguityRemover(Job job, TypeSystem ts, NodeFactory nf, boolean visitSigs, boolean visitBodies) {
        super(job, ts, nf);
        this.visitSigs = visitSigs;
        this.visitBodies = visitBodies;
    }
    
    protected Context enterScope(Node parent, Node n) {
        Context c = super.enterScope(parent, n);
        
        Scheduler scheduler = job.extensionInfo().scheduler();
        ParsedClassType ct = c.currentClassScope();
        
        if (parent instanceof ClassMember && (n instanceof Stmt || n instanceof Expr)) {
            List l = new ArrayList(c.goalStack());
            l.remove(scheduler.SupertypesResolved(ct));
            l.remove(scheduler.SignaturesResolved(ct));
            c = c.pushGoalStack(l);
        }
        else if (n instanceof FieldDecl || n instanceof MethodDecl || n instanceof ConstructorDecl) {
            c = c.pushGoal(scheduler.SignaturesResolved(ct));
        }
        else if (n instanceof ClassDecl) {
            c = c.pushGoal(scheduler.SupertypesResolved(((ClassDecl) n).type()));
        }<commit_msg>Made instanceof in enterScope more precise.  This code should really be moved to enterChildScope in subclasses of Node.<commit_after>package polyglot.visit;

import java.util.*;

import polyglot.ast.*;
import polyglot.frontend.*;
import polyglot.frontend.Job;
import polyglot.frontend.MissingDependencyException;
import polyglot.frontend.goals.Goal;
import polyglot.main.Report;
import polyglot.types.*;
import polyglot.util.*;

/**
 * A visitor which traverses the AST and remove ambiguities found in fields,
 * method signatures and the code itself.
 */
public class AmbiguityRemover extends DisambiguationDriver
{
    boolean visitSigs;
    boolean visitBodies;
    
    public AmbiguityRemover(Job job, TypeSystem ts, NodeFactory nf) {
        this(job, ts, nf, true, true);
    }
    
    public AmbiguityRemover(Job job, TypeSystem ts, NodeFactory nf, boolean visitSigs, boolean visitBodies) {
        super(job, ts, nf);
        this.visitSigs = visitSigs;
        this.visitBodies = visitBodies;
    }
    
    protected Context enterScope(Node parent, Node n) {
        Context c = super.enterScope(parent, n);
        
        Scheduler scheduler = job.extensionInfo().scheduler();
        ParsedClassType ct = c.currentClassScope();
        
        if ((parent instanceof ProcedureDecl && n == ((ProcedureDecl) parent).body())
         || (parent instanceof FieldDecl && n == ((FieldDecl) parent).init())) {
            List l = new ArrayList(c.goalStack());
            l.remove(scheduler.SupertypesResolved(ct));
            l.remove(scheduler.SignaturesResolved(ct));
            c = c.pushGoalStack(l);
        }
        else if (n instanceof FieldDecl || n instanceof MethodDecl || n instanceof ConstructorDecl) {
            c = c.pushGoal(scheduler.SignaturesResolved(ct));
        }
        else if (n instanceof ClassDecl) {
            c = c.pushGoal(scheduler.SupertypesResolved(((ClassDecl) n).type()));
        }
{'fraction_non_alphanumeric': 0.1018970189701897, 'fraction_numerical': 0.0, 'mean_word_length': 2.9945887445887447, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '810677', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1059, 'n_words': 284}