source: dev/trunk/jenga/src/smoothie/Variable.cpp@ 174

Last change on this file since 174 was 174, checked in by dai_9181, 17 years ago

LexicalScopeを移動

File size: 1.9 KB
Line 
1#include <jenga/include/smoothie/Smoothie.h>
2#include <jenga/include/smoothie/Class.h>
3
4bool Variable::IsEqualSymbol( const Symbol &symbol, bool isSupportStaticMember ) const
5{
6 if( GetName() == symbol.GetName()
7 && NamespaceScopes::IsSameArea( this->namespaceScopes, symbol.GetNamespaceScopes() ) )
8 {
9 return true;
10 }
11
12 if( isSupportStaticMember && symbol.GetNamespaceScopes().size() >= 1 )
13 {
14 // 静的メンバを考慮
15 NamespaceScopes namespaceScopes( symbol.GetNamespaceScopes() );
16 string name = namespaceScopes[namespaceScopes.size()-1] + "." + symbol.GetName();
17 namespaceScopes.pop_back();
18
19 return IsEqualSymbol( Symbol( namespaceScopes, name ), false );
20 }
21 return false;
22}
23
24
25bool Variables::DuplicateCheck( const Symbol &symbol ) const
26{
27 //レキシカルスコープを考慮して重複判定
28 for( int i=(int)this->size()-1; i>=0 ; i-- ){
29 Variable &var = *(*this)[i];
30 if( var.bLiving //現在のスコープで有効なもの
31 && var.ScopeLevel == Smoothie::Temp::pLexicalScopes->GetNowLevel() //現在のスコープと同一レベル
32 ){
33 if( var.IsEqualSymbol( symbol ) ){
34 return true;
35 }
36 }
37 }
38 return false;
39}
40
41const Variable *Variables::BackSearch( const Symbol &symbol ) const
42{
43 //レキシカルスコープを考慮してバックサーチ
44 for( int i=(int)this->size()-1; i>=0 ; i-- ){
45 Variable &var = *(*this)[i];
46 if( var.bLiving //現在のスコープで有効なもの
47 && var.ScopeLevel <= Smoothie::Temp::pLexicalScopes->GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)
48 ){
49 if( var.IsEqualSymbol( symbol ) ){
50 return &var;
51 }
52 }
53 }
54 return NULL;
55}
56
57const Variable *Variables::Find( const Symbol &symbol )const
58{
59 int max = (int)this->size();
60 for( int i=0; i<max; i++ ){
61 Variable *pVar = (*this)[i];
62 if( pVar->IsEqualSymbol( symbol ) ){
63 return pVar;
64 }
65 }
66 return NULL;
67}
Note: See TracBrowser for help on using the repository browser.