source: dev/trunk/abdev/BasicCompiler_Common/BreakPoint.cpp@ 238

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

コード全体のリファクタリングを実施

File size: 4.1 KB
Line 
1#include "stdafx.h"
2
3#include <jenga/include/common/Environment.h>
4#include <jenga/include/smoothie/Source.h>
5
6#include "common.h"
7
8//////////////////////////
9// ブレークポイント
10//////////////////////////
11
12CDBBreakPoint *pobj_DBBreakPoint;
13
14CFileBreakPoint::CFileBreakPoint(char *lpszFileName,int iLineNum){
15 this->lpszFileName=(char *)HeapAlloc(hHeap,0,lstrlen(lpszFileName)+1);
16 lstrcpy(this->lpszFileName,lpszFileName);
17
18 piLine=(int *)HeapAlloc(hHeap,0,sizeof(int));
19 piLine[0]=iLineNum;
20 num=1;
21}
22CFileBreakPoint::~CFileBreakPoint(){
23 HeapDefaultFree(lpszFileName);
24 HeapDefaultFree(piLine);
25}
26void CFileBreakPoint::add(int iLineNum){
27 piLine=(int *)HeapReAlloc(hHeap,0,piLine,(num+1)*sizeof(int));
28 piLine[num]=iLineNum;
29 num++;
30}
31void CFileBreakPoint::remove(int iLineNum){
32 int i;
33 for(i=0;i<num;i++){
34 if(iLineNum==piLine[i]) break;
35 }
36 if(i==num) return;
37
38 num--;
39 for(;i<num;i++){
40 piLine[i]=piLine[i+1];
41 }
42}
43
44void CFileBreakPoint::update(char *OpBuffer){
45 extern INCLUDEFILEINFO IncludeFileInfo;
46
47 int FileNum;
48 for(FileNum=0;FileNum<IncludeFileInfo.FilesNum;FileNum++){
49 if(lstrcmpi(IncludeFileInfo.ppFileNames[FileNum],lpszFileName)==0) break;
50 }
51 if(FileNum==IncludeFileInfo.FilesNum) return;
52
53 int i;
54 for(i=0;;i++){
55 if(IncludeFileInfo.LineOfFile[i]==FileNum||
56 IncludeFileInfo.LineOfFile[i]==-1) break;
57 }
58 if(IncludeFileInfo.LineOfFile[i]==-1) return;
59
60 int FileBaseLine;
61 FileBaseLine=i;
62
63 int i2,nCount=0;
64 for(i2=0;;i2++){
65 if(IncludeFileInfo.LineOfFile[FileBaseLine+i2]==-1){
66 //ソースコードの終端行
67 break;
68 }
69
70 if(i2==piLine[nCount]){
71 extern int MaxLineInfoNum;
72 extern LINEINFO *pLineInfo;
73
74loop:
75 int tempCp;
76 tempCp=GetCpFromLine(FileBaseLine+i2);
77
78 int i3;
79 for(i3=0;i3<MaxLineInfoNum-1;i3++){
80 if(pLineInfo[i3].TopCp==tempCp) break;
81 }
82 if(i3==MaxLineInfoNum-1){
83 i2--;
84 goto loop;
85 }
86
87 OpBuffer[pLineInfo[i3].TopObp]=(char)0xCC;
88
89 nCount++;
90 if(nCount>=num) break;
91 }
92 }
93}
94
95
96CDBBreakPoint::CDBBreakPoint(){
97 ppItem=(CFileBreakPoint **)HeapAlloc(hHeap,0,1);
98 num=0;
99
100 char *buffer;
101 buffer=(char *)HeapAlloc(hHeap,0,65535);
102
103 HANDLE hFile=CreateFile(
104 ( Jenga::Common::Environment::GetAppDir() + "\\ab_breakpoint.tmp" ).c_str(),
105 GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
106 if(hFile!=INVALID_HANDLE_VALUE){
107 DWORD dwAccBytes;
108 ReadFile(hFile,buffer,MAX_PATH,&dwAccBytes,NULL);
109 CloseHandle(hFile);
110 buffer[dwAccBytes]=0;
111 }
112 else buffer[0]=0;
113
114 int i=0,i2;
115 char szFilePath[MAX_PATH];
116 while(buffer[i]){
117 //ファイルパス
118 i=GetOneParameter(buffer,i,szFilePath);
119 RemoveStringQuotes(szFilePath);
120
121 while(buffer[i]!='\n'&&buffer[i]!='\0'){
122 //行番号
123 char temporary[1024];
124 i=GetOneParameter(buffer,i,temporary);
125 i2=atoi(temporary);
126
127 insert(szFilePath,i2);
128 }
129
130 while(buffer[i]=='\n') i++;
131
132 if(buffer[i]=='\0') break;
133 }
134
135 HeapDefaultFree(buffer);
136}
137CDBBreakPoint::~CDBBreakPoint(){
138 int i;
139 for(i=0;i<num;i++){
140 delete ppItem[i];
141 }
142 HeapDefaultFree(ppItem);
143}
144void CDBBreakPoint::insert(char *lpszFileName,int iLineNum){
145 int i;
146 for(i=0;i<num;i++){
147 if(lstrcmpi(ppItem[i]->lpszFileName,lpszFileName)==0){
148 ppItem[i]->add(iLineNum);
149 return;
150 }
151 }
152
153 if(i==num){
154 ppItem=(CFileBreakPoint **)HeapReAlloc(hHeap,0,ppItem,(num+1)*sizeof(CFileBreakPoint *));
155 ppItem[num]=new CFileBreakPoint(lpszFileName,iLineNum);
156 num++;
157 }
158}
159void CDBBreakPoint::remove(char *lpszFileName,int iLineNum){
160 int i;
161 for(i=0;i<num;i++){
162 if(lstrcmpi(lpszFileName,ppItem[i]->lpszFileName)==0){
163 ppItem[i]->remove(iLineNum);
164 break;
165 }
166 }
167 if(i==num) return;
168
169 if(ppItem[i]->num==0){
170 delete ppItem[i];
171
172 num--;
173 for(;i<num;i++){
174 ppItem[i]=ppItem[i+1];
175 }
176 }
177}
178
179char *CDBBreakPoint::update(char *OpBuffer,int SizeOf_CodeSection){
180 char *buffer;
181 buffer=(char *)HeapAlloc(hHeap,0,SizeOf_CodeSection);
182 memcpy(buffer,OpBuffer,SizeOf_CodeSection);
183
184 int i;
185 for(i=0;i<num;i++){
186 ppItem[i]->update(buffer);
187 }
188
189 return buffer;
190}
Note: See TracBrowser for help on using the repository browser.