File: NormalizeAssocLists.hpp

package info (click to toggle)
fauhdlc 20180504-3.1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,064 kB
  • sloc: cpp: 23,188; ansic: 6,077; yacc: 3,764; lex: 763; makefile: 605; python: 412; xml: 403; sh: 61
file content (198 lines) | stat: -rw-r--r-- 5,850 bytes parent folder | download | duplicates (3)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* $Id$
 *
 * Normalize association lists.
 *
 * Copyright (C) 2008-2009 FAUmachine Team <info@faumachine.org>.
 * This program is free software. You can redistribute it and/or modify it
 * under the terms of the GNU General Public License, either version 2 of
 * the License, or (at your option) any later version. See COPYING.
 */

#ifndef __NORMALIZE_ASSOC_LISTS_HPP_INCLUDED
#define __NORMALIZE_ASSOC_LISTS_HPP_INCLUDED

#include "frontend/visitor/NullVisitor.hpp"
#include <list>
#include "frontend/ast/Location.hpp"
#include "frontend/misc/DeclarativeRegion.hpp"
#include "frontend/ast/ValDeclaration.hpp"

namespace ast {

//! normalize association lists.
/** This class will reorder association lists into the corresponding
 *  order of the defining port-/parameter-list.
 *  FIXME: what to do with composites? and conversion functions?
 *  FIXME: 
 */
class NormalizeAssocLists : public NullVisitor {
public:
	//! c'tor: initialize members.
	NormalizeAssocLists(
		) : 	pickedUpVal(NULL), 
			pos(-1), 
			positional(true),
			region(NULL),
			arch(NULL),
			hiddenCounter(0) {}

private:
	/** Visit a CompInstStat node.
	 *  @param node CompInstStat node that get's visited.
	 */
	virtual void visit(CompInstStat& node);

	/** Visit a AssociationElement node.
	 *  @param node AssociationElement node that get's visited.
	 */
	virtual void visit(AssociationElement& node);

	/** visit a SimpleName
         *  @param node node that get's visited.
         */
	virtual void visit(SimpleName &node);

	/** visit a TemporaryName
         *  @param node node that get's visited.
         */
	virtual void visit(TemporaryName &node);

	/** visit a SelectedName
         *  @param node node that get's visited.
         */
	virtual void visit(SelectedName &node);

	/** visit a AttributeName
         *  @param node node that get's visited.
         */
	virtual void visit(AttributeName &node);

	/** Visit a Architecture node.
	 *
	 *  @param node Architecture node that get's visited.
	 */
	virtual void visit(Architecture& node);

	/** Visit a Library node.
	 *  @param node Library node that get's visited.
	 */
	virtual void visit(Library &node);

	/** Visit a LibraryList node.
	 *  @param node LibraryList node that get's visited.
	 */
	virtual void visit(LibraryList &node);

	/** find val in formals and return the position. Also remove it from
	 *  from formals and report an error in case val is not in formals.
	 *  @param val ValDeclaration to find/delete in current formals list
	 *  @param loc error location for error reporting.
	 *  @return position number or -1 on error.
	 */
	int findAndRemove(const ValDeclaration *val, Location errLoc);

	/** add associations for unassociated ports of a CompInstStat.
	 *  Reports errors.
	 *  @param node instantiation statement.
	 */
	void addMissingPortAssocs(CompInstStat &node);

	/** add associations for unassociated generics of a CompInstStat.
	 *  Reports errors.
	 *  @param node instantiation statement.
	 */
	void addMissingGenericAssocs(CompInstStat &node);

	/** add associations for unassociated ports/generics of a 
	 *  CompInstStat.
	 *  Reports errors.
	 *  @param node instantiation statement.
	 *  @param unassociated list of unassociated elements.
	 *  @param kind element kind (for error reporting)
	 *  @param symbolType type of symbol when registering hidden symbols.
	 *  @param mapList list of map aspect (generic map, port map).
	 */
	template <typename T>
	void
	addMissingAssocs(
		CompInstStat &node,
		std::list<ValDeclaration*> &unassociated,
		const char *kind,
		enum symType symbolType,
		std::list<AssociationElement*> &mapList);

	/** add one missing association. To be called by addMissingPortAssocs.
	  * Reports errors.
	  * @param loc location for error reporting.
	  * @param formal declaration of the corresponding formal of an open
	  *        association.
	  * @param kind element kind (for reporting errors).
	  * @param symbolType type of symbol when registering hidden symbols.
	  * @param mapList list of map aspect (generic map, port map).
	  */
	template <typename T>
	void
	addMissingAssoc(
		const Location &loc,
		ValDeclaration &formal,
		const char *kind,
		enum symType symbolType,
		std::list<AssociationElement *> &mapList);

	template <typename T>
	static 
	T *createVal(
		std::string *name,
		enum ValDeclaration::Mode pMode,
		Expression *varInit,
		SubtypeIndication *si,
		Location loc);

public:
	/* FIXME used in GenCode as well, move somewhere where it makes 
	 *       more sense!
	 */
	/** make a simple name referring to ValDeclaration val which resides
	 *  in the declarative region lookupRegion.
	 *  @param val ValDeclaration that should be referred to.
	 *  @param lookupRegion region in which val is declared.
	 *  @param loc Location of the generated name.
	 *  @return SimpleName referring to val or NULL on error.
	 */
	static SimpleName *
	makeNameOfVal(
		const ValDeclaration *val,
		const DeclarativeRegion *lookupRegion,
		Location loc);
private:

	/** current list of formals (ports, generics). 
	  * Consumed ports/generics will be removed. */
	std::list<ValDeclaration*> formals;
	
	/** when traversing to a named association, the picked up 
	 *  declaration lands here */
	const ValDeclaration *pickedUpVal;

	/** current position of the first element of ports. */
	int pos;

	/** positional association used so far? */
	bool positional;

	/** region of the entity to lookup ports */
	const DeclarativeRegion *region;

	/** surrounding Architecture of a CompInstStat (or NULL) */
	const Architecture *arch;

	/** counter so that hidden signals have a unique name */
	int hiddenCounter;

	/** order predicate used for sorting port maps by position */
	static bool sortPosPred(AssociationElement *l, AssociationElement *r);
};

}; /* namespace ast */

#endif /* __NORMALIZE_ASSOC_LISTS_HPP_INCLUDED */