aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/PrologException.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/PrologException.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/PrologException.cs118
1 files changed, 103 insertions, 15 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/PrologException.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/PrologException.cs
index 2a23fe1..9a1f00d 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/PrologException.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/YieldProlog/PrologException.cs
@@ -1,20 +1,20 @@
1/* 1/*
2 * Copyright (C) 2007-2008, Jeff Thompson 2 * Copyright (C) 2007-2008, Jeff Thompson
3 * 3 *
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met: 7 * modification, are permitted provided that the following conditions are met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright 11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the copyright holder nor the names of its contributors 14 * * Neither the name of the copyright holder nor the names of its contributors
15 * may be used to endorse or promote products derived from this software 15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission. 16 * without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -43,7 +43,6 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
43 /// Create a PrologException with the given Term. The printable exception message is the full Term. 43 /// Create a PrologException with the given Term. The printable exception message is the full Term.
44 /// </summary> 44 /// </summary>
45 /// <param name="Term">the term of the exception</param> 45 /// <param name="Term">the term of the exception</param>
46 /// </param>
47 public PrologException(object Term) 46 public PrologException(object Term)
48 : base(YP.getValue(Term).ToString()) 47 : base(YP.getValue(Term).ToString())
49 { 48 {
@@ -54,18 +53,107 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.YieldProlog
54 /// Create a PrologException where the Term is error(ErrorTerm, Message). 53 /// Create a PrologException where the Term is error(ErrorTerm, Message).
55 /// This uses YP.makeCopy to copy the ErrorTerm and Message so that they are valid after unbinding. 54 /// This uses YP.makeCopy to copy the ErrorTerm and Message so that they are valid after unbinding.
56 /// </summary> 55 /// </summary>
57 /// <param name="ErrorTerm">the term of the exception</param> 56 /// <param name="ErrorTerm">the error term of the error</param>
58 /// <param name="Messsage">the message, converted to a string, to use as the printable exception message 57 /// <param name="Messsage">the message term of the error. If this is a string, it is converted to an
58 /// Atom so it can be used by Prolog code.
59 /// Message, converted to a string, is use as the printable exception message.
59 /// </param> 60 /// </param>
60 public PrologException(object ErrorTerm, object Message) 61 public PrologException(object ErrorTerm, object Message)
61 : base(YP.getValue(Message).ToString()) 62 : base(YP.getValue(Message).ToString())
62 { 63 {
64 if (Message is string)
65 Message = Atom.a((string)Message);
63 _term = YP.makeCopy(new Functor2(Atom.a("error"), ErrorTerm, Message), new Variable.CopyStore()); 66 _term = YP.makeCopy(new Functor2(Atom.a("error"), ErrorTerm, Message), new Variable.CopyStore());
64 } 67 }
65 68
66 public object Term 69 public class TypeErrorInfo
70 {
71 public readonly Atom _Type;
72 public readonly object _Culprit;
73 public readonly object _Message;
74
75 public TypeErrorInfo(Atom Type, object Culprit, object Message)
76 {
77 _Type = Type;
78 _Culprit = Culprit;
79 _Message = Message;
80 }
81 }
82 /// <summary>
83 /// Return the TypeErrorInfo for this exception, or null if _term does not match
84 /// error(type_error(Type, Culprit), Message).
85 /// </summary>
86 /// <returns></returns>
87 public TypeErrorInfo getTypeErrorInfo()
88 {
89 if (!(_term is Functor2 && ((Functor2)_term)._name._name == "error"))
90 return null;
91 object errorTerm = ((Functor2)_term)._arg1;
92 if (!(errorTerm is Functor2 && ((Functor2)errorTerm)._name._name == "type_error"))
93 return null;
94 if (!(((Functor2)errorTerm)._arg1 is Atom))
95 return null;
96 return new TypeErrorInfo
97 ((Atom)((Functor2)errorTerm)._arg1, ((Functor2)errorTerm)._arg2, ((Functor2)_term)._arg2);
98 }
99
100 public class ExistenceErrorInfo
101 {
102 public readonly Atom _Type;
103 public readonly object _Culprit;
104 public readonly object _Message;
105
106 public ExistenceErrorInfo(Atom Type, object Culprit, object Message)
107 {
108 _Type = Type;
109 _Culprit = Culprit;
110 _Message = Message;
111 }
112
113 /// <summary>
114 /// If _Type is procedure and _Culprit is name/artity, return the name. Otherwise return null.
115 /// </summary>
116 /// <returns></returns>
117 public object getProcedureName()
118 {
119 if (!(_Type._name == "procedure" &&
120 _Culprit is Functor2 && ((Functor2)_Culprit)._name == Atom.SLASH))
121 return null;
122 return ((Functor2)_Culprit)._arg1;
123 }
124
125 /// <summary>
126 /// If _Type is procedure and _Culprit is name/arity and arity is an integer, return the arity.
127 /// Otherwise return -1.
128 /// </summary>
129 /// <returns></returns>
130 public int getProcedureArity()
131 {
132 if (!(_Type._name == "procedure" &&
133 _Culprit is Functor2 && ((Functor2)_Culprit)._name == Atom.SLASH))
134 return -1;
135 if (!(((Functor2)_Culprit)._arg2 is int))
136 return -1;
137 return (int)((Functor2)_Culprit)._arg2;
138 }
139 }
140 /// <summary>
141 /// Return the ExistenceErrorInfo for this exception, or null if _term does not match
142 /// error(existence_error(Type, Culprit), Message). If the returned ExistenceErrorInfo _Culprit is
143 /// procedure, you can use its getProcedureName and getProcedureArity.
144 /// </summary>
145 /// <returns></returns>
146 public ExistenceErrorInfo getExistenceErrorInfo()
67 { 147 {
68 get { return _term; } 148 if (!(_term is Functor2 && ((Functor2)_term)._name._name == "error"))
149 return null;
150 object errorTerm = ((Functor2)_term)._arg1;
151 if (!(errorTerm is Functor2 && ((Functor2)errorTerm)._name._name == "existence_error"))
152 return null;
153 if (!(((Functor2)errorTerm)._arg1 is Atom))
154 return null;
155 return new ExistenceErrorInfo
156 ((Atom)((Functor2)errorTerm)._arg1, ((Functor2)errorTerm)._arg2, ((Functor2)_term)._arg2);
69 } 157 }
70 } 158 }
71} 159}