//Mike Maxim
//Abstract syntax for expressions involving basic operators

package edu.cmu.cs.l3.absyn;

public class ASOpExpression extends ASExpression {

    /** Construct an expression from an operation
     * @param p Position in source
     * @param oper The operatoe being used
     * @param left The abstract syntax of the left side of the operation
     * @param right The abstract syntax of the right side of the operation
     */
    public ASOpExpression(int p, int oper, ASExpression left, ASExpression right) {
	super(p); m_oper = oper;
	m_left = left; m_right = right;

	m_classname = "ASOpExpression";
    }

    //Operator classes
    public static final int ARITH=0,BITWISE=1,BOOLOP=2,RELATIONAL=3, POINTER=4;

    // Arith
    public final static int PLUS=0, MINUS=1, MUL=2, DIV=3, MOD=4, NEG=5;
    // Bitwise
    public final static int LSHIFT=35,RSHIFT=36,BOR=37,BAND=38,BXOR=39, BFLIP=40;
    // Bool Op
    public final static int AND=10,OR=11,XOR=12, NOT=13;
    // Relational
    public final static int EQ=23,NE=24,LT=25,LE=26,GT=27,GE=28;
    //Pointer
    public final static int PADD=50, PMINUS=51, PEQ = 52, PNEQ = 53;

    /** Return the left side of the expression */
    public ASExpression getLeft() {
	return m_left;
    }

    /** Return the right side of the expression */
    public ASExpression getRight() {
	return m_right;
    }

    /** Return the operator */
    public int getOperator() {
	return m_oper;
    }

    /** Return the operator class */
    public int getOperatorClass() {
	if (m_oper >= PLUS && m_oper <= NEG) {
	    return ARITH;
	}
	else if (m_oper >= ASOpExpression.LSHIFT && m_oper <= BFLIP) {
	    return BITWISE;
	}
	else if (m_oper >= AND && m_oper <= NOT) {
	    return BOOLOP;
	}
	else if (m_oper >= EQ && m_oper <= GE) {
	    return RELATIONAL;
	}
        else if (m_oper >= ASOpExpression.PADD && m_oper <= PNEQ)
            return POINTER;
	else {
	    return -1;
	}
    }

    private int m_oper;
    private ASExpression m_left, m_right;
}