Skip to content

Commit

Permalink
Showing 6 changed files with 12 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
@@ -38,14 +38,9 @@ public abstract class ReadBERNode extends PackNode {

@Child private FixnumOrBignumNode fixnumOrBignumNode;

private final int length;
private final boolean ignoreStar;

public ReadBERNode(RubyContext context, int length, boolean ignoreStar) {
public ReadBERNode(RubyContext context) {
super(context);
fixnumOrBignumNode = FixnumOrBignumNode.create(context, null);
this.length = length;
this.ignoreStar = ignoreStar;
}

@Specialization
Original file line number Diff line number Diff line change
@@ -97,10 +97,10 @@ public Object read(VirtualFrame frame, byte[] source) {

if (a != -1 && b != -1) {
if (c == -1 && s == '=') {
if ((b & 15) > 0) throw new FormatException("invalid base64");
if ((b & 15) != 0) throw new FormatException("invalid base64");
lElem[index++] = (byte)((a << 2 | b >> 4) & 255);
} else if(c != -1 && s == '=') {
if ((c & 3) > 0) throw new FormatException("invalid base64");
if ((c & 3) != 0) throw new FormatException("invalid base64");
lElem[index++] = (byte)((a << 2 | b >> 4) & 255);
lElem[index++] = (byte)((b << 4 | c >> 2) & 255);
}
Original file line number Diff line number Diff line change
@@ -31,11 +31,8 @@
})
public abstract class ReadMIMEStringNode extends PackNode {

private final int length;

public ReadMIMEStringNode(RubyContext context, int length) {
public ReadMIMEStringNode(RubyContext context) {
super(context);
this.length = length;
}

@Specialization
@@ -44,8 +41,6 @@ public Object read(VirtualFrame frame, byte[] source) {

final ByteBuffer encode = ByteBuffer.wrap(source, getSourcePosition(frame), getSourceLength(frame) - getSourcePosition(frame));

int occurrences = length;

byte[] lElem = new byte[Math.max(encode.remaining(),0)];
int index = 0;
for(;;) {
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
@@ -37,31 +37,10 @@
})
public abstract class ReadUUStringNode extends PackNode {

private final int length;
private final boolean ignoreStar;

public ReadUUStringNode(RubyContext context, int length, boolean ignoreStar) {
public ReadUUStringNode(RubyContext context) {
super(context);
this.length = length;
this.ignoreStar = ignoreStar;
}

/*@Specialization
public Object write(long bytes) {
throw new NoImplicitConversionException(bytes, "String");
}

@Specialization(guards = "isEmpty(bytes)")
public Object writeEmpty(VirtualFrame frame, ByteList bytes) {
return null;
}
@Specialization(guards = "!isEmpty(bytes)")
public Object write(VirtualFrame frame, ByteList bytes) {
writeBytes(frame, encode(bytes));
return null;
}*/

@Specialization
protected Object encode(VirtualFrame frame, byte[] source) {
CompilerDirectives.transferToInterpreter();
Original file line number Diff line number Diff line change
@@ -183,7 +183,7 @@ public void exitUtf8Character(PackParser.Utf8CharacterContext ctx) {
public void exitBerInteger(PackParser.BerIntegerContext ctx) {
appendNode(applyCount(ctx.count(),
WriteValueNodeGen.create(context,
ReadBERNodeGen.create(context, 0, false, new SourceNode()))));
ReadBERNodeGen.create(context, new SourceNode()))));
}

@Override
@@ -276,45 +276,18 @@ public void exitHexStringLowFirst(PackParser.HexStringLowFirstContext ctx) {
public void exitUuString(PackParser.UuStringContext ctx) {
//unify(PackEncoding.US_ASCII);

final int length;
final boolean ignoreStar;

if (ctx.count() == null) {
length = 1;
ignoreStar = false;
} else if (ctx.count().INT() == null) {
length = 0;
ignoreStar = true;
} else {
length = Integer.parseInt(ctx.count().INT().getText());
ignoreStar = false;
}

appendNode(
WriteValueNodeGen.create(context,
ReadUUStringNodeGen.create(context, length, ignoreStar,
ReadUUStringNodeGen.create(context,
new SourceNode())));
}

@Override
public void exitMimeString(PackParser.MimeStringContext ctx) {
//unify(PackEncoding.US_ASCII);

int length;

if (ctx.INT() == null) {
length = 72;
} else {
length = Integer.parseInt(ctx.INT().getText());

if (length <= 1) {
length = 72;
}
}

appendNode(WriteValueNodeGen.create(context,
ReadMIMEStringNodeGen.create(context, length, new SourceNode())));

ReadMIMEStringNodeGen.create(context, new SourceNode())));
}

@Override
@@ -505,40 +478,6 @@ private PackNode readIntegerX(int size, ByteOrder byteOrder, PackNode readNode,
return convert;
}

private void binaryString(byte padding, boolean padOnNull, boolean appendNull, PackParser.CountContext count) {
unify(PackEncoding.ASCII_8BIT);

final boolean pad;
final int width;

if (count != null && count.INT() != null) {
pad = true;
width = Integer.parseInt(count.INT().getText());
} else {
pad = false;

if (count != null && count.INT() == null) {
padOnNull = false;
}

width = 1;
}

final boolean takeAll;

if (count != null && count.INT() == null) {
takeAll = true;
} else {
takeAll = false;
}

appendNode(WriteBinaryStringNodeGen.create(context, pad, padOnNull,
width, padding, takeAll, appendNull,
ReadStringNodeGen.create(context, true, "to_str",
false, context.getCoreLibrary().getNilObject(), new SourceNode())));

}

private void bitString(ByteOrder byteOrder, PackParser.CountContext ctx) {
final boolean star;
final int length;
@@ -587,9 +526,5 @@ private PackNode applyCount(PackParser.CountContext count, PackNode node) {
return new StarNode(context, node);
}
}

private void unify(PackEncoding other) {
encoding = encoding.unifyWith(other);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* Copyright (c) 2015, 2016 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
@@ -11,7 +11,7 @@

public class MissingValue {

public static MissingValue INSTANCE = new MissingValue();
public static final MissingValue INSTANCE = new MissingValue();

private MissingValue() {
}

0 comments on commit 800748a

Please sign in to comment.