~ubuntu-branches/ubuntu/saucy/faust/saucy

« back to all changes in this revision

Viewing changes to compiler/evaluate/environment.cpp

  • Committer: Package Import Robot
  • Author(s): Mario Lang
  • Date: 2012-04-04 13:52:01 UTC
  • mfrom: (1.1.6) (3.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120404135201-hpsrk87x3hga94tc
Tags: 0.9.46-2
* Fix "ftbfs with GCC-4.7":
  - debian/patches/unistd: Include <unistd.h> where necessary.
    (Closes: #667163)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
}
30
30
 
31
31
 
 
32
 
 
33
/**
 
34
 * Push a new environment barrier on top of an existing environment so
 
35
 * that searchIdDef (used by the pattern matcher) will not look after
 
36
 * the barrier. This barrier will not any influence on regular environment
 
37
 * lookup.
 
38
 * @param lenv the old environment
 
39
 * @return the new environment
 
40
*/
 
41
Sym BARRIER = symbol ("BARRIER");
 
42
 
 
43
Tree pushEnvBarrier(Tree lenv)
 
44
{
 
45
    return tree(BARRIER, lenv);
 
46
}
 
47
 
 
48
 
 
49
/**
 
50
 * Test if the environment is a barrier (or nil) so
 
51
 * that searchIdDef will know where to stop when searching
 
52
 * an environment.
 
53
 * @param lenv the environment to test
 
54
 * @return true is barrier reached
 
55
*/
 
56
bool isEnvBarrier(Tree lenv)
 
57
{
 
58
    return isNil(lenv) || (lenv->node() == Node(BARRIER));
 
59
}
 
60
 
 
61
 
32
62
/**
33
63
 * Add a definition (as a property) to the current top level layer. Check
34
64
 * and warn for multiple definitions.
94
124
 
95
125
 
96
126
/**
97
 
 * Search the environment for the definition of a symbol
98
 
 * ID and return it.
 
127
 * Search the environment (until first barrier) for
 
128
 * the definition of a symbol ID and return it. Used by the
 
129
 * pattern matcher.
99
130
 * @param id the symbol ID to search
100
131
 * @param def where to store the definition if any
101
132
 * @param lenv the environment
104
135
bool searchIdDef(Tree id, Tree& def, Tree lenv)
105
136
{
106
137
    // search the environment until a definition is found
107
 
    // or nil (the empty environment) is reached
108
 
    while (!isNil(lenv) && !getProperty(lenv, id, def)) {
 
138
    // or a barrier (or nil) is reached
 
139
 
 
140
    while (!isEnvBarrier(lenv) && !getProperty(lenv, id, def)) {
109
141
        lenv = lenv->branch(0);
110
142
    }
111
 
    return !isNil(lenv);
 
143
    return !isEnvBarrier(lenv);
112
144
}
113
145
 
114
146
/**