1 21 22 package java_cup.anttask; 23 24 import org.apache.tools.ant.Task; 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.types.Path; 27 28 import java.util.List ; 29 import java.util.ArrayList ; 30 import java.io.File ; 31 import java.io.FileReader ; 32 import java.io.BufferedReader ; 33 import java.io.IOException ; 34 import java.net.URL ; 35 36 import java_cup.version; 37 38 public class CUPTask extends Task 39 { 40 private String srcfile=null; 41 private String parser=null; 42 private String _package=null; 43 private String symbols=null; 44 private String destdir=null; 45 private boolean _interface=false; 46 private boolean nonterms=false; 47 private String expect=null; 48 private boolean compact_red=false; 49 private boolean nowarn=false; 50 private boolean nosummary=false; 51 private boolean progress=false; 52 private boolean dump_grammar=false; 53 private boolean dump_states=false; 54 private boolean dump_tables=false; 55 private boolean dump=false; 56 private boolean time=false; 57 private boolean debug=false; 58 private boolean nopositions=false; 59 private boolean noscanner=false; 60 private boolean force=false; 61 private boolean quiet=false; 62 63 68 69 public void execute() throws BuildException 70 { 71 List sc = new ArrayList (); if (parser!=null) { sc.add("-parser"); sc.add(parser);} 74 else parser="parser"; if (_package!=null){ sc.add("-package"); sc.add(_package); } 76 if (symbols!=null) { sc.add("-symbols"); sc.add(symbols); } 77 else symbols="sym"; 78 if (expect!=null) { sc.add("-expect"); sc.add(expect); } 79 if (_interface) { sc.add("-interface"); } 80 if (nonterms) { sc.add("-nonterms"); } 81 if (compact_red) { sc.add("-compact_red"); } 82 if (nowarn) { sc.add("-nowarn"); } 83 if (nosummary) { sc.add("-nosummary");} 84 if (progress) { sc.add("-progress"); } 85 if (dump_grammar) { sc.add("-dump_grammar"); } 86 if (dump_states) { sc.add("-dump_states"); } 87 if (dump_tables) { sc.add("-dump_tables"); } 88 if (dump) { sc.add("-dump"); } 89 if (time) { sc.add("-time"); } 90 if (debug) { sc.add("-debug"); } 91 if (nopositions) { sc.add("-nopositions"); } 92 if (noscanner) { sc.add("-noscanner"); } 93 if (!quiet) log ("This is "+version.title_str); 94 if (!quiet) log ("Authors : "+version.author_str); 95 if (!quiet) log ("Bugreports to petter@cs.tum.edu"); 96 97 String packagename = inspect(srcfile); 99 100 101 if (destdir==null) { 103 destdir=System.getProperty("user.dir"); 104 if (!quiet) log("No destination directory specified; using working directory: "+destdir); 105 } 106 File dest = new File (destdir+packagename); 107 if (!(dest).exists()) { 108 if (!quiet) log("Destination directory didn't exist; creating new one: "+destdir+packagename); 109 dest.mkdirs(); 110 force=true; 111 } 112 else { 113 if (force&& !quiet) { log("anyway, this generation will be processed because of option force set to \"true\""); } 114 else { if (!quiet) log("checking, whether this run is necessary"); } 115 File parserfile = new File (destdir+packagename,parser+".java"); 117 File symfile = new File (destdir+packagename,symbols+".java"); 118 File cupfile = new File (srcfile); 119 120 if (!parserfile.exists() || !symfile.exists()) { 121 if (!quiet) log("Either Parserfile or Symbolfile didn't exist"); 122 force=true; 123 }else { if (!quiet) log("Parserfile and symbolfile are existing"); } 124 125 126 if (parserfile.lastModified()<=cupfile.lastModified()) { 127 if (!quiet) log("Parserfile "+parserfile+" isn't actual"); 128 force=true; 129 }else { if (!quiet) log("Parserfile "+parserfile+" is actual"); } 130 131 if (symfile.lastModified()<=cupfile.lastModified()) { 132 if (!quiet) log("Symbolfile "+symfile+" isn't actual"); 133 force=true; 134 }else { if (!quiet) log("Symbolfile"+symfile+" is actual"); } 135 136 137 if (!force) { 138 if (!quiet) log("skipping generation of "+srcfile); 139 if (!quiet) log("use option force=\"true\" to override"); 140 return; 141 } 142 } 143 144 sc.add("-destdir"); 145 sc.add(dest.getAbsolutePath()); 146 147 if (srcfile==null) throw new BuildException("Input file needed: Specify <cup srcfile=\"myfile.cup\"> "); 149 if (!(new File (srcfile)).exists()) throw new BuildException("Input file not found: srcfile=\""+srcfile+"\" "); 150 151 sc.add(srcfile); 152 String [] args = new String [sc.size()]; 153 for (int i=0;i<args.length;i++) args[i]=(String )sc.get(i); 154 155 156 try { 157 java_cup.Main.main(args); 158 }catch(Exception e){ 159 log("CUP error occured int CUP task: "+e); 160 } 161 162 173 176 179 } 180 181 188 protected String inspect(String cupfile){ 189 try{ 190 BufferedReader br = new BufferedReader (new FileReader (cupfile)); 191 while (br.ready()){ 192 String line = br.readLine(); 193 if ((line.startsWith("package"))&&(line.indexOf(";")!=-1)) 194 { 195 String result = line.substring(8,line.indexOf(";")); 196 result = result.replace('.',System.getProperty("file.separator").charAt(0)); 197 return System.getProperty("file.separator") + result; 198 } 199 200 } 201 }catch (IOException ioe){ 202 } 203 return ""; 204 } 205 206 211 public boolean getQuiet() { 212 return this.quiet; 213 } 214 215 220 public void setQuiet(boolean argquiet) { 221 this.quiet = argquiet; 222 } 223 228 public boolean getForce() { 229 return this.force; 230 } 231 232 237 public void setForce(boolean argforce) { 238 this.force = argforce; 239 } 240 245 public String getPackage() { 246 return this._package; 247 } 248 249 254 public void setPackage(String arg_package) { 255 this._package = arg_package; 256 } 257 258 263 public String getDestdir() { 264 return this.destdir; 265 } 266 267 272 public void setDestdir(String destdir) { 273 this.destdir = destdir; 274 } 275 276 281 public boolean isInterface() { 282 return this._interface; 283 } 284 285 290 public void setInterface(boolean arg_interface) { 291 this._interface = arg_interface; 292 } 293 294 298 public String getSrcfile() { 299 return srcfile; 300 } 301 302 306 public void setSrcfile(String newSrcfile) { 307 this.srcfile = newSrcfile; 308 } 309 310 311 312 317 public String getParser() { 318 return this.parser; 319 } 320 321 326 public void setParser(String argParser){ 327 this.parser = argParser; 328 } 329 330 335 public String getSymbols() { 336 return this.symbols; 337 } 338 339 344 public void setSymbols(String argSymbols){ 345 this.symbols = argSymbols; 346 } 347 348 353 public boolean isNonterms() { 354 return this.nonterms; 355 } 356 357 362 public void setNonterms(boolean argNonterms){ 363 this.nonterms = argNonterms; 364 } 365 366 371 public String getExpect() { 372 return this.expect; 373 } 374 375 380 public void setExpect(String argExpect){ 381 this.expect = argExpect; 382 } 383 384 389 public boolean isCompact_red() { 390 return this.compact_red; 391 } 392 393 398 public void setCompact_red(boolean argCompact_red){ 399 this.compact_red = argCompact_red; 400 } 401 402 407 public boolean isNowarn() { 408 return this.nowarn; 409 } 410 411 416 public void setNowarn(boolean argNowarn){ 417 this.nowarn = argNowarn; 418 } 419 420 425 public boolean isNosummary() { 426 return this.nosummary; 427 } 428 429 434 public void setNosummary(boolean argNosummary){ 435 this.nosummary = argNosummary; 436 } 437 438 443 public boolean isProgress() { 444 return this.progress; 445 } 446 447 452 public void setProgress(boolean argProgress){ 453 this.progress = argProgress; 454 } 455 456 461 public boolean isDump_grammar() { 462 return this.dump_grammar; 463 } 464 465 470 public void setDump_grammar(boolean argDump_grammar){ 471 this.dump_grammar = argDump_grammar; 472 } 473 474 479 public boolean isDump_states() { 480 return this.dump_states; 481 } 482 483 488 public void setDump_states(boolean argDump_states){ 489 this.dump_states = argDump_states; 490 } 491 492 497 public boolean isDump_tables() { 498 return this.dump_tables; 499 } 500 501 506 public void setDump_tables(boolean argDump_tables){ 507 this.dump_tables = argDump_tables; 508 } 509 510 515 public boolean isDump() { 516 return this.dump; 517 } 518 519 524 public void setDump(boolean argDump){ 525 this.dump = argDump; 526 } 527 528 533 public boolean isTime() { 534 return this.time; 535 } 536 537 542 public void setTime(boolean argTime){ 543 this.time = argTime; 544 } 545 546 551 public boolean isDebug() { 552 return this.debug; 553 } 554 555 560 public void setDebug(boolean argDebug){ 561 this.debug = argDebug; 562 } 563 564 569 public boolean isNopositions() { 570 return this.nopositions; 571 } 572 573 578 public void setNopositions(boolean argNopositions){ 579 this.nopositions = argNopositions; 580 } 581 582 587 public boolean isNoscanner() { 588 return this.noscanner; 589 } 590 591 596 public void setNoscanner(boolean argNoscanner){ 597 this.noscanner = argNoscanner; 598 } 599 600 601 } 602 603 604 605 | Popular Tags |