~ubuntu-branches/ubuntu/raring/verilator/raring-proposed

« back to all changes in this revision

Viewing changes to src/V3SymTable.h

  • Committer: Package Import Robot
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2013-01-13 11:25:29 UTC
  • mfrom: (1.2.16)
  • Revision ID: package-import@ubuntu.com-20130113112529-1jn3n8rbf8glvu2c
Tags: 3.844-1
* New upstream release.
* debian/copyright: Updated copyright years.
* Refresh patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
//
7
7
//*************************************************************************
8
8
//
9
 
// Copyright 2003-2012 by Wilson Snyder.  This program is free software; you can
 
9
// Copyright 2003-2013 by Wilson Snyder.  This program is free software; you can
10
10
// redistribute it and/or modify it under the terms of either the GNU
11
11
// Lesser General Public License Version 3 or the Perl Artistic License
12
12
// Version 2.0.
53
53
    VSymEnt*    m_parentp;      // Table that created this table, dot notation needed to resolve into it
54
54
    AstPackage* m_packagep;     // Package node is in (for V3LinkDot, unused here)
55
55
    string      m_symPrefix;    // String to prefix symbols with (for V3LinkDot, unused here)
 
56
    bool        m_exported;     // Allow importing
 
57
    bool        m_imported;     // Was imported
56
58
#ifdef VL_DEBUG
57
59
    static int debug() {
58
60
        static int level = -1;
86
88
    }
87
89
 
88
90
    // METHODS
 
91
    VSymEnt(VSymGraph* graphp, const VSymEnt* symp);  // Below
89
92
    VSymEnt(VSymGraph* graphp, AstNode* nodep);  // Below
90
93
    ~VSymEnt() {
91
94
        // Change links so we coredump if used
107
110
    AstNode* nodep() const { if (!this) return NULL; else return m_nodep; }  // null check so can call .findId(...)->nodep()
108
111
    string symPrefix() const { return m_symPrefix; }
109
112
    void symPrefix(const string& name) { m_symPrefix = name; }
 
113
    bool exported() const { return m_exported; }
 
114
    void exported(bool flag) { m_exported = flag; }
 
115
    bool imported() const { return m_imported; }
 
116
    void imported(bool flag) { m_imported = flag; }
110
117
    void insert(const string& name, VSymEnt* entp) {
111
118
        UINFO(9, "     SymInsert se"<<(void*)this<<" '"<<name<<"' se"<<(void*)entp<<"  "<<entp->nodep()<<endl);
112
119
        if (name != "" && m_idNameMap.find(name) != m_idNameMap.end()) {
145
152
        if (m_fallbackp) return m_fallbackp->findIdFallback(name);
146
153
        return NULL;
147
154
    }
148
 
    bool import(const VSymEnt* srcp, const string& id_or_star) {
 
155
private:
 
156
    bool importOneSymbol(VSymGraph* graphp, const string& name, const VSymEnt* srcp) {
 
157
        if (srcp->exported()
 
158
            && !findIdFlat(name)) {  // Don't insert over existing entry
 
159
            VSymEnt* symp = new VSymEnt(graphp, srcp);
 
160
            symp->exported(false);  // Can't reimport an import without an export
 
161
            symp->imported(true);
 
162
            reinsert(name, symp);
 
163
            return true;
 
164
        } else {
 
165
            return false;
 
166
        }
 
167
    }
 
168
public:
 
169
    bool import(VSymGraph* graphp, const VSymEnt* srcp, const string& id_or_star) {
149
170
        // Import tokens from source symbol table into this symbol table
150
171
        // Returns true if successful
151
172
        bool any = false;
152
173
        if (id_or_star != "*") {
153
174
            IdNameMap::const_iterator it = srcp->m_idNameMap.find(id_or_star);
154
175
            if (it != m_idNameMap.end()) {
155
 
                reinsert(it->first, it->second);
156
 
                any = true;
 
176
                importOneSymbol(graphp, it->first, it->second);
157
177
            }
 
178
            any = true;  // Legal, though perhaps lint questionable to import nothing
158
179
        } else {
159
180
            for (IdNameMap::const_iterator it=srcp->m_idNameMap.begin(); it!=srcp->m_idNameMap.end(); ++it) {
160
 
                reinsert(it->first, it->second);
161
 
                any = true;
 
181
                if (importOneSymbol(graphp, it->first, it->second)) any = true;
162
182
            }
163
183
        }
164
184
        return any;
236
256
 
237
257
//######################################################################
238
258
 
239
 
inline VSymEnt::VSymEnt(VSymGraph* m_graphp, AstNode* nodep)
 
259
inline VSymEnt::VSymEnt(VSymGraph* graphp, AstNode* nodep)
240
260
    : m_nodep(nodep) {
241
261
    // No argument to set fallbackp, as generally it's wrong to set it in the new call,
242
262
    // Instead it needs to be set on a "findOrNew()" return, as it may have been new'ed
244
264
    m_fallbackp = NULL;
245
265
    m_parentp = NULL;
246
266
    m_packagep = NULL;
247
 
    m_graphp->pushNewEnt(this);
 
267
    m_exported = true;
 
268
    m_imported = false;
 
269
    graphp->pushNewEnt(this);
 
270
}
 
271
 
 
272
inline VSymEnt::VSymEnt(VSymGraph* graphp, const VSymEnt* symp)
 
273
    : m_nodep(symp->nodep()) {
 
274
    m_fallbackp = symp->m_fallbackp;
 
275
    m_parentp  = symp->m_parentp;
 
276
    m_packagep = symp->m_packagep;
 
277
    m_exported = symp->m_exported;
 
278
    m_imported = symp->m_imported;
 
279
    graphp->pushNewEnt(this);
248
280
}
249
281
 
250
282
#endif // guard