Package org.yinwang.pysonar.ast

Source Code of org.yinwang.pysonar.ast.IfExp

package org.yinwang.pysonar.ast;

import org.jetbrains.annotations.NotNull;
import org.yinwang.pysonar.State;
import org.yinwang.pysonar.types.Type;
import org.yinwang.pysonar.types.UnionType;


public class IfExp extends Node {

    public Node test;
    public Node body;
    public Node orelse;


    public IfExp(Node test, Node body, Node orelse, String file, int start, int end) {
        super(file, start, end);
        this.test = test;
        this.body = body;
        this.orelse = orelse;
        addChildren(test, body, orelse);
    }


    @NotNull
    @Override
    public Type transform(State s) {
        Type type1, type2;
        transformExpr(test, s);

        if (body != null) {
            type1 = transformExpr(body, s);
        } else {
            type1 = Type.CONT;
        }
        if (orelse != null) {
            type2 = transformExpr(orelse, s);
        } else {
            type2 = Type.CONT;
        }
        return UnionType.union(type1, type2);
    }


    @NotNull
    @Override
    public String toString() {
        return "<IfExp:" + start + ":" + test + ":" + body + ":" + orelse + ">";
    }

}
TOP

Related Classes of org.yinwang.pysonar.ast.IfExp

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.