ACT Library
Loading...
Searching...
No Matches
namespaces.h
Go to the documentation of this file.
1/*************************************************************************
2 *
3 * This file is part of the ACT library
4 *
5 * Copyright (c) 2011, 2018-2019 Rajit Manohar
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 **************************************************************************
23 */
24#ifndef __NAMESPACES_H__
25#define __NAMESPACES_H__
26
27#include <common/hash.h>
28#include <common/list.h>
29#include <common/bitset.h>
30#include <common/array.h>
31
40class Act;
41class ActBody;
42class UserDef;
43class Type;
44class InstType;
45class ActId;
46class AExpr;
47class AExprstep;
48class ActNamespace;
50class ActTypeiter;
51class ValueIdx;
52class act_connection;
53class act_languages;
54struct act_chp;
55struct act_prs;
56struct act_spec;
57class Array;
58
59
77class Scope {
78 public:
79
84 Scope(Scope *parent, int is_expanded = 0);
86
90 Scope *Parent () { return up; }
91
99 InstType *Lookup (const char *s);
100
112 InstType *Lookup (ActId *id, int err = 1);
113
121 void refineBaseType (const char *s, InstType *u);
122
130 InstType *FullLookup (const char *s);
131
139 int isGlobal (const char *s);
140
152
164
171 ValueIdx *LookupVal (const char *s);
172
179 ValueIdx *FullLookupVal (const char *s);
180
190 int Add (const char *s, InstType *it);
191
197 void Del (const char *s);
198
202 void FlushExpand ();
203
208 void Merge (Scope *s);
209
214 void Print (FILE *fp);
215
220 void setUserDef (UserDef *_u) { u = _u; }
221
225 void mkFunction () { is_function = 1; }
226
230 int isFunction() { return is_function; }
231
236 UserDef *getUserDef () { return u; }
237
242 void setNamespace (ActNamespace *_ns) { ns = _ns; }
243
249
255 unsigned long AllocPInt(int count = 1);
256
264 void DeallocPInt(unsigned long idx, int count = 1);
265
271 void setPInt(unsigned long id, unsigned long val);
272
278 int issetPInt (unsigned long id);
279
284 unsigned long getPInt(unsigned long id);
285
286 unsigned long AllocPInts(int count = 1);
287 void DeallocPInts(unsigned long idx, int count = 1);
288 int issetPInts (unsigned long id);
289 long getPInts(unsigned long id);
290 void setPInts(unsigned long id, long val);
291
295 unsigned long AllocPReal(int count = 1);
296
300 void DeallocPReal(unsigned long idx, int count = 1);
301
305 int issetPReal (unsigned long id);
306
310 double getPReal(unsigned long id);
311
315 void setPReal(unsigned long id, double val);
316
320 unsigned long AllocPBool(int count = 1);
321
325 void DeallocPBool(unsigned long idx, int count = 1);
326
330 int issetPBool (unsigned long id);
331
335 int getPBool(unsigned long id);
336
340 void setPBool(unsigned long id, int val);
341
345 unsigned long AllocPType(int count = 1);
346
350 void DeallocPType(unsigned long idx, int count = 1);
351
355 int issetPType (unsigned long id);
356
360 InstType *getPType(unsigned long id);
361
365 void setPType(unsigned long id, InstType *val);
366
370 int isExpanded () { return expanded; }
371
377 void BindParam (const char *s, InstType *tt);
378
384 void BindParam (ActId *id, InstType *tt);
385
391 void BindParam (const char *s, AExpr *ae);
392
398 void BindParam (ActId *id, AExpr *ae);
399
404 void BindParam (ActId *id, AExprstep *aes, int idx = -1);
405
410 void playBody (ActBody *b); /* create instances in the scope based
411 on what is in the body */
412
417 const char *getName();
418
428 static void printConnections (FILE *fp, act_connection *cx, bool force = false);
429
430 private:
431 struct Hashtable *H; /* maps names to InstTypes, if
432 unexpanded; maps to ValueIdx if expanded. */
434
435 UserDef *u; /* if it is a user-defined type */
436 unsigned int expanded:1; /* if it is an expanded scope */
437 ActNamespace *ns; /* if it is a namespace scope */
438
439 int is_function; /* 1 if this is a function scope */
440
441 /* values that are per scope, rather than per instance */
442 A_DECL (unsigned long, vpint);
443 bitset_t *vpint_set;
444
445 A_DECL (long, vpints);
446 bitset_t *vpints_set;
447
448 A_DECL (double, vpreal);
449 bitset_t *vpreal_set;
450
451 A_DECL (InstType *, vptype);
452 bitset_t *vptype_set;
453
454 unsigned long vpbool_len;
455 bitset_t *vpbool;
456 bitset_t *vpbool_set;
457
458 friend class ActInstiter;
460};
461
462
470 public:
477 ActNamespace (const char *s);
478
485 ActNamespace (ActNamespace *ns, const char *s);
486
488
494 const char *getName () { return self_bucket->key; }
495
502 ActNamespace *findNS (const char *s);
503
504
511 UserDef *findType (const char *s);
512
518 InstType *findInstance (const char *s);
519
520
527 int findName (const char *s);
528
529
535 int isExported () { return exported; }
536
540 void MkExported () { exported = 1; }
541
545 void clrExported () { exported = 0; }
546
551 ActNamespace *Parent () { return parent; }
552
557 char *Name (bool add_colon = false);
558
563 void Unlink ();
564
571 void Link (ActNamespace *up, const char *name);
572
573
582 int CreateType (const char *s, UserDef *u);
583
592 int EditType (const char *s, UserDef *u);
593
599 Scope *CurScope () { return I; }
600
601
605 void Expand ();
606
610 void enum2Int ();
611
615 void Print (FILE *fp);
616
620 int isExpanded() { return I->isExpanded(); }
621
622
626 static void Init ();
627
631 static ActNamespace *Global () { return global; }
632
636 static class Act *Act() { return act; }
637
641 static void setAct (class Act *a);
642
647 void setBody (ActBody *b) { B = b; }
648
654
658 ActBody *getBody () { return B; }
659
664
669
674
680
684 list_t *getProcList();
685
689 list_t *getDataList();
690
694 list_t *getChanList();
695
696 private:
697
699
703 hash_bucket_t *self_bucket;
704
708 struct Hashtable *N;
709
716 struct Hashtable *T;
717
723
728
733
737 unsigned int exported;
738
743
747 static class Act *act;
748
752 static int creating_global;
753
760 void _init (ActNamespace *parent, const char *s);
761
762
771 void _subst_globals (list_t *subst, InstType *it, const char *s);
772
773 /* second phase */
774 void _subst_globals_addconn (list_t *subst, listitem_t *start,
775 InstType *it, const char *s);
776
777 friend class Act;
778 friend class ActNamespaceiter;
779 friend class ActTypeiter;
780};
781
782
783
798class ActOpen {
799 public:
802
813 int Open(ActNamespace *ns, const char *newname = NULL);
814
815
823 list_t *findAll (ActNamespace *cur, const char *s);
824 ActNamespace *find (ActNamespace *cur, const char *s);
825
834 ActNamespace *findType (ActNamespace *cur, const char *s);
835
836
837 private:
841 list_t *search_path;
842};
843
844#endif /* __NAMESPACES_H__ */
Array expressions.
Definition: act_array.h:529
Class for stepping through an array expression element-by-element.
Definition: act_array.h:631
This class is used to hold the contents of the body of any user-defined type or namespace....
Definition: body.h:52
The main Act class used to read in an ACT file and create basic data structures. All design informati...
Definition: act.h:334
This class is used to store Act identifiers that correspond to instances. Identifiers have an optiona...
Definition: act_id.h:56
This is an iterator that, when passed a Scope pointer, allows you to iterate through all instances wi...
Definition: iter.h:95
The ActNamespace class holds all the information about a namespace.
Definition: namespaces.h:469
unsigned int exported
Definition: namespaces.h:737
Scope * I
Definition: namespaces.h:722
ActBody * B
Definition: namespaces.h:727
ActNamespace * Parent()
Definition: namespaces.h:551
void _init(ActNamespace *parent, const char *s)
InstType * findInstance(const char *s)
void AppendBody(ActBody *b)
act_prs * getprs()
ActNamespace * findNS(const char *s)
char * Name(bool add_colon=false)
struct Hashtable * T
Definition: namespaces.h:716
static class Act * Act()
Definition: namespaces.h:636
void enum2Int()
static void Init()
static ActNamespace * global
Definition: namespaces.h:742
void setBody(ActBody *b)
Definition: namespaces.h:647
act_languages * lang
the sub-languages in the namespace
Definition: namespaces.h:698
struct Hashtable * N
Definition: namespaces.h:708
list_t * getSubNamespaces()
ActBody * getBody()
Definition: namespaces.h:658
int isExported()
Definition: namespaces.h:535
void _subst_globals_addconn(list_t *subst, listitem_t *start, InstType *it, const char *s)
list_t * getDataList()
ActNamespace(const char *s)
void _subst_globals(list_t *subst, InstType *it, const char *s)
int findName(const char *s)
static void setAct(class Act *a)
hash_bucket_t * self_bucket
Definition: namespaces.h:703
Scope * CurScope()
Definition: namespaces.h:599
ActNamespace(ActNamespace *ns, const char *s)
int isExpanded()
Definition: namespaces.h:620
act_spec * getspec()
static class Act * act
Definition: namespaces.h:747
list_t * getChanList()
int EditType(const char *s, UserDef *u)
const char * getName()
Definition: namespaces.h:494
static ActNamespace * Global()
Definition: namespaces.h:631
static int creating_global
Definition: namespaces.h:752
void Link(ActNamespace *up, const char *name)
void Print(FILE *fp)
void MkExported()
Definition: namespaces.h:540
UserDef * findType(const char *s)
ActNamespace * parent
Definition: namespaces.h:732
int CreateType(const char *s, UserDef *u)
void clrExported()
Definition: namespaces.h:545
list_t * getProcList()
act_languages * getlang()
Definition: namespaces.h:673
This is an iterator that, when passed an ActNamespace pointer, allows you to iterate through nested n...
Definition: iter.h:65
Functions to manage namespace search paths.
Definition: namespaces.h:798
list_t * search_path
Definition: namespaces.h:841
int Open(ActNamespace *ns, const char *newname=NULL)
ActNamespace * findType(ActNamespace *cur, const char *s)
list_t * findAll(ActNamespace *cur, const char *s)
ActNamespace * find(ActNamespace *cur, const char *s)
This is an iterator that, when passed an ActNamespace pointer, allows you to iterate through all user...
Definition: iter.h:153
This is an iterator that, when passed a Scope pointer, allows you to iterate through all the uinque p...
Definition: iter.h:186
Dense arrays, sparse arrays, and array dereferences.
Definition: act_array.h:65
An instance type.
Definition: inst.h:92
This is the data structure that holds all instances and their associated types within a scope....
Definition: namespaces.h:77
void DeallocPBool(unsigned long idx, int count=1)
void BindParam(ActId *id, AExpr *ae)
void DeallocPInts(unsigned long idx, int count=1)
unsigned long AllocPType(int count=1)
InstType * FullLookup(ActId *id, Array **aref)
void setPType(unsigned long id, InstType *val)
void setUserDef(UserDef *_u)
Definition: namespaces.h:220
A_DECL(unsigned long, vpint)
void setNamespace(ActNamespace *_ns)
Definition: namespaces.h:242
unsigned long getPInt(unsigned long id)
void Del(const char *s)
void BindParam(ActId *id, AExprstep *aes, int idx=-1)
void mkFunction()
Definition: namespaces.h:225
struct Hashtable * H
Definition: namespaces.h:431
void BindParam(const char *s, InstType *tt)
int getPBool(unsigned long id)
bitset_t * vptype_set
Definition: namespaces.h:452
A_DECL(double, vpreal)
bitset_t * vpbool_set
Definition: namespaces.h:456
void DeallocPInt(unsigned long idx, int count=1)
void setPInts(unsigned long id, long val)
bitset_t * vpreal_set
Definition: namespaces.h:449
ValueIdx * FullLookupVal(const char *s)
const char * getName()
int issetPReal(unsigned long id)
A_DECL(long, vpints)
ActNamespace * getNamespace()
Definition: namespaces.h:248
long getPInts(unsigned long id)
InstType * localLookup(ActId *id, Array **aref)
int is_function
Definition: namespaces.h:439
A_DECL(InstType *, vptype)
unsigned int expanded
Definition: namespaces.h:436
ActNamespace * ns
Definition: namespaces.h:437
int issetPBool(unsigned long id)
int issetPInts(unsigned long id)
bitset_t * vpint_set
Definition: namespaces.h:443
unsigned long AllocPInts(int count=1)
void setPInt(unsigned long id, unsigned long val)
Scope(Scope *parent, int is_expanded=0)
bitset_t * vpints_set
Definition: namespaces.h:446
unsigned long AllocPBool(int count=1)
void refineBaseType(const char *s, InstType *u)
unsigned long AllocPInt(int count=1)
void Merge(Scope *s)
ValueIdx * LookupVal(const char *s)
InstType * getPType(unsigned long id)
bitset_t * vpbool
Definition: namespaces.h:455
int issetPInt(unsigned long id)
InstType * Lookup(const char *s)
void DeallocPReal(unsigned long idx, int count=1)
void setPBool(unsigned long id, int val)
int isExpanded()
Definition: namespaces.h:370
Scope * Parent()
Definition: namespaces.h:90
UserDef * u
Definition: namespaces.h:435
unsigned long vpbool_len
Definition: namespaces.h:454
int Add(const char *s, InstType *it)
int isFunction()
Definition: namespaces.h:230
Scope * up
Definition: namespaces.h:433
void setPReal(unsigned long id, double val)
void DeallocPType(unsigned long idx, int count=1)
InstType * FullLookup(const char *s)
double getPReal(unsigned long id)
void playBody(ActBody *b)
int issetPType(unsigned long id)
InstType * Lookup(ActId *id, int err=1)
void BindParam(ActId *id, InstType *tt)
void FlushExpand()
UserDef * getUserDef()
Definition: namespaces.h:236
void BindParam(const char *s, AExpr *ae)
unsigned long AllocPReal(int count=1)
static void printConnections(FILE *fp, act_connection *cx, bool force=false)
void Print(FILE *fp)
int isGlobal(const char *s)
The abstract base class for all types in the system.
Definition: basetype.h:45
UserDef stores information that is common to all user-defined types. User-defined types are more comp...
Definition: types.h:310
This class is used to create an instance in a scope. The name comes from the fact that this is used t...
Definition: value.h:342
Connections.
Definition: value.h:113
This holds all the sub-langugae bodies in a namespace/user-defined type definition.
Definition: lang.h:641
Holds a CHP sub-language.
Definition: lang.h:367
Structure that holds all the prs { } blocks in a particular scope. This is a linked-list of blocks,...
Definition: lang.h:194
The specification sub-language.
Definition: lang.h:397