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
0df5b04c
Commit
0df5b04c
authored
Dec 08, 2020
by
zygzagZ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend abstract ClassDef, add ParseError, WIP TypeCheck
parent
1f3906a4
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
290 additions
and
217 deletions
+290
-217
Absyn.h
Absyn.h
+11
-0
Info.cpp
Info.cpp
+0
-0
Info.h
Info.h
+30
-0
Latte.cpp
Latte.cpp
+8
-0
Makefile
Makefile
+6
-3
ParseError.h
ParseError.h
+12
-0
TypeCheck.cpp
TypeCheck.cpp
+119
-116
TypeCheck.h
TypeCheck.h
+104
-98
No files found.
Absyn.h
View file @
0df5b04c
...
@@ -258,6 +258,9 @@ public:
...
@@ -258,6 +258,9 @@ public:
class
ClassDef
:
public
Visitable
class
ClassDef
:
public
Visitable
{
{
public:
public:
virtual
PIdent
*
getName
()
const
=
0
;
virtual
PIdent
*
getParent
()
const
=
0
;
virtual
ClassBlock
*
getBlock
()
const
=
0
;
virtual
ClassDef
*
clone
()
const
=
0
;
virtual
ClassDef
*
clone
()
const
=
0
;
};
};
...
@@ -436,6 +439,10 @@ public:
...
@@ -436,6 +439,10 @@ public:
virtual
void
accept
(
Visitor
*
v
);
virtual
void
accept
(
Visitor
*
v
);
virtual
ClassDefN
*
clone
()
const
;
virtual
ClassDefN
*
clone
()
const
;
void
swap
(
ClassDefN
&
);
void
swap
(
ClassDefN
&
);
virtual
PIdent
*
getName
()
const
{
return
pident_
;
};
virtual
PIdent
*
getParent
()
const
{
return
NULL
;
};
virtual
ClassBlock
*
getBlock
()
const
{
return
classblock_
;
};
};
};
class
ClassDefE
:
public
ClassDef
class
ClassDefE
:
public
ClassDef
...
@@ -452,6 +459,10 @@ public:
...
@@ -452,6 +459,10 @@ public:
virtual
void
accept
(
Visitor
*
v
);
virtual
void
accept
(
Visitor
*
v
);
virtual
ClassDefE
*
clone
()
const
;
virtual
ClassDefE
*
clone
()
const
;
void
swap
(
ClassDefE
&
);
void
swap
(
ClassDefE
&
);
virtual
PIdent
*
getName
()
const
{
return
pident_1
;
};
virtual
PIdent
*
getParent
()
const
{
return
pident_2
;
};
virtual
ClassBlock
*
getBlock
()
const
{
return
classblock_
;
};
};
};
class
ClassBl
:
public
ClassBlock
class
ClassBl
:
public
ClassBlock
...
...
Info.cpp
0 → 100644
View file @
0df5b04c
Info.h
0 → 100644
View file @
0df5b04c
#ifndef INFO_HEADER
#define INFO_HEADER
#include "Absyn.h"
using
namespace
std
;
class
VarInfo
{
string
name
;
string
type
;
bool
operator
<
(
const
VarInfo
&
other
)
const
{
return
name
!=
other
.
name
?
name
<
other
.
name
:
type
<
other
.
type
;
}
}
class
FunctionInfo
:
VarInfo
{
vector
<
VarInfo
>
arguments
;
};
class
ClassInfo
:
VarInfo
{
ClassInfo
*
parent
;
public:
ClassInfo
*
getParent
()
const
{
return
parent
;
};
vector
<
FunctionInfo
>
functions
;
vector
<
VarInfo
>
variables
;
};
vector
<
ClassInfo
>
classes
;
vector
<
FunctionInfo
>
functions
;
Latte.cpp
View file @
0df5b04c
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
#include "Printer.h"
#include "Printer.h"
#include "Absyn.h"
#include "Absyn.h"
// #include "Compiler.h"
// #include "Compiler.h"
#include "ParseError.h"
#include "TypeCheck.h"
#include <fstream>
#include <fstream>
#include <iostream>
#include <iostream>
#include <filesystem>
#include <filesystem>
...
@@ -63,6 +65,12 @@ int main(int argc, char ** argv)
...
@@ -63,6 +65,12 @@ int main(int argc, char ** argv)
binaryPath
=
argv
[
0
];
binaryPath
=
argv
[
0
];
std
::
filesystem
::
path
file
(
filename
?
filename
:
"Instant"
);
std
::
filesystem
::
path
file
(
filename
?
filename
:
"Instant"
);
TypeCheck
checker
;
try
{
checker
.
check
(
parse_tree
);
}
catch
(
ParseError
&
e
)
{
std
::
cerr
<<
e
.
what
()
<<
std
::
endl
;
}
/*Compiler c(file);
/*Compiler c(file);
std::string out = c.compile(parse_tree);
std::string out = c.compile(parse_tree);
...
...
Makefile
View file @
0df5b04c
CC
=
g++
CC
=
g++
CCFLAGS
=
-g
-W
-Wall
-O3
-std
=
c++1z
CCFLAGS
=
-g
-W
-Wall
-O3
-std
=
c++1z
-Wno-unused-parameter
FLEX
=
flex
FLEX
=
flex
FLEX_OPTS
=
-PGrammar
FLEX_OPTS
=
-PGrammar
...
@@ -7,7 +7,7 @@ FLEX_OPTS=-PGrammar
...
@@ -7,7 +7,7 @@ FLEX_OPTS=-PGrammar
BISON
=
bison
BISON
=
bison
BISON_OPTS
=
-t
-pGrammar
BISON_OPTS
=
-t
-pGrammar
OBJS
=
Absyn.o Lexer.o Parser.o Printer.o
OBJS
=
Absyn.o Lexer.o Parser.o Printer.o
TypeCheck.o
.PHONY
:
clean distclean
.PHONY
:
clean distclean
...
@@ -44,5 +44,8 @@ Printer.o : Printer.cpp Printer.h Absyn.h
...
@@ -44,5 +44,8 @@ Printer.o : Printer.cpp Printer.h Absyn.h
Skeleton.o
:
Skeleton.cpp Skeleton.h Absyn.h
Skeleton.o
:
Skeleton.cpp Skeleton.h Absyn.h
${
CC
}
${
CCFLAGS
}
-Wno-unused-parameter
-c
Skeleton.cpp
${
CC
}
${
CCFLAGS
}
-Wno-unused-parameter
-c
Skeleton.cpp
Latte.o
:
Latte.cpp Parser.h Printer.h Absyn.h
Latte.o
:
Latte.cpp Parser.h Printer.h Absyn.h
ParseError.h
${
CC
}
${
CCFLAGS
}
-c
Latte.cpp
${
CC
}
${
CCFLAGS
}
-c
Latte.cpp
TypeCheck.o
:
TypeCheck.cpp TypeCheck.h Absyn.h ParseError.h
${
CC
}
${
CCFLAGS
}
-c
TypeCheck.cpp
ParseError.h
0 → 100644
View file @
0df5b04c
#ifndef ERROR_HEADER
#define ERROR_HEADER
#include <string>
using
namespace
std
;
class
ParseError
:
std
::
exception
{
string
msg
;
public:
ParseError
(
string
reason
)
:
msg
(
reason
)
{}
const
char
*
what
()
{
return
msg
.
data
();
}
};
#endif
\ No newline at end of file
TypeCheck.cpp
View file @
0df5b04c
This diff is collapsed.
Click to expand it.
TypeCheck.h
View file @
0df5b04c
...
@@ -5,107 +5,113 @@
...
@@ -5,107 +5,113 @@
#include "Absyn.h"
#include "Absyn.h"
class
Skeleton
:
public
Visitor
class
TypeCheck
:
public
Visitor
{
{
enum
State
{
initialized
,
buildInfo
,
checkType
}
state
;
public:
public:
void
visitProgram
(
Program
*
p
);
TypeCheck
()
:
state
(
initialized
)
{};
void
visitTopDef
(
TopDef
*
p
);
void
check
(
Visitable
*
v
);
void
visitFunDef
(
FunDef
*
p
);
protected:
void
visitArg
(
Arg
*
p
);
void
visitProgram
(
Program
*
p
);
void
visitClassDef
(
ClassDef
*
p
);
void
visitTopDef
(
TopDef
*
p
);
void
visitClassBlock
(
ClassBlock
*
p
);
void
visitFunDef
(
FunDef
*
p
);
void
visitClassBlockDef
(
ClassBlockDef
*
p
);
void
visitArg
(
Arg
*
p
);
void
visitBlock
(
Block
*
p
);
void
visitClassDef
(
ClassDef
*
p
);
void
visitStmt
(
Stmt
*
p
);
void
visitClassBlock
(
ClassBlock
*
p
);
void
visitItem
(
Item
*
p
);
void
visitClassBlockDef
(
ClassBlockDef
*
p
);
void
visitType
(
Type
*
p
);
void
visitBlock
(
Block
*
p
);
void
visitExpr
(
Expr
*
p
);
void
visitStmt
(
Stmt
*
p
);
void
visitAddOp
(
AddOp
*
p
);
void
visitItem
(
Item
*
p
);
void
visitMulOp
(
MulOp
*
p
);
void
visitType
(
Type
*
p
);
void
visitRelOp
(
RelOp
*
p
);
void
visitExpr
(
Expr
*
p
);
void
visitProg
(
Prog
*
p
);
void
visitAddOp
(
AddOp
*
p
);
void
visitFnDef
(
FnDef
*
p
);
void
visitMulOp
(
MulOp
*
p
);
void
visitClDef
(
ClDef
*
p
);
void
visitRelOp
(
RelOp
*
p
);
void
visitFuncDef
(
FuncDef
*
p
);
void
visitProg
(
Prog
*
p
);
void
visitAr
(
Ar
*
p
);
void
visitFnDef
(
FnDef
*
p
);
void
visitClassDefN
(
ClassDefN
*
p
);
void
visitClDef
(
ClDef
*
p
);
void
visitClassDefE
(
ClassDefE
*
p
);
void
visitFuncDef
(
FuncDef
*
p
);
void
visitClassBl
(
ClassBl
*
p
);
void
visitAr
(
Ar
*
p
);
void
visitClassMthd
(
ClassMthd
*
p
);
void
visitClassDefN
(
ClassDefN
*
p
);
void
visitClassFld
(
ClassFld
*
p
);
void
visitClassDefE
(
ClassDefE
*
p
);
void
visitBlk
(
Blk
*
p
);
void
visitClassBl
(
ClassBl
*
p
);
void
visitEmpty
(
Empty
*
p
);
void
visitClassMthd
(
ClassMthd
*
p
);
void
visitBStmt
(
BStmt
*
p
);
void
visitClassFld
(
ClassFld
*
p
);
void
visitDecl
(
Decl
*
p
);
void
visitBlk
(
Blk
*
p
);
void
visitNoInit
(
NoInit
*
p
);
void
visitEmpty
(
Empty
*
p
);
void
visitInit
(
Init
*
p
);
void
visitBStmt
(
BStmt
*
p
);
void
visitAss
(
Ass
*
p
);
void
visitDecl
(
Decl
*
p
);
void
visitTableAss
(
TableAss
*
p
);
void
visitNoInit
(
NoInit
*
p
);
void
visitTableIncr
(
TableIncr
*
p
);
void
visitInit
(
Init
*
p
);
void
visitTableDecr
(
TableDecr
*
p
);
void
visitAss
(
Ass
*
p
);
void
visitIncr
(
Incr
*
p
);
void
visitTableAss
(
TableAss
*
p
);
void
visitDecr
(
Decr
*
p
);
void
visitTableIncr
(
TableIncr
*
p
);
void
visitRet
(
Ret
*
p
);
void
visitTableDecr
(
TableDecr
*
p
);
void
visitVRet
(
VRet
*
p
);
void
visitIncr
(
Incr
*
p
);
void
visitCond
(
Cond
*
p
);
void
visitDecr
(
Decr
*
p
);
void
visitCondElse
(
CondElse
*
p
);
void
visitRet
(
Ret
*
p
);
void
visitWhile
(
While
*
p
);
void
visitVRet
(
VRet
*
p
);
void
visitSExp
(
SExp
*
p
);
void
visitCond
(
Cond
*
p
);
void
visitForEach
(
ForEach
*
p
);
void
visitCondElse
(
CondElse
*
p
);
void
visitInt
(
Int
*
p
);
void
visitWhile
(
While
*
p
);
void
visitStr
(
Str
*
p
);
void
visitSExp
(
SExp
*
p
);
void
visitBool
(
Bool
*
p
);
void
visitForEach
(
ForEach
*
p
);
void
visitVoid
(
Void
*
p
);
void
visitInt
(
Int
*
p
);
void
visitArray
(
Array
*
p
);
void
visitStr
(
Str
*
p
);
void
visitClassT
(
ClassT
*
p
);
void
visitBool
(
Bool
*
p
);
void
visitFun
(
Fun
*
p
);
void
visitVoid
(
Void
*
p
);
void
visitEVar
(
EVar
*
p
);
void
visitArray
(
Array
*
p
);
void
visitELitInt
(
ELitInt
*
p
);
void
visitClassT
(
ClassT
*
p
);
void
visitELitTrue
(
ELitTrue
*
p
);
void
visitFun
(
Fun
*
p
);
void
visitELitFalse
(
ELitFalse
*
p
);
void
visitEVar
(
EVar
*
p
);
void
visitEApp
(
EApp
*
p
);
void
visitELitInt
(
ELitInt
*
p
);
void
visitEString
(
EString
*
p
);
void
visitELitTrue
(
ELitTrue
*
p
);
void
visitENewArray
(
ENewArray
*
p
);
void
visitELitFalse
(
ELitFalse
*
p
);
void
visitENewClass
(
ENewClass
*
p
);
void
visitEApp
(
EApp
*
p
);
void
visitEClsMmbr
(
EClsMmbr
*
p
);
void
visitEString
(
EString
*
p
);
void
visitEClsMthd
(
EClsMthd
*
p
);
void
visitENewArray
(
ENewArray
*
p
);
void
visitNull
(
Null
*
p
);
void
visitENewClass
(
ENewClass
*
p
);
void
visitEIndexAcc
(
EIndexAcc
*
p
);
void
visitEClsMmbr
(
EClsMmbr
*
p
);
void
visitECast
(
ECast
*
p
);
void
visitEClsMthd
(
EClsMthd
*
p
);
void
visitNeg
(
Neg
*
p
);
void
visitNull
(
Null
*
p
);
void
visitNot
(
Not
*
p
);
void
visitEIndexAcc
(
EIndexAcc
*
p
);
void
visitEMul
(
EMul
*
p
);
void
visitECast
(
ECast
*
p
);
void
visitEAdd
(
EAdd
*
p
);
void
visitNeg
(
Neg
*
p
);
void
visitERel
(
ERel
*
p
);
void
visitNot
(
Not
*
p
);
void
visitEAnd
(
EAnd
*
p
);
void
visitEMul
(
EMul
*
p
);
void
visitEOr
(
EOr
*
p
);
void
visitEAdd
(
EAdd
*
p
);
void
visitPlus
(
Plus
*
p
);
void
visitERel
(
ERel
*
p
);
void
visitMinus
(
Minus
*
p
);
void
visitEAnd
(
EAnd
*
p
);
void
visitTimes
(
Times
*
p
);
void
visitEOr
(
EOr
*
p
);
void
visitDiv
(
Div
*
p
);
void
visitPlus
(
Plus
*
p
);
void
visitMod
(
Mod
*
p
);
void
visitMinus
(
Minus
*
p
);
void
visitLTH
(
LTH
*
p
);
void
visitTimes
(
Times
*
p
);
void
visitLE
(
LE
*
p
);
void
visitDiv
(
Div
*
p
);
void
visitGTH
(
GTH
*
p
);
void
visitMod
(
Mod
*
p
);
void
visitGE
(
GE
*
p
);
void
visitLTH
(
LTH
*
p
);
void
visitEQU
(
EQU
*
p
);
void
visitLE
(
LE
*
p
);
void
visitNE
(
NE
*
p
);
void
visitGTH
(
GTH
*
p
);
void
visitListTopDef
(
ListTopDef
*
p
);
void
visitGE
(
GE
*
p
);
void
visitListArg
(
ListArg
*
p
);
void
visitEQU
(
EQU
*
p
);
void
visitListClassBlockDef
(
ListClassBlockDef
*
p
);
void
visitNE
(
NE
*
p
);
void
visitListStmt
(
ListStmt
*
p
);
void
visitListTopDef
(
ListTopDef
*
p
);
void
visitListItem
(
ListItem
*
p
);
void
visitListArg
(
ListArg
*
p
);
void
visitListType
(
ListType
*
p
);
void
visitListClassBlockDef
(
ListClassBlockDef
*
p
);
void
visitListExpr
(
ListExpr
*
p
);
void
visitListStmt
(
ListStmt
*
p
);
void
visitPIdent
(
PIdent
*
p
);
void
visitListItem
(
ListItem
*
p
);
void
visitListType
(
ListType
*
p
);
void
visitInteger
(
Integer
x
);
void
visitListExpr
(
ListExpr
*
p
);
void
visitChar
(
Char
x
);
void
visitPIdent
(
PIdent
*
p
);
void
visitDouble
(
Double
x
);
void
visitString
(
String
x
);
void
visitIdent
(
Ident
x
);
void
visitInteger
(
Integer
x
);
void
visitChar
(
Char
x
);
void
visitDouble
(
Double
x
);
void
visitString
(
String
x
);
void
visitIdent
(
Ident
x
);
};
};
#endif
#endif
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