KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > coffer > extension > ProcedureDeclExt_c


1 package polyglot.ext.coffer.extension;
2
3 import polyglot.ast.*;
4 import polyglot.types.*;
5 import polyglot.util.*;
6 import polyglot.ext.jl.ast.*;
7 import polyglot.ext.coffer.types.*;
8 import polyglot.ext.coffer.ast.*;
9
10 import java.util.*;
11
12 /** The Coffer extension of the <code>ProcedureDecl</code> node.
13  *
14  * @see polyglot.ast.ProcedureDecl
15  */

16 public class ProcedureDeclExt_c extends CofferExt_c {
17     public void checkHeldKeys(KeySet held, KeySet stored) throws SemanticException {
18         ProcedureDecl n = (ProcedureDecl) node();
19
20         CofferProcedureInstance pi =
21             (CofferProcedureInstance) n.procedureInstance();
22             
23         checkHeldKeys(held, pi.returnKeys(), n.position());
24
25     }
26     public void checkHeldKeysThrowConstraint(ThrowConstraint tc, KeySet held, KeySet stored)
27     throws SemanticException {
28         checkHeldKeys(held, tc.keys(), tc.throwType().position());
29         
30     }
31     
32     private void checkHeldKeys(KeySet held, KeySet returnKeys, Position pos) throws SemanticException {
33         if (! held.equals(returnKeys)) {
34             KeySet too_much = held.removeAll(returnKeys);
35             KeySet not_enough = returnKeys.removeAll(held);
36
37             if (too_much.size() == 1) {
38                 Key k = (Key) too_much.iterator().next();
39                 throw new SemanticException(KeysToString(too_much) +
40                                             " not freed at return.",
41                                             pos);
42             }
43             else if (! too_much.isEmpty()) {
44                 throw new SemanticException(KeysToString(too_much) +
45                                             " not freed at return.",
46                                             pos);
47             }
48
49             /*
50             if (! not_enough.isEmpty())
51                 throw new SemanticException(KeysToString(not_enough) +
52                                             " not held at return.",
53                                             n.position());
54                                             */

55         }
56     }
57 }
58
Popular Tags