Skip to content

Commit

Permalink
Add variadic value declarations
Browse files Browse the repository at this point in the history
For #46.
  • Loading branch information
lucaswerkmeister committed Aug 2, 2014
1 parent 6a084e9 commit 1585bd7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion source/ceylon/ast/core/AnyValue.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ shared abstract class AnyValue()
of ValueDeclaration | ValueDefinition | ValueGetterDefinition
extends TypedDeclaration() {

shared actual formal [Annotations, Type|Modifier, LIdentifier, AnySpecifier|Block=] children;
shared actual formal [Annotations, Type|VariadicType|Modifier, LIdentifier, AnySpecifier|Block=] children;
}
5 changes: 3 additions & 2 deletions source/ceylon/ast/core/Editor.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ shared /* abstract */ class Editor() satisfies NarrowingTransformer<Node> { // T
shared actual default TypeParameters transformTypeParameters(TypeParameters that)
=> that.copy(that.typeParameters.collect(transformTypeParameter));
shared actual default ValueDeclaration transformValueDeclaration(ValueDeclaration that) {
Type|DynamicModifier transformTypeOrDynamicModifier(Type|DynamicModifier that) {
Type|VariadicType|DynamicModifier transformTypeOrVariadicTypeOrDynamicModifier(Type|VariadicType|DynamicModifier that) {
switch (that)
case (is Type) { return transformType(that); }
case (is VariadicType) { return transformVariadicType(that); }
case (is DynamicModifier) { return transformDynamicModifier(that); }
}
return that.copy(transformLIdentifier(that.name), transformTypeOrDynamicModifier(that.type), transformAnnotations(that.annotations));
return that.copy(transformLIdentifier(that.name), transformTypeOrVariadicTypeOrDynamicModifier(that.type), transformAnnotations(that.annotations));
}
shared actual default ValueDefinition transformValueDefinition(ValueDefinition that) {
return that.copy(transformLIdentifier(that.name), transformTypeOrValueModifierOrDynamicModifier(that.type), transformAnySpecifier(that.definition), transformAnnotations(that.annotations));
Expand Down
4 changes: 2 additions & 2 deletions source/ceylon/ast/core/TypedDeclaration.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ shared abstract class TypedDeclaration()

"The type of the declaration, or a
modifier indicating type inference."
shared formal Type|Modifier type;
shared formal Type|VariadicType|Modifier type;
"The definition of the declaration, if present."
shared formal AnySpecifier|Block? definition;

shared actual formal [Annotations, Type|Modifier, LIdentifier, AnySpecifier|Block=] children;
shared actual formal [Annotations, Type|VariadicType|Modifier, LIdentifier, AnySpecifier|Block=] children;
}
13 changes: 9 additions & 4 deletions source/ceylon/ast/core/ValueDeclaration.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ shared class ValueDeclaration(name, type, annotations = Annotations())

"The name of the declared value."
shared actual MemberName name;
"The type of the declared value."
shared actual Type|DynamicModifier type;
"The type of the declared value.
This can be:
- a proper [[Type]],
- a [[variadic type|VariadicType]] for the declaration of a variadic [[parameter|ParameterReference]], or
- a [[’`dynamic`’ modifier|DynamicModifier]] to indicate the absence of a type."
shared actual Type|VariadicType|DynamicModifier type;
"The annotations of the declared value."
shared actual Annotations annotations;
"A value declaration has no definition."
shared actual Null definition = null;

shared actual [Annotations, Type|DynamicModifier, LIdentifier] children = [annotations, type, name];
shared actual [Annotations, Type|VariadicType|DynamicModifier, LIdentifier] children = [annotations, type, name];

shared actual Result transform<out Result>(Transformer<Result> transformer)
=> transformer.transformValueDeclaration(this);
Expand All @@ -41,7 +46,7 @@ shared class ValueDeclaration(name, type, annotations = Annotations())
shared actual Integer hash
=> 31 * (name.hash + 31 * (type.hash + 31 * annotations.hash));

shared ValueDeclaration copy(MemberName name = this.name, Type|DynamicModifier type = this.type, Annotations annotations = this.annotations) {
shared ValueDeclaration copy(MemberName name = this.name, Type|VariadicType|DynamicModifier type = this.type, Annotations annotations = this.annotations) {
value ret = ValueDeclaration(name, type, annotations);
copyExtraInfoTo(ret);
return ret;
Expand Down
1 change: 1 addition & 0 deletions source/ceylon/ast/redhat/RedHatTransformer.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -1607,6 +1607,7 @@ shared class RedHatTransformer(TokenFactory tokens) satisfies NarrowingTransform
value type = that.type;
switch (type)
case (is Type) { ret.type = transformType(type); }
case (is VariadicType) { ret.type = transformVariadicType(type); }
case (is DynamicModifier) { ret.type = transformDynamicModifier(type); }
ret.identifier = transformLIdentifier(that.name);
ret.endToken = tokens.token(";", semicolon);
Expand Down
11 changes: 7 additions & 4 deletions source/ceylon/ast/redhat/ValueDeclaration.ceylon
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import ceylon.ast.core {
ValueDeclaration,
DynamicModifier,
Type
Type,
VariadicType
}
import com.redhat.ceylon.compiler.typechecker.tree {
Tree {
JAttributeDeclaration=AttributeDeclaration,
JDynamicModifier=DynamicModifier,
JStaticType=StaticType
JStaticType=StaticType,
JSequencedType=SequencedType
}
}

"Converts a RedHat AST [[AttributeDeclaration|JAttributeDeclaration]] to a `ceylon.ast` [[ValueDeclaration]]."
shared ValueDeclaration valueDeclarationToCeylon(JAttributeDeclaration valueDeclaration) {
"Must not have a specification"
assert (!valueDeclaration.specifierOrInitializerExpression exists);
assert (is JStaticType|JDynamicModifier jType = valueDeclaration.type);
Type|DynamicModifier type;
assert (is JStaticType|JSequencedType|JDynamicModifier jType = valueDeclaration.type);
Type|VariadicType|DynamicModifier type;
switch (jType)
case (is JStaticType) { type = typeToCeylon(jType); }
case (is JSequencedType) { type = variadicTypeToCeylon(jType); }
case (is JDynamicModifier) { type = dynamicModifierToCeylon(jType); }
return ValueDeclaration(lIdentifierToCeylon(valueDeclaration.identifier), type, annotationsToCeylon(valueDeclaration.annotationList));
}
Expand Down

0 comments on commit 1585bd7

Please sign in to comment.