Permalink
Browse files

Fixes http://ironruby.codeplex.com/workitem/5787: grammar for alias a…

…nd undef should accept quoted symbols
  • Loading branch information...
tmat committed Mar 6, 2011
1 parent 7917cfe commit ca71b4d388c5f26505d31aa7d4184e88c973c5b5
View
@@ -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
@@ -706,6 +706,7 @@ public partial class Tests {
ProtocolCaching3,
ProtocolCaching4,
MethodAliasExpression,
+ AliasUndefWithQuotedSymbols,
BasicObject1,
BasicObject2,
ClassDuplication1,
@@ -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]
+");
+ }
}
}
@@ -552,7 +552,9 @@ public static class IDictionaryOps {
if (maxDepth == 0) {
return ToArray(self);
- } else if (maxDepth > 0) {
+ }
+
+ if (maxDepth > 0) {
maxDepth--;
}
@@ -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;
}
@@ -19,6 +19,7 @@
using MSA = Microsoft.Scripting.Ast;
#endif
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Scripting;
@@ -1,33 +0,0 @@
-/* ****************************************************************************
- *
- * Copyright (c) Microsoft Corporation.
- *
- * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
- * copy of the license can be found in the License.html file at the root of this distribution. If
- * you cannot locate the Apache License, Version 2.0, please send an email to
- * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
- * by the terms of the Apache License, Version 2.0.
- *
- * You must not remove this notice, or any other, from this software.
- *
- *
- * ***************************************************************************/
-
-using System.Dynamic;
-using Microsoft.Scripting;
-
-namespace IronRuby.Compiler.Ast {
- public struct Identifier {
- private readonly string/*!*/ _name;
- private readonly SourceSpan _location;
-
- public string/*!*/ Name { get { return _name; } }
- public SourceSpan Location { get { return _location; } }
-
- public Identifier(string/*!*/ name, SourceSpan location) {
- _name = name;
- _location = location;
- }
- }
-
-}
@@ -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; }
}
@@ -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;
@@ -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) {
@@ -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;
@@ -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);
Oops, something went wrong.

0 comments on commit ca71b4d

Please sign in to comment.