[174] | 1 | #include <jenga/include/smoothie/LexicalScoping.h>
|
---|
| 2 | #include <jenga/include/smoothie/SmoothieException.h>
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 | CScope::CScope( int level, int addr, SCOPE_TYPE TypeOfStatement ){
|
---|
| 6 | this->level = level;
|
---|
| 7 | this->StartAddress = addr;
|
---|
| 8 | this->TypeOfStatement = TypeOfStatement;
|
---|
| 9 |
|
---|
| 10 | pBreakSchedule = (DWORD *)malloc( 1 );
|
---|
| 11 | nBreakSchedule = 0;
|
---|
| 12 | }
|
---|
| 13 | CScope::~CScope(){
|
---|
| 14 | free( pBreakSchedule );
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | int CScope::GetStartAddress(){
|
---|
| 18 | return StartAddress;
|
---|
| 19 | }
|
---|
| 20 | SCOPE_TYPE CScope::GetTypeOfStatement(){
|
---|
| 21 | return TypeOfStatement;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | CScope *CLexicalScopes::SearchScope( SCOPE_TYPE TypeOfStatement ){
|
---|
| 28 | for( int i = level; i>=0; i-- ){
|
---|
| 29 | if( ppScopes[i]->GetTypeOfStatement() == TypeOfStatement ){
|
---|
| 30 | return ppScopes[i];
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 | return NULL;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | CLexicalScopes::CLexicalScopes(){
|
---|
| 37 | ppScopes = (CScope **)malloc( 1 );
|
---|
| 38 | level=0;
|
---|
| 39 | }
|
---|
| 40 | CLexicalScopes::~CLexicalScopes(){
|
---|
| 41 | free( ppScopes );
|
---|
| 42 | }
|
---|
| 43 | void CLexicalScopes::Init(int addr){
|
---|
| 44 | // TODO: エラーチェック
|
---|
| 45 |
|
---|
| 46 | level = -1;
|
---|
| 47 | Start( addr, SCOPE_TYPE_BASE );
|
---|
| 48 | }
|
---|
| 49 | void CLexicalScopes::Start( int addr, SCOPE_TYPE TypeOfStatement ){
|
---|
| 50 | level++;
|
---|
| 51 | ppScopes = (CScope **)realloc( ppScopes, ( level + 1 ) * sizeof( CScope * ) );
|
---|
| 52 | ppScopes[level] = CreateScope( level, addr, TypeOfStatement );
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | int CLexicalScopes::GetNowLevel(){
|
---|
| 56 | return level;
|
---|
| 57 | }
|
---|
| 58 | void CLexicalScopes::SetNowLevel( int level ){
|
---|
| 59 | this->level = level;
|
---|
| 60 | }
|
---|
| 61 | int CLexicalScopes::GetStartAddress(){
|
---|
| 62 | return ppScopes[level]->GetStartAddress();
|
---|
| 63 | }
|
---|