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
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:
class
ClassDef
:
public
Visitable
{
public:
virtual
PIdent
*
getName
()
const
=
0
;
virtual
PIdent
*
getParent
()
const
=
0
;
virtual
ClassBlock
*
getBlock
()
const
=
0
;
virtual
ClassDef
*
clone
()
const
=
0
;
};
...
...
@@ -436,6 +439,10 @@ public:
virtual
void
accept
(
Visitor
*
v
);
virtual
ClassDefN
*
clone
()
const
;
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
...
...
@@ -452,6 +459,10 @@ public:
virtual
void
accept
(
Visitor
*
v
);
virtual
ClassDefE
*
clone
()
const
;
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
...
...
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 @@
#include "Printer.h"
#include "Absyn.h"
// #include "Compiler.h"
#include "ParseError.h"
#include "TypeCheck.h"
#include <fstream>
#include <iostream>
#include <filesystem>
...
...
@@ -63,6 +65,12 @@ int main(int argc, char ** argv)
binaryPath
=
argv
[
0
];
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);
std::string out = c.compile(parse_tree);
...
...
Makefile
View file @
0df5b04c
CC
=
g++
CCFLAGS
=
-g
-W
-Wall
-O3
-std
=
c++1z
CCFLAGS
=
-g
-W
-Wall
-O3
-std
=
c++1z
-Wno-unused-parameter
FLEX
=
flex
FLEX_OPTS
=
-PGrammar
...
...
@@ -7,7 +7,7 @@ FLEX_OPTS=-PGrammar
BISON
=
bison
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
...
...
@@ -44,5 +44,8 @@ Printer.o : Printer.cpp Printer.h Absyn.h
Skeleton.o
:
Skeleton.cpp Skeleton.h Absyn.h
${
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
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
/*** BNFC-Generated Visitor Design Pattern Skeleton. ***/
/* This implements the common visitor design pattern.
Note that this method uses Visitor-traversal of lists, so
List->accept() does NOT traverse the list. This allows different
algorithms to use context information differently. */
#include "TypeCheck.h"
void
Skeleton
::
visitProgram
(
Program
*
t
)
{}
//abstract class
void
Skeleton
::
visitTopDef
(
TopDef
*
t
)
{}
//abstract class
void
Skeleton
::
visitFunDef
(
FunDef
*
t
)
{}
//abstract class
void
Skeleton
::
visitArg
(
Arg
*
t
)
{}
//abstract class
void
Skeleton
::
visitClassDef
(
ClassDef
*
t
)
{}
//abstract class
void
Skeleton
::
visitClassBlock
(
ClassBlock
*
t
)
{}
//abstract class
void
Skeleton
::
visitClassBlockDef
(
ClassBlockDef
*
t
)
{}
//abstract class
void
Skeleton
::
visitBlock
(
Block
*
t
)
{}
//abstract class
void
Skeleton
::
visitStmt
(
Stmt
*
t
)
{}
//abstract class
void
Skeleton
::
visitItem
(
Item
*
t
)
{}
//abstract class
void
Skeleton
::
visitType
(
Type
*
t
)
{}
//abstract class
void
Skeleton
::
visitExpr
(
Expr
*
t
)
{}
//abstract class
void
Skeleton
::
visitAddOp
(
AddOp
*
t
)
{}
//abstract class
void
Skeleton
::
visitMulOp
(
MulOp
*
t
)
{}
//abstract class
void
Skeleton
::
visitRelOp
(
RelOp
*
t
)
{}
//abstract class
void
Skeleton
::
visitPIdent
(
PIdent
*
p_ident
)
#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
)
{
t
->
getName
()
->
accept
(
this
);
if
(
t
->
getParent
())
t
->
getParent
()
->
accept
(
this
);
t
->
getBlock
()
->
accept
(
this
);
}
void
TypeCheck
::
visitClassBlock
(
ClassBlock
*
t
)
{}
//abstract class
void
TypeCheck
::
visitClassBlockDef
(
ClassBlockDef
*
t
)
{}
//abstract class
void
TypeCheck
::
visitBlock
(
Block
*
t
)
{}
//abstract class
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
)
{
/* Code For PIdent Goes Here */
...
...
@@ -33,7 +32,7 @@ void Skeleton::visitPIdent(PIdent *p_ident)
}
void
Skeleton
::
visitProg
(
Prog
*
prog
)
void
TypeCheck
::
visitProg
(
Prog
*
prog
)
{
/* Code For Prog Goes Here */
...
...
@@ -41,7 +40,7 @@ void Skeleton::visitProg(Prog *prog)
}
void
Skeleton
::
visitFnDef
(
FnDef
*
fn_def
)
void
TypeCheck
::
visitFnDef
(
FnDef
*
fn_def
)
{
/* Code For FnDef Goes Here */
...
...
@@ -49,7 +48,7 @@ void Skeleton::visitFnDef(FnDef *fn_def)
}
void
Skeleton
::
visitClDef
(
ClDef
*
cl_def
)
void
TypeCheck
::
visitClDef
(
ClDef
*
cl_def
)
{
/* Code For ClDef Goes Here */
...
...
@@ -57,7 +56,7 @@ void Skeleton::visitClDef(ClDef *cl_def)
}
void
Skeleton
::
visitFuncDef
(
FuncDef
*
func_def
)
void
TypeCheck
::
visitFuncDef
(
FuncDef
*
func_def
)
{
/* Code For FuncDef Goes Here */
...
...
@@ -68,7 +67,7 @@ void Skeleton::visitFuncDef(FuncDef *func_def)
}
void
Skeleton
::
visitAr
(
Ar
*
ar
)
void
TypeCheck
::
visitAr
(
Ar
*
ar
)
{
/* Code For Ar Goes Here */
...
...
@@ -77,26 +76,17 @@ void Skeleton::visitAr(Ar *ar)
}
void
Skeleton
::
visitClassDefN
(
ClassDefN
*
class_def_n
)
void
TypeCheck
::
visitClassDefN
(
ClassDefN
*
class_def_n
)
{
/* Code For ClassDefN Goes Here */
class_def_n
->
pident_
->
accept
(
this
);
class_def_n
->
classblock_
->
accept
(
this
);
visitClassDef
(
class_def_n
);
}
void
Skeleton
::
visitClassDefE
(
ClassDefE
*
class_def_e
)
void
TypeCheck
::
visitClassDefE
(
ClassDefE
*
class_def_e
)
{
/* Code For ClassDefE Goes Here */
class_def_e
->
pident_1
->
accept
(
this
);
class_def_e
->
pident_2
->
accept
(
this
);
class_def_e
->
classblock_
->
accept
(
this
);
visitClassDef
(
class_def_e
);
}
void
Skeleton
::
visitClassBl
(
ClassBl
*
class_bl
)
void
TypeCheck
::
visitClassBl
(
ClassBl
*
class_bl
)
{
/* Code For ClassBl Goes Here */
...
...
@@ -104,7 +94,7 @@ void Skeleton::visitClassBl(ClassBl *class_bl)
}
void
Skeleton
::
visitClassMthd
(
ClassMthd
*
class_mthd
)
void
TypeCheck
::
visitClassMthd
(
ClassMthd
*
class_mthd
)
{
/* Code For ClassMthd Goes Here */
...
...
@@ -112,7 +102,7 @@ void Skeleton::visitClassMthd(ClassMthd *class_mthd)
}
void
Skeleton
::
visitClassFld
(
ClassFld
*
class_fld
)
void
TypeCheck
::
visitClassFld
(
ClassFld
*
class_fld
)
{
/* Code For ClassFld Goes Here */
...
...
@@ -121,7 +111,7 @@ void Skeleton::visitClassFld(ClassFld *class_fld)
}
void
Skeleton
::
visitBlk
(
Blk
*
blk
)
void
TypeCheck
::
visitBlk
(
Blk
*
blk
)
{
/* Code For Blk Goes Here */
...
...
@@ -129,14 +119,14 @@ void Skeleton::visitBlk(Blk *blk)
}
void
Skeleton
::
visitEmpty
(
Empty
*
empty
)
void
TypeCheck
::
visitEmpty
(
Empty
*
empty
)
{
/* Code For Empty Goes Here */
}
void
Skeleton
::
visitBStmt
(
BStmt
*
b_stmt
)
void
TypeCheck
::
visitBStmt
(
BStmt
*
b_stmt
)
{
/* Code For BStmt Goes Here */
...
...
@@ -144,7 +134,7 @@ void Skeleton::visitBStmt(BStmt *b_stmt)
}
void
Skeleton
::
visitDecl
(
Decl
*
decl
)
void
TypeCheck
::
visitDecl
(
Decl
*
decl
)
{
/* Code For Decl Goes Here */
...
...
@@ -153,7 +143,7 @@ void Skeleton::visitDecl(Decl *decl)
}
void
Skeleton
::
visitAss
(
Ass
*
ass
)
void
TypeCheck
::
visitAss
(
Ass
*
ass
)
{
/* Code For Ass Goes Here */
...
...
@@ -162,7 +152,7 @@ void Skeleton::visitAss(Ass *ass)
}
void
Skeleton
::
visitTableAss
(
TableAss
*
table_ass
)
void
TypeCheck
::
visitTableAss
(
TableAss
*
table_ass
)
{
/* Code For TableAss Goes Here */
...
...
@@ -172,7 +162,7 @@ void Skeleton::visitTableAss(TableAss *table_ass)
}
void
Skeleton
::
visitTableIncr
(
TableIncr
*
table_incr
)
void
TypeCheck
::
visitTableIncr
(
TableIncr
*
table_incr
)
{
/* Code For TableIncr Goes Here */
...
...
@@ -181,7 +171,7 @@ void Skeleton::visitTableIncr(TableIncr *table_incr)
}
void
Skeleton
::
visitTableDecr
(
TableDecr
*
table_decr
)
void
TypeCheck
::
visitTableDecr
(
TableDecr
*
table_decr
)
{
/* Code For TableDecr Goes Here */
...
...
@@ -190,7 +180,7 @@ void Skeleton::visitTableDecr(TableDecr *table_decr)
}
void
Skeleton
::
visitIncr
(
Incr
*
incr
)
void
TypeCheck
::
visitIncr
(
Incr
*
incr
)
{
/* Code For Incr Goes Here */
...
...
@@ -198,7 +188,7 @@ void Skeleton::visitIncr(Incr *incr)
}
void
Skeleton
::
visitDecr
(
Decr
*
decr
)
void
TypeCheck
::
visitDecr
(
Decr
*
decr
)
{
/* Code For Decr Goes Here */
...
...
@@ -206,7 +196,7 @@ void Skeleton::visitDecr(Decr *decr)
}
void
Skeleton
::
visitRet
(
Ret
*
ret
)
void
TypeCheck
::
visitRet
(
Ret
*
ret
)
{
/* Code For Ret Goes Here */
...
...
@@ -214,14 +204,14 @@ void Skeleton::visitRet(Ret *ret)
}
void
Skeleton
::
visitVRet
(
VRet
*
v_ret
)
void
TypeCheck
::
visitVRet
(
VRet
*
v_ret
)
{
/* Code For VRet Goes Here */
}
void
Skeleton
::
visitCond
(
Cond
*
cond
)
void
TypeCheck
::
visitCond
(
Cond
*
cond
)
{
/* Code For Cond Goes Here */
...
...
@@ -230,7 +220,7 @@ void Skeleton::visitCond(Cond *cond)
}
void
Skeleton
::
visitCondElse
(
CondElse
*
cond_else
)
void
TypeCheck
::
visitCondElse
(
CondElse
*
cond_else
)
{
/* Code For CondElse Goes Here */
...
...
@@ -240,7 +230,7 @@ void Skeleton::visitCondElse(CondElse *cond_else)
}
void
Skeleton
::
visitWhile
(
While
*
while_
)
void
TypeCheck
::
visitWhile
(
While
*
while_
)
{
/* Code For While Goes Here */
...
...
@@ -249,7 +239,7 @@ void Skeleton::visitWhile(While *while_)
}
void
Skeleton
::
visitSExp
(
SExp
*
s_exp
)
void
TypeCheck
::
visitSExp
(
SExp
*
s_exp
)
{
/* Code For SExp Goes Here */
...
...
@@ -257,7 +247,7 @@ void Skeleton::visitSExp(SExp *s_exp)
}
void
Skeleton
::
visitForEach
(
ForEach
*
for_each
)
void
TypeCheck
::
visitForEach
(
ForEach
*
for_each
)
{
/* Code For ForEach Goes Here */
...
...
@@ -268,7 +258,7 @@ void Skeleton::visitForEach(ForEach *for_each)
}
void
Skeleton
::
visitNoInit
(
NoInit
*
no_init
)
void
TypeCheck
::
visitNoInit
(
NoInit
*
no_init
)
{
/* Code For NoInit Goes Here */
...
...
@@ -276,7 +266,7 @@ void Skeleton::visitNoInit(NoInit *no_init)
}
void
Skeleton
::
visitInit
(
Init
*
init
)
void
TypeCheck
::
visitInit
(
Init
*
init
)
{
/* Code For Init Goes Here */
...
...
@@ -285,35 +275,35 @@ void Skeleton::visitInit(Init *init)
}
void
Skeleton
::
visitInt
(
Int
*
int_
)
void
TypeCheck
::
visitInt
(
Int
*
int_
)
{
/* Code For Int Goes Here */
}
void
Skeleton
::
visitStr
(
Str
*
str
)
void
TypeCheck
::
visitStr
(
Str
*
str
)
{
/* Code For Str Goes Here */
}
void
Skeleton
::
visitBool
(
Bool
*
bool_
)
void
TypeCheck
::
visitBool
(
Bool
*
bool_
)
{
/* Code For Bool Goes Here */
}
void
Skeleton
::
visitVoid
(
Void
*
void_
)
void
TypeCheck
::
visitVoid
(
Void
*
void_
)
{
/* Code For Void Goes Here */
}
void
Skeleton
::
visitArray
(
Array
*
array
)
void
TypeCheck
::
visitArray
(
Array
*
array
)
{
/* Code For Array Goes Here */
...
...
@@ -321,7 +311,7 @@ void Skeleton::visitArray(Array *array)
}
void
Skeleton
::
visitClassT
(
ClassT
*
class_t
)
void
TypeCheck
::
visitClassT
(
ClassT
*
class_t
)
{
/* Code For ClassT Goes Here */
...
...
@@ -329,7 +319,7 @@ void Skeleton::visitClassT(ClassT *class_t)
}
void
Skeleton
::
visitFun
(
Fun
*
fun
)
void
TypeCheck
::
visitFun
(
Fun
*
fun
)
{
/* Code For Fun Goes Here */
...
...
@@ -338,7 +328,7 @@ void Skeleton::visitFun(Fun *fun)
}
void
Skeleton
::
visitEVar
(
EVar
*
e_var
)
void
TypeCheck
::
visitEVar
(
EVar
*
e_var
)
{
/* Code For EVar Goes Here */
...
...
@@ -346,7 +336,7 @@ void Skeleton::visitEVar(EVar *e_var)
}
void
Skeleton
::
visitELitInt
(
ELitInt
*
e_lit_int
)
void
TypeCheck
::
visitELitInt
(
ELitInt
*
e_lit_int
)
{
/* Code For ELitInt Goes Here */
...
...
@@ -354,21 +344,21 @@ void Skeleton::visitELitInt(ELitInt *e_lit_int)
}
void
Skeleton
::
visitELitTrue
(
ELitTrue
*
e_lit_true
)
void
TypeCheck
::
visitELitTrue
(
ELitTrue
*
e_lit_true
)
{
/* Code For ELitTrue Goes Here */
}
void
Skeleton
::
visitELitFalse
(
ELitFalse
*
e_lit_false
)
void
TypeCheck
::
visitELitFalse
(
ELitFalse
*
e_lit_false
)
{
/* Code For ELitFalse Goes Here */
}
void
Skeleton
::
visitEApp
(
EApp
*
e_app
)
void
TypeCheck
::
visitEApp
(
EApp
*
e_app
)
{
/* Code For EApp Goes Here */
...
...
@@ -377,7 +367,7 @@ void Skeleton::visitEApp(EApp *e_app)
}
void
Skeleton
::
visitEString
(
EString
*
e_string
)
void
TypeCheck
::
visitEString
(
EString
*
e_string
)
{
/* Code For EString Goes Here */
...
...
@@ -385,7 +375,7 @@ void Skeleton::visitEString(EString *e_string)
}
void
Skeleton
::
visitENewArray
(
ENewArray
*
e_new_array
)
void
TypeCheck
::
visitENewArray
(
ENewArray
*
e_new_array
)
{
/* Code For ENewArray Goes Here */
...
...
@@ -394,7 +384,7 @@ void Skeleton::visitENewArray(ENewArray *e_new_array)
}
void
Skeleton
::
visitENewClass
(
ENewClass
*
e_new_class
)
void
TypeCheck
::
visitENewClass
(
ENewClass
*
e_new_class
)
{
/* Code For ENewClass Goes Here */
...
...
@@ -402,7 +392,7 @@ void Skeleton::visitENewClass(ENewClass *e_new_class)
}
void
Skeleton
::
visitEClsMmbr
(
EClsMmbr
*
e_cls_mmbr
)
void
TypeCheck
::
visitEClsMmbr
(
EClsMmbr
*
e_cls_mmbr
)
{
/* Code For EClsMmbr Goes Here */
...
...
@@ -411,7 +401,7 @@ void Skeleton::visitEClsMmbr(EClsMmbr *e_cls_mmbr)
}
void
Skeleton
::
visitEClsMthd
(
EClsMthd
*
e_cls_mthd
)
void
TypeCheck
::
visitEClsMthd
(
EClsMthd
*
e_cls_mthd
)
{
/* Code For EClsMthd Goes Here */
...
...
@@ -421,14 +411,14 @@ void Skeleton::visitEClsMthd(EClsMthd *e_cls_mthd)
}
void
Skeleton
::
visitNull
(
Null
*
null
)
void
TypeCheck
::
visitNull
(
Null
*
null
)
{
/* Code For Null Goes Here */
}
void
Skeleton
::
visitEIndexAcc
(
EIndexAcc
*
e_index_acc
)
void
TypeCheck
::
visitEIndexAcc
(
EIndexAcc
*
e_index_acc
)
{
/* Code For EIndexAcc Goes Here */
...
...
@@ -437,7 +427,7 @@ void Skeleton::visitEIndexAcc(EIndexAcc *e_index_acc)
}
void
Skeleton
::
visitECast
(
ECast
*
e_cast
)
void
TypeCheck
::
visitECast
(
ECast
*
e_cast
)
{
/* Code For ECast Goes Here */
...
...
@@ -446,7 +436,7 @@ void Skeleton::visitECast(ECast *e_cast)
}
void
Skeleton
::
visitNeg
(
Neg
*
neg
)
void
TypeCheck
::
visitNeg
(
Neg
*
neg
)
{
/* Code For Neg Goes Here */
...
...
@@ -454,7 +444,7 @@ void Skeleton::visitNeg(Neg *neg)
}
void
Skeleton
::
visitNot
(
Not
*
not_
)
void
TypeCheck
::
visitNot
(
Not
*
not_
)
{
/* Code For Not Goes Here */
...
...
@@ -462,7 +452,7 @@ void Skeleton::visitNot(Not *not_)
}
void
Skeleton
::
visitEMul
(
EMul
*
e_mul
)
void
TypeCheck
::
visitEMul
(
EMul
*
e_mul
)
{
/* Code For EMul Goes Here */
...
...
@@ -472,7 +462,7 @@ void Skeleton::visitEMul(EMul *e_mul)
}
void
Skeleton
::
visitEAdd
(
EAdd
*
e_add
)
void
TypeCheck
::
visitEAdd
(
EAdd
*
e_add
)
{
/* Code For EAdd Goes Here */
...
...
@@ -482,7 +472,7 @@ void Skeleton::visitEAdd(EAdd *e_add)
}
void
Skeleton
::
visitERel
(
ERel
*
e_rel
)
void
TypeCheck
::
visitERel
(
ERel
*
e_rel
)
{
/* Code For ERel Goes Here */
...
...
@@ -492,7 +482,7 @@ void Skeleton::visitERel(ERel *e_rel)
}
void
Skeleton
::
visitEAnd
(
EAnd
*
e_and
)
void
TypeCheck
::
visitEAnd
(
EAnd
*
e_and
)
{
/* Code For EAnd Goes Here */
...
...
@@ -501,7 +491,7 @@ void Skeleton::visitEAnd(EAnd *e_and)
}
void
Skeleton
::
visitEOr
(
EOr
*
e_or
)
void
TypeCheck
::
visitEOr
(
EOr
*
e_or
)
{
/* Code For EOr Goes Here */
...
...
@@ -510,77 +500,77 @@ void Skeleton::visitEOr(EOr *e_or)
}
void
Skeleton
::
visitPlus
(
Plus
*
plus
)
void
TypeCheck
::
visitPlus
(
Plus
*
plus
)
{
/* Code For Plus Goes Here */
}
void
Skeleton
::
visitMinus
(
Minus
*
minus
)
void
TypeCheck
::
visitMinus
(
Minus
*
minus
)
{
/* Code For Minus Goes Here */
}
void
Skeleton
::
visitTimes
(
Times
*
times
)
void
TypeCheck
::
visitTimes
(
Times
*
times
)
{
/* Code For Times Goes Here */
}
void
Skeleton
::
visitDiv
(
Div
*
div
)
void
TypeCheck
::
visitDiv
(
Div
*
div
)
{
/* Code For Div Goes Here */
}
void
Skeleton
::
visitMod
(
Mod
*
mod
)
void
TypeCheck
::
visitMod
(
Mod
*
mod
)
{
/* Code For Mod Goes Here */
}
void
Skeleton
::
visitLTH
(
LTH
*
lth
)
void
TypeCheck
::
visitLTH
(
LTH
*
lth
)
{
/* Code For LTH Goes Here */
}
void
Skeleton
::
visitLE
(
LE
*
le
)
void
TypeCheck
::
visitLE
(
LE
*
le
)
{
/* Code For LE Goes Here */
}
void
Skeleton
::
visitGTH
(
GTH
*
gth
)
void
TypeCheck
::
visitGTH
(
GTH
*
gth
)
{
/* Code For GTH Goes Here */
}
void
Skeleton
::
visitGE
(
GE
*
ge
)
void
TypeCheck
::
visitGE
(
GE
*
ge
)
{
/* Code For GE Goes Here */
}
void
Skeleton
::
visitEQU
(
EQU
*
equ
)
void
TypeCheck
::
visitEQU
(
EQU
*
equ
)
{
/* Code For EQU Goes Here */
}
void
Skeleton
::
visitNE
(
NE
*
ne
)
void
TypeCheck
::
visitNE
(
NE
*
ne
)
{
/* Code For NE Goes Here */
...
...
@@ -588,7 +578,7 @@ void Skeleton::visitNE(NE *ne)
}
void
Skeleton
::
visitListTopDef
(
ListTopDef
*
list_top_def
)
void
TypeCheck
::
visitListTopDef
(
ListTopDef
*
list_top_def
)
{
for
(
ListTopDef
::
iterator
i
=
list_top_def
->
begin
()
;
i
!=
list_top_def
->
end
()
;
++
i
)
{
...
...
@@ -596,7 +586,7 @@ void Skeleton::visitListTopDef(ListTopDef *list_top_def)
}
}
void
Skeleton
::
visitListArg
(
ListArg
*
list_arg
)
void
TypeCheck
::
visitListArg
(
ListArg
*
list_arg
)
{
for
(
ListArg
::
iterator
i
=
list_arg
->
begin
()
;
i
!=
list_arg
->
end
()
;
++
i
)
{
...
...
@@ -604,7 +594,7 @@ void Skeleton::visitListArg(ListArg *list_arg)
}
}
void
Skeleton
::
visitListClassBlockDef
(
ListClassBlockDef
*
list_class_block_def
)
void
TypeCheck
::
visitListClassBlockDef
(
ListClassBlockDef
*
list_class_block_def
)
{
for
(
ListClassBlockDef
::
iterator
i
=
list_class_block_def
->
begin
()
;
i
!=
list_class_block_def
->
end
()
;
++
i
)
{
...
...
@@ -612,7 +602,7 @@ void Skeleton::visitListClassBlockDef(ListClassBlockDef *list_class_block_def)
}
}
void
Skeleton
::
visitListStmt
(
ListStmt
*
list_stmt
)
void
TypeCheck
::
visitListStmt
(
ListStmt
*
list_stmt
)
{
for
(
ListStmt
::
iterator
i
=
list_stmt
->
begin
()
;
i
!=
list_stmt
->
end
()
;
++
i
)
{
...
...
@@ -620,7 +610,7 @@ void Skeleton::visitListStmt(ListStmt *list_stmt)
}
}
void
Skeleton
::
visitListItem
(
ListItem
*
list_item
)
void
TypeCheck
::
visitListItem
(
ListItem
*
list_item
)
{
for
(
ListItem
::
iterator
i
=
list_item
->
begin
()
;
i
!=
list_item
->
end
()
;
++
i
)
{
...
...
@@ -628,7 +618,7 @@ void Skeleton::visitListItem(ListItem *list_item)
}
}
void
Skeleton
::
visitListType
(
ListType
*
list_type
)
void
TypeCheck
::
visitListType
(
ListType
*
list_type
)
{
for
(
ListType
::
iterator
i
=
list_type
->
begin
()
;
i
!=
list_type
->
end
()
;
++
i
)
{
...
...
@@ -636,7 +626,7 @@ void Skeleton::visitListType(ListType *list_type)
}
}
void
Skeleton
::
visitListExpr
(
ListExpr
*
list_expr
)
void
TypeCheck
::
visitListExpr
(
ListExpr
*
list_expr
)
{
for
(
ListExpr
::
iterator
i
=
list_expr
->
begin
()
;
i
!=
list_expr
->
end
()
;
++
i
)
{
...
...
@@ -645,30 +635,43 @@ void Skeleton::visitListExpr(ListExpr *list_expr)
}
void
Skeleton
::
visitInteger
(
Integer
x
)
void
TypeCheck
::
visitInteger
(
Integer
x
)
{
/* Code for Integer Goes Here */
}
void
Skeleton
::
visitChar
(
Char
x
)
void
TypeCheck
::
visitChar
(
Char
x
)
{
/* Code for Char Goes Here */
}
void
Skeleton
::
visitDouble
(
Double
x
)
void
TypeCheck
::
visitDouble
(
Double
x
)
{
/* Code for Double Goes Here */
}
void
Skeleton
::
visitString
(
String
x
)
void
TypeCheck
::
visitString
(
String
x
)
{
/* Code for String Goes Here */
}
void
Skeleton
::
visitIdent
(
Ident
x
)
void
TypeCheck
::
visitIdent
(
Ident
x
)
{
/* Code for Ident Goes Here */
}
void
TypeCheck
::
check
(
Visitable
*
v
)
{
if
(
state
!=
State
::
initialized
)
{
throw
std
::
runtime_error
(
"already initialized"
);
}
state
=
State
::
buildInfo
;
v
->
accept
(
this
);
state
=
State
::
checkType
;
v
->
accept
(
this
);
}
\ No newline at end of file
TypeCheck.h
View file @
0df5b04c
...
...
@@ -5,107 +5,113 @@
#include "Absyn.h"
class
Skeleton
:
public
Visitor
class
TypeCheck
:
public
Visitor
{
enum
State
{
initialized
,
buildInfo
,
checkType
}
state
;
public:
void
visitProgram
(
Program
*
p
);
void
visitTopDef
(
TopDef
*
p
);
void
visitFunDef
(
FunDef
*
p
);
void
visitArg
(
Arg
*
p
);
void
visitClassDef
(
ClassDef
*
p
);
void
visitClassBlock
(
ClassBlock
*
p
);
void
visitClassBlockDef
(
ClassBlockDef
*
p
);
void
visitBlock
(
Block
*
p
);
void
visitStmt
(
Stmt
*
p
);
void
visitItem
(
Item
*
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
);
void
visitClassMthd
(
ClassMthd
*
p
);
void
visitClassFld
(
ClassFld
*
p
);
void
visitBlk
(
Blk
*
p
);
void
visitEmpty
(
Empty
*
p
);
void
visitBStmt
(
BStmt
*
p
);
void
visitDecl
(
Decl
*
p
);
void
visitNoInit
(
NoInit
*
p
);
void
visitInit
(
Init
*
p
);
void
visitAss
(
Ass
*
p
);
void
visitTableAss
(
TableAss
*
p
);
void
visitTableIncr
(
TableIncr
*
p
);
void
visitTableDecr
(
TableDecr
*
p
);
void
visitIncr
(
Incr
*
p
);
void
visitDecr
(
Decr
*
p
);
void
visitRet
(
Ret
*
p
);
void
visitVRet
(
VRet
*
p
);
void
visitCond
(
Cond
*
p
);
void
visitCondElse
(
CondElse
*
p
);
void
visitWhile
(
While
*
p
);
void
visitSExp
(
SExp
*
p
);
void
visitForEach
(
ForEach
*
p
);
void
visitInt
(
Int
*
p
);
void
visitStr
(
Str
*
p
);
void
visitBool
(
Bool
*
p
);
void
visitVoid
(
Void
*
p
);
void
visitArray
(
Array
*
p
);
void
visitClassT
(
ClassT
*
p
);
void
visitFun
(
Fun
*
p
);
void
visitEVar
(
EVar
*
p
);
void
visitELitInt
(
ELitInt
*
p
);
void
visitELitTrue
(
ELitTrue
*
p
);
void
visitELitFalse
(
ELitFalse
*
p
);
void
visitEApp
(
EApp
*
p
);
void
visitEString
(
EString
*
p
);
void
visitENewArray
(
ENewArray
*
p
);
void
visitENewClass
(
ENewClass
*
p
);
void
visitEClsMmbr
(
EClsMmbr
*
p
);
void
visitEClsMthd
(
EClsMthd
*
p
);
void
visitNull
(
Null
*
p
);
void
visitEIndexAcc
(
EIndexAcc
*
p
);
void
visitECast
(
ECast
*
p
);
void
visitNeg
(
Neg
*
p
);
void
visitNot
(
Not
*
p
);
void
visitEMul
(
EMul
*
p
);
void
visitEAdd
(
EAdd
*
p
);
void
visitERel
(
ERel
*
p
);
void
visitEAnd
(
EAnd
*
p
);
void
visitEOr
(
EOr
*
p
);
void
visitPlus
(
Plus
*
p
);
void
visitMinus
(
Minus
*
p
);
void
visitTimes
(
Times
*
p
);
void
visitDiv
(
Div
*
p
);
void
visitMod
(
Mod
*
p
);
void
visitLTH
(
LTH
*
p
);
void
visitLE
(
LE
*
p
);
void
visitGTH
(
GTH
*
p
);
void
visitGE
(
GE
*
p
);
void
visitEQU
(
EQU
*
p
);
void
visitNE
(
NE
*
p
);
void
visitListTopDef
(
ListTopDef
*
p
);
void
visitListArg
(
ListArg
*
p
);
void
visitListClassBlockDef
(
ListClassBlockDef
*
p
);
void
visitListStmt
(
ListStmt
*
p
);
void
visitListItem
(
ListItem
*
p
);
void
visitListType
(
ListType
*
p
);
void
visitListExpr
(
ListExpr
*
p
);
void
visitPIdent
(
PIdent
*
p
);
void
visitInteger
(
Integer
x
);
void
visitChar
(
Char
x
);
void
visitDouble
(
Double
x
);
void
visitString
(
String
x
);
void
visitIdent
(
Ident
x
);
TypeCheck
()
:
state
(
initialized
)
{};
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
visitClassBlock
(
ClassBlock
*
p
);
void
visitClassBlockDef
(
ClassBlockDef
*
p
);
void
visitBlock
(
Block
*
p
);
void
visitStmt
(
Stmt
*
p
);
void
visitItem
(
Item
*
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
);
void
visitClassMthd
(
ClassMthd
*
p
);
void
visitClassFld
(
ClassFld
*
p
);
void
visitBlk
(
Blk
*
p
);
void
visitEmpty
(
Empty
*
p
);
void
visitBStmt
(
BStmt
*
p
);
void
visitDecl
(
Decl
*
p
);
void
visitNoInit
(
NoInit
*
p
);
void
visitInit
(
Init
*
p
);
void
visitAss
(
Ass
*
p
);
void
visitTableAss
(
TableAss
*
p
);
void
visitTableIncr
(
TableIncr
*
p
);
void
visitTableDecr
(
TableDecr
*
p
);
void
visitIncr
(
Incr
*
p
);
void
visitDecr
(
Decr
*
p
);
void
visitRet
(
Ret
*
p
);
void
visitVRet
(
VRet
*
p
);
void
visitCond
(
Cond
*
p
);
void
visitCondElse
(
CondElse
*
p
);
void
visitWhile
(
While
*
p
);
void
visitSExp
(
SExp
*
p
);
void
visitForEach
(
ForEach
*
p
);
void
visitInt
(
Int
*
p
);
void
visitStr
(
Str
*
p
);
void
visitBool
(
Bool
*
p
);
void
visitVoid
(
Void
*
p
);
void
visitArray
(
Array
*
p
);
void
visitClassT
(
ClassT
*
p
);
void
visitFun
(
Fun
*
p
);
void
visitEVar
(
EVar
*
p
);
void
visitELitInt
(
ELitInt
*
p
);
void
visitELitTrue
(
ELitTrue
*
p
);
void
visitELitFalse
(
ELitFalse
*
p
);
void
visitEApp
(
EApp
*
p
);
void
visitEString
(
EString
*
p
);
void
visitENewArray
(
ENewArray
*
p
);
void
visitENewClass
(
ENewClass
*
p
);
void
visitEClsMmbr
(
EClsMmbr
*
p
);
void
visitEClsMthd
(
EClsMthd
*
p
);
void
visitNull
(
Null
*
p
);
void
visitEIndexAcc
(
EIndexAcc
*
p
);
void
visitECast
(
ECast
*
p
);
void
visitNeg
(
Neg
*
p
);
void
visitNot
(
Not
*
p
);
void
visitEMul
(
EMul
*
p
);
void
visitEAdd
(
EAdd
*
p
);
void
visitERel
(
ERel
*
p
);
void
visitEAnd
(
EAnd
*
p
);
void
visitEOr
(
EOr
*
p
);
void
visitPlus
(
Plus
*
p
);
void
visitMinus
(
Minus
*
p
);
void
visitTimes
(
Times
*
p
);
void
visitDiv
(
Div
*
p
);
void
visitMod
(
Mod
*
p
);
void
visitLTH
(
LTH
*
p
);
void
visitLE
(
LE
*
p
);
void
visitGTH
(
GTH
*
p
);
void
visitGE
(
GE
*
p
);
void
visitEQU
(
EQU
*
p
);
void
visitNE
(
NE
*
p
);
void
visitListTopDef
(
ListTopDef
*
p
);
void
visitListArg
(
ListArg
*
p
);
void
visitListClassBlockDef
(
ListClassBlockDef
*
p
);
void
visitListStmt
(
ListStmt
*
p
);
void
visitListItem
(
ListItem
*
p
);
void
visitListType
(
ListType
*
p
);
void
visitListExpr
(
ListExpr
*
p
);
void
visitPIdent
(
PIdent
*
p
);
void
visitInteger
(
Integer
x
);
void
visitChar
(
Char
x
);
void
visitDouble
(
Double
x
);
void
visitString
(
String
x
);
void
visitIdent
(
Ident
x
);
};
#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