Skip to content

Enable method overloading and overriding #70

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

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
70eedf6
Add opcodes for type conversions to code-generator.ts
AprupKale Jan 14, 2025
64e245d
Add implicit type conversions in MethodInvocation to code-generator.ts
AprupKale Jan 14, 2025
a33c9af
Add implicit type conversions in MethodInvocation to code-generator.ts
AprupKale Jan 14, 2025
1848b4d
Handle stack size during primitive type conversions in code-generator.ts
AprupKale Jan 14, 2025
f88069e
Handle type conversions in binary expressions in code-generator.ts
AprupKale Jan 21, 2025
db87720
Fix bugs with float conversions
AprupKale Jan 21, 2025
6e0a2d7
Allow primitive types to be safely converted to String
AprupKale Jan 21, 2025
7e58159
Allow primitive types other than boolean in ternary conditional
AprupKale Jan 21, 2025
6bbafe7
Fix bugs in type checker
AprupKale Jan 21, 2025
57eeb8b
Enable unary expressions for non-integer types
AprupKale Jan 21, 2025
2a2cc0b
Fix bug in type conversion for binary expressions
AprupKale Jan 25, 2025
0799bf7
Add type cast support to the compiler
AprupKale Jan 25, 2025
fe76603
Add type cast support to the type checker
AprupKale Jan 26, 2025
345a8c8
Add switch statement support to the AST extractor and the compiler
AprupKale Feb 17, 2025
2038d8b
Add switch statement support to the compiler for integer like types (…
AprupKale Feb 18, 2025
91691ad
Add switch statement support to the compiler for String type
AprupKale Feb 18, 2025
54c0e05
Add overloading support to the compiler
AprupKale Mar 4, 2025
c12fbb8
Handle ambiguity during overloading in the compiler
AprupKale Mar 4, 2025
28a59e1
Modify type checker for overloading support
AprupKale Mar 4, 2025
f0c86ed
Change symbol-table.ts and compiler.ts logic for overriding. Add test…
AprupKale Apr 3, 2025
374c8c1
Add test cases for method overriding.
AprupKale Apr 3, 2025
35bcce8
Fix bugs in symbol-table.ts and compiler.ts logic. Add method invocat…
AprupKale Apr 3, 2025
d4d4bf1
Fix method invocation logic in target loading for qualified calls
AprupKale Apr 3, 2025
1ca1198
Fix bugs in method invocation logic for static method calls, and in s…
AprupKale Apr 6, 2025
0bc9b53
Modify the compiler to return multiple class files with their file na…
AprupKale Apr 6, 2025
d2517b2
Fix bug to not allow final methods to be overriden
AprupKale Apr 6, 2025
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
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "1.0.13",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": ["dist"],
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/source-academy/java-slang.git"
Expand Down Expand Up @@ -40,5 +42,6 @@
"java-parser": "^2.0.5",
"lodash": "^4.17.21",
"peggy": "^4.0.2"
}
},
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}
5 changes: 5 additions & 0 deletions src/ClassFile/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { ConstantInfo } from './constants'
import { FieldInfo } from './fields'
import { MethodInfo } from './methods'

export interface Class {
classFile: ClassFile
className: string
}

export interface ClassFile {
magic: number
minorVersion: number
Expand Down
139 changes: 139 additions & 0 deletions src/ast/__tests__/expression-extractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1035,3 +1035,142 @@ describe("extract ClassInstanceCreationExpression correctly", () => {
expect(ast).toEqual(expectedAst);
});
});

describe("extract CastExpression correctly", () => {
it("extract CastExpression int to char correctly", () => {
const programStr = `
class Test {
void test() {
char c = (char) 65;
}
}
`;

const expectedAst: AST = {
kind: "CompilationUnit",
importDeclarations: [],
topLevelClassOrInterfaceDeclarations: [
{
kind: "NormalClassDeclaration",
classModifier: [],
typeIdentifier: "Test",
classBody: [
{
kind: "MethodDeclaration",
methodModifier: [],
methodHeader: {
result: "void",
identifier: "test",
formalParameterList: [],
},
methodBody: {
kind: "Block",
blockStatements: [
{
kind: "LocalVariableDeclarationStatement",
localVariableType: "char",
variableDeclaratorList: [
{
kind: "VariableDeclarator",
variableDeclaratorId: "c",
variableInitializer: {
kind: "CastExpression",
type: "char",
expression: {
kind: "Literal",
literalType: {
kind: "DecimalIntegerLiteral",
value: "65",
},
location: expect.anything(),
},
location: expect.anything(),
},
},
],
location: expect.anything(),
},
],
location: expect.anything(),
},
location: expect.anything(),
},
],
location: expect.anything(),
},
],
location: expect.anything(),
};

const ast = parse(programStr);
expect(ast).toEqual(expectedAst);
});

it("extract CastExpression double to int correctly", () => {
const programStr = `
class Test {
void test() {
int x = (int) 3.14;
}
}
`;

const expectedAst: AST = {
kind: "CompilationUnit",
importDeclarations: [],
topLevelClassOrInterfaceDeclarations: [
{
kind: "NormalClassDeclaration",
classModifier: [],
typeIdentifier: "Test",
classBody: [
{
kind: "MethodDeclaration",
methodModifier: [],
methodHeader: {
result: "void",
identifier: "test",
formalParameterList: [],
},
methodBody: {
kind: "Block",
blockStatements: [
{
kind: "LocalVariableDeclarationStatement",
localVariableType: "int",
variableDeclaratorList: [
{
kind: "VariableDeclarator",
variableDeclaratorId: "x",
variableInitializer: {
kind: "CastExpression",
type: "int",
expression: {
kind: "Literal",
literalType: {
kind: "DecimalFloatingPointLiteral",
value: "3.14",
}
},
location: expect.anything(),
},
},
],
location: expect.anything(),
},
],
location: expect.anything(),
},
location: expect.anything(),
},
],
location: expect.anything(),
},
],
location: expect.anything(),
};

const ast = parse(programStr);
expect(ast).toEqual(expectedAst);
});
});
Loading