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
0b617d1c
Commit
0b617d1c
authored
Jan 02, 2021
by
zygzagZ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup
parent
9cab866a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6 additions
and
167 deletions
+6
-167
Compiler.h
src/Compiler.h
+0
-161
Info.h
src/Info.h
+6
-2
TypeCheck.cpp
src/TypeCheck.cpp
+0
-3
TypeCheck.h
src/TypeCheck.h
+0
-1
No files found.
src/Compiler.h
View file @
0b617d1c
...
...
@@ -16,167 +16,6 @@ public:
private:
std
::
filesystem
::
path
file
;
std
::
stringstream
buf
;
// enum State {
// initialized,
// findClasses,
// findFunctions,
// visit
// } state;
// shared_ptr<Scope> scope;
// shared_ptr<Type> lastType, returnType;
// set<int> posv;
// vector<pair<ClassInfoPtr, ClassDef*>> classDefs;
// void checkFunction(FunctionInfoPtr f);
// void checkReturnStatement(shared_ptr<Type> type, Stmt *stmt);
// void checkFunctionRet();
// void addIOFunctions(Type &type);
// void setupEnv();
// template<typename T>
// shared_ptr<T> evalExpr(Visitable *expr) {
// if (!expr) throw runtime_error("No expr to eval");
// lastType = nullptr;
// try {
// expr->accept(this);
// } catch (const ParseError &err) {
// throw ParseError(err, expr);
// }
// shared_ptr<T> ret = dynamic_pointer_cast<T>(lastType);
// if (!ret) {
// T expect;
// throw InvalidTypeError(expect, {lastType}, expr);
// }
// lastType = nullptr;
// return ret;
// };
// shared_ptr<Type> evalExpr(Visitable *expr) {
// if (!expr) throw runtime_error("No expr to eval");
// try {
// expr->accept(this);
// } catch (const ParseError &err) {
// throw ParseError(err, expr);
// }
// if (!lastType) throw ParseError("No expression type", expr);
// auto ret = lastType;
// lastType = nullptr;
// return ret;
// };
// public:
// BindingPtr getParentBinding() const { return scope->currentClass ? static_pointer_cast<Binding>(scope->currentClass) : static_pointer_cast<Binding>(scope); }
// TypeCheck();
// void check(Visitable *v);
// protected:
// void visitClassDef(ClassDef *p);
// void visitProg(Prog *p);
// void visitFnDef(FnDef *p);
// void visitClDef(ClDef *p);
// void visitFuncDef(FuncDef *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 visitBStmt(BStmt *p);
// void visitDecl(Decl *p);
// void visitAss(Ass *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 visitEIndexAcc(EIndexAcc *p);
// void visitEClsMmbr(EClsMmbr *p);
// void visitEApp(EApp *p);
// void visitELitInt(ELitInt *p);
// void visitELitTrue(ELitTrue *p);
// void visitELitFalse(ELitFalse *p);
// void visitEString(EString *p);
// void visitENewArray(ENewArray *p);
// void visitENewClass(ENewClass *p);
// void visitNullCast(NullCast *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 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 visitString(String x);
// // 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 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) {
// p->type_->accept(this);
// if (dynamic_cast<Void*>(p->type_)) {
// throw ParseError("Void argument", p->type_);
// }
// };
// // exprs
// 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) {};
// // terminals
// void visitDouble(Double x) {};
// void visitIdent(Ident x) {};
};
#endif
src/Info.h
View file @
0b617d1c
...
...
@@ -8,16 +8,20 @@ using namespace std;
#include "InfoList.h"
class
VarInfo
{
class
VarInfo
:
public
std
::
enable_shared_from_this
<
VarInfo
>
{
public:
VarInfo
(
PIdent
*
ident
,
TypePtr
type
)
:
ident
(
ident
),
name
(
ident
->
string_
),
type
(
type
),
lineLocation
(
ident
->
lineno
)
{}
VarInfo
(
PIdent
*
ident
,
Type
*
type
=
nullptr
)
:
ident
(
ident
),
name
(
ident
->
string_
),
type
(
type
?
type
->
clone
()
:
nullptr
),
lineLocation
(
ident
->
lineno
)
{}
VarInfo
(
string
name
,
TypePtr
type
)
:
name
(
name
),
type
(
type
),
lineLocation
(
-
1
)
{}
VarInfo
(
string
name
,
TypePtr
type
)
:
ident
(
nullptr
),
name
(
name
),
type
(
type
),
lineLocation
(
-
1
)
{}
VarInfo
(
Ar
*
arg
)
:
VarInfo
(
arg
->
pident_
,
arg
->
type_
)
{}
virtual
~
VarInfo
()
{}
virtual
string
kind
()
const
{
return
"variable"
;
}
string
describe
()
const
{
return
kind
()
+
" "
+
name
+
" at line "
+
to_string
(
lineLocation
);
}
ClassInfoPtr
toClass
()
{
return
dynamic_pointer_cast
<
ClassInfo
>
(
shared_from_this
());
}
VarInfoPtr
toVar
()
{
return
dynamic_pointer_cast
<
VarInfo
>
(
shared_from_this
());
}
FunctionInfoPtr
toFunction
()
{
return
dynamic_pointer_cast
<
FunctionInfo
>
(
shared_from_this
());
}
PIdent
*
ident
;
string
name
;
TypePtr
type
;
...
...
src/TypeCheck.cpp
View file @
0b617d1c
#include "TypeCheck.h"
#include "ParseError.h"
#include <stdexcept>
#include <iostream>
#include "Printer.h"
#include <climits>
...
...
@@ -27,7 +26,6 @@ void TypeCheck::visitClassDef(ClassDef *t) {
void
TypeCheck
::
visitPIdent
(
PIdent
*
p_ident
)
{
// visitString(p_ident->string_);
auto
var
=
scope
->
currentBinding
->
variables
[
p_ident
];
p_ident
->
var
=
var
;
lastType
=
var
->
type
;
...
...
@@ -324,7 +322,6 @@ void TypeCheck::visitEClsMmbr(EClsMmbr *e_cls_mmbr)
}
VarInfoPtr
var
=
klass
->
variables
[
e_cls_mmbr
->
pident_
];
if
(
!
var
||
var
==
scope
->
variables
.
local
(
e_cls_mmbr
->
pident_
->
string_
))
{
cout
<<
"undef clsmmbr !var"
<<
endl
;
throw
UndefinedError
(
e_cls_mmbr
->
pident_
);
}
lastType
=
var
->
type
;
...
...
src/TypeCheck.h
View file @
0b617d1c
#ifndef TYPECHECK_HEADER
#define TYPECHECK_HEADER
/* You might want to change the above name. */
#include "Absyn.h"
#include "Info.h"
...
...
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