/src/org/ooc/backend/cdirty/VersionBlockWriter.java

http://github.com/nddrylliog/ooc · Java · 62 lines · 47 code · 14 blank · 1 comment · 0 complexity · 55981211dc4a2bcde01a1d6971ffc5c9 MD5 · raw file

  1. package org.ooc.backend.cdirty;
  2. import java.io.IOException;
  3. import org.ooc.frontend.model.VersionBlock;
  4. import org.ooc.frontend.model.VersionNodes.VersionAnd;
  5. import org.ooc.frontend.model.VersionNodes.VersionName;
  6. import org.ooc.frontend.model.VersionNodes.VersionNegation;
  7. import org.ooc.frontend.model.VersionNodes.VersionNodeVisitor;
  8. import org.ooc.frontend.model.VersionNodes.VersionOr;
  9. import org.ooc.frontend.model.VersionNodes.VersionParen;
  10. public class VersionBlockWriter {
  11. public static void writeVersionBlockStart(VersionBlock versionBlock, final CGenerator cgen) throws IOException {
  12. cgen.current.app("\n\n#if ");
  13. versionBlock.getVersion().accept(new VersionNodeVisitor() {
  14. public void visit(VersionOr versionOr) throws IOException {
  15. cgen.current.app("(");
  16. versionOr.getLeft().accept(this);
  17. cgen.current.app(" || ");
  18. versionOr.getRight().accept(this);
  19. cgen.current.app(")");
  20. }
  21. public void visit(VersionAnd versionAnd) throws IOException {
  22. cgen.current.app("(");
  23. versionAnd.getLeft().accept(this);
  24. cgen.current.app(" && ");
  25. versionAnd.getRight().accept(this);
  26. cgen.current.app(")");
  27. }
  28. public void visit(VersionNegation versionNegation) throws IOException {
  29. cgen.current.app("(");
  30. cgen.current.app("!(");
  31. versionNegation.getInner().accept(this);
  32. cgen.current.app("))");
  33. }
  34. public void visit(VersionName versionName) throws IOException {
  35. cgen.current.app("defined(").app(versionName.getName()).app(")");
  36. }
  37. public void visit(VersionParen versionParen) throws IOException {
  38. cgen.current.app('(');
  39. versionParen.getInner().accept(this);
  40. cgen.current.app(')');
  41. }
  42. });
  43. //cgen.current.nl();
  44. }
  45. public static void writeVersionBlockEnd(CGenerator cgen) throws IOException {
  46. cgen.current.app("\n#endif");
  47. }
  48. }