-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jean Privat <[email protected]>
- Loading branch information
Showing
8 changed files
with
249 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This file is part of NIT ( http://www.nitlanguage.org ). | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Test the AST printer by reading modules and printing the body of their methods | ||
module test_astprinter | ||
|
||
import test_phase | ||
import frontend | ||
#import transform # Not yet :) | ||
|
||
import astprinter | ||
|
||
redef fun do_work(mainmodule, given_mmodules, modelbuilder) | ||
do | ||
# We iterate the model instead of the ast for classes and methods | ||
for m in given_mmodules do | ||
for cd in m.mclassdefs do | ||
for pd in cd.mpropdefs do | ||
print "# {pd}" | ||
var node = modelbuilder.mentity2node(pd) | ||
assert node != null | ||
node.print_tree | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
|
@@ -10,3 +10,4 @@ test_loader | |
get_mclasses | ||
^nit | ||
test_astbuilder | ||
test_astprinter |
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 |
---|---|---|
|
@@ -47,3 +47,4 @@ repeating_key_xor_solve | |
nitpm | ||
nitdoc | ||
test_astbuilder | ||
test_astprinter |
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,2 @@ | ||
1 | ||
1 |
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,2 @@ | ||
Usage: [OPTION]... <file.nit>... | ||
Use --help for help |
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,87 @@ | ||
# syntax_expr$Sys$main | ||
var a | ||
var b: Bool | ||
var c: Collection[Int] = [1] | ||
var d = 1 | ||
a = 1.+(2).-(3.unary -./(4).*(5).%(6.**(2))) | ||
b = true and not false or true or a.<(0) or a.<=(0) or a.==(0) or a.!=(0) or a.>=(0) or a.>(0) | ||
a = 1.&(2).|(3.unary ~.^(4.<<(5).>>(6))) | ||
a = 1.<=>(2) | ||
c = [1..2[ | ||
c = [1..2] | ||
c = [1, 2, 3] | ||
a += 1 | ||
a -= 1 | ||
a *= 1 | ||
a /= 1 | ||
a %= 1 | ||
a **= 1 | ||
a &= 1 | ||
a |= 1 | ||
a ^= 1 | ||
a <<= 1 | ||
a >>= 1 | ||
a = 1 | ||
print(a) | ||
print(a) | ||
a.abs | ||
a.max(2) | ||
a.max(2) | ||
a.setbit(0, 1) | ||
c = new Array[Int].defaultinit | ||
c = new Array[Int].with_capacity(10) | ||
a = new Array[Int].with_capacity(10).length | ||
c.add(1) | ||
a = a isa Array[Int] | ||
a = null | ||
if b then a = 1 | ||
d = a.as(not null) | ||
d = a.as(Int) | ||
do end | ||
do a = 1 | ||
do | ||
a = 1 | ||
a = 1 | ||
end | ||
if b then end | ||
if b then a = 1 | ||
if b then | ||
a = 2 | ||
a = 2 | ||
end | ||
if b then a = 3 | ||
if b then a = 4 else a = 5 | ||
if b then a = 6 else | ||
a = 7 | ||
a = 7 | ||
end | ||
if b then end | ||
if b then end | ||
if b then else a = 8 | ||
if b then else | ||
a = 9 | ||
a = 9 | ||
end | ||
if b then if b then a = 1 | ||
if b then | ||
if b then | ||
a = 2 | ||
a = 3 | ||
end | ||
end | ||
a = if b then 1 else 2 | ||
a = if b then if b then 3 else 4 else if b then 5 else 6 | ||
for i in c do end | ||
for i in c do | ||
a = 1 | ||
a = 1 | ||
end | ||
for i in c, j in c do end | ||
var m = new HashMap[String, String].defaultinit | ||
for k, v in m do end | ||
loop | ||
if b then break | ||
if b then continue | ||
end | ||
assert b | ||
if not b then return |
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,118 @@ | ||
# This file is part of NIT ( http://www.nitlanguage.org ). | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
var a | ||
var b: Bool | ||
var c: Collection[Int] = [1] | ||
var d = 1 | ||
a = 1 + 2 - - 3 / 4 * 5 % 6 ** 2 | ||
b = true and not false or true or a < 0 or a <= 0 or a == 0 or a != 0 or a >= 0 or a > 0 | ||
a = 1 & 2 | ~3 ^ 4 << 5 >> 6 | ||
a = 1 <=> 2 | ||
c = [1..2[ | ||
c = [1..2] | ||
c = [1,2,3] | ||
|
||
a += 1 | ||
a -= 1 | ||
a *= 1 | ||
a /= 1 | ||
a %= 1 | ||
a **= 1 | ||
|
||
a &= 1 | ||
a |= 1 | ||
a ^= 1 | ||
a <<= 1 | ||
a >>= 1 | ||
|
||
a = 1 | ||
print(a) | ||
print a | ||
a.abs | ||
a.max(2) | ||
a.max 2 | ||
a.setbit(0, 1) | ||
|
||
c = new Array[Int] | ||
c = new Array[Int].with_capacity(10) | ||
a = new Array[Int].with_capacity(10).length | ||
c.add(1) | ||
|
||
a = a isa Array[Int] | ||
a = null | ||
if b then a = 1 | ||
d = a.as(not null) | ||
d = a.as(Int) | ||
|
||
|
||
do end | ||
do a = 1 | ||
do | ||
a = 1 | ||
a = 1 | ||
end | ||
|
||
if b then end | ||
if b then a = 1 | ||
if b then | ||
a = 2 | ||
a = 2 | ||
end | ||
if b then a = 3 else end | ||
if b then a = 4 else a = 5 | ||
if b then a = 6 else | ||
a = 7 | ||
a = 7 | ||
end | ||
if b then | ||
else | ||
end | ||
if b then else end | ||
if b then else a = 8 | ||
if b then else | ||
a = 9 | ||
a = 9 | ||
end | ||
if b then | ||
if b then | ||
a = 1 | ||
end | ||
end | ||
if b then | ||
if b then | ||
a = 2 | ||
a = 3 | ||
end | ||
end | ||
|
||
a = if b then 1 else 2 | ||
a = if b then if b then 3 else 4 else if b then 5 else 6 | ||
|
||
for i in c do end | ||
for i in c do | ||
a = 1 | ||
a = 1 | ||
end | ||
for i in c, j in c do end | ||
var m = new HashMap[String,String] | ||
for k, v in m do end | ||
|
||
loop | ||
if b then break | ||
if b then continue | ||
end | ||
|
||
assert b | ||
if not b then return |
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 @@ | ||
syntax_expr.nit |