📄 notesscopes.txt
字号:
Notes re scopes
The current system of maintaining and using scope information is relatively
simplistic but appears to be reasonably effective. However, it has caused
some productions to be more complex than would otherwise be the case.
The current scope level is held in Dictionary.hpp as "int currentScope".
"currentScope" is initialised to zero by constructor for dictionary.cpp
when "class symbols" is constructed in CPPParser.init() in
CPPParser.cpp (generated from CPP_parser.g)
CPPParser.init() then sets "templateParameterScope" to zero with
templateParameterScope = symbols->getCurrentScopeIndex();
This top level scope is not currently being used but is kept in reserve
in case of some future need.
CPPParser.init() then sets "externalScope" to 1 with,
symbols->saveScope(); // Advance currentScope from 0 to 1
externalScope = symbols->getCurrentScopeIndex();
"externalScope" is used for all type names and template parameter names
and they remain in place from declaration to the end of the parse.
CPPParser.init() then declares "std" in external scope and the scope level
advanced to 2 for local scopes
CPPSymbol *a = new CPPSymbol("std", CPPSymbol::otTypedef);
symbols->define("std", a);
symbols->saveScope(); // Advance currentScope from 1 to 2 (and higher)
for all other symbols which are treated as locals
The value "currentScope" is obtained using "dictionary->getCurrentScopeIndex()"
Local scopes increase "currentScope" by 1 for each nested local scope.
Variables declared after types with identical names used to hide the typename but
now a search for an identical typename will find it.
At the end of each local scope "currentScope" is reduced by 1 and all variables
(not typenames) declared in the scope are removed from the dictionary.
At the end of a parse "exitExternalScope() in Support.cpp is entered via
"translation_unit" in CPP_parser.g which then reduces the remaining scope
level by 1 twice. If this reduces "current Scope" to 0 a good end message is
displayed, otherwise a warning message is displayed.
Version 3.1 November 2005
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -