-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First correct implementation of Interfaces
- Loading branch information
Showing
23 changed files
with
390 additions
and
25 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,8 @@ | ||
package com.ruke.vrjassc; | ||
|
||
public class Config { | ||
|
||
public static final String VTYPE_NAME = "vtype"; | ||
public static final String STRUCT_HASHTABLE_NAME = "vrjass_structs"; | ||
|
||
} |
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
68 changes: 68 additions & 0 deletions
68
src/main/java/com/ruke/vrjassc/translator/InterfaceMethodDefinition.java
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,68 @@ | ||
package com.ruke.vrjassc.translator; | ||
|
||
import com.ruke.vrjassc.Config; | ||
import com.ruke.vrjassc.translator.expression.BooleanExpression; | ||
import com.ruke.vrjassc.translator.expression.BooleanExpression.Operator; | ||
import com.ruke.vrjassc.translator.expression.ElseIfStatement; | ||
import com.ruke.vrjassc.translator.expression.ExpressionList; | ||
import com.ruke.vrjassc.translator.expression.FunctionDefinition; | ||
import com.ruke.vrjassc.translator.expression.FunctionExpression; | ||
import com.ruke.vrjassc.translator.expression.FunctionStatement; | ||
import com.ruke.vrjassc.translator.expression.IfStatement; | ||
import com.ruke.vrjassc.translator.expression.RawExpression; | ||
import com.ruke.vrjassc.translator.expression.ReturnStatement; | ||
import com.ruke.vrjassc.translator.expression.VariableExpression; | ||
import com.ruke.vrjassc.vrjassc.symbol.ClassSymbol; | ||
import com.ruke.vrjassc.vrjassc.symbol.FunctionSymbol; | ||
import com.ruke.vrjassc.vrjassc.symbol.InterfaceSymbol; | ||
import com.ruke.vrjassc.vrjassc.symbol.Symbol; | ||
|
||
public class InterfaceMethodDefinition { | ||
|
||
public static FunctionDefinition build(InterfaceSymbol _interface, FunctionSymbol method) { | ||
FunctionDefinition function = new FunctionDefinition(method); | ||
IfStatement checks = new IfStatement(new RawExpression("false")); | ||
ElseIfStatement check = null; | ||
Symbol implementation = null; | ||
FunctionExpression func = null; | ||
ExpressionList params = new ExpressionList(); | ||
|
||
params.add(new RawExpression("this")); | ||
|
||
for (Symbol param : method.getParams()) { | ||
params.add(new VariableExpression(param, null)); | ||
} | ||
|
||
for (ClassSymbol _class : _interface.getImplementations()) { | ||
check = new ElseIfStatement( | ||
new BooleanExpression( | ||
new RawExpression(Config.VTYPE_NAME), | ||
Operator.EQUAL_EQUAL, | ||
new RawExpression(String.valueOf(_class.getTypeId())) | ||
) | ||
); | ||
|
||
implementation = _class.resolve(method.getName()); | ||
func = new FunctionExpression(implementation, false, params); | ||
|
||
if (method.getType() == null) { | ||
check.add(new FunctionStatement(func)); | ||
} else { | ||
check.add(new ReturnStatement(func)); | ||
} | ||
|
||
checks.add(check); | ||
} | ||
|
||
function.add(checks); | ||
|
||
if (method.getType() == null) { | ||
function.add(new FunctionStatement(func)); | ||
} else { | ||
function.add(new ReturnStatement(func)); | ||
} | ||
|
||
return function; | ||
} | ||
|
||
} |
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
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
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
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
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
1 change: 0 additions & 1 deletion
1
src/main/java/com/ruke/vrjassc/translator/expression/VariableStatement.java
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
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
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
Oops, something went wrong.