source: dev/BasicCompiler_Common/LexicalScoping.cpp@ 17

Last change on this file since 17 was 5, checked in by dai_9181, 18 years ago
File size: 1.3 KB
Line 
1#include "common.h"
2#ifdef _AMD64_
3#include "../BasicCompiler64/opcode.h"
4#else
5#include "../BasicCompiler32/opcode.h"
6#endif
7
8
9CLexicalScopes obj_LexScopes;
10
11CLexicalScopes::CLexicalScopes(){
12 level=0;
13}
14CLexicalScopes::~CLexicalScopes(){
15}
16void CLexicalScopes::Init(int addr){
17 level=0;
18 StartAddresses[level]=addr;
19}
20void CLexicalScopes::LevelUp(int addr){
21 level++;
22 StartAddresses[level]=addr;
23}
24void CLexicalScopes::LevelDown(void){
25 //デストラクタを呼ぶ
26 CallDestrouctorsOfScope();
27
28 //スコープレベルを下げる
29 level--;
30 if(level<0){
31 SetError(300,NULL,cp);
32 return;
33 }
34
35 extern BOOL bCompilingGlobal;
36 VARIABLE *pVar;
37 int num;
38 if(bCompilingGlobal){
39 //グローバル領域をコンパイルしているとき
40 extern VARIABLE *GlobalVar;
41 extern int MaxGlobalVarNum;
42 pVar=GlobalVar;
43 num=MaxGlobalVarNum;
44 }
45 else{
46 //ローカル領域をコンパイルしているとき
47 extern VARIABLE *LocalVar;
48 extern int MaxLocalVarNum;
49 pVar=LocalVar;
50 num=MaxLocalVarNum;
51 }
52
53 for(int i=0;i<num;i++){
54 if(pVar[i].bLiving&&pVar[i].ScopeLevel==level+1){
55 pVar[i].bLiving=0;
56 extern int obp;
57 pVar[i].ScopeEndAddress=obp;
58 }
59 }
60}
61
62int CLexicalScopes::GetNowLevel(void){
63 return level;
64}
65int CLexicalScopes::GetStartAddress(void){
66 return StartAddresses[level];
67}
Note: See TracBrowser for help on using the repository browser.