KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > annotation > tags > ArrayCheckTag


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2000 Feng Qian
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /*
21  * Modified by the Sable Research Group and others 1997-1999.
22  * See the 'credits' file distributed with Soot for the complete list of
23  * contributors. (Soot is distributed at http://www.sable.mcgill.ca/soot)
24  */

25
26 package soot.jimple.toolkits.annotation.tags;
27
28 import soot.*;
29
30 import java.util.*;
31 import java.io.*;
32
33 /** Implementation of the Tag interface for array bounds checks.
34  */

35 public class ArrayCheckTag implements OneByteCodeTag
36 {
37     private final static String JavaDoc NAME = "ArrayCheckTag";
38
39     private boolean lowerCheck = true;
40     private boolean upperCheck = true;
41
42     /**
43      * A tag represents two bounds checks of an array reference.
44      * The value 'true' indicates check needed.
45      */

46     public ArrayCheckTag(boolean lower, boolean upper)
47     {
48     lowerCheck = lower;
49     upperCheck = upper;
50     }
51
52     /**
53      * Returns back the check information in binary form, which
54      * will be written into the class file.
55      */

56     public byte[] getValue()
57     {
58         byte[] value = new byte[1];
59
60     value[0] = 0;
61     
62     if (lowerCheck)
63         value[0] |= 0x01;
64     
65     if (upperCheck)
66         value[0] |= 0x02;
67
68     return value;
69     }
70    
71   /** Needs upper bound check?
72    */

73     public boolean isCheckUpper()
74     {
75     return upperCheck;
76     }
77    
78   /** Needs lower bound check?
79    */

80     public boolean isCheckLower()
81     {
82     return lowerCheck;
83     }
84
85     public String JavaDoc getName()
86     {
87     return NAME;
88     }
89
90     public String JavaDoc toString()
91     {
92     return (lowerCheck ? "[potentially unsafe lower bound]": "[safe lower bound]") +"" + (upperCheck ? "[potentially unsafe upper bound]":"[safe upper bound]");
93     }
94 }
95
96
97
Popular Tags