-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TupleType is the abstract supertype of ListTupleType (previously just called TupleType) and LengthTupleType. Closes #52.
- Loading branch information
1 parent
3ee7245
commit 8b6c3fd
Showing
17 changed files
with
244 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"A length-based tuple type, that is, | ||
an [[element type|elementType]], followed by a [[length]] enclosed in brackets. | ||
`T[n]` is a shortcut for a tuple of exactly `n` `T` elements; | ||
for instance, `Integer[3]` is equivalent to `[Integer,Integer,Integer]`. | ||
Examples: | ||
Boolean[8] | ||
Integer[3]" | ||
shared class LengthTupleType(elementType, length) | ||
extends TupleType() { | ||
|
||
"The element type." | ||
shared PrimaryType elementType; | ||
"The length. | ||
This may only be a decimal iteral; | ||
hexadecimal and binary lengths are illegal." | ||
shared IntegerLiteral length; | ||
|
||
assert (!(length.text.startsWith("$") || length.text.startsWith("#"))); | ||
|
||
shared actual [PrimaryType, IntegerLiteral] children = [elementType, length]; | ||
|
||
shared actual Result transform<out Result>(Transformer<Result> transformer) | ||
=> transformer.transformLengthTupleType(this); | ||
|
||
shared actual Boolean equals(Object that) { | ||
if (is LengthTupleType that) { | ||
return elementType == that.elementType && length == that.length; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
shared actual Integer hash | ||
=> 31 * (elementType.hash + 31 * length.hash); | ||
|
||
shared LengthTupleType copy(PrimaryType elementType = this.elementType, IntegerLiteral length = this.length) { | ||
value ret = LengthTupleType(elementType, length); | ||
copyExtraInfoTo(ret); | ||
return ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
"A primary type; only [[intersection|IntersectionType]] | ||
and [[union types|UnionType]] come before these." | ||
shared abstract class PrimaryType() | ||
of SimpleType | ListTupleType | IterableType | GroupedType | OptionalType | SequentialType | CallableType | ||
of SimpleType | TupleType | IterableType | GroupedType | OptionalType | SequentialType | CallableType | ||
extends UnionableType() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"A tuple type, which may be either [[list-based|ListTupleType]] (commonly just called a “tuple type”) or [[length-based|LengthTupleType]]. | ||
Examples: | ||
[String,Integer,Integer] | ||
Boolean[8]" | ||
shared abstract class TupleType() | ||
of ListTupleType | LengthTupleType | ||
extends PrimaryType() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import ceylon.ast.core { | ||
LengthTupleType, | ||
Node, | ||
PrimaryType | ||
} | ||
import com.redhat.ceylon.compiler.typechecker.tree { | ||
Tree { | ||
JSequenceType=SequenceType | ||
}, | ||
JNode=Node | ||
} | ||
|
||
"Converts a RedHat AST [[SequenceType|JSequenceType]] to a `ceylon.ast` [[LengthTupleType]]." | ||
shared LengthTupleType lengthTupleTypeToCeylon(JSequenceType lengthTupleType, Anything(JNode,Node) update = noop) { | ||
assert (is PrimaryType elementType = typeToCeylon(lengthTupleType.elementType, update)); | ||
assert (exists jLength = lengthTupleType.length); | ||
value result = LengthTupleType(elementType, integerLiteralToCeylon(jLength, update)); | ||
update(lengthTupleType, result); | ||
return result; | ||
} | ||
|
||
"Compiles the given [[code]] for a Length Tuple Type | ||
into a [[LengthTupleType]] using the Ceylon compiler | ||
(more specifically, the rule for a `primaryType`)." | ||
shared LengthTupleType? compileLengthTupleType(String code, Anything(JNode,Node) update = noop) { | ||
if (is JSequenceType jPrimaryType = createParser(code).primaryType(), | ||
jPrimaryType.length exists) { | ||
return lengthTupleTypeToCeylon(jPrimaryType, update); | ||
} else { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import ceylon.ast.core { | ||
TupleType, | ||
Node | ||
} | ||
import com.redhat.ceylon.compiler.typechecker.tree { | ||
Tree { | ||
JSequenceType=SequenceType, | ||
JTupleType=TupleType | ||
}, | ||
JNode=Node | ||
} | ||
|
||
"Converts a RedHat AST [[TupleType|JTupleType]] or [[SequenceType|JSequenceType]] to a `ceylon.ast` [[TupleType]]." | ||
shared TupleType tupleTypeToCeylon(JTupleType|JSequenceType tupleType, Anything(JNode,Node) update = noop) { | ||
switch (tupleType) | ||
case (is JTupleType) { return listTupleTypeToCeylon(tupleType, update); } | ||
case (is JSequenceType) { return lengthTupleTypeToCeylon(tupleType, update); } | ||
} | ||
|
||
"Compiles the given [[code]] for a Tuple Type | ||
into a [[TupleType]] using the Ceylon compiler | ||
(more specifically, the rule for a `primaryType`)." | ||
shared TupleType? compileTupleType(String code, Anything(JNode,Node) update = noop) { | ||
if (is JTupleType|JSequenceType jPrimaryType = createParser(code).primaryType()) { | ||
if (is JSequenceType jPrimaryType, !jPrimaryType.length exists) { | ||
return null; | ||
} else { | ||
return tupleTypeToCeylon(jPrimaryType, update); | ||
} | ||
} else { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.