Skip to content
Snippets Groups Projects
Select Git revision
  • 4ca233ba03ebf5559d0594fe67b24a9cc7b6e52f
  • master default protected
  • release/1.1.4
  • release/1.1.3
  • release/1.1.1
  • 1.4.2
  • 1.4.1
  • 1.4.0
  • 1.3.0
  • 1.2.1
  • 1.2.0
  • 1.1.5
  • 1.1.4
  • 1.1.3
  • 1.1.1
  • 1.1.0
  • 1.0.9
  • 1.0.8
  • 1.0.7
  • v1.0.5
  • 1.0.5
21 results

PredicateVsExpression.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    PredicateVsExpression.java 2.88 KiB
    package de.tla2b.analysis;
    
    import de.tla2b.global.BBuildIns;
    import de.tla2b.global.BBuiltInOPs;
    import de.tla2b.global.TranslationGlobals;
    import tla2sany.semantic.*;
    import tlc2.tool.BuiltInOPs;
    
    import java.util.HashMap;
    
    public class PredicateVsExpression extends BuiltInOPs implements ASTConstants,
    	BBuildIns, TranslationGlobals {
    
    	private final HashMap<OpDefNode, DefinitionType> definitionsTypeMap;
    
    	public enum DefinitionType {
    		PREDICATE, EXPRESSION
    	}
    
    	public DefinitionType getDefinitionType(OpDefNode def) {
    		return definitionsTypeMap.get(def);
    	}
    
    	public PredicateVsExpression(ModuleNode moduleNode) {
    		this.definitionsTypeMap = new HashMap<>();
    		OpDefNode[] defs = moduleNode.getOpDefs();
    
    		for (OpDefNode def : defs) {
    			DefinitionType type = visitSemanticNode(def.getBody());
    			definitionsTypeMap.put(def, type);
    		}
    
    	}
    
    	private DefinitionType visitSemanticNode(SemanticNode s) {
    		switch (s.getKind()) {
    			case OpApplKind: {
    				return visitOppApplNode((OpApplNode) s);
    			}
    
    			case LetInKind: {
    				LetInNode letInNode = (LetInNode) s;
    				return visitSemanticNode(letInNode.getBody());
    			}
    
    		}
    
    		return DefinitionType.EXPRESSION;
    	}
    
    	private DefinitionType visitOppApplNode(OpApplNode opApplNode) {
    		int kind = opApplNode.getOperator().getKind();
    
    		if (kind == BuiltInKind) {
    			switch (getOpCode(opApplNode.getOperator().getName())) {
    				case OPCODE_eq: // =
    				case OPCODE_noteq: // /=
    				case OPCODE_cl: // $ConjList
    				case OPCODE_land: // \land
    				case OPCODE_dl: // $DisjList
    				case OPCODE_lor: // \/
    				case OPCODE_equiv: // \equiv
    				case OPCODE_implies: // =>
    				case OPCODE_lnot: // \lnot
    				case OPCODE_be: // \E x \in S : P
    				case OPCODE_bf: // \A x \in S : P
    				case OPCODE_in: // \in
    				case OPCODE_subseteq: // \subseteq {1,2} <: {1,2,3}
    				case OPCODE_unchanged: {
    					return DefinitionType.PREDICATE;