1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef FILE_SOURCE_CODE_H
6#define FILE_SOURCE_CODE_H
7
8
9#include <Locker.h>
10
11#include <Array.h>
12
13#include "SourceCode.h"
14
15
16class LocatableFile;
17class SourceFile;
18
19
20class FileSourceCode : public SourceCode {
21public:
22								FileSourceCode(LocatableFile* file,
23									SourceFile* sourceFile,
24									SourceLanguage* language);
25	virtual						~FileSourceCode();
26
27			status_t			Init();
28			status_t			AddSourceLocation(
29									const SourceLocation& location);
30
31	virtual	bool				Lock();
32	virtual	void				Unlock();
33
34	virtual	SourceLanguage*		GetSourceLanguage() const;
35
36	virtual	int32				CountLines() const;
37	virtual	const char*			LineAt(int32 index) const;
38	virtual int32				LineLengthAt(int32 index) const;
39
40	virtual	bool				GetStatementLocationRange(
41									const SourceLocation& location,
42									SourceLocation& _start,
43									SourceLocation& _end) const;
44
45	virtual	LocatableFile*		GetSourceFile() const;
46
47private:
48			int32				_FindSourceLocationIndex(
49									const SourceLocation& location,
50									bool& _foundMatch) const;
51
52private:
53			BLocker				fLock;
54			LocatableFile*		fFile;
55			SourceFile*			fSourceFile;
56			SourceLanguage*		fLanguage;
57			Array<SourceLocation> fSourceLocations;
58};
59
60
61#endif	// FILE_BASED_SOURCE_CODE_H
62