source: dev/trunk/abdev/BasicCompiler_Common/src/Variable.cpp@ 327

Last change on this file since 327 was 288, checked in by dai_9181, 17 years ago
File size: 2.9 KB
Line 
1#include "stdafx.h"
2
3#include <jenga/include/smoothie/Smoothie.h>
4
5#include <Compiler.h>
6#include <Variable.h>
7
8/*
9TODO: 消す
10bool Variable::IsEqualSymbol( const Symbol &symbol, bool isSupportStaticMember ) const
11{
12 if( GetName() == symbol.GetName()
13 && compiler.GetNamespaceSupporter().IsSameAreaNamespace( this->GetNamespaceScopes(), symbol.GetNamespaceScopes() ) )
14 {
15 return true;
16 }
17
18 if( isSupportStaticMember && symbol.GetNamespaceScopes().size() >= 1 )
19 {
20 // 静的メンバを考慮
21 NamespaceScopes namespaceScopes( symbol.GetNamespaceScopes() );
22 string name = namespaceScopes[namespaceScopes.size()-1] + "." + symbol.GetName();
23 namespaceScopes.pop_back();
24
25 return IsEqualSymbol( Symbol( namespaceScopes, name ), false );
26 }
27 return false;
28}*/
29
30
31bool Variables::DuplicateCheck( const Symbol &symbol ) const
32{
33 //レキシカルスコープを考慮して重複判定
34 for( int i=(int)this->size()-1; i>=0 ; i-- ){
35 const Variable *pVar = (*this)[i];
36 if( pVar->bLiving //現在のスコープで有効なもの
37 && pVar->GetScopeLevel() == compiler.codeGenerator.lexicalScopes.GetNowLevel() //現在のスコープと同一レベル
38 )
39 {
40 if( pVar->IsEqualSymbol( symbol ) ){
41 return true;
42 }
43 }
44 }
45 return false;
46}
47
48const Variable *Variables::BackSearch( const Symbol &symbol ) const
49{
50 //レキシカルスコープを考慮してバックサーチ
51 for( int i=(int)this->size()-1; i>=0 ; i-- ){
52 const Variable *pVar = (*this)[i];
53 if( pVar->bLiving //現在のスコープで有効なもの
54 && pVar->GetScopeLevel() <= compiler.codeGenerator.lexicalScopes.GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)
55 ){
56 if( pVar->IsEqualSymbol( symbol ) ){
57 return pVar;
58 }
59 }
60 }
61 return NULL;
62}
63
64const Variable *Variables::Find( const Symbol &symbol )const
65{
66 int max = (int)this->size();
67 for( int i=0; i<max; i++ ){
68 Variable *pVar = (*this)[i];
69 if( pVar->IsEqualSymbol( symbol ) ){
70 return pVar;
71 }
72 }
73 return NULL;
74}
75
76void GlobalVars::Add( Variable *pVar, bool isResetOffsetAddress )
77{
78 int alignment = 0;
79 if( pVar->GetType().IsStruct() ){
80 alignment = pVar->GetType().GetClass().GetFixedAlignment();
81 }
82
83 if( pVar->HasInitData() ){
84 //初期バッファがあるとき
85
86 if( isResetOffsetAddress )
87 {
88 if( alignment ){
89 if( initAreaBuffer.GetSize() % alignment ){
90 initAreaBuffer.Resize( initAreaBuffer.GetSize() + ( alignment - (initAreaBuffer.GetSize() % alignment) ) );
91 }
92 }
93
94 pVar->SetOffsetAddress( initAreaBuffer.GetSize() );
95
96 initAreaBuffer.Resize( initAreaBuffer.GetSize() + pVar->GetMemorySize() );
97 }
98 }
99 else{
100 //初期バッファがないとき
101
102 if( alignment ){
103 if( allSize % alignment ){
104 allSize += alignment - (allSize % alignment);
105 }
106 }
107
108 pVar->SetOffsetAddress( allSize | 0x80000000 );
109 allSize += pVar->GetMemorySize();
110 }
111
112 push_back( pVar );
113}
Note: See TracBrowser for help on using the repository browser.