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