Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify unbounded ids in binary expressions #11125

Merged
merged 1 commit into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions src/Engine/ProtoCore/Parser/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2325,6 +2325,7 @@ void Associative_Number(out ProtoCore.AST.AssociativeAST.AssociativeNode node) {
else
{
node.line = line; node.col = col;
node.endLine = t.line; node.endCol = t.col;
}

} else SynErr(93);
Expand All @@ -2339,10 +2340,9 @@ void Associative_Char(out ProtoCore.AST.AssociativeAST.AssociativeNode node) {

node = new ProtoCore.AST.AssociativeAST.CharNode()
{
Value = t.val.Substring(1, t.val.Length - 2),
line = t.line,
col = t.col
Value = t.val.Substring(1, t.val.Length - 2)
};
NodeUtils.SetNodeLocation(node, t);

}

Expand All @@ -2351,7 +2351,7 @@ void Associative_String(out ProtoCore.AST.AssociativeAST.AssociativeNode node) {
Expect(4);
node = new ProtoCore.AST.AssociativeAST.StringNode()
{
Value = GetEscapedString(t.val.Length <= 2 ? "" : t.val.Substring(1, t.val.Length - 2)),
Value = GetEscapedString(t.val.Length <= 2 ? "" : t.val.Substring(1, t.val.Length - 2))
};
NodeUtils.SetNodeLocation(node, t);

Expand Down Expand Up @@ -3710,10 +3710,9 @@ void Imperative_Char(out ProtoCore.AST.ImperativeAST.ImperativeNode node) {

node = new ProtoCore.AST.ImperativeAST.CharNode()
{
Value = t.val.Substring(1, t.val.Length - 2),
line = t.line,
col = t.col
};
Value = t.val.Substring(1, t.val.Length - 2)
};
NodeUtils.SetNodeLocation(node, t);

}

Expand All @@ -3722,10 +3721,9 @@ void Imperative_String(out ProtoCore.AST.ImperativeAST.ImperativeNode node) {
Expect(4);
node = new ProtoCore.AST.ImperativeAST.StringNode()
{
Value = GetEscapedString(t.val.Length <= 2 ? "" : t.val.Substring(1, t.val.Length - 2)),
line = t.line,
col = t.col
Value = GetEscapedString(t.val.Length <= 2 ? "" : t.val.Substring(1, t.val.Length - 2))
};
NodeUtils.SetNodeLocation(node, t);

}

Expand Down Expand Up @@ -3756,7 +3754,8 @@ void Imperative_num(out ProtoCore.AST.ImperativeAST.ImperativeNode node) {

if (ProtoCore.DSASM.Constants.kInvalidIndex != line)
{
node.line = line; node.col = col;
node.line = line; node.col = col;
node.endLine = t.line; node.endCol = t.col;
}
else
{
Expand All @@ -3775,10 +3774,15 @@ void Imperative_num(out ProtoCore.AST.ImperativeAST.ImperativeNode node) {
node = new ProtoCore.AST.ImperativeAST.NullNode();
}

if (ProtoCore.DSASM.Constants.kInvalidIndex != line){
node.line = line; node.col = col; }
else{
NodeUtils.SetNodeLocation(node, t); }
if (ProtoCore.DSASM.Constants.kInvalidIndex != line)
{
node.line = line; node.col = col;
node.endLine = t.line; node.endCol = t.col;
}
else
{
NodeUtils.SetNodeLocation(node, t);
}

} else SynErr(118);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Engine/ProtoCore/Parser/atg/Associative.atg
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,7 @@ Associative_Number<out ProtoCore.AST.AssociativeAST.AssociativeNode node>
else
{
node.line = line; node.col = col;
node.endLine = t.line; node.endCol = t.col;
}
.)
)
Expand All @@ -1453,10 +1454,9 @@ Associative_Char<out ProtoCore.AST.AssociativeAST.AssociativeNode node>

node = new ProtoCore.AST.AssociativeAST.CharNode()
{
Value = t.val.Substring(1, t.val.Length - 2),
line = t.line,
col = t.col
Value = t.val.Substring(1, t.val.Length - 2)
};
NodeUtils.SetNodeLocation(node, t);
.)
.

Expand All @@ -1466,7 +1466,7 @@ Associative_String<out ProtoCore.AST.AssociativeAST.AssociativeNode node>
(.
node = new ProtoCore.AST.AssociativeAST.StringNode()
{
Value = GetEscapedString(t.val.Length <= 2 ? "" : t.val.Substring(1, t.val.Length - 2)),
Value = GetEscapedString(t.val.Length <= 2 ? "" : t.val.Substring(1, t.val.Length - 2))
};
NodeUtils.SetNodeLocation(node, t);
.)
Expand Down
28 changes: 16 additions & 12 deletions src/Engine/ProtoCore/Parser/atg/Imperative.atg
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,9 @@ Imperative_Char<out ProtoCore.AST.ImperativeAST.ImperativeNode node>

node = new ProtoCore.AST.ImperativeAST.CharNode()
{
Value = t.val.Substring(1, t.val.Length - 2),
line = t.line,
col = t.col
};
Value = t.val.Substring(1, t.val.Length - 2)
};
NodeUtils.SetNodeLocation(node, t);
.)
.

Expand All @@ -763,10 +762,9 @@ Imperative_String<out ProtoCore.AST.ImperativeAST.ImperativeNode node>
textstring (.
node = new ProtoCore.AST.ImperativeAST.StringNode()
{
Value = GetEscapedString(t.val.Length <= 2 ? "" : t.val.Substring(1, t.val.Length - 2)),
line = t.line,
col = t.col
Value = GetEscapedString(t.val.Length <= 2 ? "" : t.val.Substring(1, t.val.Length - 2))
};
NodeUtils.SetNodeLocation(node, t);
.)
.

Expand Down Expand Up @@ -1147,7 +1145,8 @@ Imperative_num<out ProtoCore.AST.ImperativeAST.ImperativeNode node>

if (ProtoCore.DSASM.Constants.kInvalidIndex != line)
{
node.line = line; node.col = col;
node.line = line; node.col = col;
node.endLine = t.line; node.endCol = t.col;
}
else
{
Expand All @@ -1167,10 +1166,15 @@ Imperative_num<out ProtoCore.AST.ImperativeAST.ImperativeNode node>
node = new ProtoCore.AST.ImperativeAST.NullNode();
}

if (ProtoCore.DSASM.Constants.kInvalidIndex != line){
node.line = line; node.col = col; }
else{
NodeUtils.SetNodeLocation(node, t); }
if (ProtoCore.DSASM.Constants.kInvalidIndex != line)
{
node.line = line; node.col = col;
node.endLine = t.line; node.endCol = t.col;
}
else
{
NodeUtils.SetNodeLocation(node, t);
}
.)
)
.
Expand Down
19 changes: 19 additions & 0 deletions test/Engine/ProtoTest/GraphCompiler/NewFrontEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,24 @@ public void TestUnboundIdentifierInUnnamedSignedExpression()
Assert.AreEqual(1, inputIdentifier.Count);
Assert.AreEqual("a", inputIdentifier.ElementAt(0).Value);
}

[Test]
public void TestUnboundIdentifierInBinaryExpression()
{
var binaryExpressions = new[] { "x==-0.5;", "x>0.5;", "x<-1;", "x!=1;", "x<=\"a\";", "x>='a';", "x==true;", "x!=false;", "x==null;" };

foreach (var expression in binaryExpressions)
{
ElementResolver elementResolver = new ElementResolver();
ParseParam parseParam = new ParseParam(Guid.NewGuid(), expression, elementResolver);

Assert.IsTrue(CompilerUtils.PreCompileCodeBlock(thisTest.CreateTestCore(), ref parseParam));
Assert.IsTrue(parseParam.ParsedNodes != null && parseParam.ParsedNodes.Any());

var inputIdentifier = parseParam.UnboundIdentifiers;
Assert.AreEqual(1, inputIdentifier.Count);
Assert.AreEqual("x", inputIdentifier.ElementAt(0).Value);
}
}
}
}