Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

Commit

Permalink
Fixes http://ironruby.codeplex.com/workitem/5787: grammar for alias a…
Browse files Browse the repository at this point in the history
…nd undef should accept quoted symbols
  • Loading branch information
tmat committed Mar 6, 2011
1 parent 7917cfe commit ca71b4d
Show file tree
Hide file tree
Showing 21 changed files with 2,063 additions and 2,237 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,6 +3,8 @@ obj/
/bin/
Solutions/*.suo
*.csproj.user
TestResult.xml
Solutions/TestResults/

# TODO - testing scripts should not created this file here
debug.log
1 change: 1 addition & 0 deletions Languages/Ruby/IronRuby.Tests/RubyTests.cs
Expand Up @@ -706,6 +706,7 @@ public partial class Tests {
ProtocolCaching3,
ProtocolCaching4,
MethodAliasExpression,
AliasUndefWithQuotedSymbols,
BasicObject1,
BasicObject2,
ClassDuplication1,
Expand Down
23 changes: 23 additions & 0 deletions Languages/Ruby/IronRuby.Tests/Runtime/AliasTests.cs
Expand Up @@ -265,5 +265,28 @@ module MyModule
", 1, 0);
}, "nil");
}

public void AliasUndefWithQuotedSymbols() {
TestOutput(@"
class A
def ab
end
def c
end
alias :'d' :'c'
p instance_methods(false).sort
undef :""a#{'b'}"", :'c'
p instance_methods(false).sort
end
", @"
[:ab, :c, :d]
[:d]
");
}
}
}
4 changes: 3 additions & 1 deletion Languages/Ruby/Libraries/Extensions/IDictionaryOps.cs
Expand Up @@ -552,7 +552,9 @@ public static class IDictionaryOps {

if (maxDepth == 0) {
return ToArray(self);
} else if (maxDepth > 0) {
}

if (maxDepth > 0) {
maxDepth--;
}

Expand Down
11 changes: 7 additions & 4 deletions Languages/Ruby/Libraries/ParseTree/IronRubyParseTreeOps.cs
Expand Up @@ -908,21 +908,24 @@ private sealed class AstVisitor : Walker {
CreateSymbol("$" + node.OldName)
);
} else {
// TODO: handle constructed symbols
_result = MakeNode(NodeKind.alias,
MakeNode(NodeKind.lit, CreateSymbol(node.NewName)),
MakeNode(NodeKind.lit, CreateSymbol(node.OldName))
MakeNode(NodeKind.lit, CreateSymbol((string)node.NewName.Value)),
MakeNode(NodeKind.lit, CreateSymbol((string)node.OldName.Value))
);
}
return false;
}

public override bool Enter(UndefineStatement/*!*/ node) {
if (node.Items.Count == 1) {
_result = MakeNode(NodeKind.undef, MakeNode(NodeKind.lit, CreateSymbol(node.Items[0].Name)));
// TODO: handle constructed symbols
_result = MakeNode(NodeKind.undef, MakeNode(NodeKind.lit, CreateSymbol((string)node.Items[0].Value)));
} else {
var block = MakeNode(NodeKind.block, node.Items.Count);
foreach (var item in node.Items) {
block.Add(MakeNode(NodeKind.undef, MakeNode(NodeKind.lit, CreateSymbol(item.Name))));
// TODO: handle constructed symbols
block.Add(MakeNode(NodeKind.undef, MakeNode(NodeKind.lit, CreateSymbol((string)item.Value))));
}
_result = block;
}
Expand Down
1 change: 1 addition & 0 deletions Languages/Ruby/Ruby/Compiler/Ast/Expressions/Expression.cs
Expand Up @@ -19,6 +19,7 @@
using MSA = Microsoft.Scripting.Ast;
#endif

using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Scripting;
Expand Down
33 changes: 0 additions & 33 deletions Languages/Ruby/Ruby/Compiler/Ast/Identifier.cs

This file was deleted.

12 changes: 6 additions & 6 deletions Languages/Ruby/Ruby/Compiler/Ast/Statements/AliasStatement.cs
Expand Up @@ -28,15 +28,15 @@ namespace IronRuby.Compiler.Ast {
using Ast = MSA.Expression;

public partial class AliasStatement : Expression {
private readonly string/*!*/ _newName;
private readonly string/*!*/ _oldName;
private readonly ConstructedSymbol _newName;
private readonly ConstructedSymbol _oldName;
private readonly bool _isMethodAlias;

public string/*!*/ NewName {
public ConstructedSymbol NewName {
get { return _newName; }
}

public string/*!*/ OldName {
public ConstructedSymbol OldName {
get { return _oldName; }
}

Expand All @@ -48,7 +48,7 @@ public partial class AliasStatement : Expression {
get { return !_isMethodAlias; }
}

public AliasStatement(bool isMethodAlias, string/*!*/ newName, string/*!*/ oldName, SourceSpan location)
public AliasStatement(bool isMethodAlias, ConstructedSymbol newName, ConstructedSymbol oldName, SourceSpan location)
: base(location) {
Assert.NotNull(newName, oldName);
_newName = newName;
Expand All @@ -58,7 +58,7 @@ public AliasStatement(bool isMethodAlias, string/*!*/ newName, string/*!*/ oldNa

internal override MSA.Expression/*!*/ Transform(AstGenerator/*!*/ gen) {
return (_isMethodAlias ? Methods.AliasMethod : Methods.AliasGlobalVariable).
OpCall(gen.CurrentScopeVariable, AstUtils.Constant(_newName), AstUtils.Constant(_oldName));
OpCall(gen.CurrentScopeVariable, _newName.Transform(gen), _oldName.Transform(gen));
}

internal override MSA.Expression/*!*/ TransformRead(AstGenerator/*!*/ gen) {
Expand Down
10 changes: 5 additions & 5 deletions Languages/Ruby/Ruby/Compiler/Ast/Statements/UndefineStatement.cs
Expand Up @@ -20,6 +20,7 @@
#endif

using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Scripting;
using Microsoft.Scripting.Utils;
using AstUtils = Microsoft.Scripting.Ast.Utils;
Expand All @@ -28,23 +29,22 @@ namespace IronRuby.Compiler.Ast {
using Ast = MSA.Expression;

public partial class UndefineStatement : Expression {
private readonly List<Identifier>/*!*/ _items;
private readonly List<ConstructedSymbol>/*!*/ _items;

public List<Identifier>/*!*/ Items {
public List<ConstructedSymbol>/*!*/ Items {
get { return _items; }
}

public UndefineStatement(List<Identifier>/*!*/ items, SourceSpan location)
public UndefineStatement(List<ConstructedSymbol>/*!*/ items, SourceSpan location)
: base(location) {
Assert.NotNull(items);

_items = items;
}

internal override MSA.Expression/*!*/ Transform(AstGenerator/*!*/ gen) {
MSA.Expression[] result = new MSA.Expression[_items.Count + 1];
for (int i = 0; i < _items.Count; i++) {
result[i] = Methods.UndefineMethod.OpCall(gen.CurrentScopeVariable, AstUtils.Constant(_items[i].Name));
result[i] = Methods.UndefineMethod.OpCall(gen.CurrentScopeVariable, _items[i].Transform(gen));
}
result[_items.Count] = AstUtils.Empty();
return Ast.Block(result);
Expand Down

0 comments on commit ca71b4d

Please sign in to comment.