Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
latte
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zygzagZ
latte
Commits
062c55e3
Commit
062c55e3
authored
Dec 10, 2020
by
zygzagZ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
37c6faa0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
52 deletions
+33
-52
Absyn.h
Absyn.h
+2
-2
Grammar.cf
Grammar.cf
+8
-8
Info.h
Info.h
+1
-1
TypeCheck.cpp
TypeCheck.cpp
+9
-29
TypeCheck.h
TypeCheck.h
+13
-12
No files found.
Absyn.h
View file @
062c55e3
...
...
@@ -163,6 +163,8 @@ public:
class
Arg
:
public
Visitable
{
public:
Type
*
type_
;
PIdent
*
pident_
;
virtual
Arg
*
clone
()
const
=
0
;
};
...
...
@@ -343,8 +345,6 @@ public:
class
Ar
:
public
Arg
{
public:
Type
*
type_
;
PIdent
*
pident_
;
Ar
(
const
Ar
&
);
Ar
&
operator
=
(
const
Ar
&
);
...
...
Grammar.cf
View file @
062c55e3
position token PIdent (letter (letter|digit|'_'|'\'')*) ;
-- programs ------------------------------------------------
entrypoints Program ;
Prog. Program ::= [TopDef] ;
Prog.
Program ::= [TopDef] ;
FnDef. TopDef ::= FunDef ;
ClDef. TopDef ::= ClassDef ;
separator nonempty TopDef "" ;
separator
nonempty TopDef "" ;
-- function def --------------------------------------------
FuncDef. FunDef ::= Type PIdent "(" [Arg] ")" Block ;
Ar. Arg ::= Type PIdent;
Ar.
Arg ::= Type PIdent;
separator Arg "," ;
-- class def -----------------------------------------------
ClassDefN. ClassDef ::= "class" PIdent ClassBlock ;
...
...
@@ -15,7 +15,7 @@ ClassDefE. ClassDef ::= "class" PIdent "extends" PIdent ClassBlock ;
ClassBl. ClassBlock ::= "{" [ClassBlockDef] "}" ;
ClassMthd. ClassBlockDef ::= FunDef ;
ClassFld. ClassBlockDef ::= Type [Item] ";" ;
separator ClassBlockDef "" ;
separator
ClassBlockDef "" ;
-- statements ----------------------------------------------
Blk. Block ::= "{" [Stmt] "}" ;
separator Stmt "" ;
...
...
@@ -24,7 +24,7 @@ BStmt. Stmt ::= Block ;
Decl. Stmt ::= Type [Item] ";" ;
NoInit. Item ::= PIdent ;
Init. Item ::= PIdent "=" Expr ;
separator nonempty Item "," ;
separator
nonempty Item "," ;
Ass. Stmt ::= Expr "=" Expr ";" ;
TableAss. Stmt ::= PIdent "[" Expr "]" "=" Expr ";" ;
TableIncr. Stmt ::= PIdent "[" Expr "]" "++" ";" ;
...
...
@@ -33,8 +33,8 @@ Incr. Stmt ::= PIdent "++" ";" ;
Decr. Stmt ::= PIdent "--" ";" ;
Ret. Stmt ::= "return" Expr ";" ;
VRet. Stmt ::= "return" ";" ;
Cond. Stmt ::= "if" "(" Expr ")" Stmt
;
CondElse. Stmt ::= "if" "(" Expr ")" Stmt "else" Stmt
;
Cond. Stmt ::= "if" "(" Expr ")" Stmt ;
CondElse. Stmt ::= "if" "(" Expr ")" Stmt "else" Stmt ;
While. Stmt ::= "while" "(" Expr ")" Stmt ;
SExp. Stmt ::= Expr ";" ;
ForEach. Stmt ::= "for" "(" Type PIdent ":" Expr ")" Stmt ;
...
...
@@ -85,4 +85,4 @@ NE. RelOp ::= "!=" ;
-- comments ------------------------------------------------
comment "#" ;
comment "//" ;
comment "/*" "*/" ;
\ No newline at end of file
comment "/*" "*/" ;
Info.h
View file @
062c55e3
...
...
@@ -31,7 +31,7 @@ public:
weak_ptr
<
ClassInfo
>
klass
;
weak_ptr
<
Binding
>
binding
;
FunctionInfo
(
FuncDef
*
expr
,
ClassInfoPtr
klass
=
nullptr
);
FunctionInfo
(
PIdent
*
ident
,
ClassInfoPtr
klass
=
nullptr
)
:
VarInfo
(
ident
),
block
(
NULL
),
klass
(
klass
)
{};
//
FunctionInfo(PIdent *ident, ClassInfoPtr klass = nullptr) : VarInfo(ident), block(NULL), klass(klass) {};
};
...
...
TypeCheck.cpp
View file @
062c55e3
...
...
@@ -2,10 +2,6 @@
#include "ParseError.h"
#include <stdexcept>
void
TypeCheck
::
visitProgram
(
Program
*
t
)
{}
//abstract class
void
TypeCheck
::
visitTopDef
(
TopDef
*
t
)
{}
//abstract class
void
TypeCheck
::
visitFunDef
(
FunDef
*
t
)
{}
//abstract class
void
TypeCheck
::
visitArg
(
Arg
*
t
)
{}
//abstract class
void
TypeCheck
::
visitClassDef
(
ClassDef
*
t
)
{
const
string
name
=
t
->
getName
()
->
string_
;
ClassInfoPtr
parent
=
NULL
;
...
...
@@ -23,14 +19,6 @@ void TypeCheck::visitClassDef(ClassDef *t) {
scope
.
currentClass
=
NULL
;
}
void
TypeCheck
::
visitStmt
(
Stmt
*
t
)
{}
//abstract class
void
TypeCheck
::
visitItem
(
Item
*
t
)
{}
//abstract class
void
TypeCheck
::
visitType
(
Type
*
t
)
{}
//abstract class
void
TypeCheck
::
visitExpr
(
Expr
*
t
)
{}
//abstract class
void
TypeCheck
::
visitAddOp
(
AddOp
*
t
)
{}
//abstract class
void
TypeCheck
::
visitMulOp
(
MulOp
*
t
)
{}
//abstract class
void
TypeCheck
::
visitRelOp
(
RelOp
*
t
)
{}
//abstract class
void
TypeCheck
::
visitPIdent
(
PIdent
*
p_ident
)
{
visitString
(
p_ident
->
string_
);
...
...
@@ -63,22 +51,14 @@ void TypeCheck::visitClDef(ClDef *cl_def)
void
TypeCheck
::
visitFuncDef
(
FuncDef
*
def
)
{
FunctionInfoPtr
f
=
make_shared
<
FunctionInfo
>
(
def
->
pident_
,
scope
.
currentClass
);
FunctionInfoPtr
f
=
make_shared
<
FunctionInfo
>
(
def
,
scope
.
currentClass
);
// FunctionInfo tworzy argumenty
f
->
block
=
def
->
block_
;
auto
&
targetVector
=
scope
.
currentClass
?
scope
.
currentClass
->
functions
:
scope
.
functions
;
targetVector
<<
f
;
}
void
TypeCheck
::
visitAr
(
Ar
*
ar
)
{
/* Code For Ar Goes Here */
ar
->
type_
->
accept
(
this
);
ar
->
pident_
->
accept
(
this
);
}
void
TypeCheck
::
visitClassDefN
(
ClassDefN
*
class_def_n
)
{
visitClassDef
(
class_def_n
);
...
...
@@ -136,19 +116,19 @@ void TypeCheck::visitBStmt(BStmt *b_stmt)
void
TypeCheck
::
visitDecl
(
Decl
*
decl
)
{
/* Code For Decl Goes Here */
decl
->
type_
->
accept
(
this
);
Type
*
type
=
decl
->
type_
;
for
(
auto
el
:
*
decl
->
listitem_
)
{
el
->
pident_
->
accept
(
this
);
for
(
Item
*
el
:
*
decl
->
listitem_
)
{
el
->
expr_
->
accept
(
this
);
VarInfoPtr
var
=
make_shared
<
VarInfo
>
(
el
->
pident_
,
type
);
scope
.
currentBinding
.
variables
<<
var
;
}
}
void
TypeCheck
::
visitAss
(
Ass
*
ass
)
{
/* Code For Ass Goes Here */
auto
var
=
scope
.
currentBinding
.
variables
[]
ass
->
expr_1
->
accept
(
this
);
ass
->
expr_2
->
accept
(
this
);
...
...
TypeCheck.h
View file @
062c55e3
...
...
@@ -23,22 +23,11 @@ public:
TypeCheck
();
void
check
(
Visitable
*
v
);
protected:
void
visitProgram
(
Program
*
p
);
void
visitTopDef
(
TopDef
*
p
);
void
visitFunDef
(
FunDef
*
p
);
void
visitArg
(
Arg
*
p
);
void
visitClassDef
(
ClassDef
*
p
);
void
visitStmt
(
Stmt
*
p
);
void
visitType
(
Type
*
p
);
void
visitExpr
(
Expr
*
p
);
void
visitAddOp
(
AddOp
*
p
);
void
visitMulOp
(
MulOp
*
p
);
void
visitRelOp
(
RelOp
*
p
);
void
visitProg
(
Prog
*
p
);
void
visitFnDef
(
FnDef
*
p
);
void
visitClDef
(
ClDef
*
p
);
void
visitFuncDef
(
FuncDef
*
p
);
void
visitAr
(
Ar
*
p
);
void
visitClassDefN
(
ClassDefN
*
p
);
void
visitClassDefE
(
ClassDefE
*
p
);
void
visitClassBl
(
ClassBl
*
p
);
...
...
@@ -103,15 +92,27 @@ protected:
// abstract
// topdefs
void
visitProgram
(
Program
*
t
)
{}
//abstract class
void
visitTopDef
(
TopDef
*
t
)
{}
//abstract class
void
visitFunDef
(
FunDef
*
t
)
{}
//abstract class
void
visitBlock
(
Block
*
t
)
{};
void
visitClassBlock
(
ClassBlock
*
p
)
{};
void
visitClassBlockDef
(
ClassBlockDef
*
p
)
{};
void
visitItem
(
Item
*
p
);
void
visitItem
(
Item
*
p
)
{};
void
visitArg
(
Arg
*
p
)
{}
void
visitStmt
(
Stmt
*
p
)
{};
void
visitType
(
Type
*
p
)
{};
void
visitExpr
(
Expr
*
p
)
{};
void
visitAddOp
(
AddOp
*
p
)
{};
void
visitMulOp
(
MulOp
*
p
)
{};
void
visitRelOp
(
RelOp
*
p
)
{};
// stmts
void
visitEmpty
(
Empty
*
p
)
{};
void
visitNoInit
(
NoInit
*
p
)
{};
void
visitInit
(
Init
*
p
)
{};
void
visitAr
(
Ar
*
p
)
{};
// exprs
void
visitPlus
(
Plus
*
p
)
{};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment