1 26 27 package org.objectweb.openccm.command.lib; 28 29 import org.objectweb.openccm.command.api.Compiler; 31 import org.objectweb.util.cmdline.api.CommandLine; 32 import org.objectweb.util.cpp.lib.PreprocessorApplication; 33 34 42 43 public abstract class CompilerBase 44 extends CommandOnASTBase 45 implements Compiler 46 { 47 53 54 private PreprocessorApplication preprocessor_; 55 56 62 67 public 68 CompilerBase(CommandLine commandLine) 69 { 70 this(commandLine, true); 71 } 72 73 80 public 81 CompilerBase(CommandLine commandLine, boolean withPreprocessorOptions) 82 { 83 super(commandLine); 85 86 preprocessor_ = new PreprocessorApplication(commandLine, false, withPreprocessorOptions); 88 preprocessor_.setConsole(getConsole()); 89 } 90 91 97 103 109 115 121 127 134 public org.objectweb.openccm.ast.api.FileScope 135 compile(String filename) 136 { 137 if (!new java.io.File (filename).exists()) 138 getConsole().error("File " + filename + " not found!"); 139 140 getConsole().message("Reading from file " + filename + "..."); 141 142 java.io.File file = preprocessor_.preprocess(filename); 144 if(file == null) return null; 145 146 org.objectweb.openccm.parser.lib.ErrorManager errorManager = null; 148 org.objectweb.openccm.parser.api.Parser parser = null; 149 try 150 { 151 errorManager = new org.objectweb.openccm.parser.lib.ErrorManager(filename); 152 parser = new org.objectweb.openccm.parser.lib.Parser( 153 new java.io.FileInputStream (file), 154 getAST(), 155 errorManager); 156 } 157 catch(java.io.FileNotFoundException e) 158 { 159 getConsole().error("File " + file.toString() + " not found!"); 160 return null; 161 } 162 163 getConsole().message("Compiling " + filename + " file..."); 165 org.objectweb.openccm.ast.api.FileScope result = parser.parseCIDL(); 166 167 int nbErrors = errorManager.getNbErrors(); 168 int nbWarnings = errorManager.getNbWarnings(); 169 170 if (result == null) 171 { 172 String msg = "Compilation failed: " + nbErrors + " error"; 173 if(nbErrors > 1) msg += 's'; 174 msg += ", " + nbWarnings + " warning"; 175 if(nbWarnings > 1) msg += 's'; 176 msg += '.'; 177 getConsole().error(msg); 178 } else { 179 String msg = "Compilation completed: " + nbWarnings + " warning"; 180 if(nbWarnings > 1) msg += 's'; 181 msg += '.'; 182 getConsole().message(msg); 183 } 184 185 try 188 { 189 file.delete(); 190 } 191 catch(Exception e) 192 { 193 getConsole().error("Problem when deleting temporary file " + file.toString()); 194 report_exception(e); 195 } 196 197 return result; 198 } 199 200 205 public org.objectweb.util.cpp.api.PreprocessorApplication 206 getPreprocessorApplication() 207 { 208 return preprocessor_; 209 } 210 211 } 217 | Popular Tags |