File: define.cc

package info (click to toggle)
oxref 2.02.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 692 kB
  • sloc: cpp: 1,282; makefile: 131; sh: 48
file content (50 lines) | stat: -rw-r--r-- 1,445 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
#include "store.ih"

void Store::define(std::string const &symbol, bool isFunction)
{
    auto iter = find_if(
                    d_xrefVector.begin(), d_xrefVector.end(),
                    [&](XrefData const &data)
                    {
                        return data.isDefined(symbol);
                    }
                );

    if (iter != d_xrefVector.end())
        return;                         // symbol already defined

    iter = find_if(
                d_xrefVector.begin(), d_xrefVector.end(),
                [&](XrefData const &xrefData)
                {
                    return xrefData.hasSymbol(symbol);
                }
            );

    size_t currentIdx;

    if (iter != d_xrefVector.end())
    {
        currentIdx = iter - d_xrefVector.begin();
        d_xrefVector[currentIdx].setLocation(d_sourceFile, d_objFile);
        d_defIdx.push_back(currentIdx);
    }
    else
    {

                            // new symbol: defined at index currentIdx, 
                            // any *UND* elements are for function currentIdx
                            // if not a function, then d_currentIdx isn't 
                            // used with *UND* elements
        d_defIdx.push_back(currentIdx = d_xrefVector.size());

        d_xrefVector.push_back(
                XrefData(d_sourceFile, d_objFile, isFunction, symbol)
        );
    }

    if (isFunction)
        d_currentIdx = currentIdx;
}