aboutsummaryrefslogtreecommitdiff
path: root/src/lang/PInstantiationException.java
blob: e5af166ccb87b06288c9ded11ae0ff2e91381522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package jp.ac.kobe_u.cs.prolog.lang;
/**
 * Instantiation error.<br>
 * There will be an instantiation error 
 * when an argument of one of its components is a variable,
 * and an instantiated argument or component is required.
 *
 * @author Mutsunori Banbara (banbara@kobe-u.ac.jp)
 * @author Naoyuki Tamura (tamura@kobe-u.ac.jp)
 * @version 1.0
 */
public class PInstantiationException extends BuiltinException {
    /** A functor symbol of <code>instantiation/2</code>. */
    public static final SymbolTerm INSTANTIATION_ERROR = SymbolTerm.makeSymbol("instantiation_error", 2);

    /** Constructs a new <code>PInstantiationException</code>. */
    public PInstantiationException(){}

    /** Constructs a new <code>PInstantiationException</code>
     * with the given arguments. */
    public PInstantiationException(Operation _goal, int _argNo) {
	this.goal    = _goal;
	this.argNo   = _argNo;
    }

    /** Returns a term representation of this <code>PInstantiationException</code>:
     * <code>instantiation_error(goal,argNo)</code>.
     */
    public Term getMessageTerm() {
	Term[] args = {new JavaObjectTerm(goal), new IntegerTerm(argNo)};
	return new StructureTerm(INSTANTIATION_ERROR, args);
    }

    /** Returns a string representation of this <code>PInstantiationException</code>. */
    public String toString() {
	String s = "{INSTANTIATION ERROR: " + goal.toString();
	if (argNo > 0)
	    s += " - arg " + argNo;
	s += "}";
	return s;
    }
}