| 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 | import fi.helsinki.cs.titokone.devices.DeviceNames; | |
| 9 | ||
| 10 | /** | |
| 11 | * This class is used by compiler when it compiles code. For each line | |
| 12 | * compiled compiler asks CompileDebugger to create a CompileInfo object and | |
| 13 | * passes it to the GUIBrain. | |
| 14 | */ | |
| 15 | public class CompileDebugger { | |
| 16 | ||
| 17 | /** | |
| 18 | * This field contains current CompileInfo object. | |
| 19 | */ | |
| 20 | private CompileInfo info; | |
| 21 | ||
| 22 | /** | |
| 23 | * This field contains current phase of compilation. | |
| 24 | */ | |
| 25 | private int phase; | |
| 26 | ||
| 27 | /** | |
| 28 | * This field contains current statusmessage. | |
| 29 | */ | |
| 30 | private String statusMessage; | |
| 31 | ||
| 32 | /** | |
| 33 | * This field contains current comment. This string is created by | |
| 34 | * debugger when its different methods are called. | |
| 35 | */ | |
| 36 | private String comment; | |
| 37 | ||
| 38 | /*----------- Constructor -----------*/ | |
| 39 | ||
| 40 | /** | |
| 41 | * This is the only constructor for CompileDebugger. It is called | |
| 42 | * when compiler is created. | |
| 43 | */ | |
| 44 | public CompileDebugger() { | |
| 45 | } | |
| 46 | ||
| 47 | /*----------- Compiler instructions -----------*/ | |
| 48 | ||
| 49 | /** | |
| 50 | * This method tells that an EQU was found and it is added to the | |
| 51 | * symboltable. | |
| 52 | * | |
| 53 | * @param name String containing name of the symbol. | |
| 54 | * @param value Int containing the value. | |
| 55 | */ | |
| 56 | public void foundEQU(String name, int value) { | |
| 57 | 1 | info.setSymbolFound(); |
| 58 | 1 | info.setSymbolName(name, value); |
| 59 | } | |
| 60 | ||
| 61 | /** | |
| 62 | * This method tells debugger that a DS compiler instruction was found | |
| 63 | * and it is added to the symboltable. | |
| 64 | * | |
| 65 | * @param name String containing name of the symbol. | |
| 66 | */ | |
| 67 | public void foundDS(String name) { | |
| 68 | 1 | info.setSymbolFound(); |
| 69 | 1 | info.setSymbolName(name); |
| 70 | } | |
| 71 | ||
| 72 | /** | |
| 73 | * This method tells debugger that a DC compiler instruction was found | |
| 74 | * and it is added to the symboltable. | |
| 75 | * | |
| 76 | * @param name String containing name of the symbol. | |
| 77 | */ | |
| 78 | public void foundDC(String name) { | |
| 79 | 1 | info.setSymbolFound(); |
| 80 | 1 | info.setSymbolName(name); |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * This Method tells debugger that a symbol was used as an | |
| 85 | * address. | |
| 86 | * | |
| 87 | * @param name String containing name of the symbol. | |
| 88 | */ | |
| 89 | public void foundSymbol(String name) { | |
| 90 | 1 | info.setSymbolFound(); |
| 91 | Integer value; | |
| 92 | ||
| 93 | 4 | if((value = SvcNames.lookupIgnoringCase(name)) != null || |
| 94 | (value = DeviceNames.lookupIgnoringCase(name)) != null) | |
| 95 | 2 | info.setSymbolName(name, value); |
| 96 | else | |
| 97 | 1 | info.setSymbolName(name); |
| 98 | } | |
| 99 | ||
| 100 | /** | |
| 101 | * This method tells that for given label points to given line. | |
| 102 | * | |
| 103 | * @param name String containing name of the symbol. | |
| 104 | * @param lineNumber Int containing the linenumber of the label. | |
| 105 | */ | |
| 106 | public void foundLabel(String name, int lineNumber) { | |
| 107 | 1 | info.setLabelDefined(name, lineNumber); |
| 108 | } | |
| 109 | ||
| 110 | /** | |
| 111 | * This method sets the compiled value of a line during | |
| 112 | * the second round of compilation. | |
| 113 | */ | |
| 114 | public void setBinary(int binary) { | |
| 115 | 1 | info.setLineBinary(binary); |
| 116 | } | |
| 117 | ||
| 118 | /** | |
| 119 | * This method tells debugger that first round of compilation is | |
| 120 | * in progres and line wasn't empty. It creates CompileInfo object | |
| 121 | * and sets its phase to 1, lineNumber and lineContents fields. | |
| 122 | * | |
| 123 | * @param lineNumber Number of the compiled line. | |
| 124 | * @param lineContents String containing the symbolic command. | |
| 125 | */ | |
| 126 | public void firstPhase(int lineNumber, String lineContents) { | |
| 127 | 4 | info = new CompileInfo(CompileInfo.FIRST_ROUND, lineNumber, lineContents); |
| 128 | } | |
| 129 | ||
| 130 | /** | |
| 131 | * This method is used when all lines are checked in the first | |
| 132 | * phase of compilation and compiler is setting symbols and | |
| 133 | * labels. | |
| 134 | */ | |
| 135 | public void firstPhase() { | |
| 136 | 4 | info = new CompileInfo(CompileInfo.FINALIZING_FIRST_ROUND); |
| 137 | } | |
| 138 | ||
| 139 | /** | |
| 140 | * This method is used when all DC and DS are defined and | |
| 141 | * compiler is ready to move to the second phase. Compiler tells | |
| 142 | * debugger what are code lines and then what is dataArea in memory | |
| 143 | * and what it contains. GUIBrain then redraws GUI and writes | |
| 144 | * codelines leaving binary cells empty. Then it draws data area | |
| 145 | * where number of first data line is codeArea.length | |
| 146 | * | |
| 147 | * @param codeArea String array containing codelines. | |
| 148 | * @param dataArea String array containing data. | |
| 149 | * @param symbolTable 2-dimensional String array containing the symbol table. | |
| 150 | */ | |
| 151 | public void finalFirstPhase(String[] codeArea, String[] dataArea, String[][] symbolTable) { | |
| 152 | 1 | info.setInstructions(codeArea); |
| 153 | 1 | info.setData(dataArea); |
| 154 | 1 | info.setSymbolTable(symbolTable); |
| 155 | } | |
| 156 | ||
| 157 | /** | |
| 158 | * This method sets the comment to the compileInfo. | |
| 159 | */ | |
| 160 | public void setComment(String message) { | |
| 161 | 1 | info.setComments(message); |
| 162 | } | |
| 163 | ||
| 164 | /** | |
| 165 | * This method sets the status info to the compileInfo. | |
| 166 | */ | |
| 167 | public void setStatusMessage(String message) { | |
| 168 | 1 | info.setStatusMessage(message); |
| 169 | } | |
| 170 | ||
| 171 | /** | |
| 172 | * This method tells debugger that the second round of | |
| 173 | * compilation is in progress. It creates CompileInfo object and sets | |
| 174 | * its phase to 3. | |
| 175 | * | |
| 176 | * @param lineNumber number of the compiled line. | |
| 177 | * @param lineContents Contents of the line. | |
| 178 | */ | |
| 179 | public void secondPhase(int lineNumber, String lineContents) { | |
| 180 | 4 | info = new CompileInfo(CompileInfo.SECOND_ROUND, lineNumber, lineContents); |
| 181 | } | |
| 182 | ||
| 183 | /** | |
| 184 | * This method tells debugger that final phase of compilation is | |
| 185 | * in progress. It creates CompileInfo object and sets its phase to 4. | |
| 186 | */ | |
| 187 | public void finalPhase() { | |
| 188 | 4 | info = new CompileInfo(CompileInfo.FINALIZING); |
| 189 | } | |
| 190 | ||
| 191 | /** | |
| 192 | * This method returns the created CompileInfo-object. It sets | |
| 193 | * comments in the CompileInfo and then returns it. | |
| 194 | */ | |
| 195 | public CompileInfo lineCompiled() { | |
| 196 | 1 | return info; |
| 197 | } | |
| 198 | } | |
| 199 | ||
Mutations | ||
| 57 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setSymbolFound : NO_COVERAGE |
|
| 58 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setSymbolName : NO_COVERAGE |
|
| 68 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setSymbolFound : SURVIVED |
|
| 69 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setSymbolName : SURVIVED |
|
| 79 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setSymbolFound : NO_COVERAGE |
|
| 80 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setSymbolName : NO_COVERAGE |
|
| 90 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setSymbolFound : NO_COVERAGE |
|
| 93 |
removed call to fi/helsinki/cs/titokone/SvcNames::lookupIgnoringCase : NO_COVERAGE removed call to fi/helsinki/cs/titokone/devices/DeviceNames::lookupIgnoringCase : NO_COVERAGE negated conditional : NO_COVERAGE negated conditional : NO_COVERAGE |
|
| 95 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setSymbolName : NO_COVERAGE removed call to java/lang/Integer::intValue : NO_COVERAGE |
|
| 97 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setSymbolName : NO_COVERAGE |
|
| 107 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setLabelDefined : NO_COVERAGE |
|
| 115 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setLineBinary : SURVIVED |
|
| 127 |
Substituted 0 with 1 : SURVIVED removed call to fi/helsinki/cs/titokone/CompileInfo::<init> : KILLED -> fi.helsinki.cs.titokone.ControlTest.testGetApplicationDefinitions(fi.helsinki.cs.titokone.ControlTest) Substituted 0 with 1 : SURVIVED Removed assignment to member variable info : KILLED -> fi.helsinki.cs.titokone.ControlTest.testGetApplicationDefinitions(fi.helsinki.cs.titokone.ControlTest) |
|
| 136 |
Substituted 1 with 0 : SURVIVED removed call to fi/helsinki/cs/titokone/CompileInfo::<init> : KILLED -> fi.helsinki.cs.titokone.ControlTest.testGetApplicationDefinitions(fi.helsinki.cs.titokone.ControlTest) Removed assignment to member variable info : SURVIVED Substituted 1 with 0 : SURVIVED |
|
| 152 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setInstructions : SURVIVED |
|
| 153 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setData : SURVIVED |
|
| 154 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setSymbolTable : SURVIVED |
|
| 161 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setComments : SURVIVED |
|
| 168 |
removed call to fi/helsinki/cs/titokone/CompileInfo::setStatusMessage : SURVIVED |
|
| 180 |
removed call to fi/helsinki/cs/titokone/CompileInfo::<init> : KILLED -> fi.helsinki.cs.titokone.ControlTest.testGetApplicationDefinitions(fi.helsinki.cs.titokone.ControlTest) Substituted 2 with 3 : SURVIVED Substituted 2 with 3 : SURVIVED Removed assignment to member variable info : SURVIVED |
|
| 188 |
Substituted 3 with 4 : SURVIVED Substituted 3 with 4 : SURVIVED Removed assignment to member variable info : SURVIVED removed call to fi/helsinki/cs/titokone/CompileInfo::<init> : SURVIVED |
|
| 196 |
mutated return of Object value for fi/helsinki/cs/titokone/CompileDebugger::lineCompiled to ( if (x != null) null else throw new RuntimeException ) : KILLED -> fi.helsinki.cs.titokone.ControlTest.testGetApplicationDefinitions(fi.helsinki.cs.titokone.ControlTest) |