From d3d4c671d71b5b9555a33c8b9fba55d9c5e03dc2 Mon Sep 17 00:00:00 2001 From: RYOSUKE ISHIZUE Date: Fri, 15 Jul 2016 11:15:25 +0900 Subject: [PATCH] =?UTF-8?q?UniByteLiteral=E3=81=A8UniCharacterLiteral?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UniNodeGenerator/lib/writer.rb | 4 +- UniNodeGenerator/node_definition.rb | 6 +- .../unicoen/generator/DolittleGenerator.java | 14 +++++ .../net/unicoen/generator/JavaGenerator.java | 14 +++++ .../generator/JavaToSwiftTreeConverter.java | 14 +++++ .../unicoen/generator/SwiftCodeGenerator.java | 14 +++++ src/main/java/net/unicoen/node/Traverser.java | 10 ++++ .../java/net/unicoen/node/UniByteLiteral.java | 57 +++++++++++++++++++ .../net/unicoen/node/UniCharacterLiteral.java | 57 +++++++++++++++++++ .../parser/blockeditor/BlockGenerator.java | 14 +++++ 10 files changed, 200 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/unicoen/node/UniByteLiteral.java create mode 100644 src/main/java/net/unicoen/node/UniCharacterLiteral.java diff --git a/UniNodeGenerator/lib/writer.rb b/UniNodeGenerator/lib/writer.rb index c7c6f61..a0abed7 100644 --- a/UniNodeGenerator/lib/writer.rb +++ b/UniNodeGenerator/lib/writer.rb @@ -202,6 +202,8 @@ def write_equals(dsl, node, w) "(#{name} ? 1 : 0)" when /int/ name + when /byte|char/ + "(int)#{name}" when /long/ "(int)(#{name}^(#{name}>>32))" when /double/ @@ -275,7 +277,7 @@ def write_merge(dsl, node, w) w.block "if (that.#{name})" do w << "this.#{name} = true;" end - when /int|long|double|float/ + when /int|long|double|float|byte|char/ w.block "if (that.#{name} != 0)" do w << "this.#{name} = that.#{name};" end diff --git a/UniNodeGenerator/node_definition.rb b/UniNodeGenerator/node_definition.rb index 4cbb430..a8ef54a 100644 --- a/UniNodeGenerator/node_definition.rb +++ b/UniNodeGenerator/node_definition.rb @@ -17,9 +17,9 @@ "Int" => :int, "Long" => :long, "Double" => :double, - "String" => String -# "Byte" => :byte, -# "Character" => :char + "String" => String, + "Byte" => :byte, + "Character" => :char }.each do |name, type| x.node "#{name}Literal" do |d| d.mem "value", type diff --git a/src/main/java/net/unicoen/generator/DolittleGenerator.java b/src/main/java/net/unicoen/generator/DolittleGenerator.java index bb15142..54c22a4 100644 --- a/src/main/java/net/unicoen/generator/DolittleGenerator.java +++ b/src/main/java/net/unicoen/generator/DolittleGenerator.java @@ -14,7 +14,9 @@ import net.unicoen.node.UniBlock; import net.unicoen.node.UniBoolLiteral; import net.unicoen.node.UniBreak; +import net.unicoen.node.UniByteLiteral; import net.unicoen.node.UniCast; +import net.unicoen.node.UniCharacterLiteral; import net.unicoen.node.UniClassDec; import net.unicoen.node.UniContinue; import net.unicoen.node.UniDoWhile; @@ -397,5 +399,17 @@ public void traverseEnumConstant(UniEnumConstant node) { } + @Override + public void traverseByteLiteral(UniByteLiteral node) { + // TODO Auto-generated method stub + + } + + @Override + public void traverseCharacterLiteral(UniCharacterLiteral node) { + // TODO Auto-generated method stub + + } + } diff --git a/src/main/java/net/unicoen/generator/JavaGenerator.java b/src/main/java/net/unicoen/generator/JavaGenerator.java index f4537e9..e07faa2 100644 --- a/src/main/java/net/unicoen/generator/JavaGenerator.java +++ b/src/main/java/net/unicoen/generator/JavaGenerator.java @@ -13,7 +13,9 @@ import net.unicoen.node.UniBlock; import net.unicoen.node.UniBoolLiteral; import net.unicoen.node.UniBreak; +import net.unicoen.node.UniByteLiteral; import net.unicoen.node.UniCast; +import net.unicoen.node.UniCharacterLiteral; import net.unicoen.node.UniClassDec; import net.unicoen.node.UniContinue; import net.unicoen.node.UniDoWhile; @@ -630,5 +632,17 @@ public void traverseEnumConstant(UniEnumConstant node) { } + @Override + public void traverseByteLiteral(UniByteLiteral node) { + // TODO Auto-generated method stub + + } + + @Override + public void traverseCharacterLiteral(UniCharacterLiteral node) { + // TODO Auto-generated method stub + + } + } diff --git a/src/main/java/net/unicoen/generator/JavaToSwiftTreeConverter.java b/src/main/java/net/unicoen/generator/JavaToSwiftTreeConverter.java index d085049..c34141b 100644 --- a/src/main/java/net/unicoen/generator/JavaToSwiftTreeConverter.java +++ b/src/main/java/net/unicoen/generator/JavaToSwiftTreeConverter.java @@ -11,7 +11,9 @@ import net.unicoen.node.UniBlock; import net.unicoen.node.UniBoolLiteral; import net.unicoen.node.UniBreak; +import net.unicoen.node.UniByteLiteral; import net.unicoen.node.UniCast; +import net.unicoen.node.UniCharacterLiteral; import net.unicoen.node.UniClassDec; import net.unicoen.node.UniContinue; import net.unicoen.node.UniDoWhile; @@ -555,5 +557,17 @@ public void traverseEnumConstant(UniEnumConstant node) { } + @Override + public void traverseByteLiteral(UniByteLiteral node) { + // TODO Auto-generated method stub + + } + + @Override + public void traverseCharacterLiteral(UniCharacterLiteral node) { + // TODO Auto-generated method stub + + } + } diff --git a/src/main/java/net/unicoen/generator/SwiftCodeGenerator.java b/src/main/java/net/unicoen/generator/SwiftCodeGenerator.java index 2d0382a..1636a0d 100644 --- a/src/main/java/net/unicoen/generator/SwiftCodeGenerator.java +++ b/src/main/java/net/unicoen/generator/SwiftCodeGenerator.java @@ -14,7 +14,9 @@ import net.unicoen.node.UniBlock; import net.unicoen.node.UniBoolLiteral; import net.unicoen.node.UniBreak; +import net.unicoen.node.UniByteLiteral; import net.unicoen.node.UniCast; +import net.unicoen.node.UniCharacterLiteral; import net.unicoen.node.UniClassDec; import net.unicoen.node.UniContinue; import net.unicoen.node.UniDoWhile; @@ -893,5 +895,17 @@ else if(num>=2){ } } + @Override + public void traverseByteLiteral(UniByteLiteral node) { + // TODO Auto-generated method stub + + } + + @Override + public void traverseCharacterLiteral(UniCharacterLiteral node) { + // TODO Auto-generated method stub + + } + } \ No newline at end of file diff --git a/src/main/java/net/unicoen/node/Traverser.java b/src/main/java/net/unicoen/node/Traverser.java index b0f7737..cabfb61 100644 --- a/src/main/java/net/unicoen/node/Traverser.java +++ b/src/main/java/net/unicoen/node/Traverser.java @@ -7,6 +7,8 @@ public abstract class Traverser { public abstract void traverseLongLiteral(UniLongLiteral node); public abstract void traverseDoubleLiteral(UniDoubleLiteral node); public abstract void traverseStringLiteral(UniStringLiteral node); + public abstract void traverseByteLiteral(UniByteLiteral node); + public abstract void traverseCharacterLiteral(UniCharacterLiteral node); public abstract void traverseIdent(UniIdent node); public abstract void traverseArray(UniArray node); public abstract void traverseFieldAccess(UniFieldAccess node); @@ -61,6 +63,14 @@ public final void traverseExpr(UniExpr node) { traverseStringLiteral((UniStringLiteral)node); return; } + if (node instanceof UniByteLiteral) { + traverseByteLiteral((UniByteLiteral)node); + return; + } + if (node instanceof UniCharacterLiteral) { + traverseCharacterLiteral((UniCharacterLiteral)node); + return; + } if (node instanceof UniIdent) { traverseIdent((UniIdent)node); return; diff --git a/src/main/java/net/unicoen/node/UniByteLiteral.java b/src/main/java/net/unicoen/node/UniByteLiteral.java new file mode 100644 index 0000000..5abad4a --- /dev/null +++ b/src/main/java/net/unicoen/node/UniByteLiteral.java @@ -0,0 +1,57 @@ +package net.unicoen.node; +import net.unicoen.node_helper.*; + +public class UniByteLiteral extends UniExpr { + public byte value; + + public UniByteLiteral() { + } + + public UniByteLiteral(byte value) { + this.value = value; + } + + @Override + public String toString() { + return "ByteLiteral(" + value + ")"; + } + + @Override + public int hashCode() { + int result = 17; + result = result * 31 + (int)value; + result = result * 31 + (comments == null ? 0 : comments.hashCode()); + result = result * 31 + (codeRange == null ? 0 : codeRange.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof UniByteLiteral)) return false; + UniByteLiteral that = (UniByteLiteral)obj; + return this.value == that.value + && (this.comments == null ? that.comments == null : this.comments.equals(that.comments)) + && (this.codeRange == null ? that.codeRange == null : this.codeRange.equals(that.codeRange)); + } + + @Override + public boolean isStatement() { + return false; + } + + public void merge(UniByteLiteral that) { + if (that.value != 0) { + this.value = that.value; + } + if (that.comments != null) { + if (this.comments == null) { + this.comments = that.comments; + } else { + this.comments.addAll(that.comments); + } + } + if (that.codeRange != null) { + this.codeRange = that.codeRange; + } + } +} diff --git a/src/main/java/net/unicoen/node/UniCharacterLiteral.java b/src/main/java/net/unicoen/node/UniCharacterLiteral.java new file mode 100644 index 0000000..f981499 --- /dev/null +++ b/src/main/java/net/unicoen/node/UniCharacterLiteral.java @@ -0,0 +1,57 @@ +package net.unicoen.node; +import net.unicoen.node_helper.*; + +public class UniCharacterLiteral extends UniExpr { + public char value; + + public UniCharacterLiteral() { + } + + public UniCharacterLiteral(char value) { + this.value = value; + } + + @Override + public String toString() { + return "CharacterLiteral(" + value + ")"; + } + + @Override + public int hashCode() { + int result = 17; + result = result * 31 + (int)value; + result = result * 31 + (comments == null ? 0 : comments.hashCode()); + result = result * 31 + (codeRange == null ? 0 : codeRange.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || !(obj instanceof UniCharacterLiteral)) return false; + UniCharacterLiteral that = (UniCharacterLiteral)obj; + return this.value == that.value + && (this.comments == null ? that.comments == null : this.comments.equals(that.comments)) + && (this.codeRange == null ? that.codeRange == null : this.codeRange.equals(that.codeRange)); + } + + @Override + public boolean isStatement() { + return false; + } + + public void merge(UniCharacterLiteral that) { + if (that.value != 0) { + this.value = that.value; + } + if (that.comments != null) { + if (this.comments == null) { + this.comments = that.comments; + } else { + this.comments.addAll(that.comments); + } + } + if (that.codeRange != null) { + this.codeRange = that.codeRange; + } + } +} diff --git a/src/main/java/net/unicoen/parser/blockeditor/BlockGenerator.java b/src/main/java/net/unicoen/parser/blockeditor/BlockGenerator.java index 1771842..c14b772 100644 --- a/src/main/java/net/unicoen/parser/blockeditor/BlockGenerator.java +++ b/src/main/java/net/unicoen/parser/blockeditor/BlockGenerator.java @@ -31,7 +31,9 @@ import net.unicoen.node.UniBlock; import net.unicoen.node.UniBoolLiteral; import net.unicoen.node.UniBreak; +import net.unicoen.node.UniByteLiteral; import net.unicoen.node.UniCast; +import net.unicoen.node.UniCharacterLiteral; import net.unicoen.node.UniClassDec; import net.unicoen.node.UniContinue; import net.unicoen.node.UniDoWhile; @@ -1186,6 +1188,18 @@ public void traverseEnumConstant(UniEnumConstant node) { } + @Override + public void traverseByteLiteral(UniByteLiteral node) { + // TODO Auto-generated method stub + + } + + @Override + public void traverseCharacterLiteral(UniCharacterLiteral node) { + // TODO Auto-generated method stub + + } +