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
c7ae29b0
Commit
c7ae29b0
authored
Dec 11, 2020
by
zygzagZ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
POC
parent
5f84c1c3
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
136 additions
and
84 deletions
+136
-84
Absyn.cpp
Absyn.cpp
+14
-3
Absyn.h
Absyn.h
+4
-5
Info.cpp
Info.cpp
+6
-1
InfoList.h
InfoList.h
+1
-0
ParseError.cpp
ParseError.cpp
+1
-0
TypeCheck.cpp
TypeCheck.cpp
+108
-75
TypeCheck.h
TypeCheck.h
+2
-0
No files found.
Absyn.cpp
View file @
c7ae29b0
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include <string>
#include <string>
#include <vector>
#include <vector>
#include "Absyn.h"
#include "Absyn.h"
#include "Info.h"
/******************** PIdent ********************/
/******************** PIdent ********************/
PIdent
::
PIdent
(
String
p1
,
Integer
p2
)
PIdent
::
PIdent
(
String
p1
,
Integer
p2
)
...
@@ -1421,13 +1422,11 @@ Array *Array::clone() const
...
@@ -1421,13 +1422,11 @@ Array *Array::clone() const
ClassT
::
ClassT
(
PIdent
*
p1
)
ClassT
::
ClassT
(
PIdent
*
p1
)
{
{
pident_
=
p1
;
pident_
=
p1
;
}
}
ClassT
::
ClassT
(
const
ClassT
&
other
)
ClassT
::
ClassT
(
const
ClassT
&
other
)
{
{
pident_
=
other
.
pident_
->
clone
();
pident_
=
other
.
pident_
->
clone
();
}
}
ClassT
&
ClassT
::
operator
=
(
const
ClassT
&
other
)
ClassT
&
ClassT
::
operator
=
(
const
ClassT
&
other
)
...
@@ -1440,7 +1439,7 @@ ClassT &ClassT::operator=(const ClassT & other)
...
@@ -1440,7 +1439,7 @@ ClassT &ClassT::operator=(const ClassT & other)
void
ClassT
::
swap
(
ClassT
&
other
)
void
ClassT
::
swap
(
ClassT
&
other
)
{
{
std
::
swap
(
pident_
,
other
.
pident_
);
std
::
swap
(
pident_
,
other
.
pident_
);
std
::
swap
(
binding
,
other
.
binding
);
}
}
ClassT
::~
ClassT
()
ClassT
::~
ClassT
()
...
@@ -2895,6 +2894,18 @@ bool Fun::isEqual(Type const *other) const {
...
@@ -2895,6 +2894,18 @@ bool Fun::isEqual(Type const *other) const {
if
(
*
type_
!=
*
casted
->
type_
||
listtype_
->
size
()
!=
casted
->
listtype_
->
size
())
{
if
(
*
type_
!=
*
casted
->
type_
||
listtype_
->
size
()
!=
casted
->
listtype_
->
size
())
{
return
false
;
return
false
;
}
}
// TODO: czy sprawdzać argumenty?
}
return
false
;
}
bool
ClassT
::
isEqual
(
Type
const
*
other
)
const
{
if
(
const
ClassT
*
casted
=
dynamic_cast
<
const
ClassT
*>
(
other
))
{
BindingPtr
ba
=
binding
.
lock
(),
bb
=
casted
->
binding
.
lock
();
if
(
!
ba
||
!
bb
)
{
throw
std
::
runtime_error
(
"Binding nie znaleziony na typie klasy!"
);
}
return
ba
->
classes
[
pident_
]
==
bb
->
classes
[
pident_
];
}
}
return
false
;
return
false
;
}
}
Absyn.h
View file @
c7ae29b0
...
@@ -223,6 +223,8 @@ public:
...
@@ -223,6 +223,8 @@ public:
class
Type
:
public
Visitable
class
Type
:
public
Visitable
{
{
public:
public:
// Type() {};
// Type(const &Type other) : binding(other.binding) {};
std
::
weak_ptr
<
Binding
>
binding
;
std
::
weak_ptr
<
Binding
>
binding
;
virtual
Type
*
clone
()
const
=
0
;
virtual
Type
*
clone
()
const
=
0
;
virtual
std
::
string
printName
()
const
=
0
;
virtual
std
::
string
printName
()
const
=
0
;
...
@@ -741,11 +743,8 @@ public:
...
@@ -741,11 +743,8 @@ public:
virtual
void
accept
(
Visitor
*
v
);
virtual
void
accept
(
Visitor
*
v
);
virtual
ClassT
*
clone
()
const
;
virtual
ClassT
*
clone
()
const
;
void
swap
(
ClassT
&
);
void
swap
(
ClassT
&
);
std
::
string
printName
()
const
{
return
"class"
;
}
std
::
string
printName
()
const
{
return
"class "
+
pident_
->
string_
;
}
bool
isEqual
(
Type
const
*
other
)
const
{
bool
isEqual
(
Type
const
*
other
)
const
;
// TODO: implement ClassT comparison
return
false
;
}
};
};
class
Fun
:
public
Type
class
Fun
:
public
Type
...
...
Info.cpp
View file @
c7ae29b0
#include "Info.h"
#include "Info.h"
FunctionInfo
::
FunctionInfo
(
FuncDef
*
expr
,
ClassInfoPtr
klass
)
FunctionInfo
::
FunctionInfo
(
FuncDef
*
expr
,
ClassInfoPtr
klass
)
:
VarInfo
(
expr
->
pident_
,
expr
->
type_
),
block
(
expr
->
block_
),
klass
(
klass
)
:
VarInfo
(
expr
->
pident_
,
nullptr
),
block
(
expr
->
block_
),
klass
(
klass
)
{
{
// TODO: tutaj leakujemy listtype
ListType
*
funArgs
=
new
ListType
();
type
=
make_shared
<
Fun
>
(
expr
->
type_
,
funArgs
);
arguments
.
reserve
(
expr
->
listarg_
->
size
());
arguments
.
reserve
(
expr
->
listarg_
->
size
());
for
(
auto
arg
:
*
expr
->
listarg_
)
{
for
(
auto
arg
:
*
expr
->
listarg_
)
{
arguments
.
emplace_back
(
make_shared
<
VarInfo
>
((
Ar
*
)
arg
));
arguments
.
emplace_back
(
make_shared
<
VarInfo
>
((
Ar
*
)
arg
));
funArgs
->
emplace_back
(
arg
->
type_
);
}
}
}
}
...
...
InfoList.h
View file @
c7ae29b0
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include "Info.h"
#include "Info.h"
#include "ParseError.h"
#include "ParseError.h"
#include "TypeDefs.h"
#include "TypeDefs.h"
#include <iostream>
template
<
typename
T
>
template
<
typename
T
>
struct
Compare
struct
Compare
...
...
ParseError.cpp
View file @
c7ae29b0
...
@@ -27,6 +27,7 @@ ParseError::ParseError(string reason, Visitable *expr) : runtime_error("ParseErr
...
@@ -27,6 +27,7 @@ ParseError::ParseError(string reason, Visitable *expr) : runtime_error("ParseErr
if
(
expr
)
{
if
(
expr
)
{
ss
<<
" Expression: "
<<
PrintAbsyn
().
print
(
expr
);
ss
<<
" Expression: "
<<
PrintAbsyn
().
print
(
expr
);
}
}
msg
=
ss
.
str
();
}
}
RedefinedError
::
RedefinedError
(
PIdent
*
ident
,
VarInfoPtr
orig
)
{
RedefinedError
::
RedefinedError
(
PIdent
*
ident
,
VarInfoPtr
orig
)
{
...
...
TypeCheck.cpp
View file @
c7ae29b0
This diff is collapsed.
Click to expand it.
TypeCheck.h
View file @
c7ae29b0
...
@@ -21,7 +21,9 @@ class TypeCheck : public Visitor
...
@@ -21,7 +21,9 @@ class TypeCheck : public Visitor
void
checkFunction
(
FunctionInfoPtr
f
);
void
checkFunction
(
FunctionInfoPtr
f
);
void
checkReturnStatement
(
shared_ptr
<
Type
>
type
,
Stmt
*
stmt
);
void
checkReturnStatement
(
shared_ptr
<
Type
>
type
,
Stmt
*
stmt
);
void
checkFunctionRet
();
void
checkFunctionRet
();
void
setupEnv
();
public:
public:
BindingPtr
getParentBinding
()
const
{
return
scope
->
currentClass
?
static_pointer_cast
<
Binding
>
(
scope
->
currentClass
)
:
static_pointer_cast
<
Binding
>
(
scope
);
}
TypeCheck
();
TypeCheck
();
void
check
(
Visitable
*
v
);
void
check
(
Visitable
*
v
);
protected:
protected:
...
...
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