19
19
#ifndef __CTranslationUnit__
20
20
#define __CTranslationUnit__
22
#include "Puma/CClassDatabase.h"
23
* Abstraction of a translation unit. */
25
#include "Puma/CSemDatabase.h"
23
26
#include "Puma/UnitManager.h"
24
27
#include "Puma/CProject.h"
25
28
#include "Puma/Builder.h"
38
/** \class CTranslationUnit CTranslationUnit.h Puma/CTranslationUnit.h
39
* Abstraction of a translation unit. A translation unit is a
40
* single implementation file that a compiler can translate
41
* to an object file. In particular it contains all the code
42
* from included header files.
44
* A translation unit is created by the parser (see Puma::Parser).
45
* It encapsulates the input file and the parse results (syntax
46
* trees, semantic database). When it is destroyed, it also destroys
47
* the parse results. */
34
48
class CTranslationUnit {
36
50
CTree *_syntax_tree;
37
51
PreTree *_cpp_tree;
38
CClassDatabase _class_db;
52
CSemDatabase _class_db;
39
53
UnitManager _local_units;
57
* \param u The token unit of the input file.
58
* \param p The project information object. */
42
59
CTranslationUnit (Unit &u, CProject &p) :
44
61
_syntax_tree ((CTree*)0),
45
62
_cpp_tree ((PreTree*)0),
47
64
_local_units (p.err ()) {}
65
/** Destructor. Destroys the C/C++ syntax tree and the
66
* preprocessor syntax tree. The semantic information
67
* objects are destroyed when the semantic database
68
* member object is destroyed. */
48
69
~CTranslationUnit ()
49
70
{ destroy (_syntax_tree); destroy (_cpp_tree); }
72
/** Set the C/C++ syntax tree.
73
* \param t The root node of the syntax tree. */
51
74
void tree (CTree *t) { _syntax_tree = t; }
75
/** Set the preprocessor syntax tree.
76
* \param t The root node of the syntax tree. */
52
77
void cpp_tree (PreTree *t) { _cpp_tree = t; }
79
/** Get the C/C++ syntax tree. */
54
80
CTree *tree () const { return _syntax_tree; }
81
/** Get the C preprocessor syntax tree. */
55
82
PreTree *cpp_tree () const { return _cpp_tree; }
84
/** Get the token unit of the input file. */
57
85
Unit *unit () const { return _unit; }
58
CClassDatabase &db () const { return (CClassDatabase&)_class_db; }
86
/** Get the semantic information database. */
87
CSemDatabase &db () const { return (CSemDatabase&)_class_db; }
88
/** Get the unit manager for local units (macro expansions etc). */
59
89
UnitManager &local_units () const { return (UnitManager&)_local_units; }