1/* Copyright (C) 2021 Free Software Foundation, Inc.
2   Contributed by Oracle.
3
4   This file is part of GNU Binutils.
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 3, or (at your option)
9   any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software
18   Foundation, 51 Franklin Street - Fifth Floor, Boston,
19   MA 02110-1301, USA.  */
20
21#ifndef _SOURCEFILE_H
22#define _SOURCEFILE_H
23
24#include "Histable.h"
25#include "Map.h"
26
27template <typename Key_t, typename Value_t> class Map;
28
29#define SOURCE_FLAG_UNKNOWN 0x01
30
31class SourceFile : public HistableFile
32{
33public:
34
35  enum OpenStatus
36  {
37    OS_OK,
38    OS_NOTREAD,
39    OS_NOSRC,
40    OS_TIMESRC
41  };
42
43  SourceFile (const char *file_name);
44  virtual ~SourceFile ();
45  virtual void set_name (char *);
46  virtual char *get_name (NameFormat = NA);
47
48  bool readSource ();
49  Vector<Function *> *get_functions ();
50  DbeLine *find_dbeline (Function *func, int lineno);
51  char *getLine (int lineno);
52
53  int
54  getLineCount ()
55  {
56    return srcLines ? srcLines->size () : 0;
57  }
58
59  ino64_t
60  getInode ()
61  {
62    return srcInode;
63  }
64
65  time_t
66  getMTime ()
67  {
68    return srcMTime;
69  }
70
71  void
72  setMTime (time_t tm)
73  {
74    srcMTime = tm;
75  }
76
77  bool
78  isTmp ()
79  {
80    return isTmpFile;
81  }
82
83  void
84  setTmp (bool set)
85  {
86    isTmpFile = set;
87  }
88
89  Histable_type
90  get_type ()
91  {
92    return SOURCEFILE;
93  }
94
95  DbeLine *
96  find_dbeline (int lineno)
97  {
98    return find_dbeline (NULL, lineno);
99  }
100
101  unsigned int flags;
102
103private:
104  static int curId;         // object id
105  OpenStatus status;
106  ino64_t srcInode;         // Inode number of source file
107  time_t srcMTime;          // Creating time for source
108  Vector<char *> *srcLines; // array of pointers to lines in source
109  bool isTmpFile;           // Temporary src file to be deleted
110
111  Vector<DbeLine*> *lines;
112  Map<int, DbeLine*> *dbeLines;
113  Map<Function *, Function *> *functions;
114  bool read_stabs;
115};
116
117#endif
118