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	bool				GetStatementLocationRange(
37									const SourceLocation& location,
38									SourceLocation& _start,
39									SourceLocation& _end) const;
40
41	virtual	LocatableFile*		GetSourceFile() const;
42
43	// LineDataSource
44	virtual	int32				CountLines() const;
45	virtual	const char*			LineAt(int32 index) const;
46	virtual int32				LineLengthAt(int32 index) const;
47
48private:
49			int32				_FindSourceLocationIndex(
50									const SourceLocation& location,
51									bool& _foundMatch) const;
52
53private:
54			BLocker				fLock;
55			LocatableFile*		fFile;
56			SourceFile*			fSourceFile;
57			SourceLanguage*		fLanguage;
58			Array<SourceLocation> fSourceLocations;
59};
60
61
62#endif	// FILE_BASED_SOURCE_CODE_H
63