Fixes null captured parameters
[jpf-core.git] / src / main / gov / nasa / jpf / util / PrintUtils.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The Java Pathfinder core (jpf-core) platform is licensed under the
7  * Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and 
16  * limitations under the License.
17  */
18
19 package gov.nasa.jpf.util;
20
21 import gov.nasa.jpf.vm.MJIEnv;
22
23 import java.io.PrintStream;
24
25 public class PrintUtils {
26
27   public static void printChar (PrintStream ps, char c){
28     switch (c) {
29     case '\n': ps.print("\\n"); break;
30     case '\r': ps.print("\\r"); break;
31     case '\t': ps.print("\\t"); break;
32     case '\b': ps.print("\\b"); break;
33     case '\f': ps.print("\\f"); break;
34     case '\'': ps.print("\\'"); break;
35     case '\"': ps.print("\\\""); break;
36     case '\\': ps.print("\\"); break;
37     default: ps.print(c);
38     }
39   }
40   
41   public static void printCharLiteral (PrintStream ps, char c){
42     ps.print('\'');
43     printChar(ps, c);
44     ps.print('\'');
45   }
46   
47   public static void printStringLiteral (PrintStream ps, char[] data, int max){
48     int i;
49     if (max < 0){
50       max = data.length;
51     }
52     
53     ps.print('"');
54     for (i=0; i<max; i++){
55       printChar(ps, data[i]);
56     }
57     
58     if (i< data.length){
59       ps.print("...");
60     }
61     
62     ps.print('"');
63   }
64   
65   // this is mostly here so that we use the same convention
66   public static void printReference (PrintStream ps, int ref){
67     if (ref == MJIEnv.NULL){
68       ps.print("null");
69     } else {
70       ps.print('@');
71       ps.printf("%x", ref);
72     }
73   }
74 }