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
e9518825
Commit
e9518825
authored
Dec 09, 2020
by
zygzagZ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
InfoList to set
parent
2a6c6696
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
10 deletions
+54
-10
.gitignore
.gitignore
+2
-1
Absyn.h
Absyn.h
+7
-0
Info.h
Info.h
+2
-1
InfoList.h
InfoList.h
+25
-7
TypeCheck.cpp
TypeCheck.cpp
+16
-1
TypeCheck.h
TypeCheck.h
+2
-0
No files found.
.gitignore
View file @
e9518825
t.cpp
*.o
*.o
*.l
*.l
*.y
*.y
/lat/
/lat/
/latc
/latc
\ No newline at end of file
Absyn.h
View file @
e9518825
...
@@ -111,6 +111,11 @@ class ListType;
...
@@ -111,6 +111,11 @@ class ListType;
class
ListExpr
;
class
ListExpr
;
class
PIdent
;
class
PIdent
;
class
Binding
;
class
VarInfo
;
class
FunctionInfo
;
class
ClassInfo
;
/******************** Visitor Interfaces ********************/
/******************** Visitor Interfaces ********************/
class
Visitor
class
Visitor
...
@@ -283,6 +288,8 @@ public:
...
@@ -283,6 +288,8 @@ public:
class
Block
:
public
Visitable
class
Block
:
public
Visitable
{
{
public:
public:
std
::
weak_ptr
<
Binding
>
binding
;
std
::
weak_ptr
<
FunctionInfo
>
function
;
virtual
Block
*
clone
()
const
=
0
;
virtual
Block
*
clone
()
const
=
0
;
};
};
...
...
Info.h
View file @
e9518825
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
#include "Absyn.h"
#include "Absyn.h"
#include <memory>
#include <memory>
#include <
unordered_map
>
#include <
set
>
using
namespace
std
;
using
namespace
std
;
class
VarInfo
;
class
VarInfo
;
class
FunctionInfo
;
class
FunctionInfo
;
...
@@ -68,6 +68,7 @@ public:
...
@@ -68,6 +68,7 @@ public:
InfoList
<
ClassInfo
>
classes
;
InfoList
<
ClassInfo
>
classes
;
InfoList
<
FunctionInfo
>
functions
;
InfoList
<
FunctionInfo
>
functions
;
ClassInfoPtr
currentClass
;
ClassInfoPtr
currentClass
;
FunctionInfoPtr
currentFunction
;
Scope
();
Scope
();
};
};
...
...
InfoList.h
View file @
e9518825
#include "Info.h"
#include "Info.h"
template
<
typename
T
>
struct
Compare
{
using
is_transparent
=
void
;
bool
operator
()
(
const
T
&
a
,
const
T
&
b
)
const
{
return
a
->
name
<
b
->
name
;
}
bool
operator
()
(
const
T
&
a
,
const
string
&
b
)
const
{
return
a
->
name
<
b
;
}
bool
operator
()
(
const
string
&
a
,
const
T
&
b
)
const
{
return
a
<
b
->
name
;
}
};
template
<
typename
T
,
template
<
typename
T
,
typename
=
typename
std
::
enable_if
<
std
::
is_base_of
<
VarInfo
,
T
>::
value
>::
type
,
typename
=
typename
std
::
enable_if
<
std
::
is_base_of
<
VarInfo
,
T
>::
value
>::
type
,
typename
TPtr
=
shared_ptr
<
T
>>
typename
TPtr
=
shared_ptr
<
T
>>
class
InfoList
:
public
unordered_map
<
string
,
TPtr
>
{
class
InfoList
:
public
set
<
TPtr
,
Compare
<
TPtr
>
>
{
public:
public:
InfoList
<
T
>
*
parent
;
InfoList
<
T
>
*
parent
;
InfoList
(
InfoList
<
T
>
*
parent
=
nullptr
)
:
parent
(
parent
)
{};
InfoList
(
InfoList
<
T
>
*
parent
=
nullptr
)
:
parent
(
parent
)
{};
...
@@ -11,15 +30,14 @@ public:
...
@@ -11,15 +30,14 @@ public:
TPtr
ret
=
local
(
name
);
TPtr
ret
=
local
(
name
);
return
ret
?
ret
:
parent
?
(
*
parent
)[
name
]
:
nullptr
;
return
ret
?
ret
:
parent
?
(
*
parent
)[
name
]
:
nullptr
;
}
}
TPtr
local
(
string
name
)
const
{
TPtr
local
(
string
name
)
const
{
auto
p
=
(
*
this
).
find
(
name
);
const
auto
p
=
this
->
find
(
name
);
if
(
p
!=
this
->
end
())
{
return
p
!=
this
->
end
()
?
*
p
:
nullptr
;
return
p
->
second
;
}
return
nullptr
;
}
}
void
add
(
TPtr
obj
)
{
void
add
(
TPtr
obj
)
{
this
->
emplace
(
obj
->
name
,
obj
);
this
->
emplace
(
obj
);
}
}
InfoList
<
T
>&
operator
<<
(
TPtr
obj
)
{
InfoList
<
T
>&
operator
<<
(
TPtr
obj
)
{
...
...
TypeCheck.cpp
View file @
e9518825
...
@@ -644,4 +644,19 @@ void TypeCheck::check(Visitable *v)
...
@@ -644,4 +644,19 @@ void TypeCheck::check(Visitable *v)
}
}
state
=
State
::
checkType
;
state
=
State
::
checkType
;
v
->
accept
(
this
);
v
->
accept
(
this
);
}
\ No newline at end of file
for
(
auto
c
:
scope
.
classes
)
{
for
(
auto
f
:
c
->
functions
)
{
}
}
}
void
TypeCheck
::
checkFunction
(
FunctionInfoPtr
f
)
{
scope
.
currentFunction
=
f
;
f
->
block
->
accept
(
this
);
scope
.
currentFunction
=
nullptr
;
}
TypeCheck.h
View file @
e9518825
...
@@ -17,6 +17,8 @@ class TypeCheck : public Visitor
...
@@ -17,6 +17,8 @@ class TypeCheck : public Visitor
Scope
scope
;
Scope
scope
;
shared_ptr
<
Type
>
lastType
;
shared_ptr
<
Type
>
lastType
;
void
checkFunction
(
FunctionInfoPtr
f
);
public:
public:
TypeCheck
();
TypeCheck
();
void
check
(
Visitable
*
v
);
void
check
(
Visitable
*
v
);
...
...
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