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

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

Binaryクラスを追加

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 Variable &var = *(*this)[i];
36 if( var.bLiving //現在のスコープで有効なもの
37 && var.GetScopeLevel() == compiler.codeGenerator.lexicalScopes.GetNowLevel() //現在のスコープと同一レベル
38 )
39 {
40 if( var.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 Variable &var = *(*this)[i];
53 if( var.bLiving //現在のスコープで有効なもの
54 && var.GetScopeLevel() <= compiler.codeGenerator.lexicalScopes.GetNowLevel() //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)
55 ){
56 if( var.IsEqualSymbol( symbol ) ){
57 return &var;
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 Variables::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( alignment ){
87 if( allInitSize % alignment ){
88 allInitSize += alignment - (allInitSize % alignment);
89 }
90 }
91
92 if( isResetOffsetAddress )
93 {
94 pVar->SetOffsetAddress( allInitSize );
95 }
96 allInitSize += pVar->GetMemorySize();
97 }
98 else{
99 //初期バッファがないとき
100
101 if( alignment ){
102 if( allSize % alignment ){
103 allSize += alignment - (allSize % alignment);
104 }
105 }
106
107 if( !isResetOffsetAddress )
108 {
109 Jenga::Throw( "[Variables::Add] 初期バッファがない変数に対してisResetOffsetAddressをfalseにできない" );
110 }
111
112 pVar->SetOffsetAddress( allSize | 0x80000000 );
113 allSize += pVar->GetMemorySize();
114 }
115
116 push_back( pVar );
117}
Note: See TracBrowser for help on using the repository browser.