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

Entrega final #73

Open
wants to merge 91 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
2ed2bb1
adding llast project, lexer almost done
Feb 17, 2022
de5c80e
update
Feb 18, 2022
94cc224
lexer done
Feb 18, 2022
b7a6d56
working on parser
Feb 18, 2022
1261f2c
working on parser
Feb 22, 2022
8f6cd5f
-
Feb 23, 2022
d7be5b1
working on semantic errors
Feb 24, 2022
a794daf
cleaning
JessyGigato Feb 23, 2022
6357abe
starting cil :-O
JessyGigato Feb 24, 2022
811f369
working on semantic
Feb 24, 2022
6c71296
Merge branch 'master' of https://github.com/ycimadevila/cool-compiler…
Feb 24, 2022
ece974d
still workin on cil
JessyGigato Feb 25, 2022
e84d7dd
Merge branch 'master' of https://github.com/ycimadevila/cool-compiler…
JessyGigato Feb 25, 2022
f7aa846
working on type checker
Feb 25, 2022
5580762
still working on cil v2 :-(
JessyGigato Feb 26, 2022
d8c222f
working on semantic, typer checker, report
Feb 26, 2022
69bf6e7
Merge branch 'master' of https://github.com/ycimadevila/cool-compiler…
Feb 26, 2022
e06cc83
half semantic tests done :')
Mar 2, 2022
360a095
cool-to-cil-yet
JessyGigato Mar 11, 2022
32c3566
merging
JessyGigato Mar 11, 2022
f0c4aec
testing semantic
Mar 11, 2022
b7146b3
Merge branch 'master' of https://github.com/ycimadevila/cool-compiler…
JessyGigato Mar 11, 2022
6317abd
visit-cil
JessyGigato Mar 11, 2022
1ab6967
fixing
JessyGigato Mar 11, 2022
2d45c28
cyclic dependency fixed
Mar 11, 2022
5adce7c
Merge branch 'master' of https://github.com/ycimadevila/cool-compiler…
JessyGigato Mar 11, 2022
61fd2fb
--
JessyGigato Mar 11, 2022
43d5304
fixing errors
JessyGigato Mar 11, 2022
27064a6
semantic donde, hope it works X')
Mar 11, 2022
3426470
fixing entry
Mar 11, 2022
787aa4a
-
Mar 11, 2022
80ef284
Merge branch 'master' of https://github.com/ycimadevila/cool-compiler…
JessyGigato Mar 11, 2022
c1632b3
-
Mar 12, 2022
84066cf
cil almost complete
JessyGigato Mar 13, 2022
8bc5d33
fixing errors
JessyGigato Mar 13, 2022
44dd6fe
declaration collector
ycimadevila Mar 13, 2022
056c979
--
JessyGigato Mar 13, 2022
25333cd
fixing errors
Mar 13, 2022
e057784
-
Mar 13, 2022
1db2187
-
Mar 13, 2022
565cba3
updating ast and fixing pos
Mar 31, 2022
137e91f
fixing inference errors
JessyGigato Apr 3, 2022
7f131f8
semantic_test case done!
ycimadevila Sep 21, 2022
8d74bf3
-
ycimadevila Sep 21, 2022
e49ef63
fixing errors
ycimadevila Sep 22, 2022
e75ad07
-
ycimadevila Sep 29, 2022
4500113
coge generation ast-null
ycimadevila Oct 9, 2022
4f3bd56
new ast with types, skeleton
ycimadevila Oct 10, 2022
9ce53ed
binary and unary almost done
ycimadevila Oct 10, 2022
9aa128a
while and block almost done
ycimadevila Oct 12, 2022
948a638
var, new almost done, fixing errors, working on methCallNode
ycimadevila Oct 13, 2022
f040d94
fixing errors, casenode done
ycimadevila Oct 13, 2022
e14a3c4
updating cil nodes
ycimadevila Oct 21, 2022
1c30be0
working on ast cil, adding new features, working on cool-cil
JessyGigato Oct 25, 2022
1b42e14
starting arithmetic expression,starting main
JessyGigato Oct 25, 2022
82ad55c
fixing errors, functions almost done
ycimadevila Nov 2, 2022
c73c2a6
adding functins, error at cil.PN, cleaning function bugs
ycimadevila Nov 2, 2022
6a80b1d
cool.arithm almost done
ycimadevila Nov 2, 2022
6bcf9be
--
ycimadevila Nov 4, 2022
2d1b9eb
-, cil to mips
ycimadevila Nov 5, 2022
96406a6
fixing bugs, working on CaseNode
ycimadevila Nov 5, 2022
651307a
fixing locals, casenode
JessyGigato Nov 7, 2022
2bc88df
case almost done
JessyGigato Nov 8, 2022
0ffb0d3
mips-ast, cil-to-mips skeleton
ycimadevila Nov 8, 2022
4dc1c3a
--
ycimadevila Nov 9, 2022
1de2b15
mips arithmetics almost done
JessyGigato Nov 9, 2022
5215048
working on allocate
ycimadevila Nov 10, 2022
6f771b9
--
ycimadevila Nov 10, 2022
a4cd4c5
goto-if, dycall, stcall, comm fixed, error at alloc
ycimadevila Nov 10, 2022
c3dee1c
equal almost done(int, string) and copy
JessyGigato Nov 10, 2022
08267bc
read and print (str, int)
JessyGigato Nov 11, 2022
ac2445d
-, errors fixed, concatnode
JessyGigato Nov 11, 2022
c9838ac
typename, set/get (index, indexvalue)
ycimadevila Nov 12, 2022
ed10260
fixing formater, -
ycimadevila Nov 13, 2022
3ac2bcc
mips with error at functions, allocate fixed
ycimadevila Nov 13, 2022
9b87084
cg - hello word ok
ycimadevila Nov 13, 2022
42f6126
atoi, fib, print-cool ok
ycimadevila Nov 14, 2022
26c53da
fixing errors
ycimadevila Nov 14, 2022
75de922
formatter testing
ycimadevila Nov 15, 2022
8be7af7
--
ycimadevila Nov 16, 2022
05fc459
fixing typing
ycimadevila Nov 18, 2022
26156b6
--
ycimadevila Nov 19, 2022
e99f1b2
register fixing
ycimadevila Nov 20, 2022
d75fbe2
cg almost done
ycimadevila Nov 20, 2022
5670cbd
cleaning code
ycimadevila Nov 20, 2022
f9ecb05
--
ycimadevila Nov 20, 2022
3e7fc52
report
ycimadevila Nov 21, 2022
8fb1326
report update
ycimadevila Nov 21, 2022
d52d56d
adding pdf report
ycimadevila Nov 21, 2022
999b2b2
--
ycimadevila Nov 21, 2022
6ad2137
--
ycimadevila Nov 21, 2022
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
Prev Previous commit
Next Next commit
cyclic dependency fixed
ycimadevila committed Mar 11, 2022
commit 2d45c2854b3dd2d1dbad144ec24aa5a25879418f
2 changes: 1 addition & 1 deletion src/coolc.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
print('Copyright (c) 2021: Yasmin Cisneros Cimadevila & Jessy Gigato Izquierdo')

def run():
sp = subprocess.run(['python3.9', 'utils/pipeline.py', 'final-execution', input_file, output_file], capture_output=True, timeout=100)
sp = subprocess.run(['python', 'utils/pipeline.py', 'final-execution', input_file, output_file], capture_output=True, timeout=100)
dcode = sp.stdout.decode()
print(dcode)
exit(sp.returncode)
3 changes: 2 additions & 1 deletion src/utils/pipeline.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
from cool_grammar import parser, errors as parser_errors
from cool_lexer import lexer, lexer_errors
from utils.ast_nodes import Token
from utils.cyclic_dependency import CyclicDependency
from utils.cyclic_dependency import CyclicDependency, MethodChecker
from utils.formatter import Formatter, CodeBuilder
from utils.semantic import Context, Scope
from utils.inference import InferenceTypeChecker
@@ -272,6 +272,7 @@ def final_execution(program_file, program_file_out, debug: bool = False, verbose
print_errors(item)
exit(1)
CyclicDependency(context, errors)
MethodChecker(context, errors, program).visit(ast)
InferenceTypeChecker(context, errors, program).visit(ast, scope)

TypeChecker(context, errors, program).visit(ast, scope)
75 changes: 75 additions & 0 deletions src/utils/utils/cyclic_dependency.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .semantic import Context, SemanticError
from utils import visitor
from utils import ast_nodes as ast

class CyclicDependency:
def __init__(self, context: Context, errors):
@@ -47,3 +49,76 @@ def __is_cyclic__(self):
if dfs != len(self.vertex) - 2:
raise SemanticError('Existe un ciclo en el Γ‘rbol de dependencias')


class MethodChecker:
def __init__(self, context: Context, errors, program):
self.context: Context = context
self.current_type = None
self.errors = errors
self.program = program

def get_tokencolumn(self, str, pos):
column = 1
temp_pos = pos
while str[temp_pos] != '\n':
if temp_pos == 0: break
temp_pos -= 1
column += 1
return column if column > 1 else 2

@visitor.on("node")
def visit(self, node):
pass

@visitor.when(ast.ProgramNode)
def visit(self, node: ast.ProgramNode):
for data in node.class_list:
self.visit(data)

@visitor.when(ast.ClassDecNode)
def visit(self, node: ast.ClassDecNode):
self.current_type = self.context.get_type(node.name)

for data in node.data:
if isinstance(data, ast.MethodDecNode):
self.visit(data)

@visitor.when(ast.AttributeDecNode)
def visit(self, node: ast.AttributeDecNode):
try:
attribute, owner = self.current_type.parent.get_attribute(node.name)
line, lexpos = node.type_pos
self.errors.append(f'({line}, {self.get_tokencolumn(self.program, lexpos)}) - SemanticError: Attribute "{attribute.name}" already defined in "{owner.name}", attributes cannot be overridden')
except SemanticError:
pass

@visitor.when(ast.MethodDecNode)
def visit(self, node: ast.MethodDecNode):
# TODO: Change the comparison overriding
current_method = self.current_type.get_method(node.name)
try:
original_method, _ = self.current_type.parent.get_method(
node.name, owner=True
)

current_count = len(current_method.param_types)
original_count = len(original_method.param_types)
if current_count != original_count:
self.errors.append(f'({node.line}, {self.get_tokencolumn(self.program, node.lexpos)}) - SemanticError: In redefinded method "{node.name}", param type "{original_count}" is different from original param type "{current_count}"')

counter = min(original_count, current_count)
for i in range(counter):
current_type = current_method.param_types[i].name
original_type = original_method.param_types[i].name
if current_type != original_type:
line, lexpos = node.p_types_pos[i]
self.errors.append(self.errors.append(f'({line}, {self.get_tokencolumn(self.program, lexpos)}) - SemanticError: In redefinded method "{node.name}", param type "{current_type}" is different from original param type "{original_method}"'))

current_return_type = current_method.return_type.name
original_return_type = original_method.return_type.name
if current_return_type != original_return_type:
line, lexpos = node.r_types_pos
self.errors.append(f'({line}, {self.get_tokencolumn(self.program, lexpos)}) - SemanticError: In redefinded method "{node.name}", return type "{current_return_type}" is different from original return type "{original_return_type}"')
except SemanticError:
pass

6 changes: 3 additions & 3 deletions src/utils/utils/semantic.py
Original file line number Diff line number Diff line change
@@ -73,14 +73,14 @@ def define_attribute(self, name: str, typex):
else:
raise SemanticError(f'Attribute "{name}" is already defined in {self.name}.')

def get_method(self, name: str):
def get_method(self, name: str, owner=False):
try:
return self.methods[name]
return self.methods[name] if not owner else (self.methods[name], self)
except KeyError:
if self.parent is None:
raise SemanticError(f'Method "{name}" is not defined in {self.name}.')
try:
return self.parent.get_method(name)
return self.parent.get_method(name, owner)
except SemanticError:
raise SemanticError(f'Method "{name}" is not defined in {self.name}.')

28 changes: 14 additions & 14 deletions src/utils/utils/type_analysis.py
Original file line number Diff line number Diff line change
@@ -222,13 +222,13 @@ def visit(self, node: ast.MethodDecNode):
param_types.append(self.context.get_type(typex))
except SemanticError:
param_types.append(ErrorType())
line, lexpos = node.p_types_positions[i]
line, lexpos = node.p_types_pos[i]
self.errors.append(f'({line}, {self.get_tokencolumn(self.program, lexpos)}) - TypeError: Undefined param type "{typex}" in method "{node.name}", in class "{self.current_type.name}"')
try:
return_type = self.context.get_type(node.type)
except SemanticError:
return_type = ErrorType()
line, lexpos = node.r_types_position
line, lexpos = node.r_types_pos
self.errors.append(f'({line}, {self.get_tokencolumn(self.program, lexpos)}) - TypeError: Undefined return type "{node.type}" in method "{node.name}", in class "{self.current_type.name}"')
try:
self.current_type.define_method(node.name, param_names, param_types, return_type)
@@ -340,24 +340,24 @@ def visit(self, node: ast.LetNode, scope: Scope):
if id_ == 'self':
l, lp = node.dec_names_pos[pos]
self.errors.append(f'({l}, {lp}) - SemanticError: "self" cannot be bound in a "let" expression')
else:
try:
if type_ != "SELF_TYPE":
var_type = self.context.get_type(type_)
else:
var_type = self.current_type
except SemanticError:
line, lexpos = node.dec_types_pos[pos]
self.errors.append(f'({line}, {self.get_tokencolumn(self.program, lexpos)}) - TypeError: Type "{type_}" is not defined')
var_type = ErrorType()
continue
try:
if type_ != "SELF_TYPE":
var_type = self.context.get_type(type_)
else:
var_type = self.current_type

except SemanticError:
line, lexpos = node.dec_types_pos[pos]
self.errors.append(f'({line}, {self.get_tokencolumn(self.program, lexpos)}) - TypeError: Type "{type_}" is not defined')
var_type = ErrorType()
scope.define_variable(id_, var_type)

expr_type = None
if exp is not None:
expr_type = self.visit(exp, scope.create_child())
if expr_type is not None and not expr_type.conforms_to(var_type):
self.errors.append(f'({node.line}, {self.get_tokencolumn(self.program, self.lexpos)}) - TypeError: Cannot convert "{expr_type.name}" into "{var_type.name}".')
self.errors.append(f'({node.line}, {self.get_tokencolumn(self.program, node.lexpos)}) - TypeError: Cannot convert "{expr_type.name}" into "{var_type.name}".')

# if exp is not None:
# return_type = self.visit(exp, sc)