Skip to content

Commit 7d3fd86

Browse files
committed
Fix tests
1 parent 10ed446 commit 7d3fd86

10 files changed

Lines changed: 760 additions & 51 deletions

File tree

.idea/workspace.xml

Lines changed: 23 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/ko/carbonel/compiler/generated/AttrTinyRustParser.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,16 +1207,7 @@ private List<TinyRustLexerToken> matchToken_Stmt_star(){
12071207
private List<TinyRustLexerToken> matchToken_Stmt(){
12081208
enter("matchToken_Stmt");
12091209
List<TinyRustLexerToken> result = null;
1210-
if (peek(TinyRustTokenType.OPN_BRACE)){
1211-
st.newBlock();
1212-
TinyRustLexerToken v_1 = match(TinyRustTokenType.OPN_BRACE);
1213-
List<TinyRustLexerToken> v_2 = matchToken_Method_factored();
1214-
} else if (peek(TinyRustTokenType.RETURN)){
1215-
st.newReturn();
1216-
TinyRustLexerToken v_1 = match(TinyRustTokenType.RETURN);
1217-
List<TinyRustLexerToken> v_2 = matchToken_Stmt_factored();
1218-
st.endReturn();
1219-
} else if (peek(TinyRustTokenType.IF)){
1210+
if (peek(TinyRustTokenType.IF)){
12201211
st.newIf();
12211212
TinyRustLexerToken v_1 = match(TinyRustTokenType.IF);
12221213
TinyRustLexerToken v_2 = match(TinyRustTokenType.OPN_PAREN);
@@ -1226,20 +1217,17 @@ private List<TinyRustLexerToken> matchToken_Stmt(){
12261217
List<TinyRustLexerToken> v_6 = matchToken_Stmt();
12271218
List<TinyRustLexerToken> v_7 = matchToken_Stmt_factored_factored_factored();
12281219
st.ifEnd();
1229-
} else if (peek(TinyRustTokenType.ATTR_ID, TinyRustTokenType.SELF)){
1230-
st.newAssign();
1231-
List<TinyRustLexerToken> v_1 = matchToken_Assign();
1232-
TinyRustLexerToken v_2 = match(TinyRustTokenType.SEMI_COLON);
12331220
} else if (peek(TinyRustTokenType.OPN_PAREN)){
12341221
st.newExpr();
12351222
TinyRustLexerToken v_1 = match(TinyRustTokenType.OPN_PAREN);
12361223
List<TinyRustLexerToken> v_2 = matchToken_ExpOr();
12371224
TinyRustLexerToken v_3 = match(TinyRustTokenType.CLS_PAREN);
12381225
TinyRustLexerToken v_4 = match(TinyRustTokenType.SEMI_COLON);
12391226
st.endExpr();
1240-
} else if (peek(TinyRustTokenType.SEMI_COLON)){
1241-
st.newEmpty();
1242-
TinyRustLexerToken v_1 = match(TinyRustTokenType.SEMI_COLON);
1227+
} else if (peek(TinyRustTokenType.OPN_BRACE)){
1228+
st.newBlock();
1229+
TinyRustLexerToken v_1 = match(TinyRustTokenType.OPN_BRACE);
1230+
List<TinyRustLexerToken> v_2 = matchToken_Method_factored();
12431231
} else if (peek(TinyRustTokenType.WHILE)){
12441232
st.newWhile();
12451233
TinyRustLexerToken v_1 = match(TinyRustTokenType.WHILE);
@@ -1249,6 +1237,18 @@ private List<TinyRustLexerToken> matchToken_Stmt(){
12491237
st.whileBody();
12501238
List<TinyRustLexerToken> v_6 = matchToken_Stmt();
12511239
st.endWhile();
1240+
} else if (peek(TinyRustTokenType.SEMI_COLON)){
1241+
st.newEmpty();
1242+
TinyRustLexerToken v_1 = match(TinyRustTokenType.SEMI_COLON);
1243+
} else if (peek(TinyRustTokenType.ATTR_ID, TinyRustTokenType.SELF)){
1244+
st.newAssign();
1245+
List<TinyRustLexerToken> v_1 = matchToken_Assign();
1246+
TinyRustLexerToken v_2 = match(TinyRustTokenType.SEMI_COLON);
1247+
} else if (peek(TinyRustTokenType.RETURN)){
1248+
st.newReturn();
1249+
TinyRustLexerToken v_1 = match(TinyRustTokenType.RETURN);
1250+
List<TinyRustLexerToken> v_2 = matchToken_Stmt_factored();
1251+
st.endReturn();
12521252
} else {
12531253
handleUnexpectedToken("Stmt", Set.of(TinyRustTokenType.ATTR_ID, TinyRustTokenType.IF, TinyRustTokenType.OPN_BRACE, TinyRustTokenType.OPN_PAREN, TinyRustTokenType.RETURN, TinyRustTokenType.SELF, TinyRustTokenType.SEMI_COLON, TinyRustTokenType.WHILE));
12541254
}

src/main/java/ko/carbonel/compiler/intermediate/tinyRust/ts/ClassEntry.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ public void checkForCycles() {
154154

155155
@Override
156156
public Optional<VariableEntry> resolveVarName(TinyRustLexerToken name) {
157+
if (name.type().equals(TinyRustTokenType.SELF)){
158+
return Optional.of(new VariableEntry(root, name, TypeEntry.ofClass(this), false));
159+
}
157160
return Scope.firstOf(
158161
() -> Scope.searchForVar(fields, name),
159162
() -> Optional.ofNullable(superClassLink).flatMap(it -> it.resolveVarName(name))

src/main/java/ko/carbonel/compiler/intermediate/tinyRust/ts/TypeEntry.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ public static TypeEntry arrayOf(TinyRustLexerToken type) {
5858
return arrayType(type);
5959
}
6060

61+
public static TypeEntry ofClass(ClassEntry classEntry) {
62+
TypeEntry typeEntry = nonArrayType(new TinyRustLexerToken(TinyRustTokenType.CLASS_ID, classEntry.name.lexeme(), classEntry.name.location()));
63+
typeEntry.classLink = classEntry;
64+
return typeEntry;
65+
}
66+
6167
private static TypeEntry nonArrayType(TinyRustLexerToken first) {
6268
return new TypeEntry(first, false);
6369
}

src/test/resources/ast/18.ast.json

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"classEntries": [
3+
{
4+
"name": {"lexeme": "I32"},
5+
"methods": []
6+
},
7+
{
8+
"name": {"lexeme": "Bool"},
9+
"methods": []
10+
},
11+
{
12+
"name": {"lexeme": "Char"},
13+
"methods": []
14+
},
15+
{
16+
"name": {"lexeme": "Str"},
17+
"methods": []
18+
},
19+
{
20+
"name": {"lexeme": "Object"},
21+
"methods": []
22+
},
23+
{
24+
"name": {"lexeme": "IO"},
25+
"methods": [
26+
{
27+
"block": {"statements": []},
28+
"name": {"lexeme": "out_str"}
29+
},
30+
{
31+
"block": {"statements": []},
32+
"name": {"lexeme": "out_i32"}
33+
},
34+
{
35+
"block": {"statements": []},
36+
"name": {"lexeme": "out_bool"}
37+
},
38+
{
39+
"block": {"statements": []},
40+
"name": {"lexeme": "out_char"}
41+
},
42+
{
43+
"block": {"statements": []},
44+
"name": {"lexeme": "in_str"}
45+
},
46+
{
47+
"block": {"statements": []},
48+
"name": {"lexeme": "in_i32"}
49+
},
50+
{
51+
"block": {"statements": []},
52+
"name": {"lexeme": "in_bool"}
53+
},
54+
{
55+
"block": {"statements": []},
56+
"name": {"lexeme": "in_char"}
57+
}
58+
]
59+
},
60+
{
61+
"name": {"lexeme": "A"},
62+
"methods": [
63+
{
64+
"block": {"statements": [{"returnExpression": {
65+
"base": {"fieldName": {"lexeme": "self"}},
66+
"chain": {"fieldName": {"lexeme": "a"}}
67+
}}]},
68+
"name": {"lexeme": "test"}
69+
},
70+
{
71+
"block": {"statements": [{"returnExpression": {"fieldName": {"lexeme": "a"}}}]},
72+
"name": {"lexeme": "test1"}
73+
}
74+
]
75+
}
76+
],
77+
"main": {
78+
"block": {"statements": []},
79+
"name": {"lexeme": "main"}
80+
}
81+
}

src/test/resources/ast/18.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*ERROR
2+
MissingReturnStatementError
3+
*/
4+
class A{
5+
pub I32: a;
6+
fn test() -> I32{
7+
Bool: a;
8+
return self.a;
9+
}
10+
fn test1() -> Bool{
11+
Bool: a;
12+
return a;
13+
}
14+
fn test2() -> I32{
15+
}
16+
}
17+
fn main(){
18+
}

0 commit comments

Comments
 (0)