Skip to content

Commit 1fc4b90

Browse files
committed
more updates to support dataflow with structs
1 parent 67fc02a commit 1fc4b90

File tree

10 files changed

+61
-6
lines changed

10 files changed

+61
-6
lines changed

act/check.cc

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ static InstType *_act_get_var_type (Scope *s, ActId *id, ActId **retid,
132132
}
133133

134134
bool subchan_conv = false;
135+
ActId *orig_id = id;
135136

136137
if (id->Rest ()) {
137138
while (id->Rest()) {
@@ -140,6 +141,14 @@ static InstType *_act_get_var_type (Scope *s, ActId *id, ActId **retid,
140141
subchan_conv = true;
141142
}
142143
u = dynamic_cast<UserDef *>(it->BaseType ());
144+
if (!u && !subchan) {
145+
char *tmpbuf;
146+
MALLOC (tmpbuf, char, 10240);
147+
orig_id->sPrint (tmpbuf, 10240);
148+
typecheck_err ("Identifier `%s' has an illegal use of `.' in this context.", tmpbuf);
149+
FREE (tmpbuf);
150+
return NULL;
151+
}
143152
Assert (u, "This should have been caught during parsing!");
144153
id = id->Rest();
145154
it = u->Lookup (id);
@@ -257,6 +266,9 @@ int act_type_var_gen (Scope *s, ActId *id, InstType **xit, bool subchan)
257266
int is_strict;
258267

259268
it = _act_get_var_type (s, id, &id, &is_strict, subchan);
269+
if (!it) {
270+
return T_ERR;
271+
}
260272

261273
if (!it->arrayInfo() && id->arrayInfo()) {
262274
char *tmpbuf;
@@ -299,7 +311,8 @@ static InstType *_act_special_expr_insttype (Scope *s, Expr *e, int *islocal,
299311

300312
if (e->type == E_VAR) {
301313
/* special case #1 */
302-
it = act_actual_insttype (s, (ActId *)e->u.e.l, islocal);
314+
it = act_actual_insttype (s, (ActId *)e->u.e.l, islocal,
315+
only_chan == 0 ? false : true);
303316
return it;
304317
}
305318
else if (e->type == E_FUNCTION) {
@@ -349,7 +362,8 @@ static InstType *_act_special_expr_insttype (Scope *s, Expr *e, int *islocal,
349362
Assert (e->u.e.r->type == E_VAR, "What?");
350363
it = act_actual_insttype (u->CurScope(),
351364
(ActId *) e->u.e.r->u.e.l,
352-
islocal);
365+
islocal,
366+
only_chan == 0 ? false : true);
353367
return it;
354368
}
355369
else if (e->type == E_PSTRUCT) {
@@ -1274,6 +1288,7 @@ int act_type_expr (Scope *s, Expr *e, int *width, int only_chan)
12741288
ActId *tmp, *theid;
12751289
theid = (ActId *) e->u.e.l;
12761290
InstType *it = _act_get_var_type (s, theid, &tmp, NULL, true);
1291+
Assert (it, "This should not happen");
12771292

12781293
if (it->getDir() == Type::OUT) {
12791294
InstType *it2 = s->FullLookup (theid->getName());
@@ -1510,7 +1525,7 @@ int act_type_expr (Scope *s, Expr *e, int *width, int only_chan)
15101525
Returns the insttype for the ID.
15111526
If islocal != NULL, set to 1 if this is a local id within the scope
15121527
*/
1513-
InstType *act_actual_insttype (Scope *s, ActId *id, int *islocal)
1528+
InstType *act_actual_insttype (Scope *s, ActId *id, int *islocal, bool subchan)
15141529
{
15151530
InstType *it;
15161531

@@ -1572,6 +1587,10 @@ InstType *act_actual_insttype (Scope *s, ActId *id, int *islocal)
15721587
}
15731588
UserDef *u;
15741589
u = dynamic_cast<UserDef *>(it->BaseType ());
1590+
if (!u && subchan && TypeFactory::isChanType (it)) {
1591+
u = dynamic_cast<UserDef *>
1592+
(TypeFactory::getChanDataType (it)->BaseType());
1593+
}
15751594
Assert (u, "This should have been caught during parsing!");
15761595

15771596
/* HERE: APPLY MAP! */
@@ -2166,7 +2185,7 @@ int act_type_conn (Scope *s, ActId *id, AExpr *rae)
21662185
*/
21672186

21682187
int lhslocal;
2169-
InstType *lhs = act_actual_insttype (s, id, &lhslocal);
2188+
InstType *lhs = act_actual_insttype (s, id, &lhslocal, false);
21702189

21712190
if (!lhs) return T_ERR;
21722191

act/lang.m4

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,6 +3165,9 @@ w_chan_int_expr "->" [ "[" wpint_expr [ "," wpint_expr ] "]" ] expr_id
31653165
if (_act_id_is_true_false ($4)) {
31663166
$E("Dataflow RHS can't be true/false!");
31673167
}
3168+
if (_act_id_is_enum_const ($0->os, $0->curns, $4)) {
3169+
$E("Can't use an enumeration constant in this context!");
3170+
}
31683171
InstType *it;
31693172
if (act_type_var ($0->scope, $4, &it) != T_CHAN) {
31703173
$e("Identifier on the RHS of a dataflow expression must be of channel type");
@@ -3456,6 +3459,9 @@ expr_id_or_star[ActId *]: expr_id
34563459
if (_act_id_is_true_false ($1)) {
34573460
$E("Can't use true/false in this context!");
34583461
}
3462+
if (_act_id_is_enum_const ($0->os, $0->curns, $1)) {
3463+
$E("Can't use an enumeration constant in this context!");
3464+
}
34593465
return $1;
34603466
}}
34613467
| "*"

act/scope.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ void Scope::BindParam (ActId *id, AExpr *ae)
12551255
AExprstep *aes = NULL;
12561256

12571257
if (subrange_info) {
1258-
actual = act_actual_insttype (this, id, NULL);
1258+
actual = act_actual_insttype (this, id, NULL, false);
12591259
}
12601260
else {
12611261
actual = vx->t;

act/test/lang/139.act

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
deftype rec (int a, b) { }
2+
3+
defproc test()
4+
{
5+
chan(rec) a;
6+
chan(int) x;
7+
8+
dataflow {
9+
x -> a.a
10+
}
11+
}
12+
13+
test t;

act/test/lang/140.act

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
deftype rec (int a, b) { }
2+
3+
defproc test()
4+
{
5+
chan(rec) a;
6+
chan(int) x;
7+
8+
dataflow {
9+
a.a + a.b -> x
10+
}
11+
}
12+
13+
test t;

act/test/lang/runs/139.act.stderr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ERROR: File `139.act', line 9, col 6
2+
Identifier on the RHS of a dataflow expression must be of channel type
3+
ID: a.a

act/test/lang/runs/139.act.stdout

Whitespace-only changes.

act/test/lang/runs/140.act.stderr

Whitespace-only changes.

act/test/lang/runs/140.act.stdout

Whitespace-only changes.

act/typecheck.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,10 @@ InstType *act_expr_insttype (Scope *s, Expr *e, int *islocal, int only_chan);
237237
* @param id is the identifier
238238
* @param islocal is used to return 1 if the identifier is only
239239
* accessible within the local scope specified, 0 otherwise
240+
* @param subchan has the same meaning as act_type_var_gen
240241
* @return the type of the identifier (NULL if not found)
241242
*/
242-
InstType *act_actual_insttype (Scope *s, ActId *id, int *islocal);
243+
InstType *act_actual_insttype (Scope *s, ActId *id, int *islocal, bool subchan);
243244

244245
/**
245246
* Used to record the line, column, and file for error reporting

0 commit comments

Comments
 (0)