source: dev/trunk/jenga/src/smoothie/LexicalScoping.cpp@ 186

Last change on this file since 186 was 186, checked in by dai_9181, 17 years ago
File size: 2.1 KB
Line 
1#include <jenga/include/smoothie/LexicalScoping.h>
2#include <jenga/include/smoothie/SmoothieException.h>
3#include <jenga/include/smoothie/Variable.h>
4#include <jenga/include/smoothie/Procedure.h>
5
6
7CScope::CScope( int level, int addr, SCOPE_TYPE TypeOfStatement ){
8 this->level = level;
9 this->StartAddress = addr;
10 this->TypeOfStatement = TypeOfStatement;
11
12 pBreakSchedule = (DWORD *)malloc( 1 );
13 nBreakSchedule = 0;
14}
15CScope::~CScope(){
16 free( pBreakSchedule );
17}
18
19int CScope::GetStartAddress(){
20 return StartAddress;
21}
22SCOPE_TYPE CScope::GetTypeOfStatement(){
23 return TypeOfStatement;
24}
25
26
27
28
29CScope *CLexicalScopes::SearchScope( SCOPE_TYPE TypeOfStatement ){
30 for( int i = level; i>=0; i-- ){
31 if( ppScopes[i]->GetTypeOfStatement() == TypeOfStatement ){
32 return ppScopes[i];
33 }
34 }
35 return NULL;
36}
37
38CLexicalScopes::CLexicalScopes(){
39 ppScopes = (CScope **)malloc( 1 );
40 level=0;
41}
42CLexicalScopes::~CLexicalScopes(){
43 free( ppScopes );
44}
45void CLexicalScopes::Init(int addr){
46 // TODO: エラーチェック
47
48 level = -1;
49 Start( addr, SCOPE_TYPE_BASE );
50}
51void CLexicalScopes::Start( int addr, SCOPE_TYPE TypeOfStatement ){
52 level++;
53 ppScopes = (CScope **)realloc( ppScopes, ( level + 1 ) * sizeof( CScope * ) );
54 ppScopes[level] = CreateScope( level, addr, TypeOfStatement );
55}
56void CLexicalScopes::End(){
57 if( level <= 0 ){
58 SmoothieException::Throw();
59 return;
60 }
61
62 //デストラクタを呼ぶ
63 CallDestructorsOfScopeEnd();
64
65 Variables &vars = UserProc::IsGlobalAreaCompiling()?
66 globalVars :
67 UserProc::CompilingUserProc().localVars;
68
69 //使用済みローカル変数の生存チェックを外す
70 BOOST_FOREACH( Variable *pVar, vars ){
71 if(pVar->bLiving&&pVar->ScopeLevel==level){
72 pVar->bLiving=0;
73 extern int obp;
74 pVar->ScopeEndAddress=obp;
75 }
76 }
77
78
79 //スコープ抜け出しスケジュール
80 ppScopes[level]->RunScheduleOfBreak();
81
82
83 //スコープレベルを下げる
84 delete ppScopes[level];
85 level--;
86}
87
88int CLexicalScopes::GetNowLevel(){
89 return level;
90}
91void CLexicalScopes::SetNowLevel( int level ){
92 this->level = level;
93}
94int CLexicalScopes::GetStartAddress(){
95 return ppScopes[level]->GetStartAddress();
96}
Note: See TracBrowser for help on using the repository browser.