-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathentnode.cc
More file actions
130 lines (118 loc) · 4.42 KB
/
Copy pathentnode.cc
File metadata and controls
130 lines (118 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*****************************************************************************
* entnode.cc *
* *
* Description: The EntNode class is used to store a collection of entity *
* names. It stores them in alphabetical order. It is the key *
* component of the EntList classes, which are used to store *
* information on the instantiable complex entity types. This *
* file contains EntNode member function definitions. *
* *
* Created by: David Rosenfeld *
* Date: 9/18/96 *
*****************************************************************************/
#include "complexSupport.h"
#include <sc_memmgr.h>
EntNode::EntNode( char * namelist[] )
/*
* Given a list of entity names, creates a sorted linked list of EntNodes
* corresponding to the list. Final name must be "*" (otherwise we won't
* know where to stop). This function first builds the list, then sets
* this to the first element, and then deletes the first element. We do
* this to ensure that this points to the start of the list.
*/
{
int j = 1, comp = 0;
EntNode * prev, *prev2 = NULL, // prev2 - the one before prev
*newnode, *firstnode;
char * nm;
// Create a first EntNode:
firstnode = prev = new EntNode( namelist[0] );
// The following 3 lines are a ridiculous kludge to simplify testing.
// We make the assumption that ents whose name start with C or M have
// >1 supertype. (We make sure this is the case in the test file.)
// When this code becomes a part of the SCL, it'll be easy to get this
// info right from the entity structs anyway, so I'm not bothering
// writing anything more sophisticated.
if( *namelist[0] == 'c' || *namelist[0] == 'm' || *namelist[0] == 'j' ) {
firstnode->multSuprs( TRUE );
}
while( *namelist[j] != '*' ) {
nm = namelist[j];
while( prev != NULL && ( comp = strcmp( prev->name, nm ) ) < 0 ) {
prev2 = prev;
prev = prev->next;
}
// One exceptional case: If new name is same as prev, skip it:
if( comp != 0 ) {
// At this point, we know the new node belongs between prev2 and
// prev. prev or prev2 may = NULL if newnode belongs at the end of
// the list or before the beginning, respectively.
newnode = new EntNode( nm );
// Same kludge:
if( *nm == 'c' || *nm == 'm' || *nm == 'j' ) {
newnode->multSuprs( TRUE );
}
newnode->next = prev;
if( prev2 == NULL ) {
// This will be the case if the inner while was never entered.
// That happens when newnode belonged at the beginning of the
// list. If so, reset firstnode.
firstnode = newnode;
} else {
prev2->next = newnode;
}
}
// Reset for next namelist:
prev = firstnode;
prev2 = NULL;
j++;
}
// Finally, place the contents of firstnode in 'this', and delete first-
// node. This ensures that 'this' is first.
strcpy( name, firstnode->name );
next = firstnode->next;
multSupers = firstnode->multSupers;
firstnode->next = NULL;
// (Otherwise, deleting firstnode would delete entire list.)
delete firstnode;
}
void EntNode::markAll( MarkType stamp )
/*
* Marks/unmarks all the nodes in this's list (default is to mark).
*/
{
EntNode * node = this;
while( node != NULL ) {
node->mark = stamp;
node = node->next;
}
}
int EntNode::allMarked()
/*
* Returns TRUE if this and all nodes following it are marked.
*/
{
EntNode * node = this;
while( node != NULL ) {
if( node->mark == NOMARK ) {
return FALSE;
}
node = node->next;
}
return TRUE;
}
int EntNode::unmarkedCount()
/*
* Returns the number of unmarked nodes in this's list.
*/
{
int count = 0;
EntNode * node = this;
while( node != NULL ) {
if( node->mark == NOMARK ) {
count++;
}
node = node->next;
}
return count;
}