<commit_before>/*
 * MembersAdded.java
 * 
 * Author: nystrom
 * Creation date: Dec 15, 2004
 */
package polyglot.frontend.goals;

import polyglot.ast.NodeFactory;
import polyglot.frontend.*;
import polyglot.frontend.passes.CheckFieldConstantsPass;
import polyglot.frontend.passes.ConstantCheckPass;
import polyglot.types.*;
import polyglot.types.ParsedClassType;
import polyglot.types.TypeSystem;
import polyglot.util.InternalCompilerError;
import polyglot.util.StringUtil;
import polyglot.visit.ConstantChecker;
import polyglot.visit.TypeBuilder;

/**
 * Comment for <code>MembersAdded</code>
 *
 * @author nystrom
 */
public class FieldConstantsChecked extends AbstractGoal {
    FieldInstance vi;
    ParsedClassType ct;
    
    public FieldConstantsChecked(FieldInstance vi) {
        super(null);
        this.vi = vi;
        
        if (vi.container() instanceof ParsedClassType) {
            ParsedClassType ct = (ParsedClassType) vi.container();
            this.job = ct.job();
            this.ct = ct;
        }
        else if (! vi.constantValueSet()) {
            throw new InternalCompilerError(this + " is unreachable.");
        }
    }

    public Pass createPass(ExtensionInfo extInfo) {
        if (job() != null) {
            TypeSystem ts = extInfo.typeSystem();
            NodeFactory nf = extInfo.nodeFactory();
            return new ConstantCheckPass(this, new ConstantChecker(job(), ts, nf));
        }
        return new CheckFieldConstantsPass(extInfo.scheduler(), this);
    }
    
    public boolean hasBeenReached() {
        return vi.constantValueSet();
    }
    
    public ParsedClassType container() {
        return ct;
    }
    
    public FieldInstance var() {
        return vi;
    }
    
    public int hashCode() {
        return vi.hashCode() + super.hashCode();
    }
    
    public boolean equals(Object o) {
        return o instanceof FieldConstantsChecked && ((FieldConstantsChecked) o).vi.equals(vi) && super.equals(o);
    }
    
    public String toString() {
        return StringUtil.getShortNameComponent(getClass().getName()) + "(" + vi + ")";
    }
}<commit_msg>For the FieldConstantsChecked goal for field vi, allow extensions to use a different class than vi.container for running a pass to reach the goal.  Fixes an internal error in Jif where a field of a subst class is being checked.<commit_after>/*
 * MembersAdded.java
 * 
 * Author: nystrom
 * Creation date: Dec 15, 2004
 */
package polyglot.frontend.goals;

import polyglot.ast.NodeFactory;
import polyglot.frontend.*;
import polyglot.frontend.passes.CheckFieldConstantsPass;
import polyglot.frontend.passes.ConstantCheckPass;
import polyglot.types.*;
import polyglot.types.ParsedClassType;
import polyglot.types.TypeSystem;
import polyglot.util.InternalCompilerError;
import polyglot.util.StringUtil;
import polyglot.visit.ConstantChecker;
import polyglot.visit.TypeBuilder;

/**
 * Comment for <code>MembersAdded</code>
 *
 * @author nystrom
 */
public class FieldConstantsChecked extends AbstractGoal {
    FieldInstance vi;
    ParsedClassType ct;
    
    public FieldConstantsChecked(FieldInstance vi) {
        super(null);
        this.vi = vi;
        
        ParsedClassType ct = (ParsedClassType) findContainer();
        this.job = ct.job();
        this.ct = ct;
        
        if (job == null && ! vi.constantValueSet()) {
            throw new InternalCompilerError(this + " is unreachable.");
        }
    }
    
    public ParsedClassType container() {
        return ct;
    }
    
    protected ParsedClassType findContainer() {
        if (vi.container() instanceof ParsedClassType) {
            return (ParsedClassType) vi.container();
        }
        return null;
    }

    public Pass createPass(ExtensionInfo extInfo) {
        if (job() != null) {
            TypeSystem ts = extInfo.typeSystem();
            NodeFactory nf = extInfo.nodeFactory();
            return new ConstantCheckPass(this, new ConstantChecker(job(), ts, nf));
        }
        return new CheckFieldConstantsPass(extInfo.scheduler(), this);
    }
    
    public boolean hasBeenReached() {
        return vi.constantValueSet();
    }
    
    public FieldInstance var() {
        return vi;
    }
    
    public int hashCode() {
        return vi.hashCode() + super.hashCode();
    }
    
    public boolean equals(Object o) {
        return o instanceof FieldConstantsChecked && ((FieldConstantsChecked) o).vi.equals(vi) && super.equals(o);
    }
    
    public String toString() {
        return StringUtil.getShortNameComponent(getClass().getName()) + "(" + vi + ")";
    }
}
{'fraction_non_alphanumeric': 0.10439679445527399, 'fraction_numerical': 0.002599090318388564, 'mean_word_length': 2.763651181744091, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4888512', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1313, 'n_words': 318}