| 1 | // Copyright © 2004-2006 University of Helsinki, Department of Computer Science | |
| 2 | // Copyright © 2012 various contributors | |
| 3 | // This software is released under GNU Lesser General Public License 2.1. | |
| 4 | // The license text is at http://www.gnu.org/licenses/lgpl-2.1.html | |
| 5 | ||
| 6 | package fi.helsinki.cs.titokone; | |
| 7 | ||
| 8 | /** | |
| 9 | * This class is used to tell GUIBrain what compiler has done at the moment. | |
| 10 | * CompileDebugger creates objects from this class and passes them to the | |
| 11 | * GUIBrain. | |
| 12 | */ | |
| 13 | public class CompileInfo extends DebugInfo { | |
| 14 | // Variables common to both rounds. | |
| 15 | ||
| 16 | public static final short FIRST_ROUND = 0; | |
| 17 | public static final short FINALIZING_FIRST_ROUND = 1; | |
| 18 | public static final short SECOND_ROUND = 2; | |
| 19 | public static final short FINALIZING = 3; | |
| 20 | ||
| 21 | private short phase; | |
| 22 | ||
| 23 | /** | |
| 24 | * This field contains the number of the line being processed or | |
| 25 | * -1 during the finalizing phase. | |
| 26 | */ | |
| 27 | private int lineNumber; | |
| 28 | ||
| 29 | /** | |
| 30 | * This field hold the contents of a compiled line. | |
| 31 | */ | |
| 32 | private String lineContents; | |
| 33 | ||
| 34 | /** | |
| 35 | * These arrays contain codelines, data and the symboltable after first round. | |
| 36 | */ | |
| 37 | String[] instructions; | |
| 38 | String[] data; | |
| 39 | String[][] symbolTable; | |
| 40 | ||
| 41 | /** | |
| 42 | * This field is by default false, but if the compiled line was | |
| 43 | * empty (or consisted of whitespace only), the true value here says | |
| 44 | * that other checks can be skipped. | |
| 45 | */ | |
| 46 | 6 | private boolean lineEmpty = false; |
| 47 | ||
| 48 | /** | |
| 49 | * This field contains the name of a symbol found on this line | |
| 50 | * from the parameter field. It will be set to "" if no symbol | |
| 51 | * was found on this line. See also symbolValue, symbolDefined and | |
| 52 | * label variables. | |
| 53 | */ | |
| 54 | 2 | private String symbolName = ""; |
| 55 | ||
| 56 | /** | |
| 57 | * This field is true if the symbol's value was also defined on this | |
| 58 | * line. In this case, the value is set in symbolValue. | |
| 59 | */ | |
| 60 | 6 | private boolean symbolDefined = false; |
| 61 | ||
| 62 | /** | |
| 63 | * This field contains the value of the symbol found. If symbolDefined | |
| 64 | * is false, the value in this field should be ignored. | |
| 65 | */ | |
| 66 | private int symbolValue; | |
| 67 | ||
| 68 | /** | |
| 69 | * This field contains the address of the symbol. | |
| 70 | */ | |
| 71 | private int symbolAddress; | |
| 72 | ||
| 73 | /** | |
| 74 | * This field contains information if a symbol was foud. | |
| 75 | */ | |
| 76 | private boolean symbolFound; | |
| 77 | ||
| 78 | /** | |
| 79 | * This field contains information if a label was found. | |
| 80 | */ | |
| 81 | private boolean labelFound; | |
| 82 | ||
| 83 | /** | |
| 84 | * This field contains the name of a label found from the beginning of | |
| 85 | * this line. It will be set to "" if no label was found on this line. | |
| 86 | */ | |
| 87 | 2 | private String labelName = ""; |
| 88 | ||
| 89 | /** | |
| 90 | * This field contains line as a binary. | |
| 91 | */ | |
| 92 | private int lineBinary; | |
| 93 | ||
| 94 | /** | |
| 95 | * This field is true if found label was defined before. | |
| 96 | */ | |
| 97 | 6 | private boolean labelDefined = false; |
| 98 | ||
| 99 | /** | |
| 100 | * This field contains value of the current label. | |
| 101 | */ | |
| 102 | private int labelValue; | |
| 103 | ||
| 104 | // Variables for finalization phase. | |
| 105 | ||
| 106 | /** | |
| 107 | * This field contains true if we have gone through all DS and DC | |
| 108 | * commands and are setting FP and SP accordingly, or false if | |
| 109 | * we are still going through DS and DC commands. | |
| 110 | */ | |
| 111 | private boolean finalFinal; | |
| 112 | ||
| 113 | /*---------- Constructor ----------*/ | |
| 114 | ||
| 115 | /** | |
| 116 | * This is normal constructor for CompileInfo. It sets initial values for | |
| 117 | * phase, lineNumber and lineContents. | |
| 118 | * | |
| 119 | * @param phase Short indicating which phase is going on. | |
| 120 | * @param lineNumber Integer value of the current line number. | |
| 121 | * @param lineContents String containing symbolic command. | |
| 122 | */ | |
| 123 | public CompileInfo(short phase, int lineNumber, String lineContents) { | |
| 124 | 1 | this.phase = phase; |
| 125 | 1 | this.lineNumber = lineNumber; |
| 126 | 1 | this.lineContents = lineContents; |
| 127 | } | |
| 128 | ||
| 129 | /** | |
| 130 | * This constructor is used when no actual line is compiled but other | |
| 131 | * actions are made like finalizing the rounds. | |
| 132 | * | |
| 133 | * @param phase short indicating which phase is going on. | |
| 134 | */ | |
| 135 | public CompileInfo(short phase) { | |
| 136 | 1 | this.phase = phase; |
| 137 | } | |
| 138 | ||
| 139 | /*---------- set-methods ----------*/ | |
| 140 | ||
| 141 | ||
| 142 | /** | |
| 143 | * This method sets lineEmpty value to true. | |
| 144 | */ | |
| 145 | public void setLineEmpty() { | |
| 146 | 3 | lineEmpty = true; |
| 147 | } | |
| 148 | ||
| 149 | /** | |
| 150 | * This method sets symbolFound field. | |
| 151 | */ | |
| 152 | public void setSymbolFound() { | |
| 153 | 3 | symbolFound = true; |
| 154 | } | |
| 155 | ||
| 156 | /** | |
| 157 | * This method sets the name of a found symbol. | |
| 158 | * | |
| 159 | * @param name String containing the symbol name. | |
| 160 | */ | |
| 161 | public void setSymbolName(String name) { | |
| 162 | 1 | symbolName = name; |
| 163 | } | |
| 164 | ||
| 165 | /** | |
| 166 | * This method sets the name of a found symbol and its value. | |
| 167 | * | |
| 168 | * @param name Name of the symbol. | |
| 169 | * @param value Value of the symbol. | |
| 170 | */ | |
| 171 | public void setSymbolName(String name, int value) { | |
| 172 | 1 | symbolName = name; |
| 173 | 1 | symbolValue = value; |
| 174 | 3 | symbolDefined = true; |
| 175 | } | |
| 176 | ||
| 177 | /** | |
| 178 | * This method sets labelFound field. | |
| 179 | */ | |
| 180 | public void setLabelFound() { | |
| 181 | 3 | labelFound = true; |
| 182 | } | |
| 183 | ||
| 184 | /** | |
| 185 | * This method sets the name of a found label and sets the labelDefined | |
| 186 | * field to true. | |
| 187 | * | |
| 188 | * @param name Name of the label. | |
| 189 | */ | |
| 190 | public void setLabelName(String name) { | |
| 191 | 1 | labelName = name; |
| 192 | } | |
| 193 | ||
| 194 | /** | |
| 195 | * This method tells CompileInfo that a given label was defined and it's | |
| 196 | * value. It sets labelDefined field to true. | |
| 197 | * | |
| 198 | * @param name String containing the name of the label. | |
| 199 | * @param value An integer value where the label points. | |
| 200 | */ | |
| 201 | public void setLabelDefined(String name, int value) { | |
| 202 | 1 | labelName = name; |
| 203 | 1 | labelValue = value; |
| 204 | 3 | labelDefined = true; |
| 205 | 3 | labelFound = true; |
| 206 | } | |
| 207 | ||
| 208 | /** | |
| 209 | * This method tells what integer represents the compiled line of the | |
| 210 | * code. | |
| 211 | * | |
| 212 | * @param binary An integer value representing the symbolic command. | |
| 213 | */ | |
| 214 | public void setLineBinary(int binary) { | |
| 215 | 1 | lineBinary = binary; |
| 216 | } | |
| 217 | ||
| 218 | /** | |
| 219 | * This method sets the boolean field finalFinal to true. | |
| 220 | */ | |
| 221 | public void setFinal() { | |
| 222 | 3 | finalFinal = true; |
| 223 | } | |
| 224 | ||
| 225 | /** | |
| 226 | * This method sets given line to given value. | |
| 227 | * | |
| 228 | * @param lineNumber Number of the line. | |
| 229 | * @param value New value for the line. | |
| 230 | */ | |
| 231 | public void setMemoryline(int lineNumber, String value) { | |
| 232 | 1 | this.lineNumber = lineNumber; |
| 233 | 1 | lineContents = value; |
| 234 | } | |
| 235 | ||
| 236 | /** | |
| 237 | * This method sets memory array to contain all codelines after first | |
| 238 | * round of compilation. It contains only symbolic lines. | |
| 239 | * | |
| 240 | * @param instructions array containing code-lines. | |
| 241 | */ | |
| 242 | public void setInstructions(String[] instructions) { | |
| 243 | 1 | this.instructions = instructions; |
| 244 | } | |
| 245 | ||
| 246 | /** | |
| 247 | * This method sets data area of a memory to contain all codelines after first | |
| 248 | * round of compilation. It contains variable values. | |
| 249 | * | |
| 250 | * @param data array containing data-area. | |
| 251 | */ | |
| 252 | public void setData(String[] data) { | |
| 253 | 1 | this.data = data; |
| 254 | } | |
| 255 | ||
| 256 | public void setSymbolTable(String[][] symbolTable) { | |
| 257 | 1 | this.symbolTable = symbolTable; |
| 258 | } | |
| 259 | ||
| 260 | /*---------- get-methods ----------*/ | |
| 261 | ||
| 262 | /** | |
| 263 | * This message tells that an empty line or line containing only | |
| 264 | * whitespaces was compiled. | |
| 265 | */ | |
| 266 | public boolean getLineEmpty() { | |
| 267 | 1 | return lineEmpty; |
| 268 | } | |
| 269 | ||
| 270 | /** | |
| 271 | * This method returns current phase as a short. 0 for first round, 1 for | |
| 272 | * finalizing first round, 2 for second and 3 for final. | |
| 273 | * | |
| 274 | * @return Short containing phase. | |
| 275 | */ | |
| 276 | public short getPhase() { | |
| 277 | 1 | return phase; |
| 278 | } | |
| 279 | ||
| 280 | /** | |
| 281 | * This method return symbolic contents of the line. | |
| 282 | * | |
| 283 | * @return String containing symbolic representation of a compiled line. | |
| 284 | */ | |
| 285 | public String getLineContents() { | |
| 286 | 1 | return lineContents; |
| 287 | } | |
| 288 | ||
| 289 | /** | |
| 290 | * This method tells which line was processed. | |
| 291 | * | |
| 292 | * @return Int value of the line in question. | |
| 293 | */ | |
| 294 | public int getLineNumber() { | |
| 295 | 1 | return lineNumber; |
| 296 | } | |
| 297 | ||
| 298 | /** | |
| 299 | * This method returns found symbolname. | |
| 300 | * | |
| 301 | * @return String containing the name. | |
| 302 | */ | |
| 303 | public String getSymbolName() { | |
| 304 | 1 | return symbolName; |
| 305 | } | |
| 306 | ||
| 307 | /** | |
| 308 | * This method returns true if a symbol was defined. | |
| 309 | * | |
| 310 | * @return boolean containing information if symbol was defined. | |
| 311 | */ | |
| 312 | public boolean getSymbolDefined() { | |
| 313 | 1 | return symbolDefined; |
| 314 | } | |
| 315 | ||
| 316 | /** | |
| 317 | * This method returns true if a label was found. | |
| 318 | * | |
| 319 | * @return boolean containing information if label was found. | |
| 320 | */ | |
| 321 | public boolean getLabelFound() { | |
| 322 | 1 | return labelFound; |
| 323 | } | |
| 324 | ||
| 325 | /** | |
| 326 | * This method returns true if a symbol was found. | |
| 327 | * | |
| 328 | * @return boolean containing information if symbol was found. | |
| 329 | */ | |
| 330 | public boolean getSymbolFound() { | |
| 331 | 1 | return symbolFound; |
| 332 | } | |
| 333 | ||
| 334 | /** | |
| 335 | * This method returns value of current symbol. | |
| 336 | * | |
| 337 | * @return An integer containing symbol's value. | |
| 338 | */ | |
| 339 | public int getSymbolValue() { | |
| 340 | 1 | return symbolValue; |
| 341 | } | |
| 342 | ||
| 343 | /** | |
| 344 | * This method returns compiled binary machinecommand represented as an | |
| 345 | * integer value. | |
| 346 | * | |
| 347 | * @return An integer representing machine command. | |
| 348 | */ | |
| 349 | public int getLineBinary() { | |
| 350 | 1 | return lineBinary; |
| 351 | } | |
| 352 | ||
| 353 | /** | |
| 354 | * This method returns the name of the current label. | |
| 355 | * | |
| 356 | * @return Name of the current label. | |
| 357 | */ | |
| 358 | public String getLabelName() { | |
| 359 | 1 | return labelName; |
| 360 | } | |
| 361 | ||
| 362 | /** | |
| 363 | * This method returns value of the current label. | |
| 364 | * | |
| 365 | * @return An integer containing value of the label. | |
| 366 | */ | |
| 367 | public int getLabelValue() { | |
| 368 | 1 | return labelValue; |
| 369 | } | |
| 370 | ||
| 371 | /** | |
| 372 | * This method returns true if field finalFinal is set. | |
| 373 | * | |
| 374 | * @return Boolean. | |
| 375 | */ | |
| 376 | public boolean getFinalPhase() { | |
| 377 | 1 | return finalFinal; |
| 378 | } | |
| 379 | ||
| 380 | /** | |
| 381 | * This method returns codelines of the memory after compiler has finished first | |
| 382 | * round of compilation. This array contains all codelines other than white | |
| 383 | * spaces, empty lines and variable definitions has been removed. | |
| 384 | * | |
| 385 | * @return String array containing symbolic lines. | |
| 386 | */ | |
| 387 | public String[] getInstructions() { | |
| 388 | 1 | return instructions; |
| 389 | } | |
| 390 | ||
| 391 | /** | |
| 392 | * This method returns the variable values after compiler has finished first | |
| 393 | * round of compilation. This array contains all codelines but all white | |
| 394 | * spaces and empty lines has been removed. | |
| 395 | * | |
| 396 | * @return String array containing variable values. | |
| 397 | */ | |
| 398 | public String[] getData() { | |
| 399 | 1 | return data; |
| 400 | } | |
| 401 | ||
| 402 | /** | |
| 403 | * This method returns the symboltable gathered during the first round. | |
| 404 | * | |
| 405 | * @return Array representing the symboltable. Each entry has 2 values. | |
| 406 | * First position (0) tells the name of the symbol and the second one | |
| 407 | * (1) holds the value of that symbol. "" If it wasn't set. | |
| 408 | */ | |
| 409 | public String[][] getSymbolTable() { | |
| 410 | 1 | return symbolTable; |
| 411 | } | |
| 412 | ||
| 413 | } | |
| 414 | ||
Mutations | ||
| 46 |
Substituted 0 with 1 : SURVIVED Substituted 0 with 1 : SURVIVED Substituted 0 with 1 : SURVIVED Removed assignment to member variable lineEmpty : SURVIVED Substituted 0 with 1 : SURVIVED Removed assignment to member variable lineEmpty : SURVIVED |
|
| 54 |
Removed assignment to member variable symbolName : SURVIVED Removed assignment to member variable symbolName : SURVIVED |
|
| 60 |
Substituted 0 with 1 : SURVIVED Removed assignment to member variable symbolDefined : SURVIVED Substituted 0 with 1 : SURVIVED Substituted 0 with 1 : SURVIVED Removed assignment to member variable symbolDefined : SURVIVED Substituted 0 with 1 : SURVIVED |
|
| 87 |
Removed assignment to member variable labelName : SURVIVED Removed assignment to member variable labelName : SURVIVED |
|
| 97 |
Substituted 0 with 1 : SURVIVED Substituted 0 with 1 : SURVIVED Substituted 0 with 1 : SURVIVED Substituted 0 with 1 : SURVIVED Removed assignment to member variable labelDefined : SURVIVED Removed assignment to member variable labelDefined : SURVIVED |
|
| 124 |
Removed assignment to member variable phase : SURVIVED |
|
| 125 |
Removed assignment to member variable lineNumber : SURVIVED |
|
| 126 |
Removed assignment to member variable lineContents : SURVIVED |
|
| 136 |
Removed assignment to member variable phase : SURVIVED |
|
| 146 |
Substituted 1 with 0 : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE Removed assignment to member variable lineEmpty : NO_COVERAGE |
|
| 153 |
Substituted 1 with 0 : SURVIVED Substituted 1 with 0 : SURVIVED Removed assignment to member variable symbolFound : SURVIVED |
|
| 162 |
Removed assignment to member variable symbolName : SURVIVED |
|
| 172 |
Removed assignment to member variable symbolName : NO_COVERAGE |
|
| 173 |
Removed assignment to member variable symbolValue : NO_COVERAGE |
|
| 174 |
Substituted 1 with 0 : NO_COVERAGE Removed assignment to member variable symbolDefined : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE |
|
| 181 |
Removed assignment to member variable labelFound : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE |
|
| 191 |
Removed assignment to member variable labelName : NO_COVERAGE |
|
| 202 |
Removed assignment to member variable labelName : NO_COVERAGE |
|
| 203 |
Removed assignment to member variable labelValue : NO_COVERAGE |
|
| 204 |
Substituted 1 with 0 : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE Removed assignment to member variable labelDefined : NO_COVERAGE |
|
| 205 |
Substituted 1 with 0 : NO_COVERAGE Removed assignment to member variable labelFound : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE |
|
| 215 |
Removed assignment to member variable lineBinary : SURVIVED |
|
| 222 |
Substituted 1 with 0 : NO_COVERAGE Substituted 1 with 0 : NO_COVERAGE Removed assignment to member variable finalFinal : NO_COVERAGE |
|
| 232 |
Removed assignment to member variable lineNumber : NO_COVERAGE |
|
| 233 |
Removed assignment to member variable lineContents : NO_COVERAGE |
|
| 243 |
Removed assignment to member variable instructions : SURVIVED |
|
| 253 |
Removed assignment to member variable data : SURVIVED |
|
| 257 |
Removed assignment to member variable symbolTable : SURVIVED |
|
| 267 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 277 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 286 |
mutated return of Object value for fi/helsinki/cs/titokone/CompileInfo::getLineContents to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |
|
| 295 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 304 |
mutated return of Object value for fi/helsinki/cs/titokone/CompileInfo::getSymbolName to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |
|
| 313 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 322 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 331 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 340 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 350 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 359 |
mutated return of Object value for fi/helsinki/cs/titokone/CompileInfo::getLabelName to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |
|
| 368 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 377 |
replaced return of integer sized value with (x == 0 ? 1 : 0) : NO_COVERAGE |
|
| 388 |
mutated return of Object value for fi/helsinki/cs/titokone/CompileInfo::getInstructions to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |
|
| 399 |
mutated return of Object value for fi/helsinki/cs/titokone/CompileInfo::getData to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |
|
| 410 |
mutated return of Object value for fi/helsinki/cs/titokone/CompileInfo::getSymbolTable to ( if (x != null) null else throw new RuntimeException ) : NO_COVERAGE |